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 atest -c 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;
|
||||
@@ -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();
|
||||
|
||||
@@ -1452,6 +1458,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 {
|
||||
/**
|
||||
|
Reference in New Issue
Block a user