diff options
author | Jeff Sharkey <jsharkey@android.com> | 2011-12-15 15:47:12 -0800 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2011-12-15 15:55:00 -0800 |
commit | 3df273e45864ba595b4d870fa3f6c81a770078e2 (patch) | |
tree | c3b359622baf5016a30341922e8d20d69f28808a /services/java/com/android/server/NetworkManagementService.java | |
parent | 27c751dc0011fca9f88502a720670457cc22793f (diff) | |
download | frameworks_base-3df273e45864ba595b4d870fa3f6c81a770078e2.zip frameworks_base-3df273e45864ba595b4d870fa3f6c81a770078e2.tar.gz frameworks_base-3df273e45864ba595b4d870fa3f6c81a770078e2.tar.bz2 |
Move NMS observers to RemoteCallbackList.
Internally uses Binder.linkToDeath() to handle case where remote
observer dies.
Change-Id: I9ae0ee6e011a9715172fa079098b108f895ae956
Diffstat (limited to 'services/java/com/android/server/NetworkManagementService.java')
-rw-r--r-- | services/java/com/android/server/NetworkManagementService.java | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/services/java/com/android/server/NetworkManagementService.java b/services/java/com/android/server/NetworkManagementService.java index b21e857..c1d8a13 100644 --- a/services/java/com/android/server/NetworkManagementService.java +++ b/services/java/com/android/server/NetworkManagementService.java @@ -46,6 +46,8 @@ import android.net.RouteInfo; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration.KeyMgmt; import android.os.INetworkManagementService; +import android.os.RemoteCallbackList; +import android.os.RemoteException; import android.os.SystemClock; import android.os.SystemProperties; import android.provider.Settings; @@ -133,8 +135,8 @@ public class NetworkManagementService extends INetworkManagementService.Stub private Thread mThread; private final CountDownLatch mConnectedSignal = new CountDownLatch(1); - // TODO: replace with RemoteCallbackList - private ArrayList<INetworkManagementEventObserver> mObservers; + private final RemoteCallbackList<INetworkManagementEventObserver> mObservers = + new RemoteCallbackList<INetworkManagementEventObserver>(); private final NetworkStatsFactory mStatsFactory = new NetworkStatsFactory(); @@ -155,7 +157,6 @@ public class NetworkManagementService extends INetworkManagementService.Stub */ private NetworkManagementService(Context context) { mContext = context; - mObservers = new ArrayList<INetworkManagementEventObserver>(); if ("simulator".equals(SystemProperties.get("ro.product.device"))) { return; @@ -202,30 +203,29 @@ public class NetworkManagementService extends INetworkManagementService.Stub } @Override - public void registerObserver(INetworkManagementEventObserver obs) { + public void registerObserver(INetworkManagementEventObserver observer) { mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); - Slog.d(TAG, "Registering observer"); - mObservers.add(obs); + mObservers.register(observer); } @Override - public void unregisterObserver(INetworkManagementEventObserver obs) { + public void unregisterObserver(INetworkManagementEventObserver observer) { mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); - Slog.d(TAG, "Unregistering observer"); - mObservers.remove(mObservers.indexOf(obs)); + mObservers.unregister(observer); } /** * Notify our observers of an interface status change */ private void notifyInterfaceStatusChanged(String iface, boolean up) { - for (INetworkManagementEventObserver obs : mObservers) { + final int length = mObservers.beginBroadcast(); + for (int i = 0; i < length; i++) { try { - obs.interfaceStatusChanged(iface, up); - } catch (Exception ex) { - Slog.w(TAG, "Observer notifier failed", ex); + mObservers.getBroadcastItem(i).interfaceStatusChanged(iface, up); + } catch (RemoteException e) { } } + mObservers.finishBroadcast(); } /** @@ -233,26 +233,28 @@ public class NetworkManagementService extends INetworkManagementService.Stub * (typically, an Ethernet cable has been plugged-in or unplugged). */ private void notifyInterfaceLinkStateChanged(String iface, boolean up) { - for (INetworkManagementEventObserver obs : mObservers) { + final int length = mObservers.beginBroadcast(); + for (int i = 0; i < length; i++) { try { - obs.interfaceLinkStateChanged(iface, up); - } catch (Exception ex) { - Slog.w(TAG, "Observer notifier failed", ex); + mObservers.getBroadcastItem(i).interfaceLinkStateChanged(iface, up); + } catch (RemoteException e) { } } + mObservers.finishBroadcast(); } /** * Notify our observers of an interface addition. */ private void notifyInterfaceAdded(String iface) { - for (INetworkManagementEventObserver obs : mObservers) { + final int length = mObservers.beginBroadcast(); + for (int i = 0; i < length; i++) { try { - obs.interfaceAdded(iface); - } catch (Exception ex) { - Slog.w(TAG, "Observer notifier failed", ex); + mObservers.getBroadcastItem(i).interfaceAdded(iface); + } catch (RemoteException e) { } } + mObservers.finishBroadcast(); } /** @@ -264,26 +266,28 @@ public class NetworkManagementService extends INetworkManagementService.Stub mActiveAlertIfaces.remove(iface); mActiveQuotaIfaces.remove(iface); - for (INetworkManagementEventObserver obs : mObservers) { + final int length = mObservers.beginBroadcast(); + for (int i = 0; i < length; i++) { try { - obs.interfaceRemoved(iface); - } catch (Exception ex) { - Slog.w(TAG, "Observer notifier failed", ex); + mObservers.getBroadcastItem(i).interfaceRemoved(iface); + } catch (RemoteException e) { } } + mObservers.finishBroadcast(); } /** * Notify our observers of a limit reached. */ private void notifyLimitReached(String limitName, String iface) { - for (INetworkManagementEventObserver obs : mObservers) { + final int length = mObservers.beginBroadcast(); + for (int i = 0; i < length; i++) { try { - obs.limitReached(limitName, iface); - } catch (Exception ex) { - Slog.w(TAG, "Observer notifier failed", ex); + mObservers.getBroadcastItem(i).limitReached(limitName, iface); + } catch (RemoteException e) { } } + mObservers.finishBroadcast(); } /** |