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

Commit 4f62c3dd authored by Jeff Davidson's avatar Jeff Davidson
Browse files

Write eUICC provisioned bit after successful download.

Bug: 38460669
Test: Unit Test / TreeHugger
Change-Id: Id7a00283a1948879c78ccb5a5fb97410cfe9a122
parent 8500c109
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@ import android.content.pm.PackageManager;
import android.os.Binder;
import android.os.Binder;
import android.os.Bundle;
import android.os.Bundle;
import android.os.ServiceManager;
import android.os.ServiceManager;
import android.provider.Settings;
import android.service.euicc.DeleteResult;
import android.service.euicc.DeleteResult;
import android.service.euicc.DownloadResult;
import android.service.euicc.DownloadResult;
import android.service.euicc.EraseResult;
import android.service.euicc.EraseResult;
@@ -377,6 +378,12 @@ public class EuiccController extends IEuiccController.Stub {
                        switch (result.result) {
                        switch (result.result) {
                            case DownloadResult.RESULT_OK:
                            case DownloadResult.RESULT_OK:
                                resultCode = OK;
                                resultCode = OK;
                                // Now that a profile has been successfully downloaded, mark the
                                // eUICC as provisioned so it appears in settings UI as appropriate.
                                Settings.Global.putInt(
                                        mContext.getContentResolver(),
                                        Settings.Global.EUICC_PROVISIONED,
                                        1);
                                if (!switchAfterDownload) {
                                if (!switchAfterDownload) {
                                    // Since we're not switching, nothing will trigger a
                                    // Since we're not switching, nothing will trigger a
                                    // subscription list refresh on its own, so request one here.
                                    // subscription list refresh on its own, so request one here.
+18 −5
Original line number Original line Diff line number Diff line
@@ -39,6 +39,7 @@ import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.content.pm.Signature;
import android.os.Parcelable;
import android.os.Parcelable;
import android.os.RemoteException;
import android.os.RemoteException;
import android.provider.Settings;
import android.service.euicc.DeleteResult;
import android.service.euicc.DeleteResult;
import android.service.euicc.DownloadResult;
import android.service.euicc.DownloadResult;
import android.service.euicc.EraseResult;
import android.service.euicc.EraseResult;
@@ -106,6 +107,7 @@ public class EuiccControllerTest extends TelephonyTest {


    @Mock private EuiccConnector mMockConnector;
    @Mock private EuiccConnector mMockConnector;
    private TestEuiccController mController;
    private TestEuiccController mController;
    private int mSavedEuiccProvisionedValue;


    private static class TestEuiccController extends EuiccController {
    private static class TestEuiccController extends EuiccController {
        // Captured arguments to addResolutionIntent
        // Captured arguments to addResolutionIntent
@@ -146,11 +148,18 @@ public class EuiccControllerTest extends TelephonyTest {
        pi.packageName = PACKAGE_NAME;
        pi.packageName = PACKAGE_NAME;
        pi.signatures = new Signature[] { new Signature(SIGNATURE_BYTES) };
        pi.signatures = new Signature[] { new Signature(SIGNATURE_BYTES) };
        when(mPackageManager.getPackageInfo(eq(PACKAGE_NAME), anyInt())).thenReturn(pi);
        when(mPackageManager.getPackageInfo(eq(PACKAGE_NAME), anyInt())).thenReturn(pi);

        mSavedEuiccProvisionedValue = Settings.Global.getInt(mContext.getContentResolver(),
                Settings.Global.EUICC_PROVISIONED, 0);
        Settings.Global.putInt(mContext.getContentResolver(),
                Settings.Global.EUICC_PROVISIONED, 0);
    }
    }


    @After
    @After
    public void tearDown() throws Exception {
    public void tearDown() throws Exception {
        super.tearDown();
        super.tearDown();
        Settings.Global.putInt(mContext.getContentResolver(),
                Settings.Global.EUICC_PROVISIONED, mSavedEuiccProvisionedValue);
    }
    }


    @Test(expected = SecurityException.class)
    @Test(expected = SecurityException.class)
@@ -342,7 +351,7 @@ public class EuiccControllerTest extends TelephonyTest {
        setHasWriteEmbeddedPermission(false);
        setHasWriteEmbeddedPermission(false);
        prepareGetDownloadableSubscriptionMetadataCall(false /* complete */, null /* result */);
        prepareGetDownloadableSubscriptionMetadataCall(false /* complete */, null /* result */);
        callDownloadSubscription(SUBSCRIPTION, true /* switchAfterDownload */, true /* complete */,
        callDownloadSubscription(SUBSCRIPTION, true /* switchAfterDownload */, true /* complete */,
                DownloadResult.success(), PACKAGE_NAME /* callingPackage */);
                DownloadResult.genericError(12345), PACKAGE_NAME /* callingPackage */);
        verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_GENERIC_ERROR,
        verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_GENERIC_ERROR,
                0 /* detailedCode */);
                0 /* detailedCode */);
        verify(mMockConnector, never()).downloadSubscription(
        verify(mMockConnector, never()).downloadSubscription(
@@ -357,7 +366,7 @@ public class EuiccControllerTest extends TelephonyTest {
                GetDownloadableSubscriptionMetadataResult.genericError(42);
                GetDownloadableSubscriptionMetadataResult.genericError(42);
        prepareGetDownloadableSubscriptionMetadataCall(true /* complete */, result);
        prepareGetDownloadableSubscriptionMetadataCall(true /* complete */, result);
        callDownloadSubscription(SUBSCRIPTION, true /* switchAfterDownload */, true /* complete */,
        callDownloadSubscription(SUBSCRIPTION, true /* switchAfterDownload */, true /* complete */,
                DownloadResult.success(), PACKAGE_NAME /* callingPackage */);
                DownloadResult.genericError(12345), PACKAGE_NAME /* callingPackage */);
        verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_GENERIC_ERROR,
        verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_GENERIC_ERROR,
                42 /* detailedCode */);
                42 /* detailedCode */);
        verify(mMockConnector, never()).downloadSubscription(
        verify(mMockConnector, never()).downloadSubscription(
@@ -372,7 +381,7 @@ public class EuiccControllerTest extends TelephonyTest {
                GetDownloadableSubscriptionMetadataResult.mustDeactivateSim();
                GetDownloadableSubscriptionMetadataResult.mustDeactivateSim();
        prepareGetDownloadableSubscriptionMetadataCall(true /* complete */, result);
        prepareGetDownloadableSubscriptionMetadataCall(true /* complete */, result);
        callDownloadSubscription(SUBSCRIPTION, true /* switchAfterDownload */, true /* complete */,
        callDownloadSubscription(SUBSCRIPTION, true /* switchAfterDownload */, true /* complete */,
                DownloadResult.success(), PACKAGE_NAME /* callingPackage */);
                DownloadResult.genericError(12345), PACKAGE_NAME /* callingPackage */);
        verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR,
        verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR,
                0 /* detailedCode */);
                0 /* detailedCode */);
        verifyResolutionIntent(EuiccService.ACTION_RESOLVE_DEACTIVATE_SIM,
        verifyResolutionIntent(EuiccService.ACTION_RESOLVE_DEACTIVATE_SIM,
@@ -400,7 +409,7 @@ public class EuiccControllerTest extends TelephonyTest {
        prepareGetDownloadableSubscriptionMetadataCall(true /* complete */, result);
        prepareGetDownloadableSubscriptionMetadataCall(true /* complete */, result);
        setHasCarrierPrivilegesOnActiveSubscription(false);
        setHasCarrierPrivilegesOnActiveSubscription(false);
        callDownloadSubscription(SUBSCRIPTION, true /* switchAfterDownload */, true /* complete */,
        callDownloadSubscription(SUBSCRIPTION, true /* switchAfterDownload */, true /* complete */,
                DownloadResult.success(), PACKAGE_NAME /* callingPackage */);
                DownloadResult.genericError(12345), PACKAGE_NAME /* callingPackage */);
        verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR,
        verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_RESOLVABLE_ERROR,
                0 /* detailedCode */);
                0 /* detailedCode */);
        verify(mMockConnector, never()).downloadSubscription(
        verify(mMockConnector, never()).downloadSubscription(
@@ -420,7 +429,7 @@ public class EuiccControllerTest extends TelephonyTest {
        pi.signatures = new Signature[] { new Signature(new byte[] { 5, 4, 3, 2, 1 }) };
        pi.signatures = new Signature[] { new Signature(new byte[] { 5, 4, 3, 2, 1 }) };
        when(mPackageManager.getPackageInfo(eq(PACKAGE_NAME), anyInt())).thenReturn(pi);
        when(mPackageManager.getPackageInfo(eq(PACKAGE_NAME), anyInt())).thenReturn(pi);
        callDownloadSubscription(SUBSCRIPTION, true /* switchAfterDownload */, true /* complete */,
        callDownloadSubscription(SUBSCRIPTION, true /* switchAfterDownload */, true /* complete */,
                DownloadResult.success(), PACKAGE_NAME /* callingPackage */);
                DownloadResult.genericError(12345), PACKAGE_NAME /* callingPackage */);
        verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_GENERIC_ERROR,
        verifyIntentSent(EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_GENERIC_ERROR,
                0 /* detailedCode */);
                0 /* detailedCode */);
        verify(mTelephonyManager, never()).checkCarrierPrivilegesForPackage(PACKAGE_NAME);
        verify(mTelephonyManager, never()).checkCarrierPrivilegesForPackage(PACKAGE_NAME);
@@ -819,6 +828,10 @@ public class EuiccControllerTest extends TelephonyTest {
                any(), eq(switchAfterDownload), anyBoolean(), any());
                any(), eq(switchAfterDownload), anyBoolean(), any());
        mController.downloadSubscription(subscription, switchAfterDownload, callingPackage,
        mController.downloadSubscription(subscription, switchAfterDownload, callingPackage,
                resultCallback);
                resultCallback);
        // EUICC_PROVISIONED setting should match whether the download was successful.
        assertEquals(complete && result.result == DownloadResult.RESULT_OK ? 1 : 0,
                Settings.Global.getInt(mContext.getContentResolver(),
                        Settings.Global.EUICC_PROVISIONED, 0));
    }
    }


    private void callDeleteSubscription(int subscriptionId, String iccid, final boolean complete,
    private void callDeleteSubscription(int subscriptionId, String iccid, final boolean complete,