Merge "Add death recipient to TelephonyRegistry."
This commit is contained in:
@@ -64,6 +64,7 @@ import java.io.PrintWriter;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Since phone process can be restarted, this class provides a centralized place
|
* Since phone process can be restarted, this class provides a centralized place
|
||||||
@@ -90,6 +91,8 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub {
|
|||||||
|
|
||||||
IBinder binder;
|
IBinder binder;
|
||||||
|
|
||||||
|
TelephonyRegistryDeathRecipient deathRecipient;
|
||||||
|
|
||||||
IPhoneStateListener callback;
|
IPhoneStateListener callback;
|
||||||
IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
|
IOnSubscriptionsChangedListener onSubscriptionsChangedListenerCallback;
|
||||||
|
|
||||||
@@ -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() {
|
private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
@@ -378,23 +396,14 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Record r;
|
|
||||||
|
|
||||||
synchronized (mRecords) {
|
synchronized (mRecords) {
|
||||||
// register
|
// register
|
||||||
find_and_add: {
|
|
||||||
IBinder b = callback.asBinder();
|
IBinder b = callback.asBinder();
|
||||||
final int N = mRecords.size();
|
Record r = add(b);
|
||||||
for (int i = 0; i < N; i++) {
|
|
||||||
r = mRecords.get(i);
|
if (r == null) {
|
||||||
if (b == r.binder) {
|
return;
|
||||||
break find_and_add;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
r = new Record();
|
|
||||||
r.binder = b;
|
|
||||||
mRecords.add(r);
|
|
||||||
if (DBG) log("listen oscl: add new record");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
r.onSubscriptionsChangedListenerCallback = callback;
|
r.onSubscriptionsChangedListenerCallback = callback;
|
||||||
@@ -496,20 +505,11 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub {
|
|||||||
|
|
||||||
synchronized (mRecords) {
|
synchronized (mRecords) {
|
||||||
// register
|
// register
|
||||||
Record r;
|
|
||||||
find_and_add: {
|
|
||||||
IBinder b = callback.asBinder();
|
IBinder b = callback.asBinder();
|
||||||
final int N = mRecords.size();
|
Record r = add(b);
|
||||||
for (int i = 0; i < N; i++) {
|
|
||||||
r = mRecords.get(i);
|
if (r == null) {
|
||||||
if (b == r.binder) {
|
return;
|
||||||
break find_and_add;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
r = new Record();
|
|
||||||
r.binder = b;
|
|
||||||
mRecords.add(r);
|
|
||||||
if (DBG) log("listen: add new record");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
r.callback = callback;
|
r.callback = callback;
|
||||||
@@ -697,16 +697,57 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub {
|
|||||||
return record.canReadPhoneState ? mCallIncomingNumber[phoneId] : "";
|
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) {
|
private void remove(IBinder binder) {
|
||||||
synchronized (mRecords) {
|
synchronized (mRecords) {
|
||||||
final int recordCount = mRecords.size();
|
final int recordCount = mRecords.size();
|
||||||
for (int i = 0; i < recordCount; i++) {
|
for (int i = 0; i < recordCount; i++) {
|
||||||
if (mRecords.get(i).binder == binder) {
|
|
||||||
if (DBG) {
|
|
||||||
Record r = mRecords.get(i);
|
Record r = mRecords.get(i);
|
||||||
|
if (r.binder == binder) {
|
||||||
|
if (DBG) {
|
||||||
log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
|
log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
|
||||||
+ " r.callback " + r.callback);
|
+ " 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);
|
mRecords.remove(i);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user