Loading services/core/java/com/android/server/TelephonyRegistry.java +73 −32 Original line number Diff line number Diff line Loading @@ -64,6 +64,7 @@ import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.NoSuchElementException; /** * Since phone process can be restarted, this class provides a centralized place Loading @@ -90,6 +91,8 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { IBinder binder; TelephonyRegistryDeathRecipient deathRecipient; IPhoneStateListener callback; IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback; Loading Loading @@ -251,6 +254,21 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { } }; private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient { private final IBinder binder; TelephonyRegistryDeathRecipient(IBinder binder) { this.binder = binder; } @Override public void binderDied() { if (DBG) log("binderDied " + binder); remove(binder); } } private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Loading Loading @@ -378,23 +396,14 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { } } Record r; synchronized (mRecords) { // register find_and_add: { IBinder b = callback.asBinder(); final int N = mRecords.size(); for (int i = 0; i < N; i++) { r = mRecords.get(i); if (b == r.binder) { break find_and_add; } } r = new Record(); r.binder = b; mRecords.add(r); if (DBG) log("listen oscl: add new record"); Record r = add(b); if (r == null) { return; } r.onSubscriptionsChangedListenerCallback = callback; Loading Loading @@ -496,20 +505,11 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { synchronized (mRecords) { // register Record r; find_and_add: { IBinder b = callback.asBinder(); final int N = mRecords.size(); for (int i = 0; i < N; i++) { r = mRecords.get(i); if (b == r.binder) { break find_and_add; } } r = new Record(); r.binder = b; mRecords.add(r); if (DBG) log("listen: add new record"); Record r = add(b); if (r == null) { return; } r.callback = callback; Loading Loading @@ -697,16 +697,57 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { return record.canReadPhoneState ? mCallIncomingNumber[phoneId] : ""; } private Record add(IBinder binder) { Record r; synchronized (mRecords) { final int N = mRecords.size(); for (int i = 0; i < N; i++) { r = mRecords.get(i); if (binder == r.binder) { // Already existed. return r; } } r = new Record(); r.binder = binder; r.deathRecipient = new TelephonyRegistryDeathRecipient(binder); try { binder.linkToDeath(r.deathRecipient, 0); } catch (RemoteException e) { if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e); // Binder already died. Return null. return null; } mRecords.add(r); if (DBG) log("add new record"); } return r; } private void remove(IBinder binder) { synchronized (mRecords) { final int recordCount = mRecords.size(); for (int i = 0; i < recordCount; i++) { if (mRecords.get(i).binder == binder) { if (DBG) { Record r = mRecords.get(i); if (r.binder == binder) { if (DBG) { log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage + " r.callback " + r.callback); } if (r.deathRecipient != null) { try { binder.unlinkToDeath(r.deathRecipient, 0); } catch (NoSuchElementException e) { if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r=" + r + " e=" + e); } } mRecords.remove(i); return; } Loading Loading
services/core/java/com/android/server/TelephonyRegistry.java +73 −32 Original line number Diff line number Diff line Loading @@ -64,6 +64,7 @@ import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.NoSuchElementException; /** * Since phone process can be restarted, this class provides a centralized place Loading @@ -90,6 +91,8 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { IBinder binder; TelephonyRegistryDeathRecipient deathRecipient; IPhoneStateListener callback; IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback; Loading Loading @@ -251,6 +254,21 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { } }; private class TelephonyRegistryDeathRecipient implements IBinder.DeathRecipient { private final IBinder binder; TelephonyRegistryDeathRecipient(IBinder binder) { this.binder = binder; } @Override public void binderDied() { if (DBG) log("binderDied " + binder); remove(binder); } } private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Loading Loading @@ -378,23 +396,14 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { } } Record r; synchronized (mRecords) { // register find_and_add: { IBinder b = callback.asBinder(); final int N = mRecords.size(); for (int i = 0; i < N; i++) { r = mRecords.get(i); if (b == r.binder) { break find_and_add; } } r = new Record(); r.binder = b; mRecords.add(r); if (DBG) log("listen oscl: add new record"); Record r = add(b); if (r == null) { return; } r.onSubscriptionsChangedListenerCallback = callback; Loading Loading @@ -496,20 +505,11 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { synchronized (mRecords) { // register Record r; find_and_add: { IBinder b = callback.asBinder(); final int N = mRecords.size(); for (int i = 0; i < N; i++) { r = mRecords.get(i); if (b == r.binder) { break find_and_add; } } r = new Record(); r.binder = b; mRecords.add(r); if (DBG) log("listen: add new record"); Record r = add(b); if (r == null) { return; } r.callback = callback; Loading Loading @@ -697,16 +697,57 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { return record.canReadPhoneState ? mCallIncomingNumber[phoneId] : ""; } private Record add(IBinder binder) { Record r; synchronized (mRecords) { final int N = mRecords.size(); for (int i = 0; i < N; i++) { r = mRecords.get(i); if (binder == r.binder) { // Already existed. return r; } } r = new Record(); r.binder = binder; r.deathRecipient = new TelephonyRegistryDeathRecipient(binder); try { binder.linkToDeath(r.deathRecipient, 0); } catch (RemoteException e) { if (VDBG) log("LinkToDeath remote exception sending to r=" + r + " e=" + e); // Binder already died. Return null. return null; } mRecords.add(r); if (DBG) log("add new record"); } return r; } private void remove(IBinder binder) { synchronized (mRecords) { final int recordCount = mRecords.size(); for (int i = 0; i < recordCount; i++) { if (mRecords.get(i).binder == binder) { if (DBG) { Record r = mRecords.get(i); if (r.binder == binder) { if (DBG) { log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage + " r.callback " + r.callback); } if (r.deathRecipient != null) { try { binder.unlinkToDeath(r.deathRecipient, 0); } catch (NoSuchElementException e) { if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r=" + r + " e=" + e); } } mRecords.remove(i); return; } Loading