diff options
Diffstat (limited to 'src/java/com/android/ims/MmTelFeatureConnection.java')
-rw-r--r-- | src/java/com/android/ims/MmTelFeatureConnection.java | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/src/java/com/android/ims/MmTelFeatureConnection.java b/src/java/com/android/ims/MmTelFeatureConnection.java index 07069219..d6954f3f 100644 --- a/src/java/com/android/ims/MmTelFeatureConnection.java +++ b/src/java/com/android/ims/MmTelFeatureConnection.java @@ -75,6 +75,11 @@ public class MmTelFeatureConnection { private IImsRegistration mRegistrationBinder; private IImsConfig mConfigBinder; + private IBinder.DeathRecipient mDeathRecipient = () -> { + Log.w(TAG, "DeathRecipient triggered, binder died."); + onRemovedOrDied(); + }; + private abstract class CallbackAdapterManager<T> { private static final String TAG = "CallbackAdapterManager"; @@ -337,14 +342,8 @@ public class MmTelFeatureConnection { } switch (feature) { case ImsFeature.FEATURE_MMTEL: { - if (mIsAvailable) { - Log.i(TAG, "MmTel disabled on slotId: " + slotId); - mIsAvailable = false; - mmTelFeatureRemoved(); - if (mStatusCallback != null) { - mStatusCallback.notifyUnavailable(); - } - } + Log.i(TAG, "MmTel removed on slotId: " + slotId); + onRemovedOrDied(); break; } case ImsFeature.FEATURE_EMERGENCY_MMTEL : { @@ -376,12 +375,23 @@ public class MmTelFeatureConnection { mContext = context; } - // Called when the MmTelFeatureConnection has received an unavailable notification. - private void mmTelFeatureRemoved() { + /** + * Called when the MmTelFeature has either been removed by Telephony or crashed. + */ + private void onRemovedOrDied() { synchronized (mLock) { - // invalidate caches. - mRegistrationBinder = null; - mConfigBinder = null; + if (mIsAvailable) { + mIsAvailable = false; + // invalidate caches. + mRegistrationBinder = null; + mConfigBinder = null; + if (mBinder != null) { + mBinder.unlinkToDeath(mDeathRecipient, 0); + } + if (mStatusCallback != null) { + mStatusCallback.notifyUnavailable(); + } + } } } @@ -434,7 +444,16 @@ public class MmTelFeatureConnection { } public void setBinder(IBinder binder) { - mBinder = binder; + synchronized (mLock) { + mBinder = binder; + try { + if (mBinder != null) { + mBinder.linkToDeath(mDeathRecipient, 0); + } + } catch (RemoteException e) { + // No need to do anything if the binder is already dead. + } + } } /** |