Loading src/com/android/settings/network/ApnEditor.java +23 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(); Loading Loading @@ -1342,6 +1348,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) { Loading src/com/android/settings/password/ChooseLockPassword.java +7 −2 Original line number Diff line number Diff line Loading @@ -960,8 +960,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(); } Loading src/com/android/settings/password/ChooseLockPattern.java +7 −2 Original line number Diff line number Diff line Loading @@ -921,8 +921,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(); } Loading tests/robotests/src/com/android/settings/network/ApnEditorTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -101,6 +102,8 @@ public class ApnEditorTest { @Mock private FragmentActivity mActivity; @Mock private UserManager mUserManager; @Mock private ProxySubscriptionManager mProxySubscriptionMgr; @Captor Loading @@ -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"; Loading Loading @@ -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() { Loading Loading
src/com/android/settings/network/ApnEditor.java +23 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(); Loading Loading @@ -1342,6 +1348,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) { Loading
src/com/android/settings/password/ChooseLockPassword.java +7 −2 Original line number Diff line number Diff line Loading @@ -960,8 +960,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(); } Loading
src/com/android/settings/password/ChooseLockPattern.java +7 −2 Original line number Diff line number Diff line Loading @@ -921,8 +921,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(); } Loading
tests/robotests/src/com/android/settings/network/ApnEditorTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -101,6 +102,8 @@ public class ApnEditorTest { @Mock private FragmentActivity mActivity; @Mock private UserManager mUserManager; @Mock private ProxySubscriptionManager mProxySubscriptionMgr; @Captor Loading @@ -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"; Loading Loading @@ -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() { Loading