Merge UP1A.231005.007

Bug: 291102124
Merged-In: I74cde8ebf8214b314a89452e73b834eac7ae8b1e
Change-Id: If0cc9b99ea3e0e6d908d8c1ed476232d3056cb5d
This commit is contained in:
Xin Li
2023-09-27 16:05:12 -07:00
4 changed files with 65 additions and 4 deletions

View File

@@ -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();
@@ -1458,6 +1464,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 {
/**

View File

@@ -1103,8 +1103,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();
}

View File

@@ -895,8 +895,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();
}

View File

@@ -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;
@@ -129,6 +132,10 @@ 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);
doReturn(mCarrierConfigManager).when(mContext)
.getSystemService(Context.CARRIER_CONFIG_SERVICE);
doReturn(mBundle).when(mCarrierConfigManager).getConfigForSubId(anyInt());
@@ -471,6 +478,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() {