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

Commit c046fae5 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Handle external calls when PhoneSwitcher is not initialized yet." into...

Merge "Handle external calls when PhoneSwitcher is not initialized yet." into rvc-dev am: 1f8d2a6e am: 263046b3

Change-Id: I81161172b25b3f37da8062f70d1037d7b3e46bee
parents 3ef8dbce 263046b3
Loading
Loading
Loading
Loading
+29 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.internal.telephony;

import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.telephony.TelephonyManager.SET_OPPORTUNISTIC_SUB_REMOTE_SERVICE_EXCEPTION;
import static android.telephony.UiccSlotInfo.CARD_STATE_INFO_PRESENT;

import android.Manifest;
@@ -35,11 +36,13 @@ import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Binder;
import android.os.ParcelUuid;
import android.os.RemoteException;
import android.os.TelephonyServiceManager.ServiceRegisterer;
import android.os.UserHandle;
import android.provider.Settings;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.telephony.AnomalyReporter;
import android.telephony.CarrierConfigManager;
import android.telephony.RadioAccessFamily;
import android.telephony.SubscriptionInfo;
@@ -2994,8 +2997,23 @@ public class SubscriptionController extends ISub.Stub {
        final long token = Binder.clearCallingIdentity();

        try {
            PhoneSwitcher.getInstance().trySetOpportunisticDataSubscription(
                    subId, needValidation, callback);
            PhoneSwitcher phoneSwitcher = PhoneSwitcher.getInstance();
            if (phoneSwitcher == null) {
                logd("Set preferred data sub: phoneSwitcher is null.");
                AnomalyReporter.reportAnomaly(
                        UUID.fromString("a3ab0b9d-f2aa-4baf-911d-7096c0d4645a"),
                        "Set preferred data sub: phoneSwitcher is null.");
                if (callback != null) {
                    try {
                        callback.onComplete(SET_OPPORTUNISTIC_SUB_REMOTE_SERVICE_EXCEPTION);
                    } catch (RemoteException exception) {
                        logd("RemoteException " + exception);
                    }
                }
                return;
            }

            phoneSwitcher.trySetOpportunisticDataSubscription(subId, needValidation, callback);
        } finally {
            Binder.restoreCallingIdentity(token);
        }
@@ -3007,7 +3025,15 @@ public class SubscriptionController extends ISub.Stub {
        final long token = Binder.clearCallingIdentity();

        try {
            return PhoneSwitcher.getInstance().getOpportunisticDataSubscriptionId();
            PhoneSwitcher phoneSwitcher = PhoneSwitcher.getInstance();
            if (phoneSwitcher == null) {
                AnomalyReporter.reportAnomaly(
                        UUID.fromString("a3ab0b9d-f2aa-4baf-911d-7096c0d4645a"),
                        "Get preferred data sub: phoneSwitcher is null.");
                return SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
            }

            return phoneSwitcher.getOpportunisticDataSubscriptionId();
        } finally {
            Binder.restoreCallingIdentity(token);
        }
+22 −0
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
package com.android.internal.telephony;

import static android.telephony.TelephonyManager.SET_OPPORTUNISTIC_SUB_REMOTE_SERVICE_EXCEPTION;

import static com.android.internal.telephony.uicc.IccCardStatus.CardState.CARDSTATE_PRESENT;

import static org.junit.Assert.assertEquals;
@@ -78,6 +80,8 @@ public class SubscriptionControllerTest extends TelephonyTest {
    private ITelephonyRegistry.Stub mTelephonyRegisteryMock;
    @Mock
    private MultiSimSettingController mMultiSimSettingControllerMock;
    @Mock
    private ISetOpportunisticDataCallback mSetOpptDataCallback;

    private static final String MAC_ADDRESS_PREFIX = "mac_";
    private static final String DISPLAY_NAME_PREFIX = "my_phone_";
@@ -1337,4 +1341,22 @@ public class SubscriptionControllerTest extends TelephonyTest {
        assertEquals("123", infoList.get(0).getIccId());
        assertEquals("456", infoList.get(1).getIccId());
    }

    @Test
    @SmallTest
    public void testSetPreferredDataSubscriptionId_phoneSwitcherNotInitialized() throws Exception {
        replaceInstance(PhoneSwitcher.class, "sPhoneSwitcher", null, null);

        mSubscriptionControllerUT.setPreferredDataSubscriptionId(1, true, mSetOpptDataCallback);
        verify(mSetOpptDataCallback).onComplete(SET_OPPORTUNISTIC_SUB_REMOTE_SERVICE_EXCEPTION);
    }

    @Test
    @SmallTest
    public void testGetPreferredDataSubscriptionId_phoneSwitcherNotInitialized() throws Exception {
        replaceInstance(PhoneSwitcher.class, "sPhoneSwitcher", null, null);

        assertEquals(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
                mSubscriptionControllerUT.getPreferredDataSubscriptionId());
    }
}