Update availability for mobile network
This CL updates the availability to behave properly when a user other than the primary user is accessing it. This also makes the api return no intent if they don't have permission to access this because attempting to go to that screen will cause a crash. Also updates tests related to this change. Test: robotests still pass Bug: 64092292 Change-Id: If9913d9ae08ee3e205ff324aaeeadc755ff1d23d
This commit is contained in:
@@ -32,7 +32,6 @@ import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
|
||||
import static android.os.UserHandle.myUserId;
|
||||
import static android.os.UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS;
|
||||
import static com.android.settingslib.RestrictedLockUtils.hasBaseUserRestriction;
|
||||
|
||||
public class MobileNetworkPreferenceController extends PreferenceController implements
|
||||
LifecycleObserver, OnResume, OnPause {
|
||||
@@ -41,22 +40,30 @@ public class MobileNetworkPreferenceController extends PreferenceController impl
|
||||
|
||||
private final boolean mIsSecondaryUser;
|
||||
private final TelephonyManager mTelephonyManager;
|
||||
private final UserManager mUserManager;
|
||||
private Preference mPreference;
|
||||
@VisibleForTesting
|
||||
PhoneStateListener mPhoneStateListener;
|
||||
|
||||
public MobileNetworkPreferenceController(Context context) {
|
||||
super(context);
|
||||
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
mIsSecondaryUser = !userManager.isAdminUser();
|
||||
mIsSecondaryUser = !mUserManager.isAdminUser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return !mIsSecondaryUser
|
||||
&& !Utils.isWifiOnly(mContext)
|
||||
&& !hasBaseUserRestriction(mContext, DISALLOW_CONFIG_MOBILE_NETWORKS, myUserId());
|
||||
return !isUserRestricted() && !Utils.isWifiOnly(mContext);
|
||||
}
|
||||
|
||||
public boolean isUserRestricted() {
|
||||
final RestrictedLockUtilsWrapper wrapper = new RestrictedLockUtilsWrapper();
|
||||
return mIsSecondaryUser ||
|
||||
wrapper.hasBaseUserRestriction(
|
||||
mContext,
|
||||
DISALLOW_CONFIG_MOBILE_NETWORKS,
|
||||
myUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user