use of android.os.UserManagerInternal in project android_frameworks_base by DirtyUnicorns.
the class SettingsProvider method startWatchingUserRestrictionChanges.
private void startWatchingUserRestrictionChanges() {
// TODO: The current design of settings looking different based on user restrictions
// should be reworked to keep them separate and system code should check the setting
// first followed by checking the user restriction before performing an operation.
UserManagerInternal userManager = LocalServices.getService(UserManagerInternal.class);
userManager.addUserRestrictionsListener((int userId, Bundle newRestrictions, Bundle prevRestrictions) -> {
// value passes the security checks, so clear binder calling id.
if (newRestrictions.containsKey(UserManager.DISALLOW_SHARE_LOCATION) != prevRestrictions.containsKey(UserManager.DISALLOW_SHARE_LOCATION)) {
final long identity = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
Setting setting = getSecureSetting(Settings.Secure.LOCATION_PROVIDERS_ALLOWED, userId);
updateSecureSetting(Settings.Secure.LOCATION_PROVIDERS_ALLOWED, setting != null ? setting.getValue() : null, userId, true);
}
} finally {
Binder.restoreCallingIdentity(identity);
}
}
if (newRestrictions.containsKey(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES) != prevRestrictions.containsKey(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES)) {
final long identity = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
Setting setting = getGlobalSetting(Settings.Global.INSTALL_NON_MARKET_APPS);
updateGlobalSetting(Settings.Global.INSTALL_NON_MARKET_APPS, setting != null ? setting.getValue() : null, userId, true);
}
} finally {
Binder.restoreCallingIdentity(identity);
}
}
if (newRestrictions.containsKey(UserManager.DISALLOW_DEBUGGING_FEATURES) != prevRestrictions.containsKey(UserManager.DISALLOW_DEBUGGING_FEATURES)) {
final long identity = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
Setting setting = getGlobalSetting(Settings.Global.ADB_ENABLED);
updateGlobalSetting(Settings.Global.ADB_ENABLED, setting != null ? setting.getValue() : null, userId, true);
}
} finally {
Binder.restoreCallingIdentity(identity);
}
}
if (newRestrictions.containsKey(UserManager.ENSURE_VERIFY_APPS) != prevRestrictions.containsKey(UserManager.ENSURE_VERIFY_APPS)) {
final long identity = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
Setting enable = getGlobalSetting(Settings.Global.PACKAGE_VERIFIER_ENABLE);
updateGlobalSetting(Settings.Global.PACKAGE_VERIFIER_ENABLE, enable != null ? enable.getValue() : null, userId, true);
Setting include = getGlobalSetting(Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB);
updateGlobalSetting(Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, include != null ? include.getValue() : null, userId, true);
}
} finally {
Binder.restoreCallingIdentity(identity);
}
}
if (newRestrictions.containsKey(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS) != prevRestrictions.containsKey(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
final long identity = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
Setting setting = getGlobalSetting(Settings.Global.PREFERRED_NETWORK_MODE);
updateGlobalSetting(Settings.Global.PREFERRED_NETWORK_MODE, setting != null ? setting.getValue() : null, userId, true);
}
} finally {
Binder.restoreCallingIdentity(identity);
}
}
});
}
use of android.os.UserManagerInternal in project android_frameworks_base by crdroidandroid.
the class SettingsProvider method startWatchingUserRestrictionChanges.
private void startWatchingUserRestrictionChanges() {
// TODO: The current design of settings looking different based on user restrictions
// should be reworked to keep them separate and system code should check the setting
// first followed by checking the user restriction before performing an operation.
UserManagerInternal userManager = LocalServices.getService(UserManagerInternal.class);
userManager.addUserRestrictionsListener((int userId, Bundle newRestrictions, Bundle prevRestrictions) -> {
// value passes the security checks, so clear binder calling id.
if (newRestrictions.containsKey(UserManager.DISALLOW_SHARE_LOCATION) != prevRestrictions.containsKey(UserManager.DISALLOW_SHARE_LOCATION)) {
final long identity = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
Setting setting = getSecureSetting(Settings.Secure.LOCATION_PROVIDERS_ALLOWED, userId);
updateSecureSetting(Settings.Secure.LOCATION_PROVIDERS_ALLOWED, setting != null ? setting.getValue() : null, userId, true);
}
} finally {
Binder.restoreCallingIdentity(identity);
}
}
if (newRestrictions.containsKey(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES) != prevRestrictions.containsKey(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES)) {
final long identity = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
Setting setting = getGlobalSetting(Settings.Global.INSTALL_NON_MARKET_APPS);
updateGlobalSetting(Settings.Global.INSTALL_NON_MARKET_APPS, setting != null ? setting.getValue() : null, userId, true);
}
} finally {
Binder.restoreCallingIdentity(identity);
}
}
if (newRestrictions.containsKey(UserManager.DISALLOW_DEBUGGING_FEATURES) != prevRestrictions.containsKey(UserManager.DISALLOW_DEBUGGING_FEATURES)) {
final long identity = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
Setting setting = getGlobalSetting(Settings.Global.ADB_ENABLED);
updateGlobalSetting(Settings.Global.ADB_ENABLED, setting != null ? setting.getValue() : null, userId, true);
}
} finally {
Binder.restoreCallingIdentity(identity);
}
}
if (newRestrictions.containsKey(UserManager.ENSURE_VERIFY_APPS) != prevRestrictions.containsKey(UserManager.ENSURE_VERIFY_APPS)) {
final long identity = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
Setting enable = getGlobalSetting(Settings.Global.PACKAGE_VERIFIER_ENABLE);
updateGlobalSetting(Settings.Global.PACKAGE_VERIFIER_ENABLE, enable != null ? enable.getValue() : null, userId, true);
Setting include = getGlobalSetting(Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB);
updateGlobalSetting(Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, include != null ? include.getValue() : null, userId, true);
}
} finally {
Binder.restoreCallingIdentity(identity);
}
}
if (newRestrictions.containsKey(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS) != prevRestrictions.containsKey(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
final long identity = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
Setting setting = getGlobalSetting(Settings.Global.PREFERRED_NETWORK_MODE);
updateGlobalSetting(Settings.Global.PREFERRED_NETWORK_MODE, setting != null ? setting.getValue() : null, userId, true);
}
} finally {
Binder.restoreCallingIdentity(identity);
}
}
});
}
Aggregations