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

Commit ffe522ba authored by Kenneth Ford's avatar Kenneth Ford Committed by Android (Google) Code Review
Browse files

Merge "Update SatelliteController to use DeviceState property API" into main

parents b6e87b41 33ae8657
Loading
Loading
Loading
Loading
+29 −3
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.internal.telephony.satellite;

import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY;
import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY;
import static android.provider.Settings.ACTION_SATELLITE_SETTING;
import static android.telephony.CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_MANUAL;
import static android.telephony.CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_TYPE;
@@ -74,6 +76,8 @@ import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.hardware.devicestate.DeviceState;
import android.hardware.devicestate.DeviceStateManager;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.nfc.NfcAdapter;
@@ -592,6 +596,10 @@ public class SatelliteController extends Handler {
                }
            };

    // List of device states returned from DeviceStateManager to determine if running on a foldable
    // device.
    private List<DeviceState> mDeviceStates = new ArrayList();

    /**
     * @return The singleton instance of SatelliteController.
     */
@@ -740,6 +748,9 @@ public class SatelliteController extends Handler {
        }
        registerDefaultSmsSubscriptionChangedBroadcastReceiver();
        updateSatelliteProvisionedStatePerSubscriberId();
        if (android.hardware.devicestate.feature.flags.Flags.deviceStatePropertyMigration()) {
            mDeviceStates = getSupportedDeviceStates();
        }
    }

    class SatelliteSubscriptionsChangedListener
@@ -4323,7 +4334,8 @@ public class SatelliteController extends Handler {
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected void setSettingsKeyToAllowDeviceRotation(int val) {
        // Only allows on a foldable device type.
        if (!isFoldable(mContext)) {
        if (!isFoldable(mContext, mDeviceStates)) {
            logd("setSettingsKeyToAllowDeviceRotation(" + val + "), device was not a foldable");
            return;
        }

@@ -4364,11 +4376,20 @@ public class SatelliteController extends Handler {
     * If the device type is foldable.
     *
     * @param context context
     * @param deviceStates list of {@link DeviceState}s provided from {@link DeviceStateManager}
     * @return {@code true} if device type is foldable. {@code false} for otherwise.
     */
    private boolean isFoldable(Context context) {
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    public boolean isFoldable(Context context, List<DeviceState> deviceStates) {
        if (android.hardware.devicestate.feature.flags.Flags.deviceStatePropertyMigration()) {
            return deviceStates.stream().anyMatch(deviceState -> deviceState.hasProperty(
                    PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY)
                    || deviceState.hasProperty(
                    PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY));
        } else {
            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.
@@ -6860,6 +6881,11 @@ public class SatelliteController extends Handler {
        mContext.registerReceiver(mDefaultSmsSubscriptionChangedBroadcastReceiver, intentFilter);
    }

    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected List<DeviceState> getSupportedDeviceStates() {
        return mContext.getSystemService(DeviceStateManager.class).getSupportedDeviceStates();
    }

    FeatureFlags getFeatureFlags() {
        return mFeatureFlags;
    }
+60 −1
Original line number Diff line number Diff line
@@ -16,6 +16,11 @@

package com.android.internal.telephony.satellite;

import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY;
import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY;
import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_CLOSED;
import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_OPEN;
import static android.hardware.devicestate.feature.flags.Flags.FLAG_DEVICE_STATE_PROPERTY_MIGRATION;
import static android.telephony.CarrierConfigManager.KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT;
import static android.telephony.CarrierConfigManager.KEY_CARRIER_SUPPORTED_SATELLITE_NOTIFICATION_HYSTERESIS_SEC_INT;
import static android.telephony.CarrierConfigManager.KEY_EMERGENCY_CALL_TO_SATELLITE_T911_HANDOVER_TIMEOUT_MILLIS_INT;
@@ -110,6 +115,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.hardware.devicestate.DeviceState;
import android.os.AsyncResult;
import android.os.Bundle;
import android.os.CancellationSignal;
@@ -121,6 +127,10 @@ import android.os.OutcomeReceiver;
import android.os.PersistableBundle;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.platform.test.annotations.RequiresFlagsDisabled;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.telephony.AccessNetworkConstants;
import android.telephony.CarrierConfigManager;
import android.telephony.CellSignalStrength;
@@ -168,6 +178,7 @@ import com.android.internal.telephony.subscription.SubscriptionManagerService;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -515,6 +526,10 @@ public class SatelliteControllerTest extends TelephonyTest {
        }
    };

    @Rule
    public final CheckFlagsRule mCheckFlagsRule =
            DeviceFlagsValueProvider.createCheckFlagsRule();

    @Before
    public void setUp() throws Exception {
        super.setUp(getClass().getSimpleName());
@@ -563,6 +578,9 @@ public class SatelliteControllerTest extends TelephonyTest {
        mContextFixture.putIntResource(
                R.integer.config_satellite_wait_for_cellular_modem_off_timeout_millis,
                TEST_WAIT_FOR_CELLULAR_MODEM_OFF_TIMEOUT_MILLIS);
        mContextFixture.putIntArrayResource(
                R.array.config_foldedDeviceStates,
                new int[0]);
        doReturn(ACTIVE_SUB_IDS).when(mMockSubscriptionManagerService).getActiveSubIdList(true);

        mCarrierConfigBundle = mContextFixture.getCarrierConfigBundle();
@@ -4234,6 +4252,41 @@ public class SatelliteControllerTest extends TelephonyTest {
        assertEquals(expectedErrorCode, resultErrorCode[0]);
    }

    @RequiresFlagsDisabled(FLAG_DEVICE_STATE_PROPERTY_MIGRATION)
    @Test
    public void testDetermineIsFoldable_overlayConfigurationValues() {
        // isFoldable should return false with the base configuration.
        assertFalse(mSatelliteControllerUT.isFoldable(mContext,
                mSatelliteControllerUT.getSupportedDeviceStates()));

        mContextFixture.putIntArrayResource(R.array.config_foldedDeviceStates, new int[2]);
        assertTrue(mSatelliteControllerUT.isFoldable(mContext,
                mSatelliteControllerUT.getSupportedDeviceStates()));
    }

    @RequiresFlagsEnabled(FLAG_DEVICE_STATE_PROPERTY_MIGRATION)
    @Test
    public void testDetermineIsFoldable_deviceStateManager() {
        // isFoldable should return false with the base configuration.
        assertFalse(mSatelliteControllerUT.isFoldable(mContext,
                mSatelliteControllerUT.getSupportedDeviceStates()));

        DeviceState foldedDeviceState = new DeviceState(new DeviceState.Configuration.Builder(
                0 /* identifier */, "FOLDED")
                .setSystemProperties(Set.of(PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY))
                .setPhysicalProperties(
                        Set.of(PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_CLOSED))
                .build());
        DeviceState unfoldedDeviceState = new DeviceState(new DeviceState.Configuration.Builder(
                1 /* identifier */, "UNFOLDED")
                .setSystemProperties(Set.of(PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY))
                .setPhysicalProperties(
                        Set.of(PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_OPEN))
                .build());
        List<DeviceState> foldableDeviceStateList = List.of(foldedDeviceState, unfoldedDeviceState);
        assertTrue(mSatelliteControllerUT.isFoldable(mContext, foldableDeviceStateList));
    }

    private boolean mProvisionState = false;
    private int mProvisionSateResultCode = -1;
    private Semaphore mProvisionSateSemaphore = new Semaphore(0);
@@ -5513,6 +5566,12 @@ public class SatelliteControllerTest extends TelephonyTest {
            return false;
        }

        @Override
        protected List<DeviceState> getSupportedDeviceStates() {
            return List.of(new DeviceState(new DeviceState.Configuration.Builder(0 /* identifier */,
                    "DEFAULT" /* name */).build()));
        }

        void setSatelliteProvisioned(@Nullable Boolean isProvisioned) {
            synchronized (mSatelliteViaOemProvisionLock) {
                mIsSatelliteViaOemProvisioned = isProvisioned;
+30 −2
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.hardware.devicestate.DeviceState;
import android.net.Uri;
import android.os.Bundle;
import android.os.Looper;
@@ -551,12 +552,13 @@ public class SatelliteSOSMessageRecommenderTest extends TelephonyTest {

    @Test
    public void testOnEmergencyCallStarted() {
        SatelliteController satelliteController = new SatelliteController(
                mContext, Looper.myLooper(), mFeatureFlags);
        SatelliteController satelliteController = new MinimalSatelliteControllerWrapper(mContext,
                Looper.myLooper(), mFeatureFlags);
        TestSOSMessageRecommender testSOSMessageRecommender = new TestSOSMessageRecommender(
                mContext,
                Looper.myLooper(),
                satelliteController, mTestImsManager);
        mTestSatelliteController.setSatelliteConnectedViaCarrierWithinHysteresisTime(true);
        testSOSMessageRecommender.onEmergencyCallStarted(mTestConnection, false);
        processAllMessages();

@@ -846,6 +848,12 @@ public class SatelliteSOSMessageRecommenderTest extends TelephonyTest {
            return carrierEmergencyCallWaitForConnectionTimeoutMillis;
        }

        @Override
        protected List<DeviceState> getSupportedDeviceStates() {
            return List.of(new DeviceState(new DeviceState.Configuration.Builder(0 /* identifier */,
                    "DEFAULT" /* name */).build()));
        }

        public void setSatelliteConnectedViaCarrierWithinHysteresisTime(
                boolean connectedViaCarrier) {
            mIsSatelliteConnectedViaCarrierWithinHysteresisTime = connectedViaCarrier;
@@ -879,6 +887,26 @@ public class SatelliteSOSMessageRecommenderTest extends TelephonyTest {
        }
    }

    /**
     * Now that {@link SatelliteController} uses
     * {@link android.hardware.devicestate.DeviceStateManager} to determine if a device is a
     * foldable or not, we have to provide a minimal wrapper for {@link SatelliteController} for
     * tests that want to use a non-fake {@link SatelliteController}.
     */
    private static class MinimalSatelliteControllerWrapper extends SatelliteController {

        protected MinimalSatelliteControllerWrapper(
                Context context, Looper looper, FeatureFlags featureFlags) {
            super(context, looper, featureFlags);
        }

        @Override
        protected List<DeviceState> getSupportedDeviceStates() {
            return List.of(new DeviceState(new DeviceState.Configuration.Builder(0 /* identifier */,
                    "DEFAULT" /* name */).build()));
        }
    }

    private static class TestImsManager extends ImsManager {

        private final List<RegistrationManager.RegistrationCallback> mCallbacks;