use of android.service.persistentdata.PersistentDataBlockManager in project android_frameworks_base by DirtyUnicorns.
the class UserRestrictionsUtils method applyUserRestriction.
/**
* Apply each user restriction.
*
* <p>See also {@link
* com.android.providers.settings.SettingsProvider#isGlobalOrSecureSettingRestrictedForUser},
* which should be in sync with this method.
*/
private static void applyUserRestriction(Context context, int userId, String key, boolean newValue) {
if (UserManagerService.DBG) {
Log.d(TAG, "Applying user restriction: userId=" + userId + " key=" + key + " value=" + newValue);
}
// When certain restrictions are cleared, we don't update the system settings,
// because these settings are changeable on the Settings UI and we don't know the original
// value -- for example LOCATION_MODE might have been off already when the restriction was
// set, and in that case even if the restriction is lifted, changing it to ON would be
// wrong. So just don't do anything in such a case. If the user hopes to enable location
// later, they can do it on the Settings UI.
// WARNING: Remember that Settings.Global and Settings.Secure are changeable via adb.
// To prevent this from happening for a given user restriction, you have to add a check to
// SettingsProvider.isGlobalOrSecureSettingRestrictedForUser.
final ContentResolver cr = context.getContentResolver();
final long id = Binder.clearCallingIdentity();
try {
switch(key) {
case UserManager.DISALLOW_CONFIG_WIFI:
if (newValue) {
android.provider.Settings.Secure.putIntForUser(cr, android.provider.Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 0, userId);
}
break;
case UserManager.DISALLOW_DATA_ROAMING:
if (newValue) {
// DISALLOW_DATA_ROAMING user restriction is set.
// Multi sim device.
SubscriptionManager subscriptionManager = new SubscriptionManager(context);
final List<SubscriptionInfo> subscriptionInfoList = subscriptionManager.getActiveSubscriptionInfoList();
if (subscriptionInfoList != null) {
for (SubscriptionInfo subInfo : subscriptionInfoList) {
android.provider.Settings.Global.putStringForUser(cr, android.provider.Settings.Global.DATA_ROAMING + subInfo.getSubscriptionId(), "0", userId);
}
}
// Single sim device.
android.provider.Settings.Global.putStringForUser(cr, android.provider.Settings.Global.DATA_ROAMING, "0", userId);
}
break;
case UserManager.DISALLOW_SHARE_LOCATION:
if (newValue) {
android.provider.Settings.Secure.putIntForUser(cr, android.provider.Settings.Secure.LOCATION_MODE, android.provider.Settings.Secure.LOCATION_MODE_OFF, userId);
}
break;
case UserManager.DISALLOW_DEBUGGING_FEATURES:
if (newValue) {
// TODO: should this be admin user?
if (userId == UserHandle.USER_SYSTEM) {
android.provider.Settings.Global.putStringForUser(cr, android.provider.Settings.Global.ADB_ENABLED, "0", userId);
}
}
break;
case UserManager.ENSURE_VERIFY_APPS:
if (newValue) {
android.provider.Settings.Global.putStringForUser(context.getContentResolver(), android.provider.Settings.Global.PACKAGE_VERIFIER_ENABLE, "1", userId);
android.provider.Settings.Global.putStringForUser(context.getContentResolver(), android.provider.Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, "1", userId);
}
break;
case UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES:
if (newValue) {
android.provider.Settings.Secure.putIntForUser(cr, android.provider.Settings.Secure.INSTALL_NON_MARKET_APPS, 0, userId);
}
break;
case UserManager.DISALLOW_RUN_IN_BACKGROUND:
if (newValue) {
int currentUser = ActivityManager.getCurrentUser();
if (currentUser != userId && userId != UserHandle.USER_SYSTEM) {
try {
ActivityManagerNative.getDefault().stopUser(userId, false, null);
} catch (RemoteException e) {
throw e.rethrowAsRuntimeException();
}
}
}
break;
case UserManager.DISALLOW_SAFE_BOOT:
// Unlike with the other restrictions, we want to propagate the new value to
// the system settings even if it is false. The other restrictions modify
// settings which could be manually changed by the user from the Settings app
// after the policies enforcing these restrictions have been revoked, so we
// leave re-setting of those settings to the user.
android.provider.Settings.Global.putInt(context.getContentResolver(), android.provider.Settings.Global.SAFE_BOOT_DISALLOWED, newValue ? 1 : 0);
break;
case UserManager.DISALLOW_FACTORY_RESET:
case UserManager.DISALLOW_OEM_UNLOCK:
if (newValue) {
PersistentDataBlockManager manager = (PersistentDataBlockManager) context.getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
if (manager != null && manager.getOemUnlockEnabled() && manager.getFlashLockState() != PersistentDataBlockManager.FLASH_LOCK_UNLOCKED) {
// Only disable OEM unlock if the bootloader is locked. If it's already
// unlocked, setting the OEM unlock enabled flag to false has no effect
// (the bootloader would remain unlocked).
manager.setOemUnlockEnabled(false);
}
}
break;
}
} finally {
Binder.restoreCallingIdentity(id);
}
}
use of android.service.persistentdata.PersistentDataBlockManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class Utils method setOemUnlockEnabled.
/**
* Allows enabling or disabling OEM unlock on this device. OEM unlocked
* devices allow users to flash other OSes to them.
*/
static void setOemUnlockEnabled(Context context, boolean enabled) {
try {
PersistentDataBlockManager manager = (PersistentDataBlockManager) context.getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
manager.setOemUnlockEnabled(enabled);
} catch (SecurityException e) {
Log.e(TAG, "Fail to set oem unlock.", e);
}
}
use of android.service.persistentdata.PersistentDataBlockManager in project android_frameworks_base by crdroidandroid.
the class UserRestrictionsUtils method applyUserRestriction.
/**
* Apply each user restriction.
*
* <p>See also {@link
* com.android.providers.settings.SettingsProvider#isGlobalOrSecureSettingRestrictedForUser},
* which should be in sync with this method.
*/
private static void applyUserRestriction(Context context, int userId, String key, boolean newValue) {
if (UserManagerService.DBG) {
Log.d(TAG, "Applying user restriction: userId=" + userId + " key=" + key + " value=" + newValue);
}
// When certain restrictions are cleared, we don't update the system settings,
// because these settings are changeable on the Settings UI and we don't know the original
// value -- for example LOCATION_MODE might have been off already when the restriction was
// set, and in that case even if the restriction is lifted, changing it to ON would be
// wrong. So just don't do anything in such a case. If the user hopes to enable location
// later, they can do it on the Settings UI.
// WARNING: Remember that Settings.Global and Settings.Secure are changeable via adb.
// To prevent this from happening for a given user restriction, you have to add a check to
// SettingsProvider.isGlobalOrSecureSettingRestrictedForUser.
final ContentResolver cr = context.getContentResolver();
final long id = Binder.clearCallingIdentity();
try {
switch(key) {
case UserManager.DISALLOW_CONFIG_WIFI:
if (newValue) {
android.provider.Settings.Secure.putIntForUser(cr, android.provider.Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 0, userId);
}
break;
case UserManager.DISALLOW_DATA_ROAMING:
if (newValue) {
// DISALLOW_DATA_ROAMING user restriction is set.
// Multi sim device.
SubscriptionManager subscriptionManager = new SubscriptionManager(context);
final List<SubscriptionInfo> subscriptionInfoList = subscriptionManager.getActiveSubscriptionInfoList();
if (subscriptionInfoList != null) {
for (SubscriptionInfo subInfo : subscriptionInfoList) {
android.provider.Settings.Global.putStringForUser(cr, android.provider.Settings.Global.DATA_ROAMING + subInfo.getSubscriptionId(), "0", userId);
}
}
// Single sim device.
android.provider.Settings.Global.putStringForUser(cr, android.provider.Settings.Global.DATA_ROAMING, "0", userId);
}
break;
case UserManager.DISALLOW_SHARE_LOCATION:
if (newValue) {
android.provider.Settings.Secure.putIntForUser(cr, android.provider.Settings.Secure.LOCATION_MODE, android.provider.Settings.Secure.LOCATION_MODE_OFF, userId);
}
break;
case UserManager.DISALLOW_DEBUGGING_FEATURES:
if (newValue) {
// TODO: should this be admin user?
if (userId == UserHandle.USER_SYSTEM) {
android.provider.Settings.Global.putStringForUser(cr, android.provider.Settings.Global.ADB_ENABLED, "0", userId);
}
}
break;
case UserManager.ENSURE_VERIFY_APPS:
if (newValue) {
android.provider.Settings.Global.putStringForUser(context.getContentResolver(), android.provider.Settings.Global.PACKAGE_VERIFIER_ENABLE, "1", userId);
android.provider.Settings.Global.putStringForUser(context.getContentResolver(), android.provider.Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, "1", userId);
}
break;
case UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES:
if (newValue) {
android.provider.Settings.Secure.putIntForUser(cr, android.provider.Settings.Secure.INSTALL_NON_MARKET_APPS, 0, userId);
}
break;
case UserManager.DISALLOW_RUN_IN_BACKGROUND:
if (newValue) {
int currentUser = ActivityManager.getCurrentUser();
if (currentUser != userId && userId != UserHandle.USER_SYSTEM) {
try {
ActivityManagerNative.getDefault().stopUser(userId, false, null);
} catch (RemoteException e) {
throw e.rethrowAsRuntimeException();
}
}
}
break;
case UserManager.DISALLOW_SAFE_BOOT:
// Unlike with the other restrictions, we want to propagate the new value to
// the system settings even if it is false. The other restrictions modify
// settings which could be manually changed by the user from the Settings app
// after the policies enforcing these restrictions have been revoked, so we
// leave re-setting of those settings to the user.
android.provider.Settings.Global.putInt(context.getContentResolver(), android.provider.Settings.Global.SAFE_BOOT_DISALLOWED, newValue ? 1 : 0);
break;
case UserManager.DISALLOW_FACTORY_RESET:
case UserManager.DISALLOW_OEM_UNLOCK:
if (newValue) {
PersistentDataBlockManager manager = (PersistentDataBlockManager) context.getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
if (manager != null && manager.getOemUnlockEnabled() && manager.getFlashLockState() != PersistentDataBlockManager.FLASH_LOCK_UNLOCKED) {
// Only disable OEM unlock if the bootloader is locked. If it's already
// unlocked, setting the OEM unlock enabled flag to false has no effect
// (the bootloader would remain unlocked).
manager.setOemUnlockEnabled(false);
}
}
break;
}
} finally {
Binder.restoreCallingIdentity(id);
}
}
Aggregations