From c918a033c3f14e5f563fea526266743286aef00b Mon Sep 17 00:00:00 2001 From: dianlujitao Date: Fri, 25 Jan 2019 15:36:02 +0800 Subject: [PATCH] TelephonyExtUtils: Handle extphone binder death * If extphone binder service is invoked after death, phone service would crash due to android.os.DeadObjectException. Change-Id: I8dec7bfd709b0443654001ecd67219a2ba8cc134 --- .../internal/util/TelephonyExtUtils.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/sdk/src/java/org/lineageos/internal/util/TelephonyExtUtils.java b/sdk/src/java/org/lineageos/internal/util/TelephonyExtUtils.java index 776470a4..77893cf9 100644 --- a/sdk/src/java/org/lineageos/internal/util/TelephonyExtUtils.java +++ b/sdk/src/java/org/lineageos/internal/util/TelephonyExtUtils.java @@ -21,6 +21,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.AsyncTask; +import android.os.IBinder.DeathRecipient; import android.os.RemoteException; import android.os.ServiceManager; import android.os.SystemProperties; @@ -81,6 +82,17 @@ public final class TelephonyExtUtils { } }; + private final DeathRecipient mDeathRecipient = new DeathRecipient() { + @Override + public void binderDied() { + if (DEBUG) Log.d(TAG, "Binder died"); + synchronized(TelephonyExtUtils.class) { + mExtTelephony.asBinder().unlinkToDeath(mDeathRecipient, 0); + mExtTelephony = null; + } + } + }; + // This class is not supposed to be instantiated externally private TelephonyExtUtils(Context context) { if (DEBUG) Log.d(TAG, "Registering listeners!"); @@ -265,10 +277,15 @@ public final class TelephonyExtUtils { try { mExtTelephony = IExtTelephony.Stub.asInterface(ServiceManager.getService("extphone")); + if (mExtTelephony != null) { + mExtTelephony.asBinder().linkToDeath(mDeathRecipient, 0); + } } catch (NoClassDefFoundError ex) { // Ignore, device does not ship with telephony-ext Log.d(TAG, "Failed to get telephony extension service!"); mNoServiceAvailable = true; + } catch (RemoteException ex) { + Log.d(TAG, "linkToDeath failed!"); } }