diff options
Diffstat (limited to 'services')
4 files changed, 297 insertions, 108 deletions
diff --git a/services/java/com/android/server/print/RemotePrintService.java b/services/java/com/android/server/print/RemotePrintService.java index ddff0ae..0d539b0 100644 --- a/services/java/com/android/server/print/RemotePrintService.java +++ b/services/java/com/android/server/print/RemotePrintService.java @@ -21,11 +21,9 @@ import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Binder; -import android.os.Build; import android.os.Handler; import android.os.IBinder; import android.os.IBinder.DeathRecipient; -import android.os.AsyncTask; import android.os.Looper; import android.os.Message; import android.os.ParcelFileDescriptor; @@ -39,8 +37,6 @@ import android.printservice.IPrintService; import android.printservice.IPrintServiceClient; import android.util.Slog; -import com.android.internal.R; - import java.io.PrintWriter; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -55,7 +51,7 @@ final class RemotePrintService implements DeathRecipient { private static final String LOG_TAG = "RemotePrintService"; - private static final boolean DEBUG = true && Build.IS_DEBUGGABLE; + private static final boolean DEBUG = false; private final Context mContext; @@ -65,7 +61,7 @@ final class RemotePrintService implements DeathRecipient { private final RemotePrintSpooler mSpooler; - private final UserState mUserState; + private final PrintServiceCallbacks mCallbacks; private final int mUserId; @@ -83,14 +79,24 @@ final class RemotePrintService implements DeathRecipient { private boolean mDestroyed; - private boolean mAllPrintJobsHandled; + private boolean mHasActivePrintJobs; private boolean mHasPrinterDiscoverySession; + private List<PrinterId> mDiscoveryPriorityList; + + private List<PrinterId> mTrackedPrinterList; + + public static interface PrintServiceCallbacks { + public void onPrintersAdded(List<PrinterInfo> printers); + public void onPrintersRemoved(List<PrinterId> printerIds); + public void onServiceDied(RemotePrintService service); + } + public RemotePrintService(Context context, ComponentName componentName, int userId, - RemotePrintSpooler spooler, UserState userState) { + RemotePrintSpooler spooler, PrintServiceCallbacks callbacks) { mContext = context; - mUserState = userState; + mCallbacks = callbacks; mComponentName = componentName; mIntent = new Intent().setComponent(mComponentName); mUserId = userId; @@ -99,15 +105,42 @@ final class RemotePrintService implements DeathRecipient { mPrintServiceClient = new RemotePrintServiceClient(this); } + public ComponentName getComponentName() { + return mComponentName; + } + public void destroy() { mHandler.sendEmptyMessage(MyHandler.MSG_DESTROY); } private void handleDestroy() { throwIfDestroyed(); + + // Stop tracking printers. + if (mTrackedPrinterList != null) { + final int trackedPrinterCount = mTrackedPrinterList.size(); + for (int i = 0; i < trackedPrinterCount; i++) { + PrinterId printerId = mTrackedPrinterList.get(i); + if (printerId.getServiceName().equals(mComponentName)) { + handleStopPrinterStateTracking(printerId); + } + } + } + + // Stop printer discovery. + if (mDiscoveryPriorityList != null) { + handleStopPrinterDiscovery(); + } + + // Destroy the discovery session. + if (mHasPrinterDiscoverySession) { + handleDestroyPrinterDiscoverySession(); + } + + // Unbind. ensureUnbound(); - mAllPrintJobsHandled = false; - mHasPrinterDiscoverySession = false; + + // Done mDestroyed = true; } @@ -121,21 +154,9 @@ final class RemotePrintService implements DeathRecipient { } private void handleBinderDied() { - mAllPrintJobsHandled = false; - mHasPrinterDiscoverySession = false; - mPendingCommands.clear(); - ensureUnbound(); - - // Makes sure all active print jobs are failed since the service - // just died. Do this off the main thread since we do to allow - // calls into the spooler on the main thread. - new AsyncTask<Void, Void, Void>() { - @Override - protected Void doInBackground(Void... params) { - failAllActivePrintJobs(); - return null; - } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null); + mPrintService.asBinder().unlinkToDeath(this, 0); + mPrintService = null; + mCallbacks.onServiceDied(this); } public void dump(PrintWriter pw, String prefix) { @@ -148,32 +169,17 @@ final class RemotePrintService implements DeathRecipient { pw.append(prefix).append(tab).append("bound=") .append(String.valueOf(isBound())).println(); pw.append(prefix).append(tab).append("hasDicoverySession=") - .append(String.valueOf(mHasPrinterDiscoverySession)); - } - - private void failAllActivePrintJobs() { - List<PrintJobInfo> printJobs = mSpooler.getPrintJobInfos(mComponentName, - PrintJobInfo.STATE_ANY_ACTIVE, PrintManager.APP_ID_ANY); - if (printJobs == null) { - return; - } - final long identity = Binder.clearCallingIdentity(); - try { - final int printJobCount = printJobs.size(); - for (int i = 0; i < printJobCount; i++) { - PrintJobInfo printJob = printJobs.get(i); - mSpooler.setPrintJobState(printJob.getId(), PrintJobInfo.STATE_FAILED, - mContext.getString(R.string.reason_unknown)); - } - } finally { - Binder.restoreCallingIdentity(identity); - } + .append(String.valueOf(mHasPrinterDiscoverySession)).println(); + pw.append(prefix).append(tab).append("isDiscoveringPrinters=") + .append(String.valueOf(mDiscoveryPriorityList != null)).println(); + pw.append(prefix).append(tab).append("trackedPrinters=") + .append((mTrackedPrinterList != null) ? mTrackedPrinterList.toString() : "null"); } private void handleOnAllPrintJobsHandled() { throwIfDestroyed(); - mAllPrintJobsHandled = true; + mHasActivePrintJobs = false; if (isBound()) { if (DEBUG) { @@ -217,7 +223,7 @@ final class RemotePrintService implements DeathRecipient { private void handleOnPrintJobQueued(final PrintJobInfo printJob) { throwIfDestroyed(); - mAllPrintJobsHandled = false; + mHasActivePrintJobs = true; if (!isBound()) { ensureBound(); @@ -296,7 +302,7 @@ final class RemotePrintService implements DeathRecipient { // If the service has no print jobs and no active discovery // session anymore we should disconnect from it. - if (mAllPrintJobsHandled) { + if (!mHasActivePrintJobs) { ensureUnbound(); } } @@ -326,6 +332,11 @@ final class RemotePrintService implements DeathRecipient { } catch (RemoteException re) { Slog.e(LOG_TAG, "Error starting printer dicovery.", re); } + // Take a note that we are doing discovery. + mDiscoveryPriorityList = new ArrayList<PrinterId>(); + if (priorityList != null) { + mDiscoveryPriorityList.addAll(priorityList); + } } } @@ -347,6 +358,8 @@ final class RemotePrintService implements DeathRecipient { if (DEBUG) { Slog.i(LOG_TAG, "[user: " + mUserId + "] stopPrinterDiscovery()"); } + // We are not doing discovery anymore. + mDiscoveryPriorityList = null; try { mPrintService.stopPrinterDiscovery(); } catch (RemoteException re) { @@ -406,6 +419,11 @@ final class RemotePrintService implements DeathRecipient { } catch (RemoteException re) { Slog.e(LOG_TAG, "Error requesting start printer tracking.", re); } + // Take a note we are tracking the printer. + if (mTrackedPrinterList == null) { + mTrackedPrinterList = new ArrayList<PrinterId>(); + } + mTrackedPrinterList.add(printerId); } } @@ -428,6 +446,11 @@ final class RemotePrintService implements DeathRecipient { if (DEBUG) { Slog.i(LOG_TAG, "[user: " + mUserId + "] stopPrinterTracking()"); } + // We are no longer tracking the printer. + mTrackedPrinterList.remove(printerId); + if (mTrackedPrinterList.isEmpty()) { + mTrackedPrinterList = null; + } try { mPrintService.stopPrinterStateTracking(printerId); } catch (RemoteException re) { @@ -461,6 +484,10 @@ final class RemotePrintService implements DeathRecipient { } mBinding = false; mPendingCommands.clear(); + mHasActivePrintJobs = false; + mHasPrinterDiscoverySession = false; + mDiscoveryPriorityList = null; + mTrackedPrinterList = null; if (isBound()) { try { mPrintService.setClient(null); @@ -500,11 +527,31 @@ final class RemotePrintService implements DeathRecipient { handleBinderDied(); return; } + // If there is a session, then the service died after creating + // a session. Hence, recreate the session. + if (mHasPrinterDiscoverySession) { + handleCreatePrinterDiscoverySession(); + } + // If there is a priority list, then the service died during + // discovery and is restarted. Hence, start discovery. + if (mDiscoveryPriorityList != null) { + handleStartPrinterDiscovery(mDiscoveryPriorityList); + } + // If there is a tracked printer list, then the service died + // during discovery and is restarted. Hence, start tracking. + if (mTrackedPrinterList != null) { + final int trackedPrinterCount = mTrackedPrinterList.size(); + for (int i = 0; i < trackedPrinterCount; i++) { + handleStartPrinterStateTracking(mTrackedPrinterList.get(i)); + } + } + // Finally, do all the pending work. final int pendingCommandCount = mPendingCommands.size(); for (int i = 0; i < pendingCommandCount; i++) { Runnable pendingCommand = mPendingCommands.get(i); pendingCommand.run(); } + mPendingCommands.clear(); } @Override @@ -677,7 +724,7 @@ final class RemotePrintService implements DeathRecipient { throwIfPrinterIdsForPrinterInfoTampered(service.mComponentName, printers); final long identity = Binder.clearCallingIdentity(); try { - service.mUserState.onPrintersAdded(printers); + service.mCallbacks.onPrintersAdded(printers); } finally { Binder.restoreCallingIdentity(identity); } @@ -691,7 +738,7 @@ final class RemotePrintService implements DeathRecipient { throwIfPrinterIdsTampered(service.mComponentName, printerIds); final long identity = Binder.clearCallingIdentity(); try { - service.mUserState.onPrintersRemoved(printerIds); + service.mCallbacks.onPrintersRemoved(printerIds); } finally { Binder.restoreCallingIdentity(identity); } diff --git a/services/java/com/android/server/print/RemotePrintSpooler.java b/services/java/com/android/server/print/RemotePrintSpooler.java index 28a6186..45469ac 100644 --- a/services/java/com/android/server/print/RemotePrintSpooler.java +++ b/services/java/com/android/server/print/RemotePrintSpooler.java @@ -21,7 +21,6 @@ import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Binder; -import android.os.Build; import android.os.IBinder; import android.os.ParcelFileDescriptor; import android.os.RemoteException; @@ -57,7 +56,7 @@ final class RemotePrintSpooler { private static final String LOG_TAG = "RemotePrintSpooler"; - private static final boolean DEBUG = true && Build.IS_DEBUGGABLE; + private static final boolean DEBUG = false; private static final long BIND_SPOOLER_SERVICE_TIMEOUT = 10000; diff --git a/services/java/com/android/server/print/UserState.java b/services/java/com/android/server/print/UserState.java index 5392975..70fe370 100644 --- a/services/java/com/android/server/print/UserState.java +++ b/services/java/com/android/server/print/UserState.java @@ -23,7 +23,8 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; -import android.os.Build; +import android.os.AsyncTask; +import android.os.Binder; import android.os.Handler; import android.os.IBinder; import android.os.Looper; @@ -32,6 +33,7 @@ import android.os.RemoteCallbackList; import android.os.RemoteException; import android.print.IPrinterDiscoveryObserver; import android.print.PrintJobInfo; +import android.print.PrintManager; import android.print.PrinterId; import android.print.PrinterInfo; import android.printservice.PrintServiceInfo; @@ -43,7 +45,9 @@ import android.util.ArraySet; import android.util.Log; import android.util.Slog; +import com.android.internal.R; import com.android.internal.os.SomeArgs; +import com.android.server.print.RemotePrintService.PrintServiceCallbacks; import com.android.server.print.RemotePrintSpooler.PrintSpoolerCallbacks; import java.io.FileDescriptor; @@ -58,11 +62,11 @@ import java.util.Set; /** * Represents the print state for a user. */ -final class UserState implements PrintSpoolerCallbacks { +final class UserState implements PrintSpoolerCallbacks, PrintServiceCallbacks { private static final String LOG_TAG = "UserState"; - private static final boolean DEBUG = true && Build.IS_DEBUGGABLE; + private static final boolean DEBUG = false; private static final int MAX_ITEMS_PER_CALLBACK = 50; @@ -246,6 +250,7 @@ final class UserState implements PrintSpoolerCallbacks { } } + @Override public void onPrintersAdded(List<PrinterInfo> printers) { synchronized (mLock) { throwIfDestroyedLocked(); @@ -257,11 +262,11 @@ final class UserState implements PrintSpoolerCallbacks { if (mPrinterDiscoverySession == null) { return; } - // Request an updated. mPrinterDiscoverySession.onPrintersAddedLocked(printers); } } + @Override public void onPrintersRemoved(List<PrinterId> printerIds) { synchronized (mLock) { throwIfDestroyedLocked(); @@ -273,11 +278,28 @@ final class UserState implements PrintSpoolerCallbacks { if (mPrinterDiscoverySession == null) { return; } - // Request an updated. mPrinterDiscoverySession.onPrintersRemovedLocked(printerIds); } } + @Override + public void onServiceDied(RemotePrintService service) { + synchronized (mLock) { + throwIfDestroyedLocked(); + // No services - nothing to do. + if (mActiveServices.isEmpty()) { + return; + } + // Fail all print jobs. + failActivePrintJobsForService(service.getComponentName()); + // No session - nothing to do. + if (mPrinterDiscoverySession == null) { + return; + } + mPrinterDiscoverySession.onServiceDiedLocked(service); + } + } + public void updateIfNeededLocked() { throwIfDestroyedLocked(); if (readConfigurationLocked()) { @@ -516,23 +538,72 @@ final class UserState implements PrintSpoolerCallbacks { if (!mActiveServices.containsKey(serviceName)) { RemotePrintService service = new RemotePrintService( mContext, serviceName, mUserId, mSpooler, this); - mActiveServices.put(serviceName, service); - if (mPrinterDiscoverySession != null) { - mPrinterDiscoverySession.onServiceAddedLocked(service); - } + addServiceLocked(service); } } else { RemotePrintService service = mActiveServices.remove(serviceName); if (service != null) { - service.destroy(); - if (mPrinterDiscoverySession != null) { - mPrinterDiscoverySession.onServiceRemovedLocked(serviceName); - } + removeServiceLocked(service); } } } } + private void addServiceLocked(RemotePrintService service) { + mActiveServices.put(service.getComponentName(), service); + if (mPrinterDiscoverySession != null) { + mPrinterDiscoverySession.onServiceAddedLocked(service); + } + } + + private void removeServiceLocked(RemotePrintService service) { + // Fail all print jobs. + failActivePrintJobsForService(service.getComponentName()); + // If discovery is in progress, tear down the service. + if (mPrinterDiscoverySession != null) { + mPrinterDiscoverySession.onServiceRemovedLocked(service); + } else { + // Otherwise, just destroy it. + service.destroy(); + } + } + + private void failActivePrintJobsForService(final ComponentName serviceName) { + // Makes sure all active print jobs are failed since the service + // just died. Do this off the main thread since we do to allow + // calls into the spooler on the main thread. + if (Looper.getMainLooper().isCurrentThread()) { + new AsyncTask<Void, Void, Void>() { + @Override + protected Void doInBackground(Void... params) { + failActivePrintJobsForServiceInternal(serviceName); + return null; + } + }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null); + } else { + failActivePrintJobsForServiceInternal(serviceName); + } + } + + private void failActivePrintJobsForServiceInternal(ComponentName serviceName) { + List<PrintJobInfo> printJobs = mSpooler.getPrintJobInfos(serviceName, + PrintJobInfo.STATE_ANY_ACTIVE, PrintManager.APP_ID_ANY); + if (printJobs == null) { + return; + } + final long identity = Binder.clearCallingIdentity(); + try { + final int printJobCount = printJobs.size(); + for (int i = 0; i < printJobCount; i++) { + PrintJobInfo printJob = printJobs.get(i); + mSpooler.setPrintJobState(printJob.getId(), PrintJobInfo.STATE_FAILED, + mContext.getString(R.string.reason_unknown)); + } + } finally { + Binder.restoreCallingIdentity(identity); + } + } + private void throwIfDestroyedLocked() { if (mDestroyed) { throw new IllegalStateException("Cannot interact with a destroyed instance."); @@ -603,17 +674,18 @@ final class UserState implements PrintSpoolerCallbacks { return; } + final boolean discoveryStarted = !mStartedPrinterDiscoveryTokens.isEmpty(); + + // Remember we got a start request to match with an end. + mStartedPrinterDiscoveryTokens.add(observer.asBinder()); + // If printer discovery is ongoing and the start request has a list // of printer to be checked, then we just request validating them. - if (!mStartedPrinterDiscoveryTokens.isEmpty() - && priorityList != null && !priorityList.isEmpty()) { + if (discoveryStarted && priorityList != null && !priorityList.isEmpty()) { validatePrinters(priorityList); return; } - // Remember we got a start request to match with an end. - mStartedPrinterDiscoveryTokens.add(observer.asBinder()); - // The service are already performing discovery - nothing to do. if (mStartedPrinterDiscoveryTokens.size() > 1) { return; @@ -822,32 +894,20 @@ final class UserState implements PrintSpoolerCallbacks { } } - public void onServiceRemovedLocked(ComponentName serviceName) { + public void onServiceRemovedLocked(RemotePrintService service) { if (mIsDestroyed) { Log.w(LOG_TAG, "Not updating removed service - session destroyed"); return; } - // No printers - nothing to do. - if (mPrinters.isEmpty()) { - return; - } - // Remove the printers for that service. - List<PrinterId> removedPrinterIds = null; - final int printerCount = mPrinters.size(); - for (int i = 0; i < printerCount; i++) { - PrinterId printerId = mPrinters.keyAt(i); - if (printerId.getServiceName().equals(serviceName)) { - if (removedPrinterIds == null) { - removedPrinterIds = new ArrayList<PrinterId>(); - } - removedPrinterIds.add(printerId); - } - } - if (!removedPrinterIds.isEmpty()) { - mHandler.obtainMessage( - SessionHandler.MSG_DISPATCH_PRINTERS_REMOVED, - removedPrinterIds).sendToTarget(); - } + // Remove the reported and tracked printers for that service. + ComponentName serviceName = service.getComponentName(); + removePrintersForServiceLocked(serviceName); + service.destroy(); + } + + public void onServiceDiedLocked(RemotePrintService service) { + // Remove the reported by that service. + removePrintersForServiceLocked(service.getComponentName()); } public void onServiceAddedLocked(RemotePrintService service) { @@ -908,6 +968,34 @@ final class UserState implements PrintSpoolerCallbacks { } } + private void removePrintersForServiceLocked(ComponentName serviceName) { + // No printers - nothing to do. + if (mPrinters.isEmpty()) { + return; + } + // Remove the printers for that service. + List<PrinterId> removedPrinterIds = null; + final int printerCount = mPrinters.size(); + for (int i = 0; i < printerCount; i++) { + PrinterId printerId = mPrinters.keyAt(i); + if (printerId.getServiceName().equals(serviceName)) { + if (removedPrinterIds == null) { + removedPrinterIds = new ArrayList<PrinterId>(); + } + removedPrinterIds.add(printerId); + } + } + final int removedPrinterCount = removedPrinterIds.size(); + for (int i = 0; i < removedPrinterCount; i++) { + mPrinters.remove(removedPrinterIds.get(i)); + } + if (removedPrinterIds != null) { + mHandler.obtainMessage( + SessionHandler.MSG_DISPATCH_PRINTERS_REMOVED, + removedPrinterIds).sendToTarget(); + } + } + private void handleDispatchPrintersAdded(List<PrinterInfo> addedPrinters) { final int observerCount = mDiscoveryObservers.beginBroadcast(); for (int i = 0; i < observerCount; i++) { @@ -1026,14 +1114,17 @@ final class UserState implements PrintSpoolerCallbacks { public static final int MSG_DISPATCH_PRINTERS_REMOVED = 4; public static final int MSG_CREATE_PRINTER_DISCOVERY_SESSION = 5; - public static final int MSG_START_PRINTER_DISCOVERY = 6; - public static final int MSG_DISPATCH_CREATE_PRINTER_DISCOVERY_SESSION = 7; - public static final int MSG_DISPATCH_DESTROY_PRINTER_DISCOVERY_SESSION = 8; - public static final int MSG_DISPATCH_START_PRINTER_DISCOVERY = 9; - public static final int MSG_DISPATCH_STOP_PRINTER_DISCOVERY = 10; - public static final int MSG_VALIDATE_PRINTERS = 11; - public static final int MSG_START_PRINTER_STATE_TRACKING = 12; - public static final int MSG_STOP_PRINTER_STATE_TRACKING = 13; + public static final int MSG_DESTROY_PRINTER_DISCOVERY_SESSION = 6; + public static final int MSG_START_PRINTER_DISCOVERY = 7; + public static final int MSG_STOP_PRINTER_DISCOVERY = 8; + public static final int MSG_DISPATCH_CREATE_PRINTER_DISCOVERY_SESSION = 9; + public static final int MSG_DISPATCH_DESTROY_PRINTER_DISCOVERY_SESSION = 10; + public static final int MSG_DISPATCH_START_PRINTER_DISCOVERY = 11; + public static final int MSG_DISPATCH_STOP_PRINTER_DISCOVERY = 12; + public static final int MSG_VALIDATE_PRINTERS = 13; + public static final int MSG_START_PRINTER_STATE_TRACKING = 14; + public static final int MSG_STOP_PRINTER_STATE_TRACKING = 15; + public static final int MSG_DESTROY_SERVICE = 16; SessionHandler(Looper looper) { super(looper, null, false); @@ -1074,11 +1165,21 @@ final class UserState implements PrintSpoolerCallbacks { service.createPrinterDiscoverySession(); } break; + case MSG_DESTROY_PRINTER_DISCOVERY_SESSION: { + RemotePrintService service = (RemotePrintService) message.obj; + service.destroyPrinterDiscoverySession(); + } break; + case MSG_START_PRINTER_DISCOVERY: { RemotePrintService service = (RemotePrintService) message.obj; service.startPrinterDiscovery(null); } break; + case MSG_STOP_PRINTER_DISCOVERY: { + RemotePrintService service = (RemotePrintService) message.obj; + service.stopPrinterDiscovery(); + } break; + case MSG_DISPATCH_CREATE_PRINTER_DISCOVERY_SESSION: { List<RemotePrintService> services = (List<RemotePrintService>) message.obj; handleDispatchCreatePrinterDiscoverySession(services); @@ -1124,7 +1225,12 @@ final class UserState implements PrintSpoolerCallbacks { PrinterId printerId = (PrinterId) args.arg2; args.recycle(); handleStopPrinterStateTracking(service, printerId); - } + } break; + + case MSG_DESTROY_SERVICE: { + RemotePrintService service = (RemotePrintService) message.obj; + service.destroy(); + } break; } } } diff --git a/services/java/com/android/server/wifi/WifiService.java b/services/java/com/android/server/wifi/WifiService.java index ed2b8fd..46f100e 100644 --- a/services/java/com/android/server/wifi/WifiService.java +++ b/services/java/com/android/server/wifi/WifiService.java @@ -170,7 +170,20 @@ public final class WifiService extends IWifiManager.Stub { } /* Client commands are forwarded to state machine */ case WifiManager.CONNECT_NETWORK: - case WifiManager.SAVE_NETWORK: + case WifiManager.SAVE_NETWORK: { + WifiConfiguration config = (WifiConfiguration) msg.obj; + if (config.isValid()) { + mWifiStateMachine.sendMessage(Message.obtain(msg)); + } else { + Slog.d(TAG, "ClientHandler.handleMessage ignoring msg=" + msg); + if (msg.what == WifiManager.CONNECT_NETWORK) { + replyFailed(msg, WifiManager.CONNECT_NETWORK_FAILED); + } else { + replyFailed(msg, WifiManager.SAVE_NETWORK_FAILED); + } + } + break; + } case WifiManager.FORGET_NETWORK: case WifiManager.START_WPS: case WifiManager.CANCEL_WPS: @@ -185,6 +198,17 @@ public final class WifiService extends IWifiManager.Stub { } } } + + private void replyFailed(Message msg, int what) { + Message reply = msg.obtain(); + reply.what = what; + reply.arg1 = WifiManager.INVALID_ARGS; + try { + msg.replyTo.send(reply); + } catch (RemoteException e) { + // There's not much we can do if reply can't be sent! + } + } } private ClientHandler mClientHandler; @@ -555,7 +579,11 @@ public final class WifiService extends IWifiManager.Stub { */ public void setWifiApEnabled(WifiConfiguration wifiConfig, boolean enabled) { enforceChangePermission(); - mWifiController.obtainMessage(CMD_SET_AP, enabled ? 1 : 0, 0, wifiConfig).sendToTarget(); + if (wifiConfig.isValid()) { + mWifiController.obtainMessage(CMD_SET_AP, enabled ? 1 : 0, 0, wifiConfig).sendToTarget(); + } else { + Slog.e(TAG, "Invalid WifiConfiguration"); + } } /** @@ -588,7 +616,11 @@ public final class WifiService extends IWifiManager.Stub { enforceChangePermission(); if (wifiConfig == null) return; - mWifiStateMachine.setWifiApConfiguration(wifiConfig); + if (wifiConfig.isValid()) { + mWifiStateMachine.setWifiApConfiguration(wifiConfig); + } else { + Slog.e(TAG, "Invalid WifiConfiguration"); + } } /** @@ -646,10 +678,15 @@ public final class WifiService extends IWifiManager.Stub { */ public int addOrUpdateNetwork(WifiConfiguration config) { enforceChangePermission(); - if (mWifiStateMachineChannel != null) { - return mWifiStateMachine.syncAddOrUpdateNetwork(mWifiStateMachineChannel, config); + if (config.isValid()) { + if (mWifiStateMachineChannel != null) { + return mWifiStateMachine.syncAddOrUpdateNetwork(mWifiStateMachineChannel, config); + } else { + Slog.e(TAG, "mWifiStateMachineChannel is not initialized"); + return -1; + } } else { - Slog.e(TAG, "mWifiStateMachineChannel is not initialized"); + Slog.e(TAG, "bad network configuration"); return -1; } } |