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

Commit ddc2de8d authored by youngtaecha's avatar youngtaecha Committed by Youngtae Cha
Browse files

Notify SatelliteAccessController when MCC changes

Bug: 347711329
Flag: com.android.internal.telephony.flags.oem_enabled_satellite_flag
Test: Build
Test: atest com.android.internal.telephony.TelephonyCountryDetectorTest

Change-Id: I39eb585d914989743ddf955672488eb609ed2c8b
parent 3a408ad4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -566,7 +566,7 @@ public class LocaleTracker extends Handler {
            }

            if (mFeatureFlags.oemEnabledSatelliteFlag()) {
                TelephonyCountryDetector.getInstance(mPhone.getContext())
                TelephonyCountryDetector.getInstance(mPhone.getContext(), mFeatureFlags)
                        .onNetworkCountryCodeChanged(mPhone, countryIso);
            }
            Intent intent = new Intent(TelephonyManager.ACTION_NETWORK_COUNTRY_CHANGED);
+38 −3
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.util.Pair;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.flags.FeatureFlags;

import java.util.ArrayList;
import java.util.HashMap;
@@ -109,6 +110,10 @@ public class TelephonyCountryDetector extends Handler {
    private Map<String, Long> mOverriddenCachedNetworkCountryCodes = new HashMap<>();
    @GuardedBy("mLock")
    private boolean mIsCountryCodesOverridden = false;
    private final RegistrantList mCountryCodeChangedRegistrants = new RegistrantList();

    private FeatureFlags mFeatureFlags = null;

    @NonNull private final LocationListener mLocationListener = new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {
@@ -186,22 +191,26 @@ public class TelephonyCountryDetector extends Handler {
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected TelephonyCountryDetector(@NonNull Looper looper, @NonNull Context context,
            @NonNull LocationManager locationManager,
            @NonNull ConnectivityManager connectivityManager) {
            @NonNull ConnectivityManager connectivityManager,
            FeatureFlags featureFlags) {
        super(looper);
        mLocationManager = locationManager;
        mGeocoder = new Geocoder(context);
        mConnectivityManager = connectivityManager;
        mFeatureFlags = featureFlags;
        initialize();
    }

    /** @return the singleton instance of the {@link TelephonyCountryDetector} */
    public static synchronized TelephonyCountryDetector getInstance(@NonNull Context context) {
    public static synchronized TelephonyCountryDetector getInstance(@NonNull Context context,
            FeatureFlags featureFlags) {
        if (sInstance == null) {
            HandlerThread handlerThread = new HandlerThread("TelephonyCountryDetector");
            handlerThread.start();
            sInstance = new TelephonyCountryDetector(handlerThread.getLooper(), context,
                    context.getSystemService(LocationManager.class),
                    context.getSystemService(ConnectivityManager.class));
                    context.getSystemService(ConnectivityManager.class),
                    featureFlags);
        }
        return sInstance;
    }
@@ -473,6 +482,12 @@ public class TelephonyCountryDetector extends Handler {
            }
        }
        evaluateRequestingLocationUpdates();
        if (mFeatureFlags.oemEnabledSatelliteFlag()) {
            logd("mCountryCodeChangedRegistrants.notifyRegistrants()");
            mCountryCodeChangedRegistrants.notifyRegistrants();
        } else {
            logd("mCountryCodeChangedRegistrants.notifyRegistrants() is not called");
        }
    }

    private void handleEventWifiConnectivityStateChanged() {
@@ -587,6 +602,26 @@ public class TelephonyCountryDetector extends Handler {
                || SystemProperties.getBoolean(BOOT_ALLOW_MOCK_MODEM_PROPERTY, false));
    }

    /**
     * Register a callback for country code changed events
     *
     * @param h    Handler to notify
     * @param what msg.what when the message is delivered
     * @param obj  AsyncResult.userObj when the message is delivered
     */
    public void registerForCountryCodeChanged(Handler h, int what, Object obj) {
        mCountryCodeChangedRegistrants.add(h, what, obj);
    }

    /**
     * Unregister a callback for country code changed events
     *
     * @param h Handler to notifyf
     */
    public void unregisterForCountryCodeChanged(Handler h) {
        mCountryCodeChangedRegistrants.remove(h);
    }

    private static void logd(@NonNull String log) {
        Rlog.d(TAG, log);
    }
+1 −1
Original line number Diff line number Diff line
@@ -545,7 +545,7 @@ public class SatelliteController extends Handler {
        // to the satellite service and HAL interface.
        mSatelliteModemInterface = SatelliteModemInterface.make(
                mContext, this, mFeatureFlags);
        mCountryDetector = TelephonyCountryDetector.getInstance(context);
        mCountryDetector = TelephonyCountryDetector.getInstance(context, mFeatureFlags);
        mCountryDetector.registerForWifiConnectivityStateChanged(this,
                EVENT_WIFI_CONNECTIVITY_STATE_CHANGED, null);

+12 −5
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import android.util.Pair;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.telephony.flags.FeatureFlags;

import org.junit.After;
import org.junit.Before;
@@ -76,6 +77,8 @@ public class TelephonyCountryDetectorTest extends TelephonyTest {
    LocaleTracker mMockLocaleTracker2;
    @Mock Location mMockLocation;
    @Mock Network mMockNetwork;
    @Mock
    private FeatureFlags mMockFeatureFlags;

    @Captor
    private ArgumentCaptor<LocationListener> mLocationListenerCaptor;
@@ -118,8 +121,9 @@ public class TelephonyCountryDetectorTest extends TelephonyTest {

        when(mLocationManager.getProviders(true)).thenReturn(Arrays.asList("TEST_PROVIDER"));

        when(mMockFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(true);
        mCountryDetectorUT = new TestTelephonyCountryDetector(
                mLooper, mContext, mLocationManager, mConnectivityManager);
                mLooper, mContext, mLocationManager, mConnectivityManager, mMockFeatureFlags);
        if (isGeoCoderImplemented()) {
            verify(mLocationManager).requestLocationUpdates(anyString(), anyLong(), anyFloat(),
                    mLocationListenerCaptor.capture());
@@ -141,8 +145,10 @@ public class TelephonyCountryDetectorTest extends TelephonyTest {
        clearInvocations(mLocationManager);
        clearInvocations(mConnectivityManager);
        when(mMockLocaleTracker.getCurrentCountry()).thenReturn("US");
        TelephonyCountryDetector inst1 = TelephonyCountryDetector.getInstance(mContext);
        TelephonyCountryDetector inst2 = TelephonyCountryDetector.getInstance(mContext);
        TelephonyCountryDetector inst1 = TelephonyCountryDetector
                .getInstance(mContext, mMockFeatureFlags);
        TelephonyCountryDetector inst2 = TelephonyCountryDetector
                .getInstance(mContext, mMockFeatureFlags);
        assertEquals(inst1, inst2);
        if (isGeoCoderImplemented()) {
            verify(mLocationManager, never()).requestLocationUpdates(anyString(), anyLong(),
@@ -386,8 +392,9 @@ public class TelephonyCountryDetectorTest extends TelephonyTest {
         * @param locationManager  The LocationManager instance.
         */
        TestTelephonyCountryDetector(Looper looper, Context context,
                LocationManager locationManager, ConnectivityManager connectivityManager) {
            super(looper, context, locationManager, connectivityManager);
                LocationManager locationManager, ConnectivityManager connectivityManager,
                FeatureFlags featureFlags) {
            super(looper, context, locationManager, connectivityManager, featureFlags);
        }

        @Override