Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6acc0131 authored by Neil Fuller's avatar Neil Fuller Committed by Android (Google) Code Review
Browse files

Merge "Change command-line interface for device_config"

parents 778339fe c94778ce
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -874,7 +874,7 @@ public final class DeviceConfig {
     *     {@link Settings.Config#SYNC_DISABLED_MODE_PERSISTENT} and {@link
     *     Settings.Config#SYNC_DISABLED_MODE_UNTIL_REBOOT}
     *
     * @see #isSyncDisabled()
     * @see #getSyncDisabled()
     * @hide
     */
    @RequiresPermission(WRITE_DEVICE_CONFIG)
@@ -884,16 +884,15 @@ public final class DeviceConfig {
    }

    /**
     * Returns the current state of sync disabling, {@code true} when disabled, {@code false}
     * otherwise.
     * Returns the current mode of sync disabling.
     *
     * @see #setSyncDisabled(int)
     * @hide
     */
    @RequiresPermission(WRITE_DEVICE_CONFIG)
    public static boolean isSyncDisabled() {
    public static @SyncDisabledMode int getSyncDisabled() {
        ContentResolver contentResolver = ActivityThread.currentApplication().getContentResolver();
        return Settings.Config.isSyncDisabled(contentResolver);
        return Settings.Config.getSyncDisabled(contentResolver);
    }

    /**
+10 −10
Original line number Diff line number Diff line
@@ -299,8 +299,8 @@ public final class Settings {
    public static final String KEY_CONFIG_SET_ALL_RETURN = "config_set_all_return";
    /** @hide */
    public static final String KEY_CONFIG_IS_SYNC_DISABLED_RETURN =
            "config_is_sync_disabled_return";
    public static final String KEY_CONFIG_GET_SYNC_DISABLED_RETURN =
            "config_get_sync_disabled_return";
    /**
     * An int extra specifying a subscription ID.
@@ -2442,10 +2442,10 @@ public final class Settings {
    public static final String CALL_METHOD_SET_SYNC_DISABLED_CONFIG = "SET_SYNC_DISABLED_config";
    /**
     * @hide - Private call() method to return whether syncs are disabled for the 'configuration'
     * table
     * @hide - Private call() method to return the current mode of sync disabling for the
     * 'configuration' table
     */
    public static final String CALL_METHOD_IS_SYNC_DISABLED_CONFIG = "IS_SYNC_DISABLED_config";
    public static final String CALL_METHOD_GET_SYNC_DISABLED_CONFIG = "GET_SYNC_DISABLED_config";
    /** @hide - Private call() method to register monitor callback for 'configuration' table */
    public static final String CALL_METHOD_REGISTER_MONITOR_CALLBACK_CONFIG =
@@ -16729,25 +16729,25 @@ public final class Settings {
        }
        /**
         * Bridge method between {@link DeviceConfig#isSyncDisabled()} and the
         * Bridge method between {@link DeviceConfig#getSyncDisabled()} and the
         * {@link com.android.providers.settings.SettingsProvider} implementation.
         *
         * @hide
         */
        @SuppressLint("AndroidFrameworkRequiresPermission")
        @RequiresPermission(Manifest.permission.WRITE_DEVICE_CONFIG)
        static boolean isSyncDisabled(@NonNull ContentResolver resolver) {
        static int getSyncDisabled(@NonNull ContentResolver resolver) {
            try {
                Bundle args = Bundle.EMPTY;
                IContentProvider cp = sProviderHolder.getProvider(resolver);
                Bundle bundle = cp.call(resolver.getAttributionSource(),
                        sProviderHolder.mUri.getAuthority(), CALL_METHOD_IS_SYNC_DISABLED_CONFIG,
                        sProviderHolder.mUri.getAuthority(), CALL_METHOD_GET_SYNC_DISABLED_CONFIG,
                        null, args);
                return bundle.getBoolean(KEY_CONFIG_IS_SYNC_DISABLED_RETURN);
                return bundle.getInt(KEY_CONFIG_GET_SYNC_DISABLED_RETURN);
            } catch (RemoteException e) {
                Log.w(TAG, "Can't query sync disabled " + DeviceConfig.CONTENT_URI, e);
            }
            return false;
            return -1;
        }
        /**
+10 −5
Original line number Diff line number Diff line
@@ -776,7 +776,8 @@ public class DeviceConfigTest {
            DeviceConfig.setSyncDisabled(Settings.Config.SYNC_DISABLED_MODE_NONE);

            // Assert starting state.
            assertThat(DeviceConfig.isSyncDisabled()).isFalse();
            assertThat(DeviceConfig.getSyncDisabled())
                    .isEqualTo(Settings.Config.SYNC_DISABLED_MODE_NONE);
            assertThat(DeviceConfig.setProperties(properties1)).isTrue();
            assertThat(DeviceConfig.getProperties(NAMESPACE, KEY).getString(KEY, DEFAULT_VALUE))
                    .isEqualTo(VALUE);
@@ -784,14 +785,16 @@ public class DeviceConfigTest {
            // Test disabled (persistent). Persistence is not actually tested, that would require
            // a host test.
            DeviceConfig.setSyncDisabled(Settings.Config.SYNC_DISABLED_MODE_PERSISTENT);
            assertThat(DeviceConfig.isSyncDisabled()).isTrue();
            assertThat(DeviceConfig.getSyncDisabled())
                    .isEqualTo(Settings.Config.SYNC_DISABLED_MODE_PERSISTENT);
            assertThat(DeviceConfig.setProperties(properties2)).isFalse();
            assertThat(DeviceConfig.getProperties(NAMESPACE, KEY).getString(KEY, DEFAULT_VALUE))
                    .isEqualTo(VALUE);

            // Return to not disabled.
            DeviceConfig.setSyncDisabled(Settings.Config.SYNC_DISABLED_MODE_NONE);
            assertThat(DeviceConfig.isSyncDisabled()).isFalse();
            assertThat(DeviceConfig.getSyncDisabled())
                    .isEqualTo(Settings.Config.SYNC_DISABLED_MODE_NONE);
            assertThat(DeviceConfig.setProperties(properties2)).isTrue();
            assertThat(DeviceConfig.getProperties(NAMESPACE, KEY).getString(KEY, DEFAULT_VALUE))
                    .isEqualTo(VALUE2);
@@ -799,14 +802,16 @@ public class DeviceConfigTest {
            // Test disabled (persistent). Absence of persistence is not actually tested, that would
            // require a host test.
            DeviceConfig.setSyncDisabled(Settings.Config.SYNC_DISABLED_MODE_UNTIL_REBOOT);
            assertThat(DeviceConfig.isSyncDisabled()).isTrue();
            assertThat(DeviceConfig.getSyncDisabled())
                    .isEqualTo(Settings.Config.SYNC_DISABLED_MODE_UNTIL_REBOOT);
            assertThat(DeviceConfig.setProperties(properties1)).isFalse();
            assertThat(DeviceConfig.getProperties(NAMESPACE, KEY).getString(KEY, DEFAULT_VALUE))
                    .isEqualTo(VALUE2);

            // Return to not disabled.
            DeviceConfig.setSyncDisabled(Settings.Config.SYNC_DISABLED_MODE_NONE);
            assertThat(DeviceConfig.isSyncDisabled()).isFalse();
            assertThat(DeviceConfig.getSyncDisabled())
                    .isEqualTo(Settings.Config.SYNC_DISABLED_MODE_NONE);
            assertThat(DeviceConfig.setProperties(properties1)).isTrue();
            assertThat(DeviceConfig.getProperties(NAMESPACE, KEY).getString(KEY, DEFAULT_VALUE))
                    .isEqualTo(VALUE);
+44 −14
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.os.ShellCallback;
import android.os.ShellCommand;
import android.provider.DeviceConfig;
import android.provider.Settings;
import android.provider.Settings.Config.SyncDisabledMode;

import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -69,7 +70,7 @@ public final class DeviceConfigService extends Binder {
            LIST,
            RESET,
            SET_SYNC_DISABLED_FOR_TESTS,
            IS_SYNC_DISABLED_FOR_TESTS,
            GET_SYNC_DISABLED_FOR_TESTS,
        }

        MyShellCommand(SettingsProvider provider) {
@@ -103,8 +104,8 @@ public final class DeviceConfigService extends Binder {
                verb = CommandVerb.RESET;
            } else if ("set_sync_disabled_for_tests".equalsIgnoreCase(cmd)) {
                verb = CommandVerb.SET_SYNC_DISABLED_FOR_TESTS;
            } else if ("is_sync_disabled_for_tests".equalsIgnoreCase(cmd)) {
                verb = CommandVerb.IS_SYNC_DISABLED_FOR_TESTS;
            } else if ("get_sync_disabled_for_tests".equalsIgnoreCase(cmd)) {
                verb = CommandVerb.GET_SYNC_DISABLED_FOR_TESTS;
                if (peekNextArg() != null) {
                    perr.println("Bad arguments");
                    return -1;
@@ -156,13 +157,8 @@ public final class DeviceConfigService extends Binder {
                } else if (verb == CommandVerb.SET_SYNC_DISABLED_FOR_TESTS) {
                    if (disableSyncMode == -1) {
                        // DISABLE_SYNC_FOR_TESTS 1st arg (required)
                        if ("none".equalsIgnoreCase(arg)) {
                            disableSyncMode = SYNC_DISABLED_MODE_NONE;
                        } else if ("persistent".equalsIgnoreCase(arg)) {
                            disableSyncMode = SYNC_DISABLED_MODE_PERSISTENT;
                        } else if ("until_reboot".equalsIgnoreCase(arg)) {
                            disableSyncMode = SYNC_DISABLED_MODE_UNTIL_REBOOT;
                        } else {
                        disableSyncMode = parseDisableSyncMode(arg);
                        if (disableSyncMode == -1) {
                            // invalid
                            perr.println("Invalid sync disabled mode: " + arg);
                            return -1;
@@ -254,8 +250,14 @@ public final class DeviceConfigService extends Binder {
                case SET_SYNC_DISABLED_FOR_TESTS:
                    DeviceConfig.setSyncDisabled(disableSyncMode);
                    break;
                case IS_SYNC_DISABLED_FOR_TESTS:
                    pout.println(DeviceConfig.isSyncDisabled());
                case GET_SYNC_DISABLED_FOR_TESTS:
                    int syncDisabledMode = DeviceConfig.getSyncDisabled();
                    String syncDisabledModeString = formatDisableSyncMode(syncDisabledMode);
                    if (syncDisabledModeString == null) {
                        perr.println("Unknown mode:" + syncDisabledMode);
                        return -1;
                    }
                    pout.println(syncDisabledModeString);
                    break;
                default:
                    perr.println("Unspecified command");
@@ -295,8 +297,9 @@ public final class DeviceConfigService extends Binder {
                    + " syncing.");
            pw.println("        persistent: Sync is disabled, this state will survive a reboot.");
            pw.println("        until_reboot: Sync is disabled until the next reboot.");
            pw.println("  is_sync_disabled_for_tests");
            pw.println("      Prints 'true' if sync is disabled, 'false' otherwise.");
            pw.println("  get_sync_disabled_for_tests");
            pw.println("      Prints one of the SYNC_DISABLED_MODE values, see"
                    + " set_sync_disabled_for_tests");
        }

        private boolean delete(IContentProvider provider, String namespace, String key) {
@@ -358,4 +361,31 @@ public final class DeviceConfigService extends Binder {
            }
        }
    }

    private static @SyncDisabledMode int parseDisableSyncMode(String arg) {
        int disableSyncMode;
        if ("none".equalsIgnoreCase(arg)) {
            disableSyncMode = SYNC_DISABLED_MODE_NONE;
        } else if ("persistent".equalsIgnoreCase(arg)) {
            disableSyncMode = SYNC_DISABLED_MODE_PERSISTENT;
        } else if ("until_reboot".equalsIgnoreCase(arg)) {
            disableSyncMode = SYNC_DISABLED_MODE_UNTIL_REBOOT;
        } else {
            disableSyncMode = -1;
        }
        return disableSyncMode;
    }

    private static String formatDisableSyncMode(@SyncDisabledMode int disableSyncMode) {
        switch (disableSyncMode) {
            case SYNC_DISABLED_MODE_NONE:
                return "none";
            case SYNC_DISABLED_MODE_PERSISTENT:
                return "persistent";
            case SYNC_DISABLED_MODE_UNTIL_REBOOT:
                return "until_reboot";
            default:
                return null;
        }
    }
}
+13 −11
Original line number Diff line number Diff line
@@ -477,10 +477,10 @@ public class SettingsProvider extends ContentProvider {
                break;
            }

            case Settings.CALL_METHOD_IS_SYNC_DISABLED_CONFIG: {
            case Settings.CALL_METHOD_GET_SYNC_DISABLED_CONFIG: {
                Bundle result = new Bundle();
                result.putBoolean(Settings.KEY_CONFIG_IS_SYNC_DISABLED_RETURN,
                        isSyncDisabledConfig());
                result.putInt(Settings.KEY_CONFIG_GET_SYNC_DISABLED_RETURN,
                        getSyncDisabledConfig());
                return result;
            }

@@ -1147,7 +1147,7 @@ public class SettingsProvider extends ContentProvider {
        enforceWritePermission(Manifest.permission.WRITE_DEVICE_CONFIG);

        synchronized (mLock) {
            if (isSyncDisabledConfigLocked()) {
            if (getSyncDisabledConfigLocked() != SYNC_DISABLED_MODE_NONE) {
                return SET_ALL_RESULT_DISABLED;
            }
            final int key = makeKey(SETTINGS_TYPE_CONFIG, UserHandle.USER_SYSTEM);
@@ -1169,15 +1169,15 @@ public class SettingsProvider extends ContentProvider {
        }
    }

    private boolean isSyncDisabledConfig() {
    private int getSyncDisabledConfig() {
        if (DEBUG) {
            Slog.v(LOG_TAG, "isSyncDisabledConfig");
            Slog.v(LOG_TAG, "getSyncDisabledConfig");
        }

        enforceWritePermission(Manifest.permission.WRITE_DEVICE_CONFIG);

        synchronized (mLock) {
            return isSyncDisabledConfigLocked();
            return getSyncDisabledConfigLocked();
        }
    }

@@ -1214,13 +1214,13 @@ public class SettingsProvider extends ContentProvider {
    }

    @GuardedBy("mLock")
    private boolean isSyncDisabledConfigLocked() {
    private int getSyncDisabledConfigLocked() {
        // Check the values used for both SYNC_DISABLED_MODE_PERSISTENT and
        // SYNC_DISABLED_MODE_UNTIL_REBOOT.

        // The SYNC_DISABLED_MODE_UNTIL_REBOOT value is cheap to check first.
        if (mSyncConfigDisabledUntilReboot) {
            return true;
            return SYNC_DISABLED_MODE_UNTIL_REBOOT;
        }

        // Now check the global setting used to implement SYNC_DISABLED_MODE_PERSISTENT.
@@ -1230,10 +1230,12 @@ public class SettingsProvider extends ContentProvider {
                    SETTINGS_TYPE_GLOBAL, UserHandle.USER_SYSTEM,
                    Global.DEVICE_CONFIG_SYNC_DISABLED);
            if (settingLocked == null) {
                return false;
                return SYNC_DISABLED_MODE_NONE;
            }
            String settingValue = settingLocked.getValue();
            return settingValue != null && !"0".equals(settingValue);
            boolean isSyncDisabledPersistent = settingValue != null && !"0".equals(settingValue);
            return isSyncDisabledPersistent
                    ? SYNC_DISABLED_MODE_PERSISTENT : SYNC_DISABLED_MODE_NONE;
        } finally {
            restoreCallingIdentity(callingIdentity);
        }