Merge "Update availability for mobile network" into oc-dr1-dev am: 4bcc3eb193

am: 7bc388d823

Change-Id: I33cb44239c0725efd34611c06ed1734a6898d943
This commit is contained in:
Salvador Martinez
2017-08-09 20:28:30 +00:00
committed by android-build-merger
5 changed files with 83 additions and 6 deletions

View File

@@ -33,7 +33,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 AbstractPreferenceController
implements PreferenceControllerMixin, LifecycleObserver, OnResume, OnPause {
@@ -42,22 +41,30 @@ public class MobileNetworkPreferenceController extends AbstractPreferenceControl
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

View File

@@ -0,0 +1,15 @@
package com.android.settings.network;
import android.content.Context;
import com.android.settingslib.RestrictedLockUtils;
/**
* Wrapper class needed to be able to test classes which use RestrictedLockUtils methods.
* Unfortunately there is no way to deal with this until robolectric is updated due to the fact
* that it is a static method and it uses new API's.
*/
public class RestrictedLockUtilsWrapper {
public boolean hasBaseUserRestriction(Context context, String userRestriction, int userId) {
return RestrictedLockUtils.hasBaseUserRestriction(context, userRestriction, userId);
}
}