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

Commit 067baa06 authored by sqian's avatar sqian
Browse files

Use ActivityManager System API to update Mcc/Mnc configuration in Mainline

Test: Treehugger; TelephonyTest
Bug: 147381728
Bug: 138545688
Change-Id: I102b4b54c9e7da691f8edd1a0f3349ace62a13f8
Merged-In: I102b4b54c9e7da691f8edd1a0f3349ace62a13f8
(cherry picked from commit 7a8a74b9)
parent e4e63765
Loading
Loading
Loading
Loading
+15 −25
Original line number Diff line number Diff line
@@ -21,9 +21,7 @@ import android.annotation.Nullable;
import android.app.ActivityManager;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.text.TextUtils;
import android.timezone.TelephonyLookup;
@@ -285,36 +283,28 @@ public final class MccTable {
        }

        if (!TextUtils.isEmpty(mccmnc)) {
            int mcc, mnc;

            int mccInt;
            try {
                mcc = Integer.parseInt(mccmnc.substring(0, 3));
                mnc = Integer.parseInt(mccmnc.substring(3));
                mccInt = Integer.parseInt(mccmnc.substring(0, 3));
            } catch (NumberFormatException | StringIndexOutOfBoundsException ex) {
                Rlog.e(LOG_TAG, "Error parsing IMSI: " + mccmnc + ". ex=" + ex);
                Rlog.e(LOG_TAG, "Error parsing mccmnc: " + mccmnc + ". ex=" + ex);
                return;
            }

            Rlog.d(LOG_TAG, "updateMccMncConfiguration: mcc=" + mcc + ", mnc=" + mnc);

            try {
                Configuration config = new Configuration();
                boolean updateConfig = false;
                if (mcc != 0) {
                    config.mcc = mcc;
                    config.mnc = mnc == 0 ? Configuration.MNC_ZERO : mnc;
                    updateConfig = true;
            if (mccInt != 0) {
                ActivityManager activityManager = (ActivityManager) context.getSystemService(
                        Context.ACTIVITY_SERVICE);
                if (!activityManager.updateMccMncConfiguration(
                        mccmnc.substring(0, 3), mccmnc.substring(3))) {
                    Rlog.d(LOG_TAG, "updateMccMncConfiguration: update mccmnc="
                            + mccmnc + " failure");
                    return;
                } else {
                    Rlog.d(LOG_TAG, "updateMccMncConfiguration: update mccmnc="
                            + mccmnc + " success");
                }

                if (updateConfig) {
                    Rlog.d(LOG_TAG, "updateMccMncConfiguration updateConfig config=" + config);
                    ActivityManager.getService().updateConfiguration(config);
            } else {
                Rlog.d(LOG_TAG, "updateMccMncConfiguration nothing to update");
            }
            } catch (RemoteException e) {
                Rlog.e(LOG_TAG, "Can't update configuration", e);
            }
        }
    }

+4 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

import android.app.ActivityManager;
import android.app.AlarmManager;
import android.app.AppOpsManager;
import android.app.DownloadManager;
@@ -225,6 +226,8 @@ public class ContextFixture implements TestFixture<Context> {
            switch (name) {
                case Context.TELEPHONY_SERVICE:
                    return mTelephonyManager;
                case Context.ACTIVITY_SERVICE:
                    return mActivityManager;
                case Context.APP_OPS_SERVICE:
                    return mAppOpsManager;
                case Context.NOTIFICATION_SERVICE:
@@ -579,6 +582,7 @@ public class ContextFixture implements TestFixture<Context> {
    private final ApplicationInfo mApplicationInfo = mock(ApplicationInfo.class);
    private final PackageManager mPackageManager = mock(PackageManager.class);
    private final TelephonyManager mTelephonyManager = mock(TelephonyManager.class);
    private final ActivityManager mActivityManager = mock(ActivityManager.class);
    private final DownloadManager mDownloadManager = mock(DownloadManager.class);
    private final AppOpsManager mAppOpsManager = mock(AppOpsManager.class);
    private final NotificationManager mNotificationManager = mock(NotificationManager.class);
+4 −0
Original line number Diff line number Diff line
@@ -312,6 +312,8 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {
                .getSubInfoUsingSlotIndexPrivileged(eq(FAKE_SUB_ID_1));
        doReturn("89012604200000000000").when(mIccRecord).getFullIccId();
        doReturn(FAKE_MCC_MNC_1).when(mTelephonyManager).getSimOperatorNumeric(FAKE_SUB_ID_1);
        when(mActivityManager.updateMccMncConfiguration(anyString(), anyString())).thenReturn(
                true);

        mUpdater.updateInternalIccState(
                IccCardConstants.INTENT_VALUE_ICC_LOADED, null, FAKE_SUB_ID_1, false);
@@ -442,6 +444,8 @@ public class SubscriptionInfoUpdaterTest extends TelephonyTest {
        doReturn(FAKE_SUB_ID_2).when(mSubscriptionController).getPhoneId(eq(FAKE_SUB_ID_2));
        doReturn(2).when(mTelephonyManager).getPhoneCount();
        doReturn(2).when(mTelephonyManager).getActiveModemCount();
        when(mActivityManager.updateMccMncConfiguration(anyString(), anyString())).thenReturn(
                true);
        doReturn(FAKE_MCC_MNC_1).when(mTelephonyManager).getSimOperatorNumeric(eq(FAKE_SUB_ID_1));
        doReturn(FAKE_MCC_MNC_2).when(mTelephonyManager).getSimOperatorNumeric(eq(FAKE_SUB_ID_2));
        verify(mSubscriptionController, times(0)).clearSubInfo();
+2 −0
Original line number Diff line number Diff line
@@ -274,6 +274,7 @@ public abstract class TelephonyTest {
    @Mock
    protected NetworkStatsManager mStatsManager;

    protected ActivityManager mActivityManager;
    protected ImsCallProfile mImsCallProfile;
    protected TelephonyManager mTelephonyManager;
    protected TelephonyRegistryManager mTelephonyRegistryManager;
@@ -404,6 +405,7 @@ public abstract class TelephonyTest {
        doReturn(mUiccProfile).when(mUiccCard).getUiccProfile();

        mTelephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
        mActivityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
        mTelephonyRegistryManager = (TelephonyRegistryManager) mContext.getSystemService(
            Context.TELEPHONY_REGISTRY_SERVICE);
        mSubscriptionManager = (SubscriptionManager) mContext.getSystemService(