Search in sources :

Example 11 with UserManagerInternal

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);
            }
        }
    });
}
Also used : UserManagerInternal(android.os.UserManagerInternal) Bundle(android.os.Bundle) Setting(com.android.providers.settings.SettingsState.Setting)

Example 12 with UserManagerInternal

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);
            }
        }
    });
}
Also used : UserManagerInternal(android.os.UserManagerInternal) Bundle(android.os.Bundle) Setting(com.android.providers.settings.SettingsState.Setting)

Aggregations

UserManagerInternal (android.os.UserManagerInternal)12 Bundle (android.os.Bundle)5 Setting (com.android.providers.settings.SettingsState.Setting)5 PackageParser (android.content.pm.PackageParser)4 UserInfo (android.content.pm.UserInfo)4 UserManager (android.os.UserManager)4 ApplicationInfo (android.content.pm.ApplicationInfo)2 EphemeralApplicationInfo (android.content.pm.EphemeralApplicationInfo)2 StorageManager (android.os.storage.StorageManager)2 VersionInfo (com.android.server.pm.Settings.VersionInfo)2 ArrayList (java.util.ArrayList)2 Message (android.os.Message)1 PackageManagerService (com.android.server.pm.PackageManagerService)1