Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit abe39e7a authored by Brad Ebinger's avatar Brad Ebinger
Browse files

Cache ITelephony/IRcsController and notify Connector upon death

Cache the Binder node to telephony and When the phone process
dies, add the ability to notify apps with persistent listeners
of the event so the event can be communicated back to the app hosting
the listener and they can take action to recover.

Bug: 160768091
Test: atest FrameworksTelephonyTests ImsCommonTests
Change-Id: Iacfce952d16dbdfcf750469f104a24f468499e3f
parent 80478ea7
Loading
Loading
Loading
Loading
+17 −4
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.os.SystemProperties;
import android.provider.Settings;
import android.telecom.TelecomManager;
import android.telephony.AccessNetworkConstants;
import android.telephony.BinderCacheManager;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyFrameworkInitializer;
@@ -376,10 +377,10 @@ public class ImsManager implements FeatureUpdates {
    private Context mContext;
    private CarrierConfigManager mConfigManager;
    private int mPhoneId;
    private final Object mLock = new Object();
    private AtomicReference<MmTelFeatureConnection> mMmTelConnectionRef = new AtomicReference<>();
    // Used for debug purposes only currently
    private boolean mConfigUpdated = false;

    private BinderCacheManager<ITelephony> mBinderCache;
    private ImsConfigListener mImsConfigListener;

    public static final String TRUE = "true";
@@ -1646,6 +1647,7 @@ public class ImsManager implements FeatureUpdates {
        mConfigManager = (CarrierConfigManager) context.getSystemService(
                Context.CARRIER_CONFIG_SERVICE);
        mExecutor = new LazyExecutor();
        mBinderCache = new BinderCacheManager<>(ImsManager::getITelephonyInterface);
        // Start off with an empty MmTelFeatureConnection, which will be replaced one an
        // ImsService is available (ImsManager expects a non-null FeatureConnection)
        associate(null, null, null);
@@ -1665,6 +1667,7 @@ public class ImsManager implements FeatureUpdates {
                Context.CARRIER_CONFIG_SERVICE);
        // Do not multithread tests
        mExecutor = Runnable::run;
        mBinderCache = new BinderCacheManager<>(ImsManager::getITelephonyInterface);
        // MmTelFeatureConnection should be replaced for tests with mMmTelFeatureConnectionFactory.
        associate(null, null, null);
    }
@@ -2390,7 +2393,13 @@ public class ImsManager implements FeatureUpdates {
    @Override
    public void registerFeatureCallback(int slotId, IImsServiceFeatureCallback cb) {
        try {
            ITelephony telephony = getITelephony();
            ITelephony telephony = mBinderCache.listenOnBinder(cb, () -> {
                try {
                    cb.imsFeatureRemoved(
                            FeatureConnector.UNAVAILABLE_REASON_SERVER_UNAVAILABLE);
                } catch (RemoteException ignore) {} // This is local.
            });

            if (telephony != null) {
                telephony.registerMmTelFeatureCallback(slotId, cb);
            } else {
@@ -2418,7 +2427,7 @@ public class ImsManager implements FeatureUpdates {
    @Override
    public void unregisterFeatureCallback(IImsServiceFeatureCallback cb) {
        try {
            ITelephony telephony = getITelephony();
            ITelephony telephony = mBinderCache.removeRunnable(cb);
            if (telephony != null) {
                telephony.unregisterImsFeatureCallback(cb);
            }
@@ -2440,6 +2449,10 @@ public class ImsManager implements FeatureUpdates {
    }

    private ITelephony getITelephony() {
        return mBinderCache.getBinder();
    }

    private static ITelephony getITelephonyInterface() {
        return ITelephony.Stub.asInterface(
                TelephonyFrameworkInitializer
                        .getTelephonyServiceManager()
+19 −5
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.os.IBinder;
import android.os.PersistableBundle;
import android.os.RemoteException;
import android.os.ServiceSpecificException;
import android.telephony.BinderCacheManager;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyFrameworkInitializer;
@@ -47,6 +48,7 @@ import android.util.Log;

import com.android.ims.internal.IImsServiceFeatureCallback;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.ITelephony;
import com.android.telephony.Rlog;

import java.util.ArrayList;
@@ -157,6 +159,8 @@ public class RcsFeatureManager implements FeatureUpdates {
    private final int mSlotId;
    private final Context mContext;
    private final Set<RcsFeatureCallbacks> mRcsFeatureCallbacks = new CopyOnWriteArraySet<>();
    private final BinderCacheManager<IImsRcsController> mBinderCache
            = new BinderCacheManager<>(RcsFeatureManager::getIImsRcsControllerInterface);

    @VisibleForTesting
    public RcsFeatureConnection mRcsFeatureConnection;
@@ -498,7 +502,13 @@ public class RcsFeatureManager implements FeatureUpdates {

    @Override
    public void registerFeatureCallback(int slotId, IImsServiceFeatureCallback cb) {
        IImsRcsController controller = getIImsRcsController();
        IImsRcsController controller = mBinderCache.listenOnBinder(cb, () -> {
            try {
                cb.imsFeatureRemoved(
                        FeatureConnector.UNAVAILABLE_REASON_SERVER_UNAVAILABLE);
            } catch (RemoteException ignore) {} // This is local.
        });

        try {
            if (controller == null) {
                Log.e(TAG, "registerRcsFeatureListener: IImsRcsController is null");
@@ -528,7 +538,7 @@ public class RcsFeatureManager implements FeatureUpdates {
    @Override
    public void unregisterFeatureCallback(IImsServiceFeatureCallback cb) {
        try {
            IImsRcsController imsRcsController = getIImsRcsController();
            IImsRcsController imsRcsController = mBinderCache.removeRunnable(cb);
            if (imsRcsController != null) {
                imsRcsController.unregisterImsFeatureCallback(cb);
            }
@@ -540,6 +550,10 @@ public class RcsFeatureManager implements FeatureUpdates {
    }

    private IImsRcsController getIImsRcsController() {
        return mBinderCache.getBinder();
    }

    private static IImsRcsController getIImsRcsControllerInterface() {
        IBinder binder = TelephonyFrameworkInitializer
                .getTelephonyServiceManager()
                .getTelephonyImsServiceRegisterer()