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

Commit ebc9d400 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Merge cherrypicks of ['googleplex-android-review.googlesource.com/24025008',...

Merge cherrypicks of ['googleplex-android-review.googlesource.com/24025008', 'googleplex-android-review.googlesource.com/24298399'] into security-aosp-rvc-release.

Change-Id: Ib24bb877c8d0a52c8ad4dc221117966ced01d4b0
parents a8fd40b6 2f308f50
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.os.UserManager;
import android.provider.Telephony;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionInfo;
@@ -264,6 +265,11 @@ public class ApnEditor extends SettingsPreferenceFragment
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        if (isUserRestricted()) {
            Log.e(TAG, "This setting isn't available due to user restriction.");
            finish();
            return;
        }

        setLifecycleForAllControllers();

@@ -1338,6 +1344,23 @@ public class ApnEditor extends SettingsPreferenceFragment
        }
    }

    @VisibleForTesting
    boolean isUserRestricted() {
        UserManager userManager = getContext().getSystemService(UserManager.class);
        if (userManager == null) {
            return false;
        }
        if (!userManager.isAdminUser()) {
            Log.e(TAG, "User is not an admin");
            return true;
        }
        if (userManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
            Log.e(TAG, "User is not allowed to configure mobile network");
            return true;
        }
        return false;
    }

    public static class ErrorDialog extends InstrumentedDialogFragment {

        public static void showError(ApnEditor editor) {
+7 −2
Original line number Diff line number Diff line
@@ -958,8 +958,13 @@ public class ChooseLockPassword extends SettingsActivity {

        @Override
        protected Pair<Boolean, Intent> saveAndVerifyInBackground() {
            final boolean success = mUtils.setLockCredential(
                    mChosenPassword, mCurrentCredential, mUserId);
            boolean success;
            try {
                success = mUtils.setLockCredential(mChosenPassword, mCurrentCredential, mUserId);
            } catch (RuntimeException e) {
                Log.e(TAG, "Failed to set lockscreen credential", e);
                success = false;
            }
            if (success) {
                unifyProfileCredentialIfRequested();
            }
+7 −2
Original line number Diff line number Diff line
@@ -902,8 +902,13 @@ public class ChooseLockPattern extends SettingsActivity {
        @Override
        protected Pair<Boolean, Intent> saveAndVerifyInBackground() {
            final int userId = mUserId;
            final boolean success = mUtils.setLockCredential(mChosenPattern, mCurrentCredential,
                    userId);
            boolean success;
            try {
                success = mUtils.setLockCredential(mChosenPattern, mCurrentCredential, userId);
            } catch (RuntimeException e) {
                Log.e(TAG, "Failed to set lockscreen credential", e);
                success = false;
            }
            if (success) {
                unifyProfileCredentialIfRequested();
            }
+29 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.content.Intent;
import android.content.res.Resources;
import android.database.Cursor;
import android.net.Uri;
import android.os.UserManager;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
@@ -101,6 +102,8 @@ public class ApnEditorTest {
    @Mock
    private FragmentActivity mActivity;
    @Mock
    private UserManager mUserManager;
    @Mock
    private ProxySubscriptionManager mProxySubscriptionMgr;

    @Captor
@@ -126,6 +129,11 @@ public class ApnEditorTest {
        doReturn(mContext.getTheme()).when(mActivity).getTheme();
        doReturn(mContext.getContentResolver()).when(mActivity).getContentResolver();

        doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
        doReturn(true).when(mUserManager).isAdminUser();
        doReturn(false).when(mUserManager)
                .hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS);

        setMockPreference(mContext);
        mApnEditorUT.mApnData = new FakeApnData(APN_DATA);
        mApnEditorUT.sNotSet = "Not Set";
@@ -450,6 +458,27 @@ public class ApnEditorTest {
        assertThat(ApnEditor.formatInteger("not an int")).isEqualTo("not an int");
    }

    @Test
    @Config(shadows = ShadowFragment.class)
    public void onCreate_notAdminUser_shouldFinish() {
        doReturn(false).when(mUserManager).isAdminUser();

        mApnEditorUT.onCreate(null);

        verify(mApnEditorUT).finish();
    }

    @Test
    @Config(shadows = ShadowFragment.class)
    public void onCreate_hasUserRestriction_shouldFinish() {
        doReturn(true).when(mUserManager)
                .hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS);

        mApnEditorUT.onCreate(null);

        verify(mApnEditorUT).finish();
    }

    @Test
    @Config(shadows = ShadowFragment.class)
    public void onCreate_noAction_shouldFinishAndNoCrash() {