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

Unverified Commit cbb7cf3b authored by Kevin F. Haggerty's avatar Kevin F. Haggerty
Browse files

Merge tag 'android-security-13.0.0_r10' of...

Merge tag 'android-security-13.0.0_r10' of https://android.googlesource.com/platform/packages/apps/Settings into staging/lineage-20.0_merge_android-security-13.0.0_r10

Android Security 13.0.0 Release 10 (10763433)

* tag 'android-security-13.0.0_r10' of https://android.googlesource.com/platform/packages/apps/Settings:
  RESTRICT AUTOMERGE: Catch exceptions from setLockCredential()
  [RESTRICT AUTOMERGE] Restrict ApnEditor settings

Conflicts:
	src/com/android/settings/password/ChooseLockPattern.java
	tests/robotests/src/com/android/settings/network/apn/ApnEditorTest.java

Change-Id: I17a1c1d33b2985daa882fe81ea8fde44cbad492a
parents e89246a4 0a88b132
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;
@@ -281,6 +282,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();

@@ -1453,6 +1459,23 @@ public class ApnEditor extends SettingsPreferenceFragment
        return apnData;
    }

    @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;
    }

    @VisibleForTesting
    static class ApnData {
        /**
+7 −2
Original line number Diff line number Diff line
@@ -1048,8 +1048,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
@@ -925,8 +925,13 @@ public class ChooseLockPattern extends SettingsActivity {
        protected Pair<Boolean, Intent> saveAndVerifyInBackground() {
            final int userId = mUserId;
            mUtils.setLockPatternSize(mPatternSize, userId);
            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
@@ -36,6 +36,7 @@ import android.content.res.Resources;
import android.database.Cursor;
import android.net.Uri;
import android.os.PersistableBundle;
import android.os.UserManager;
import android.telephony.CarrierConfigManager;
import android.view.KeyEvent;
import android.view.Menu;
@@ -102,6 +103,8 @@ public class ApnEditorTest {
    @Mock
    private FragmentActivity mActivity;
    @Mock
    private UserManager mUserManager;
    @Mock
    private ProxySubscriptionManager mProxySubscriptionMgr;
    @Mock
    private CarrierConfigManager mCarrierConfigManager;
@@ -133,6 +136,11 @@ public class ApnEditorTest {
                .getSystemService(Context.CARRIER_CONFIG_SERVICE);
        doReturn(mBundle).when(mCarrierConfigManager).getConfigForSubId(anyInt());

        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";
@@ -471,6 +479,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() {