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

Commit 14ef461f authored by Felipe Leme's avatar Felipe Leme
Browse files

Reverted ContentCapture kill-switch mechanism.

Fixes: 121153631
Fixes: 121144410

Test: atest CtsContentCaptureServiceTestCases

Change-Id: Ic0e3fe6e93a8c2aff12eebcf9872f0082a361589
parent 5e1e7099
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -5709,6 +5709,7 @@ package android.provider {
    method @RequiresPermission(android.Manifest.permission.WRITE_DEVICE_CONFIG) public static void resetToDefaults(int, @Nullable String);
    method @RequiresPermission(android.Manifest.permission.WRITE_DEVICE_CONFIG) public static boolean setProperty(String, String, String, boolean);
    field public static final String NAMESPACE_AUTOFILL = "autofill";
    field public static final String NAMESPACE_CONTENT_CAPTURE = "content_capture";
    field public static final String NAMESPACE_GAME_DRIVER = "game_driver";
    field public static final String NAMESPACE_INPUT_NATIVE_BOOT = "input_native_boot";
    field public static final String NAMESPACE_NETD_NATIVE = "netd_native";
@@ -5738,10 +5739,6 @@ package android.provider {
    field public static final String SERVICE_ENABLED = "service_enabled";
  }
  public static interface DeviceConfig.ContentCapture {
    field public static final String NAMESPACE = "content_capture";
  }
  public static interface DeviceConfig.DexBoot {
    field public static final String NAMESPACE = "dex_boot";
    field public static final String PRIV_APPS_OOB_ENABLED = "priv_apps_oob_enabled";
+2 −5
Original line number Diff line number Diff line
@@ -1787,11 +1787,7 @@ package android.provider {
    method @RequiresPermission("android.permission.READ_DEVICE_CONFIG") public static String getProperty(String, String);
    method @RequiresPermission("android.permission.WRITE_DEVICE_CONFIG") public static void resetToDefaults(int, @Nullable String);
    method @RequiresPermission("android.permission.WRITE_DEVICE_CONFIG") public static boolean setProperty(String, String, String, boolean);
  }

  public static interface DeviceConfig.ContentCapture {
    field public static final String NAMESPACE = "content_capture";
    field public static final String PROPERTY_CONTENTCAPTURE_ENABLED = "enable_contentcapture";
    field public static final String NAMESPACE_CONTENT_CAPTURE = "content_capture";
  }

  public static interface DeviceConfig.Privacy {
@@ -2723,6 +2719,7 @@ package android.view.contentcapture {
  public final class ContentCaptureManager {
    method public boolean isContentCaptureFeatureEnabled();
    method public void setContentCaptureFeatureEnabled(boolean);
    field public static final String DEVICE_CONFIG_PROPERTY_SERVICE_EXPLICITLY_ENABLED = "service_explicitly_enabled";
  }

  public final class ViewNode extends android.app.assist.AssistStructure.ViewNode {
+3 −28
Original line number Diff line number Diff line
@@ -72,39 +72,14 @@ public final class DeviceConfig {
    public static final String NAMESPACE_AUTOFILL = "autofill";

    /**
     * ContentCapture-related properties definitions.
     * Namespace for content capture feature used by on-device machine intelligence
     * to provide suggestions in a privacy-safe manner.
     *
     * @hide
     */
    @SystemApi
    @TestApi
    public interface ContentCapture {
        String NAMESPACE = "content_capture";

        /**
         * Property used by {@code com.android.server.SystemServer} on start to decide whether
         * the Content Capture service should be created or not.
         *
         * <p>Possible values are:
         *
         * <ul>
         *   <li>If set to {@code default}, it will only be set if the OEM provides and defines the
         *   service name by overlaying {@code config_defaultContentCaptureService} (this is the
         *   "default" mode)
         *   <li>If set to {@code always}, it will always be enabled, even when the resource is not
         *   overlaid (this is useful during development and to run the CTS tests on AOSP builds).
         *   <li>Otherwise, it's explicitly disabled (this could work as a "kill switch" so OEMs
         *   can disable it remotely in case of emergency by setting to something else (like
         *   {@code "false"}); notice that it's also disabled if the OEM doesn't explicitly set one
         *   of the values above).
         * </ul>
         *
         * @hide
         */
        // TODO(b/121153631): revert back to SERVICE_EXPLICITLY_ENABLED approach
        @TestApi
        String PROPERTY_CONTENTCAPTURE_ENABLED = "enable_contentcapture";
    }
    public static final String NAMESPACE_CONTENT_CAPTURE = "content_capture";

    /**
     * Namespace for all input-related features that are used at the native level.
+19 −0
Original line number Diff line number Diff line
@@ -66,6 +66,25 @@ public final class ContentCaptureManager {
     */
    private static final int SYNC_CALLS_TIMEOUT_MS = 5000;

    /**
     * DeviceConfig property used by {@code com.android.server.SystemServer} on start to decide
     * whether the Content Capture service should be created or not
     *
     * <p>By default it should *NOT* be set (or set to {@code "default"}, so the decision is based
     * on whether the OEM provides an implementation for the service), but it can be overridden to:
     *
     * <ul>
     *   <li>Provide a "kill switch" so OEMs can disable it remotely in case of emergency (when
     *   it's set to {@code "false"}).
     *   <li>Enable the CTS tests to be run on AOSP builds (when it's set to {@code "true"}).
     * </ul>
     *
     * @hide
     */
    @TestApi
    public static final String DEVICE_CONFIG_PROPERTY_SERVICE_EXPLICITLY_ENABLED =
            "service_explicitly_enabled";

    private final Object mLock = new Object();

    @NonNull
+15 −9
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ public final class ContentCaptureManagerService extends

    /**
     * Global kill-switch based on value defined by
     * {@link android.provider.DeviceConfig.ContentCapture#PROPERTY_CONTENTCAPTURE_ENABLED}.
     * {@link ContentCaptureManager#DEVICE_CONFIG_PROPERTY_SERVICE_EXPLICITLY_ENABLED}.
     */
    @GuardedBy("mLock")
    @Nullable
@@ -103,9 +103,16 @@ public final class ContentCaptureManagerService extends
        super(context, new FrameworkResourcesServiceNameResolver(context,
                com.android.internal.R.string.config_defaultContentCaptureService),
                UserManager.DISALLOW_CONTENT_CAPTURE);
        DeviceConfig.addOnPropertyChangedListener(DeviceConfig.ContentCapture.NAMESPACE,
        DeviceConfig.addOnPropertyChangedListener(DeviceConfig.NAMESPACE_CONTENT_CAPTURE,
                ActivityThread.currentApplication().getMainExecutor(),
                (namespace, name, value) -> setDisabledByDeviceConfig(value));
                (namespace, key, value) -> {
                    if (!ContentCaptureManager.DEVICE_CONFIG_PROPERTY_SERVICE_EXPLICITLY_ENABLED
                            .equals(key)) {
                        Slog.i(mTag, "Ignoring change on " + key);
                        return;
                    }
                    setDisabledByDeviceConfig(value);
                });
        setDisabledByDeviceConfig();

        // Sets which services are disabled
@@ -207,8 +214,8 @@ public final class ContentCaptureManagerService extends
    }

    private void setDisabledByDeviceConfig() {
        final String value = DeviceConfig.getProperty(DeviceConfig.ContentCapture.NAMESPACE,
                DeviceConfig.ContentCapture.PROPERTY_CONTENTCAPTURE_ENABLED);
        final String value = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_CONTENT_CAPTURE,
                ContentCaptureManager.DEVICE_CONFIG_PROPERTY_SERVICE_EXPLICITLY_ENABLED);
        setDisabledByDeviceConfig(value);
    }

@@ -219,11 +226,10 @@ public final class ContentCaptureManagerService extends

        final boolean newDisabledValue;

        if (value != null && (value.equals("default") || value.equals("always"))) {
            newDisabledValue = false;
            if (debug) Slog.d(mTag, "setDisabledByDeviceConfig(): set to false on '" + value + "'");
        } else {
        if (value != null && value.equalsIgnoreCase("false")) {
            newDisabledValue = true;
        } else {
            newDisabledValue = false;
        }

        synchronized (mLock) {
Loading