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

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

Adds the ability to override ImsService binding configs

Adds methods to override carrier/device ImsService
binding configs for GTS testing.

Bug: 77141737
Test: manual
Merged-In: I46d8e90829fb833fe7732a4611181480fc3c4600
Change-Id: I96d1dc04b7114bcedc38c72249d6b52f43539474
parent 46719a0b
Loading
Loading
Loading
Loading
+70 −9
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ import android.content.pm.ServiceInfo;
import android.os.Handler;
import android.os.Handler;
import android.os.Looper;
import android.os.Looper;
import android.os.Message;
import android.os.Message;
import android.os.PersistableBundle;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserHandle;
import android.telephony.CarrierConfigManager;
import android.telephony.CarrierConfigManager;
@@ -90,6 +91,8 @@ public class ImsResolver implements ImsServiceController.ImsServiceControllerCal
    private static final int HANDLER_START_DYNAMIC_FEATURE_QUERY = 3;
    private static final int HANDLER_START_DYNAMIC_FEATURE_QUERY = 3;
    // A query to request ImsService features has completed.
    // A query to request ImsService features has completed.
    private static final int HANDLER_DYNAMIC_FEATURE_QUERY_COMPLETE = 4;
    private static final int HANDLER_DYNAMIC_FEATURE_QUERY_COMPLETE = 4;
    // Testing: Overrides the current configuration for ImsService binding
    private static final int HANDLER_OVERRIDE_IMS_SERVICE_CONFIG = 5;


    // Delay between dynamic ImsService queries.
    // Delay between dynamic ImsService queries.
    private static final int DELAY_DYNAMIC_QUERY_MS = 5000;
    private static final int DELAY_DYNAMIC_QUERY_MS = 5000;
@@ -328,6 +331,8 @@ public class ImsResolver implements ImsServiceController.ImsServiceControllerCal
    private final Object mBoundServicesLock = new Object();
    private final Object mBoundServicesLock = new Object();
    private final int mNumSlots;
    private final int mNumSlots;
    private final boolean mIsDynamicBinding;
    private final boolean mIsDynamicBinding;
    // Package name of the default device service.
    private String mDeviceService;


    // Synchronize all messages on a handler to ensure that the cache includes the most recent
    // Synchronize all messages on a handler to ensure that the cache includes the most recent
    // version of the installed ImsServices.
    // version of the installed ImsServices.
@@ -345,7 +350,7 @@ public class ImsResolver implements ImsServiceController.ImsServiceControllerCal
            }
            }
            case HANDLER_CONFIG_CHANGED: {
            case HANDLER_CONFIG_CHANGED: {
                int slotId = (Integer) msg.obj;
                int slotId = (Integer) msg.obj;
                maybeRebindService(slotId);
                carrierConfigChanged(slotId);
                break;
                break;
            }
            }
            case HANDLER_START_DYNAMIC_FEATURE_QUERY: {
            case HANDLER_START_DYNAMIC_FEATURE_QUERY: {
@@ -362,6 +367,25 @@ public class ImsResolver implements ImsServiceController.ImsServiceControllerCal
                dynamicQueryComplete(name, features);
                dynamicQueryComplete(name, features);
                break;
                break;
            }
            }
            case HANDLER_OVERRIDE_IMS_SERVICE_CONFIG: {
                int slotId = msg.arg1;
                // arg2 will be equal to 1 if it is a carrier service.
                boolean isCarrierImsService = (msg.arg2 == 1);
                String packageName = (String) msg.obj;
                if (isCarrierImsService) {
                    Log.i(TAG, "overriding carrier ImsService - slot=" + slotId + " packageName="
                            + packageName);
                    maybeRebindService(slotId, packageName);
                } else {
                    Log.i(TAG, "overriding device ImsService -  packageName=" + packageName);
                    if (packageName == null || packageName.isEmpty()) {
                        unbindImsService(getImsServiceInfoFromCache(mDeviceService));
                    }
                    mDeviceService = packageName;
                    bindImsService(getImsServiceInfoFromCache(packageName));
                }
                break;
            }
            default:
            default:
                return false;
                return false;
        }
        }
@@ -387,8 +411,6 @@ public class ImsResolver implements ImsServiceController.ImsServiceControllerCal
                }
                }
            };
            };


    // Package name of the default device service.
    private String mDeviceService;
    // Array index corresponds to slot Id associated with the service package name.
    // Array index corresponds to slot Id associated with the service package name.
    private String[] mCarrierServices;
    private String[] mCarrierServices;
    // List index corresponds to Slot Id, Maps ImsFeature.FEATURE->bound ImsServiceController
    // List index corresponds to Slot Id, Maps ImsFeature.FEATURE->bound ImsServiceController
@@ -594,6 +616,36 @@ public class ImsResolver implements ImsServiceController.ImsServiceControllerCal
        return null;
        return null;
    }
    }


    // Used for testing only.
    public boolean overrideImsServiceConfiguration(int slotId, boolean isCarrierService,
            String packageName) {
        if (slotId < 0 || slotId >= mNumSlots) {
            Log.w(TAG, "overrideImsServiceConfiguration: invalid slotId!");
            return false;
        }

        if (packageName == null) {
            Log.w(TAG, "overrideImsServiceConfiguration: null packageName!");
            return false;
        }

        // encode boolean to int for Message.
        int carrierService = isCarrierService ? 1 : 0;
        Message.obtain(mHandler, HANDLER_OVERRIDE_IMS_SERVICE_CONFIG, slotId, carrierService,
                packageName).sendToTarget();
        return true;
    }

    // used for testing only.
    public String getImsServiceConfiguration(int slotId, boolean isCarrierService) {
        if (slotId < 0 || slotId >= mNumSlots) {
            Log.w(TAG, "getImsServiceConfiguration: invalid slotId!");
            return "";
        }

        return isCarrierService ? mCarrierServices[slotId] : mDeviceService;
    }

    private void putImsController(int slotId, int feature, ImsServiceController controller) {
    private void putImsController(int slotId, int feature, ImsServiceController controller) {
        if (slotId < 0 || slotId >= mNumSlots || feature <= ImsFeature.FEATURE_INVALID
        if (slotId < 0 || slotId >= mNumSlots || feature <= ImsFeature.FEATURE_INVALID
                || feature >= ImsFeature.FEATURE_MAX) {
                || feature >= ImsFeature.FEATURE_MAX) {
@@ -917,22 +969,31 @@ public class ImsResolver implements ImsServiceController.ImsServiceControllerCal
    // Possibly rebind to another ImsService if currently installed ImsServices were changed or if
    // Possibly rebind to another ImsService if currently installed ImsServices were changed or if
    // the SIM card has changed.
    // the SIM card has changed.
    // Called from the handler ONLY
    // Called from the handler ONLY
    private void maybeRebindService(int slotId) {
    private void maybeRebindService(int slotId, String newPackageName) {
        if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
        if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
            // not specified, replace package on all slots.
            // not specified, replace package on all slots.
            for (int i = 0; i < mNumSlots; i++) {
            for (int i = 0; i < mNumSlots; i++) {
                updateBoundCarrierServices(i);
                updateBoundCarrierServices(i, newPackageName);
            }
            }
        } else {
        } else {
            updateBoundCarrierServices(slotId);
            updateBoundCarrierServices(slotId, newPackageName);
        }
        }


    }
    }


    private void updateBoundCarrierServices(int slotId) {
    private void carrierConfigChanged(int slotId) {
        int subId = mSubscriptionManagerProxy.getSubId(slotId);
        int subId = mSubscriptionManagerProxy.getSubId(slotId);
        String newPackageName = mCarrierConfigManager.getConfigForSubId(subId).getString(
        PersistableBundle config = mCarrierConfigManager.getConfigForSubId(subId);
        if (config != null) {
            String newPackageName = config.getString(
                    CarrierConfigManager.KEY_CONFIG_IMS_PACKAGE_OVERRIDE_STRING, null);
                    CarrierConfigManager.KEY_CONFIG_IMS_PACKAGE_OVERRIDE_STRING, null);
            maybeRebindService(slotId, newPackageName);
        } else {
            Log.w(TAG, "carrierConfigChanged: CarrierConfig is null!");
        }
    }

    private void updateBoundCarrierServices(int slotId, String newPackageName) {
        if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX && slotId < mNumSlots) {
        if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX && slotId < mNumSlots) {
            String oldPackageName = mCarrierServices[slotId];
            String oldPackageName = mCarrierServices[slotId];
            mCarrierServices[slotId] = newPackageName;
            mCarrierServices[slotId] = newPackageName;