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

Commit 85c95173 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 11949167 from 046c3e8a to 24Q3-release

Change-Id: I63bf1015ca12193179d3fa7d62c280848ab73d0f
parents 20429deb 046c3e8a
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -271,7 +271,9 @@ public class DomainSelectionController {
                mHandler,
                mRestartBindingRunnable);

        int numPhones = TelephonyManager.getDefault().getActiveModemCount();
        TelephonyManager tm = mContext.getSystemService(TelephonyManager.class);
        int numPhones = tm.getSupportedModemCount();
        logi("numPhones=" + numPhones);
        mConnectionCounts = new int[numPhones];
        for (int i = 0; i < numPhones; i++) {
            mConnectionCounts[i] = 0;
+109 −0
Original line number Diff line number Diff line
@@ -133,6 +133,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -440,6 +441,9 @@ public class SatelliteController extends Handler {
    private long mSessionStartTimeStamp;
    private long mSessionProcessingTimeStamp;

    // Variable for backup and restore device's screen rotation settings.
    private String mDeviceRotationLockToBackupAndRestore = null;

    /**
     * @return The singleton instance of SatelliteController.
     */
@@ -995,6 +999,7 @@ public class SatelliteController extends Handler {
                            mWaitingForRadioDisabled = true;
                        }
                        setSettingsKeyForSatelliteMode(SATELLITE_MODE_ENABLED_TRUE);
                        setSettingsKeyToAllowDeviceRotation(SATELLITE_MODE_ENABLED_TRUE);
                        evaluateToSendSatelliteEnabledSuccess();
                    } else {
                        /**
@@ -3582,6 +3587,109 @@ public class SatelliteController extends Handler {
                    Settings.Global.SATELLITE_MODE_ENABLED, val);
    }

    /**
     * Allow screen rotation temporary in rotation locked foldable device.
     * <p>
     * Temporarily allow screen rotation user to catch satellite signals properly by UI guide in
     * emergency situations. Unlock the setting value so that the screen rotation is not locked, and
     * return it to the original value when the satellite service is finished.
     * <p>
     * Note that, only the unfolded screen will be temporarily allowed screen rotation.
     *
     * @param val {@link SATELLITE_MODE_ENABLED_TRUE} if satellite mode is enabled,
     *     {@link SATELLITE_MODE_ENABLED_FALSE} satellite mode is not enabled.
     */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected void setSettingsKeyToAllowDeviceRotation(int val) {
        // Only allows on a foldable device type.
        if (!isFoldable(mContext)) {
            return;
        }

        switch (val) {
            case SATELLITE_MODE_ENABLED_TRUE:
                mDeviceRotationLockToBackupAndRestore =
                        Settings.Secure.getString(mContentResolver,
                                Settings.Secure.DEVICE_STATE_ROTATION_LOCK);
                String unlockedRotationSettings = replaceDeviceRotationValue(
                        mDeviceRotationLockToBackupAndRestore == null
                                ? "" : mDeviceRotationLockToBackupAndRestore,
                        Settings.Secure.DEVICE_STATE_ROTATION_KEY_UNFOLDED,
                        Settings.Secure.DEVICE_STATE_ROTATION_LOCK_UNLOCKED);
                Settings.Secure.putString(mContentResolver,
                        Settings.Secure.DEVICE_STATE_ROTATION_LOCK, unlockedRotationSettings);
                logd("setSettingsKeyToAllowDeviceRotation(TRUE), RotationSettings is changed"
                        + " from " + mDeviceRotationLockToBackupAndRestore
                        + " to " + unlockedRotationSettings);
                break;
            case SATELLITE_MODE_ENABLED_FALSE:
                if (mDeviceRotationLockToBackupAndRestore == null) {
                    break;
                }
                Settings.Secure.putString(mContentResolver,
                        Settings.Secure.DEVICE_STATE_ROTATION_LOCK,
                        mDeviceRotationLockToBackupAndRestore);
                logd("setSettingsKeyToAllowDeviceRotation(FALSE), RotationSettings is restored to"
                        + mDeviceRotationLockToBackupAndRestore);
                mDeviceRotationLockToBackupAndRestore = "";
                break;
            default:
                loge("setSettingsKeyToAllowDeviceRotation(" + val + "), never reach here.");
                break;
        }
    }

    /**
     * If the device type is foldable.
     *
     * @param context context
     * @return {@code true} if device type is foldable. {@code false} for otherwise.
     */
    private boolean isFoldable(Context context) {
        return context.getResources().getIntArray(R.array.config_foldedDeviceStates).length > 0;
    }

    /**
     * Replaces a value of given a target key with a new value in a string of key-value pairs.
     * <p>
     * Replaces the value corresponding to the target key with a new value. If the key value is not
     * found in the device rotation information, it is not replaced.
     *
     * @param deviceRotationValue Device rotation key values separated by colon(':').
     * @param targetKey The key of the new item caller wants to add.
     * @param newValue  The value of the new item caller want to add.
     * @return A new string where all the key-value pairs.
     */
    private static String replaceDeviceRotationValue(
            @NonNull String deviceRotationValue, int targetKey, int newValue) {
        // Use list of Key-Value pair
        List<Pair<Integer, Integer>> keyValuePairs = new ArrayList<>();

        String[] pairs = deviceRotationValue.split(":");
        if (pairs.length % 2 != 0) {
            // Return without modifying. The key-value may be incorrect if length is an odd number.
            loge("The length of key-value pair do not match. Return without modification.");
            return deviceRotationValue;
        }

        // collect into keyValuePairs
        for (int i = 0; i < pairs.length; i += 2) {
            try {
                int key = Integer.parseInt(pairs[i]);
                int value = Integer.parseInt(pairs[i + 1]);
                keyValuePairs.add(new Pair<>(key, key == targetKey ? newValue : value));
            } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
                // Return without modifying if got exception.
                loge("got error while parsing key-value. Return without modification. e:" + e);
                return deviceRotationValue;
            }
        }

        return keyValuePairs.stream()
                .map(pair -> pair.first + ":" + pair.second) // Convert to "key:value" format
                .collect(Collectors.joining(":")); // Join pairs with colons
    }

    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected boolean areAllRadiosDisabled() {
        synchronized (mRadioStateLock) {
@@ -3636,6 +3744,7 @@ public class SatelliteController extends Handler {
            mIsEmergency = false;
            mIsSatelliteEnabled = false;
            setSettingsKeyForSatelliteMode(SATELLITE_MODE_ENABLED_FALSE);
            setSettingsKeyToAllowDeviceRotation(SATELLITE_MODE_ENABLED_FALSE);
            if (callback != null) callback.accept(error);
            updateSatelliteEnabledState(
                    false, "moveSatelliteToOffStateAndCleanUpResources");
+50 −1
Original line number Diff line number Diff line
@@ -16,8 +16,11 @@

package com.android.internal.telephony.domainselection;

import static android.telephony.DomainSelectionService.SELECTOR_TYPE_CALLING;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;

import static org.mockito.ArgumentMatchers.any;
@@ -36,6 +39,8 @@ import android.os.Handler;
import android.os.Looper;
import android.os.RemoteException;
import android.telephony.DomainSelectionService;
import android.telephony.TelephonyManager;
import android.test.mock.MockContext;

import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
@@ -71,6 +76,8 @@ public class DomainSelectionControllerTest extends TelephonyTest {
                }
            };

    Context mTestContext;

    // Mocked classes
    IDomainSelectionServiceController mMockServiceControllerBinder;
    Context mMockContext;
@@ -84,9 +91,40 @@ public class DomainSelectionControllerTest extends TelephonyTest {
    public void setUp() throws Exception {
        super.setUp(this.getClass().getSimpleName());

        when(mTelephonyManager.getSupportedModemCount()).thenReturn(2);
        mMockContext = mock(Context.class);
        mTestContext = new MockContext() {
            @Override
            public String getSystemServiceName(Class<?> serviceClass) {
                if (serviceClass == TelephonyManager.class) {
                    return Context.TELEPHONY_SERVICE;
                }
                return super.getSystemServiceName(serviceClass);
            }

            @Override
            public Object getSystemService(String name) {
                switch (name) {
                    case (Context.TELEPHONY_SERVICE) : {
                        return mTelephonyManager;
                    }
                }
                return super.getSystemService(name);
            }

            @Override
            public boolean bindService(Intent service, ServiceConnection conn, int flags) {
                return mMockContext.bindService(service, conn, flags);
            }

            @Override
            public void unbindService(ServiceConnection conn) {
                mMockContext.unbindService(conn);
            }
        };

        mMockServiceControllerBinder = mock(IDomainSelectionServiceController.class);
        mTestController = new DomainSelectionController(mMockContext,
        mTestController = new DomainSelectionController(mTestContext,
                Looper.getMainLooper(), BIND_RETRY);
        mHandler = mTestController.getHandlerForTest();

@@ -264,6 +302,17 @@ public class DomainSelectionControllerTest extends TelephonyTest {
        verify(mMockContext, times(1)).bindService(any(), any(), anyInt());
    }

    @SmallTest
    @Test
    public void testGetDomainSelectionConnection() throws Exception {
        when(mPhone.getPhoneId()).thenReturn(1);
        DomainSelectionConnection dsc = mTestController.getDomainSelectionConnection(
                mPhone, SELECTOR_TYPE_CALLING, false);

        assertNotNull(dsc);
        assertTrue(dsc instanceof NormalCallDomainSelectionConnection);
    }

    private void bindAndNullServiceError() {
        ServiceConnection connection = bindService(mTestComponentName);
        connection.onNullBinding(mTestComponentName);
+19 −0
Original line number Diff line number Diff line
@@ -786,6 +786,7 @@ public class SatelliteControllerTest extends TelephonyTest {
        // Successfully enable satellite
        mIIntegerConsumerResults.clear();
        mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled = false;
        mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled = false;
        setUpResponseForRequestSatelliteEnabled(true, false, false, SATELLITE_RESULT_SUCCESS);
        mSatelliteControllerUT.requestSatelliteEnabled(SUB_ID, true, false, false,
                mIIntegerConsumer);
@@ -795,6 +796,7 @@ public class SatelliteControllerTest extends TelephonyTest {
        assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0));
        verifySatelliteEnabled(true, SATELLITE_RESULT_SUCCESS);
        assertTrue(mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled);
        assertTrue(mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled);
        assertEquals(
                SATELLITE_MODE_ENABLED_TRUE, mSatelliteControllerUT.satelliteModeSettingValue);
        verify(mMockSatelliteSessionController, times(1)).onSatelliteEnabledStateChanged(eq(true));
@@ -805,6 +807,7 @@ public class SatelliteControllerTest extends TelephonyTest {

        // Successfully disable satellite when radio is turned off.
        mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled = false;
        mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled = false;
        setUpResponseForRequestSatelliteEnabled(false, false, false, SATELLITE_RESULT_SUCCESS);
        setRadioPower(false);
        mSatelliteControllerUT.onCellularRadioPowerOffRequested();
@@ -813,6 +816,7 @@ public class SatelliteControllerTest extends TelephonyTest {
        processAllMessages();
        verifySatelliteEnabled(false, SATELLITE_RESULT_SUCCESS);
        assertTrue(mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled);
        assertTrue(mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled);
        assertEquals(
                SATELLITE_MODE_ENABLED_FALSE, mSatelliteControllerUT.satelliteModeSettingValue);
        verify(mMockSatelliteSessionController, times(2)).onSatelliteEnabledStateChanged(eq(false));
@@ -838,6 +842,7 @@ public class SatelliteControllerTest extends TelephonyTest {
        mIIntegerConsumerResults.clear();
        clearInvocations(mMockPointingAppController);
        mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled = false;
        mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled = false;
        setUpResponseForRequestSatelliteEnabled(true, false, false,
                SATELLITE_RESULT_INVALID_MODEM_STATE);
        mSatelliteControllerUT.requestSatelliteEnabled(SUB_ID, true, false, false,
@@ -849,11 +854,13 @@ public class SatelliteControllerTest extends TelephonyTest {
        verify(mMockPointingAppController, never()).startPointingUI(anyBoolean(), anyBoolean(),
                anyBoolean());
        assertFalse(mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled);
        assertFalse(mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled);
        verify(mMockControllerMetricsStats, times(1)).reportServiceEnablementFailCount();

        // Successfully enable satellite when radio is on.
        mIIntegerConsumerResults.clear();
        mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled = false;
        mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled = false;
        setUpResponseForRequestSatelliteEnabled(true, false, false, SATELLITE_RESULT_SUCCESS);
        mSatelliteControllerUT.requestSatelliteEnabled(SUB_ID, true, false, false,
                mIIntegerConsumer);
@@ -862,6 +869,7 @@ public class SatelliteControllerTest extends TelephonyTest {
        assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0));
        verifySatelliteEnabled(true, SATELLITE_RESULT_SUCCESS);
        assertTrue(mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled);
        assertTrue(mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled);
        assertEquals(SATELLITE_MODE_ENABLED_TRUE, mSatelliteControllerUT.satelliteModeSettingValue);
        verify(mMockSatelliteSessionController, times(2)).onSatelliteEnabledStateChanged(eq(true));
        verify(mMockSatelliteSessionController, times(4)).setDemoMode(eq(false));
@@ -3458,6 +3466,7 @@ public class SatelliteControllerTest extends TelephonyTest {

        // startSendingNtnSignalStrength should be invoked when satellite is enabled
        mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled = false;
        mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled = false;
        setUpResponseForRequestSatelliteEnabled(true, false, false, SATELLITE_RESULT_SUCCESS);
        mSatelliteControllerUT.requestSatelliteEnabled(SUB_ID, true, false, false,
                mIIntegerConsumer);
@@ -3466,6 +3475,7 @@ public class SatelliteControllerTest extends TelephonyTest {
        assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0));
        verifySatelliteEnabled(true, SATELLITE_RESULT_SUCCESS);
        assertTrue(mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled);
        assertTrue(mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled);
        assertEquals(
                SATELLITE_MODE_ENABLED_TRUE, mSatelliteControllerUT.satelliteModeSettingValue);
        verify(mMockSatelliteModemInterface, times(1)).startSendingNtnSignalStrength(
@@ -3517,6 +3527,7 @@ public class SatelliteControllerTest extends TelephonyTest {
        reset(mMockSatelliteModemInterface);
        doReturn(true).when(mMockSatelliteModemInterface).isSatelliteServiceSupported();
        mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled = false;
        mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled = false;
        setUpResponseForRequestSatelliteEnabled(true, false, false, SATELLITE_RESULT_SUCCESS);
        mSatelliteControllerUT.requestSatelliteEnabled(SUB_ID, true, false, false,
                mIIntegerConsumer);
@@ -3525,6 +3536,7 @@ public class SatelliteControllerTest extends TelephonyTest {
        assertEquals(SATELLITE_RESULT_SUCCESS, (long) mIIntegerConsumerResults.get(0));
        verifySatelliteEnabled(true, SATELLITE_RESULT_SUCCESS);
        assertTrue(mSatelliteControllerUT.setSettingsKeyForSatelliteModeCalled);
        assertTrue(mSatelliteControllerUT.setSettingsKeyToAllowDeviceRotationCalled);
        assertEquals(
                SATELLITE_MODE_ENABLED_TRUE, mSatelliteControllerUT.satelliteModeSettingValue);
        verify(mMockSatelliteModemInterface, times(1)).startSendingNtnSignalStrength(
@@ -4479,6 +4491,7 @@ public class SatelliteControllerTest extends TelephonyTest {
        public boolean allRadiosDisabled = true;
        public long elapsedRealtime = 0;
        public int satelliteModeSettingValue = SATELLITE_MODE_ENABLED_FALSE;
        public boolean setSettingsKeyToAllowDeviceRotationCalled = false;

        TestSatelliteController(
                Context context, Looper looper, @NonNull FeatureFlags featureFlags) {
@@ -4498,6 +4511,12 @@ public class SatelliteControllerTest extends TelephonyTest {
            setSettingsKeyForSatelliteModeCalled = true;
        }

        @Override
        protected void setSettingsKeyToAllowDeviceRotation(int val) {
            logd("setSettingsKeyToAllowDeviceRotation: val=" + val);
            setSettingsKeyToAllowDeviceRotationCalled = true;
        }

        @Override
        protected boolean areAllRadiosDisabled() {
            return allRadiosDisabled;