Search in sources :

Example 21 with Setting

use of com.android.providers.settings.SettingsState.Setting in project android_frameworks_base by crdroidandroid.

the class SettingsProvider method getAllSystemSettings.

private Cursor getAllSystemSettings(int userId, String[] projection) {
    if (DEBUG) {
        Slog.v(LOG_TAG, "getAllSecureSystem(" + userId + ")");
    }
    // Resolve the userId on whose behalf the call is made.
    final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(userId);
    synchronized (mLock) {
        List<String> names = mSettingsRegistry.getSettingsNamesLocked(SETTINGS_TYPE_SYSTEM, callingUserId);
        final int nameCount = names.size();
        String[] normalizedProjection = normalizeProjection(projection);
        MatrixCursor result = new MatrixCursor(normalizedProjection, nameCount);
        for (int i = 0; i < nameCount; i++) {
            String name = names.get(i);
            // Determine the owning user as some profile settings are cloned from the parent.
            final int owningUserId = resolveOwningUserIdForSystemSettingLocked(callingUserId, name);
            Setting setting = mSettingsRegistry.getSettingLocked(SETTINGS_TYPE_SYSTEM, owningUserId, name);
            appendSettingToCursor(result, setting);
        }
        return result;
    }
}
Also used : Setting(com.android.providers.settings.SettingsState.Setting) MatrixCursor(android.database.MatrixCursor)

Example 22 with Setting

use of com.android.providers.settings.SettingsState.Setting in project android_frameworks_base by crdroidandroid.

the class SettingsProvider method getAllSecureSettings.

private Cursor getAllSecureSettings(int userId, String[] projection) {
    if (DEBUG) {
        Slog.v(LOG_TAG, "getAllSecureSettings(" + userId + ")");
    }
    // Resolve the userId on whose behalf the call is made.
    final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(userId);
    synchronized (mLock) {
        List<String> names = mSettingsRegistry.getSettingsNamesLocked(SETTINGS_TYPE_SECURE, callingUserId);
        final int nameCount = names.size();
        String[] normalizedProjection = normalizeProjection(projection);
        MatrixCursor result = new MatrixCursor(normalizedProjection, nameCount);
        for (int i = 0; i < nameCount; i++) {
            String name = names.get(i);
            // Determine the owning user as some profile settings are cloned from the parent.
            final int owningUserId = resolveOwningUserIdForSecureSettingLocked(callingUserId, name);
            // Special case for location (sigh).
            if (isLocationProvidersAllowedRestricted(name, callingUserId, owningUserId)) {
                continue;
            }
            Setting setting = mSettingsRegistry.getSettingLocked(SETTINGS_TYPE_SECURE, owningUserId, name);
            appendSettingToCursor(result, setting);
        }
        return result;
    }
}
Also used : Setting(com.android.providers.settings.SettingsState.Setting) MatrixCursor(android.database.MatrixCursor)

Example 23 with Setting

use of com.android.providers.settings.SettingsState.Setting 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)

Example 24 with Setting

use of com.android.providers.settings.SettingsState.Setting in project android_frameworks_base by ResurrectionRemix.

the class SettingsProvider method updateLocationProvidersAllowedLocked.

/*
     * Used to parse changes to the value of Settings.Secure.LOCATION_PROVIDERS_ALLOWED.
     * This setting contains a list of the currently enabled location providers.
     * But helper functions in android.providers.Settings can enable or disable
     * a single provider by using a "+" or "-" prefix before the provider name.
     *
     * <p>See also {@link #isGlobalOrSecureSettingRestrictedForUser()}.  If DISALLOW_SHARE_LOCATION
     * is set, the said method will only allow values with the "-" prefix.
     *
     * @returns whether the enabled location providers changed.
     */
private boolean updateLocationProvidersAllowedLocked(String value, int owningUserId, boolean forceNotify) {
    if (TextUtils.isEmpty(value)) {
        return false;
    }
    final char prefix = value.charAt(0);
    if (prefix != '+' && prefix != '-') {
        if (forceNotify) {
            final int key = makeKey(SETTINGS_TYPE_SECURE, owningUserId);
            mSettingsRegistry.notifyForSettingsChange(key, Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
        }
        return false;
    }
    // skip prefix
    value = value.substring(1);
    Setting settingValue = getSecureSetting(Settings.Secure.LOCATION_PROVIDERS_ALLOWED, owningUserId);
    String oldProviders = (settingValue != null) ? settingValue.getValue() : "";
    int index = oldProviders.indexOf(value);
    int end = index + value.length();
    // check for commas to avoid matching on partial string
    if (index > 0 && oldProviders.charAt(index - 1) != ',') {
        index = -1;
    }
    // check for commas to avoid matching on partial string
    if (end < oldProviders.length() && oldProviders.charAt(end) != ',') {
        index = -1;
    }
    String newProviders;
    if (prefix == '+' && index < 0) {
        // append the provider to the list if not present
        if (oldProviders.length() == 0) {
            newProviders = value;
        } else {
            newProviders = oldProviders + ',' + value;
        }
    } else if (prefix == '-' && index >= 0) {
        // remove leading or trailing comma
        if (index > 0) {
            index--;
        } else if (end < oldProviders.length()) {
            end++;
        }
        newProviders = oldProviders.substring(0, index);
        if (end < oldProviders.length()) {
            newProviders += oldProviders.substring(end);
        }
    } else {
        // nothing changed, so no need to update the database
        if (forceNotify) {
            final int key = makeKey(SETTINGS_TYPE_SECURE, owningUserId);
            mSettingsRegistry.notifyForSettingsChange(key, Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
        }
        return false;
    }
    return mSettingsRegistry.insertSettingLocked(SETTINGS_TYPE_SECURE, owningUserId, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, newProviders, getCallingPackage(), forceNotify);
}
Also used : Setting(com.android.providers.settings.SettingsState.Setting)

Example 25 with Setting

use of com.android.providers.settings.SettingsState.Setting in project android_frameworks_base by ResurrectionRemix.

the class SettingsProvider method getAllSystemSettings.

private Cursor getAllSystemSettings(int userId, String[] projection) {
    if (DEBUG) {
        Slog.v(LOG_TAG, "getAllSecureSystem(" + userId + ")");
    }
    // Resolve the userId on whose behalf the call is made.
    final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(userId);
    synchronized (mLock) {
        List<String> names = mSettingsRegistry.getSettingsNamesLocked(SETTINGS_TYPE_SYSTEM, callingUserId);
        final int nameCount = names.size();
        String[] normalizedProjection = normalizeProjection(projection);
        MatrixCursor result = new MatrixCursor(normalizedProjection, nameCount);
        for (int i = 0; i < nameCount; i++) {
            String name = names.get(i);
            // Determine the owning user as some profile settings are cloned from the parent.
            final int owningUserId = resolveOwningUserIdForSystemSettingLocked(callingUserId, name);
            Setting setting = mSettingsRegistry.getSettingLocked(SETTINGS_TYPE_SYSTEM, owningUserId, name);
            appendSettingToCursor(result, setting);
        }
        return result;
    }
}
Also used : Setting(com.android.providers.settings.SettingsState.Setting) MatrixCursor(android.database.MatrixCursor)

Aggregations

Setting (com.android.providers.settings.SettingsState.Setting)25 MatrixCursor (android.database.MatrixCursor)15 Bundle (android.os.Bundle)5 UserManagerInternal (android.os.UserManagerInternal)5