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

Commit be1b853b authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Cache ITelephony/IRcsController and notify Connector upon death"

parents 5a04f796 abe39e7a
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()