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

Commit 854d4081 authored by Grace Jia's avatar Grace Jia
Browse files

Track disabled car mode ICS in InCallController when UI mode changed.

Currently we only add enabled car mode ICS to the CarModeTracker when we
received the notification of an app entered car mode. However, if the
app disabled before we try to get the package information, we'll ignore
this package forever and can't switch to the car mode app even if it's
been enabled later.

Bug: 186184781
Test: atest CtsTelecomTestCases:CarModeInCallServiceTest
Change-Id: I7d12a97dae2dbfa6373fb201741baafe70bbfd20
parent 6c8d16d3
Loading
Loading
Loading
Loading
+54 −34
Original line number Original line Diff line number Diff line
@@ -485,6 +485,7 @@ public class InCallController extends CallsManagerListenerBase {
                return super.getInfo();
                return super.getInfo();
            }
            }
        }
        }

        @Override
        @Override
        protected void onDisconnected() {
        protected void onDisconnected() {
            // Save this here because super.onDisconnected() could force us to explicitly
            // Save this here because super.onDisconnected() could force us to explicitly
@@ -548,6 +549,7 @@ public class InCallController extends CallsManagerListenerBase {
        /**
        /**
         * Called when we move to a state where calls are present on the device.  Chooses the
         * Called when we move to a state where calls are present on the device.  Chooses the
         * {@link InCallService} to which we should connect.
         * {@link InCallService} to which we should connect.
         *
         * @param isCarMode {@code true} if device is in car mode, {@code false} otherwise.
         * @param isCarMode {@code true} if device is in car mode, {@code false} otherwise.
         */
         */
        public synchronized void chooseInitialInCallService(boolean isCarMode) {
        public synchronized void chooseInitialInCallService(boolean isCarMode) {
@@ -586,6 +588,7 @@ public class InCallController extends CallsManagerListenerBase {
        /**
        /**
         * Changes the active {@link InCallService} to a car mode app.  Called whenever the device
         * Changes the active {@link InCallService} to a car mode app.  Called whenever the device
         * changes to car mode or the currently active car mode app changes.
         * changes to car mode or the currently active car mode app changes.
         *
         * @param packageName The package name of the car mode app.
         * @param packageName The package name of the car mode app.
         */
         */
        public synchronized void changeCarModeApp(String packageName) {
        public synchronized void changeCarModeApp(String packageName) {
@@ -594,7 +597,8 @@ public class InCallController extends CallsManagerListenerBase {
            InCallServiceInfo currentConnectionInfo = mCurrentConnection == null ? null
            InCallServiceInfo currentConnectionInfo = mCurrentConnection == null ? null
                    : mCurrentConnection.getInfo();
                    : mCurrentConnection.getInfo();
            InCallServiceInfo carModeConnectionInfo =
            InCallServiceInfo carModeConnectionInfo =
                    getInCallServiceComponent(packageName, IN_CALL_SERVICE_TYPE_CAR_MODE_UI);
                    getInCallServiceComponent(packageName,
                            IN_CALL_SERVICE_TYPE_CAR_MODE_UI, true /* ignoreDisabed */);


            if (!Objects.equals(currentConnectionInfo, carModeConnectionInfo)) {
            if (!Objects.equals(currentConnectionInfo, carModeConnectionInfo)) {
                Log.i(this, "changeCarModeApp: " + currentConnectionInfo + " => "
                Log.i(this, "changeCarModeApp: " + currentConnectionInfo + " => "
@@ -1128,8 +1132,8 @@ public class InCallController extends CallsManagerListenerBase {
                ParcelableCall parcelableCall = ParcelableCallUtils.toParcelableCall(call,
                ParcelableCall parcelableCall = ParcelableCallUtils.toParcelableCall(call,
                        true /* includeVideoProvider */, mCallsManager.getPhoneAccountRegistrar(),
                        true /* includeVideoProvider */, mCallsManager.getPhoneAccountRegistrar(),
                        info.isExternalCallsSupported(), includeRttCall,
                        info.isExternalCallsSupported(), includeRttCall,
                        info.getType() == IN_CALL_SERVICE_TYPE_SYSTEM_UI ||
                        info.getType() == IN_CALL_SERVICE_TYPE_SYSTEM_UI
                        info.getType() == IN_CALL_SERVICE_TYPE_NON_UI);
                                || info.getType() == IN_CALL_SERVICE_TYPE_NON_UI);
                try {
                try {
                    inCallService.addCall(sanitizeParcelableCallForService(info, parcelableCall));
                    inCallService.addCall(sanitizeParcelableCallForService(info, parcelableCall));
                    updateCallTracking(call, info, true /* isAdd */);
                    updateCallTracking(call, info, true /* isAdd */);
@@ -1160,8 +1164,8 @@ public class InCallController extends CallsManagerListenerBase {
                        false /* supportsExternalCalls */,
                        false /* supportsExternalCalls */,
                        android.telecom.Call.STATE_DISCONNECTED /* overrideState */,
                        android.telecom.Call.STATE_DISCONNECTED /* overrideState */,
                        false /* includeRttCall */,
                        false /* includeRttCall */,
                        info.getType() == IN_CALL_SERVICE_TYPE_SYSTEM_UI ||
                        info.getType() == IN_CALL_SERVICE_TYPE_SYSTEM_UI
                        info.getType() == IN_CALL_SERVICE_TYPE_NON_UI
                                || info.getType() == IN_CALL_SERVICE_TYPE_NON_UI
                );
                );


                try {
                try {
@@ -1262,6 +1266,7 @@ public class InCallController extends CallsManagerListenerBase {


    /**
    /**
     * Track changes to camera usage for a call.
     * Track changes to camera usage for a call.
     *
     * @param call     The call.
     * @param call     The call.
     * @param cameraId The id of the camera to use, or {@code null} if camera is off.
     * @param cameraId The id of the camera to use, or {@code null} if camera is off.
     */
     */
@@ -1478,7 +1483,7 @@ public class InCallController extends CallsManagerListenerBase {
        if (callCompanionApps != null && !callCompanionApps.isEmpty()) {
        if (callCompanionApps != null && !callCompanionApps.isEmpty()) {
            for (String pkg : callCompanionApps) {
            for (String pkg : callCompanionApps) {
                InCallServiceInfo info = getInCallServiceComponent(pkg,
                InCallServiceInfo info = getInCallServiceComponent(pkg,
                        IN_CALL_SERVICE_TYPE_COMPANION);
                        IN_CALL_SERVICE_TYPE_COMPANION, true /* ignoreDisabled */);
                if (info != null) {
                if (info != null) {
                    nonUIInCalls.add(new InCallServiceBindingConnection(info));
                    nonUIInCalls.add(new InCallServiceBindingConnection(info));
                }
                }
@@ -1503,8 +1508,10 @@ public class InCallController extends CallsManagerListenerBase {


        InCallServiceInfo defaultDialerComponent =
        InCallServiceInfo defaultDialerComponent =
                (systemPackageName != null && systemPackageName.equals(packageName))
                (systemPackageName != null && systemPackageName.equals(packageName))
                ? getInCallServiceComponent(packageName, IN_CALL_SERVICE_TYPE_SYSTEM_UI)
                        ? getInCallServiceComponent(packageName, IN_CALL_SERVICE_TYPE_SYSTEM_UI,
                : getInCallServiceComponent(packageName, IN_CALL_SERVICE_TYPE_DEFAULT_DIALER_UI);
                        true /* ignoreDisabled */)
                        : getInCallServiceComponent(packageName,
                                IN_CALL_SERVICE_TYPE_DEFAULT_DIALER_UI, true /* ignoreDisabled */);
        /* TODO: in Android 12 re-enable this an InCallService is required by the dialer role.
        /* TODO: in Android 12 re-enable this an InCallService is required by the dialer role.
            if (packageName != null && defaultDialerComponent == null) {
            if (packageName != null && defaultDialerComponent == null) {
                // The in call service of default phone app is disabled, send notification.
                // The in call service of default phone app is disabled, send notification.
@@ -1516,7 +1523,7 @@ public class InCallController extends CallsManagerListenerBase {


    private InCallServiceInfo getCurrentCarModeComponent() {
    private InCallServiceInfo getCurrentCarModeComponent() {
        return getInCallServiceComponent(mCarModeTracker.getCurrentCarModePackage(),
        return getInCallServiceComponent(mCarModeTracker.getCurrentCarModePackage(),
                IN_CALL_SERVICE_TYPE_CAR_MODE_UI);
                IN_CALL_SERVICE_TYPE_CAR_MODE_UI, true /* ignoreDisabled */);
    }
    }


    private InCallServiceInfo getInCallServiceComponent(ComponentName componentName, int type) {
    private InCallServiceInfo getInCallServiceComponent(ComponentName componentName, int type) {
@@ -1531,8 +1538,10 @@ public class InCallController extends CallsManagerListenerBase {
        }
        }
    }
    }


    private InCallServiceInfo getInCallServiceComponent(String packageName, int type) {
    private InCallServiceInfo getInCallServiceComponent(String packageName, int type,
        List<InCallServiceInfo> list = getInCallServiceComponents(packageName, type);
            boolean ignoreDisabled) {
        List<InCallServiceInfo> list = getInCallServiceComponents(packageName, type,
                ignoreDisabled);
        if (list != null && !list.isEmpty()) {
        if (list != null && !list.isEmpty()) {
            return list.get(0);
            return list.get(0);
        }
        }
@@ -1543,8 +1552,9 @@ public class InCallController extends CallsManagerListenerBase {
        return getInCallServiceComponents(null, null, type);
        return getInCallServiceComponents(null, null, type);
    }
    }


    private List<InCallServiceInfo> getInCallServiceComponents(String packageName, int type) {
    private List<InCallServiceInfo> getInCallServiceComponents(String packageName, int type,
        return getInCallServiceComponents(packageName, null, type);
            boolean ignoreDisabled) {
        return getInCallServiceComponents(packageName, null, type, ignoreDisabled);
    }
    }


    private List<InCallServiceInfo> getInCallServiceComponents(ComponentName componentName,
    private List<InCallServiceInfo> getInCallServiceComponents(ComponentName componentName,
@@ -1554,6 +1564,12 @@ public class InCallController extends CallsManagerListenerBase {


    private List<InCallServiceInfo> getInCallServiceComponents(String packageName,
    private List<InCallServiceInfo> getInCallServiceComponents(String packageName,
            ComponentName componentName, int requestedType) {
            ComponentName componentName, int requestedType) {
        return getInCallServiceComponents(packageName, componentName, requestedType,
                true /* ignoreDisabled */);
    }

    private List<InCallServiceInfo> getInCallServiceComponents(String packageName,
            ComponentName componentName, int requestedType, boolean ignoreDisabled) {
        List<InCallServiceInfo> retval = new LinkedList<>();
        List<InCallServiceInfo> retval = new LinkedList<>();


        Intent serviceIntent = new Intent(InCallService.SERVICE_INTERFACE);
        Intent serviceIntent = new Intent(InCallService.SERVICE_INTERFACE);
@@ -1594,7 +1610,8 @@ public class InCallController extends CallsManagerListenerBase {
                } else {
                } else {
                    isRequestedType = requestedType == currentType;
                    isRequestedType = requestedType == currentType;
                }
                }
                if (isEnabled && isRequestedType) {

                if ((!ignoreDisabled || isEnabled) && isRequestedType) {
                    retval.add(new InCallServiceInfo(foundComponentName, isExternalCallsSupported,
                    retval.add(new InCallServiceInfo(foundComponentName, isExternalCallsSupported,
                            isSelfManageCallsSupported, requestedType));
                            isSelfManageCallsSupported, requestedType));
                }
                }
@@ -2009,8 +2026,11 @@ public class InCallController extends CallsManagerListenerBase {
     * {@code false} otherwise.
     * {@code false} otherwise.
     */
     */
    private boolean isCarModeInCallService(@NonNull String packageName) {
    private boolean isCarModeInCallService(@NonNull String packageName) {
        // Disabled InCallService should also be considered as a valid InCallService here so that
        // it can be added to the CarModeTracker, in case it will be enabled in future.
        InCallServiceInfo info =
        InCallServiceInfo info =
                getInCallServiceComponent(packageName, IN_CALL_SERVICE_TYPE_CAR_MODE_UI);
                getInCallServiceComponent(packageName, IN_CALL_SERVICE_TYPE_CAR_MODE_UI,
                        false /* ignoreDisabled */);
        return info != null && info.getType() == IN_CALL_SERVICE_TYPE_CAR_MODE_UI;
        return info != null && info.getType() == IN_CALL_SERVICE_TYPE_CAR_MODE_UI;
    }
    }