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!"); } }