[RESTRICT AUTOMERGE] Restrict ApnEditor settings
- Finish ApnEditor settings if user is not an admin - Finish ApnEditor settings if user has DISALLOW_CONFIG_MOBILE_NETWORKS restriction Bug: 279902472 Test: manual test make RunSettingsRoboTests ROBOTEST_FILTER=ApnEditorTest Change-Id: Iecdbbff7e21dfb11e3ba385858747a220cfd3e04
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user