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

Commit 5be4bc23 authored by joonhunshin's avatar joonhunshin Committed by Joonhun Shin
Browse files

Add checking Location service status before notification CarrierRoamingNtnEligible

Bug: 388600692
Test: atest SatelliteControllerTest
      manual test b/398686724
Flag: EXEMPT (bug fix)
Change-Id: I830e04d00e2e640f19c5a63acaf568c7f2447a6f
parent e41480ed
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ import android.content.res.Resources;
import android.database.ContentObserver;
import android.hardware.devicestate.DeviceState;
import android.hardware.devicestate.DeviceStateManager;
import android.location.LocationManager;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.nfc.NfcAdapter;
@@ -312,6 +313,7 @@ public class SatelliteController extends Handler {
    private static final int EVENT_UPDATE_SYSTEM_SELECTION_CHANNELS_DONE = 59;
    private static final int EVENT_SELECTED_NB_IOT_SATELLITE_SUBSCRIPTION_CHANGED = 60;
    private static final int CMD_EVALUATE_CARRIER_ROAMING_NTN_ELIGIBILITY_CHANGE = 61;
    private static final int CMD_LOCATION_SERVICE_STATE_CHANGED = 62;

    @NonNull private static SatelliteController sInstance;
    @NonNull private final Context mContext;
@@ -731,6 +733,17 @@ public class SatelliteController extends Handler {
        }
    };

    protected BroadcastReceiver mLocationServiceStateChangedReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            // Check whether user has turned on/off location manager from settings menu
            if (intent.getAction().equals(LocationManager.MODE_CHANGED_ACTION)) {
                plogd("mLocationServiceStateChangedReceiver");
                sendRequestAsync(CMD_LOCATION_SERVICE_STATE_CHANGED, null, null);
            }
        }
    };

    // List of device states returned from DeviceStateManager to determine if running on a foldable
    // device.
    private List<DeviceState> mDeviceStates = new ArrayList();
@@ -931,6 +944,7 @@ public class SatelliteController extends Handler {

        mSatellitePlmnListFromOverlayConfig = readSatellitePlmnsFromOverlayConfig();
        registerApplicationStateChanged();
        registerLocationServiceStateChanged();
        updateSupportedSatelliteServicesForActiveSubscriptions();
        mCarrierConfigChangeListener =
                (slotIndex, subId, carrierId, specificCarrierId) ->
@@ -2180,6 +2194,9 @@ public class SatelliteController extends Handler {
                break;
            }

            case CMD_LOCATION_SERVICE_STATE_CHANGED:
                plogd("CMD_LOCATION_SERVICE_STATE_CHANGED");
                // Fall through
            case CMD_EVALUATE_CARRIER_ROAMING_NTN_ELIGIBILITY_CHANGE: {
                plogd("CMD_EVALUATE_CARRIER_ROAMING_NTN_ELIGIBILITY_CHANGE");
                evaluateCarrierRoamingNtnEligibilityChange();
@@ -7893,6 +7910,13 @@ public class SatelliteController extends Handler {
            return false;
        }

        // Even if Location service is off, isSatelliteAccessAllowed can be true
        // when the device is in emergency call and the allowed cache is valid.
        if (!isLocationServiceEnabled()) {
            plogd("isCarrierRoamingNtnEligible: Location service is off");
            return false;
        }

        if (phone == null) {
            plogd("isCarrierRoamingNtnEligible: phone is null");
            return false;
@@ -8522,6 +8546,12 @@ public class SatelliteController extends Handler {
                mContext.RECEIVER_EXPORTED);
    }

    private void registerLocationServiceStateChanged() {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(LocationManager.MODE_CHANGED_ACTION);
        mContext.registerReceiver(mLocationServiceStateChangedReceiver, intentFilter);
    }


    private void notifyEnabledStateChanged(boolean isEnabled) {
        TelephonyRegistryManager trm = mContext.getSystemService(TelephonyRegistryManager.class);
@@ -8762,6 +8792,17 @@ public class SatelliteController extends Handler {
                == NetworkRegistrationInfo.SERVICE_TYPE_DATA);
    }

    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected boolean isLocationServiceEnabled() {
        LocationManager lm = mContext.createAttributionContext("telephony")
                .getSystemService(LocationManager.class);
        if (lm != null) {
            return lm.isLocationEnabled();
        }

        return true;
    }

    /**
     * Method to return the current satellite data service policy supported mode for the registered
     * plmn based on entitlement provisioning information. Note: If no information at
+78 −0
Original line number Diff line number Diff line
@@ -134,6 +134,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.hardware.devicestate.DeviceState;
import android.location.LocationManager;
import android.net.Uri;
import android.os.AsyncResult;
import android.os.Bundle;
@@ -285,6 +286,7 @@ public class SatelliteControllerTest extends TelephonyTest {
    @Mock private SubscriptionManager mSubscriptionManager;
    @Mock private SubscriptionInfo mSubscriptionInfo;
    @Mock private PackageManager mMockPManager;
    @Mock private Intent mMockLocationIntent;

    private Semaphore mIIntegerConsumerSemaphore = new Semaphore(0);
    private IIntegerConsumer mIIntegerConsumer = new IIntegerConsumer.Stub() {
@@ -6003,6 +6005,8 @@ public class SatelliteControllerTest extends TelephonyTest {
        private boolean callOnlySuperMethod = false;
        public boolean isSatelliteEnabledOrBeingEnabled = false;

        private boolean mLocationServiceEnabled = true;

        TestSatelliteController(
                Context context, Looper looper, @NonNull FeatureFlags featureFlags) {
            super(context, looper, featureFlags);
@@ -6124,6 +6128,11 @@ public class SatelliteControllerTest extends TelephonyTest {
            return selectedSatelliteSubId;
        }

        @Override
        protected boolean isLocationServiceEnabled() {
            return mLocationServiceEnabled;
        }

        void setSatelliteProvisioned(@Nullable Boolean isProvisioned) {
            synchronized (mDeviceProvisionLock) {
                mIsDeviceProvisioned = isProvisioned;
@@ -6201,6 +6210,14 @@ public class SatelliteControllerTest extends TelephonyTest {
        public void setCallOnlySuperMethod() {
            callOnlySuperMethod = true;
        }

        public void  setLocationServiceEnabled(boolean locationServiceEnabled) {
            mLocationServiceEnabled = locationServiceEnabled;
        }

        public BroadcastReceiver getLocationReceiver() {
            return mLocationServiceStateChangedReceiver;
        }
    }

    @Test
@@ -6923,4 +6940,65 @@ public class SatelliteControllerTest extends TelephonyTest {
        processAllMessages();
        verify(mPhone, times(0)).notifyCarrierRoamingNtnEligibleStateChanged(anyBoolean());
    }

    @Test
    public void testNotifyNtnEligibilityLocationServiceStatusChanged() {
        // Enable CarrierRoamingNtn
        mContextFixture.putBooleanResource(
                R.bool.config_satellite_should_notify_availability, true);
        when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(true);
        when(mServiceState2.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
        when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
        mSatelliteControllerUT.mIsApplicationSupportsP2P = true;
        mSatelliteControllerUT.setIsSatelliteSupported(true);
        mCarrierConfigBundle.putBoolean(KEY_SATELLITE_ATTACH_SUPPORTED_BOOL, true);
        mCarrierConfigBundle.putInt(KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT,
                CARRIER_ROAMING_NTN_CONNECT_MANUAL);
        mCarrierConfigBundle.putInt(
                KEY_CARRIER_SUPPORTED_SATELLITE_NOTIFICATION_HYSTERESIS_SEC_INT, 1 * 60);
        mCarrierConfigBundle.putBoolean(KEY_SATELLITE_ROAMING_P2P_SMS_SUPPORTED_BOOL, true);
        int[] supportedServices2 = {2};
        int[] supportedServices3 = {1, 3};
        PersistableBundle carrierSupportedSatelliteServicesPerProvider = new PersistableBundle();
        carrierSupportedSatelliteServicesPerProvider.putIntArray(
                "00102", supportedServices2);
        carrierSupportedSatelliteServicesPerProvider.putIntArray(
                "00103", supportedServices3);
        mCarrierConfigBundle.putPersistableBundle(CarrierConfigManager
                        .KEY_CARRIER_SUPPORTED_SATELLITE_SERVICES_PER_PROVIDER_BUNDLE,
                carrierSupportedSatelliteServicesPerProvider);
        for (Pair<Executor, CarrierConfigManager.CarrierConfigChangeListener> pair
                : mCarrierConfigChangedListenerList) {
            pair.first.execute(() -> pair.second.onCarrierConfigChanged(
                    /*slotIndex*/ 0, /*subId*/ SUB_ID, /*carrierId*/ 0, /*specificCarrierId*/ 0)
            );
        }
        mSatelliteControllerUT.setSatellitePhone(1);
        mSatelliteControllerUT.setSelectedSatelliteSubId(SUB_ID);
        mSatelliteControllerUT.isSatelliteProvisioned = true;
        mSatelliteControllerUT.isSatelliteAllowedCallback = null;
        mSatelliteControllerUT.setIsSatelliteAllowedState(true);
        processAllMessages();
        clearInvocations(mPhone);

        doReturn(LocationManager.MODE_CHANGED_ACTION).when(mMockLocationIntent).getAction();

        // Location service off
        mSatelliteControllerUT.setLocationServiceEnabled(false);
        BroadcastReceiver receiver = mSatelliteControllerUT.getLocationReceiver();
        receiver.onReceive(mContext, mMockLocationIntent);

        processAllMessages();

        verify(mPhone, times(1)).notifyCarrierRoamingNtnEligibleStateChanged(eq(false));
        clearInvocations(mPhone);

        // Location service off
        mSatelliteControllerUT.setLocationServiceEnabled(true);
        receiver.onReceive(mContext, mMockLocationIntent);

        processAllMessages();

        verify(mPhone, times(1)).notifyCarrierRoamingNtnEligibleStateChanged(eq(true));
    }
}