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