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

Commit 91ddecac authored by Felipe Leme's avatar Felipe Leme
Browse files

Added new APIs to let Settings enable / disable ContentCapture

Bug: 123286662
Test: atest ChildlessActivityTest#testSetContentCaptureFeatureEnabled_disabledBySettings \
        ChildlessActivityTest#testSetContentCaptureFeatureEnabled_disabledThenReEnabledBySettings\
        FrameworksCoreTests:SettingsBackupTest#secureSettingsBackedUpOrBlacklisted
Test: atest CtsContentCaptureServiceTestCases # for sanity check

Change-Id: I7cd2c36c1d7e23efb9acacf4f18cecd8838f5ac5
parent effa5f43
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -5865,6 +5865,7 @@ package android.provider {
    field public static final String AUTOFILL_USER_DATA_MAX_VALUE_LENGTH = "autofill_user_data_max_value_length";
    field public static final String AUTOFILL_USER_DATA_MIN_VALUE_LENGTH = "autofill_user_data_min_value_length";
    field public static final String COMPLETED_CATEGORY_PREFIX = "suggested.completed_category.";
    field public static final String CONTENT_CAPTURE_ENABLED = "content_capture_enabled";
    field public static final String DOZE_ALWAYS_ON = "doze_always_on";
    field public static final String HUSH_GESTURE_USED = "hush_gesture_used";
    field public static final String INSTANT_APPS_ENABLED = "instant_apps_enabled";
@@ -9200,6 +9201,10 @@ package android.view.contentcapture {
    field public static final int TYPE_VIEW_TEXT_CHANGED = 3; // 0x3
  }
  public final class ContentCaptureManager {
    method public boolean isContentCaptureFeatureEnabled();
  }
  public final class UserDataRemovalRequest implements android.os.Parcelable {
    method @NonNull public String getPackageName();
    method @NonNull public java.util.List<android.view.contentcapture.UserDataRemovalRequest.UriRequest> getUriRequests();
+1 −0
Original line number Diff line number Diff line
@@ -1542,6 +1542,7 @@ package android.provider {
    field public static final String AUTOFILL_USER_DATA_MAX_USER_DATA_SIZE = "autofill_user_data_max_user_data_size";
    field public static final String AUTOFILL_USER_DATA_MAX_VALUE_LENGTH = "autofill_user_data_max_value_length";
    field public static final String AUTOFILL_USER_DATA_MIN_VALUE_LENGTH = "autofill_user_data_min_value_length";
    field public static final String CONTENT_CAPTURE_ENABLED = "content_capture_enabled";
    field public static final String DISABLED_PRINT_SERVICES = "disabled_print_services";
    field @Deprecated public static final String ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES = "enabled_notification_policy_access_packages";
    field public static final String LOCATION_ACCESS_CHECK_DELAY_MILLIS = "location_access_check_delay_millis";
+8 −0
Original line number Diff line number Diff line
@@ -5655,6 +5655,14 @@ public final class Settings {
        public static final String AUTOFILL_USER_DATA_MIN_VALUE_LENGTH =
                "autofill_user_data_min_value_length";
        /**
         * Defines whether Content Capture is enabled  for the user.
         * @hide
         */
        @SystemApi
        @TestApi
        public static final String CONTENT_CAPTURE_ENABLED = "content_capture_enabled";
        /**
         * @deprecated Use {@link android.provider.Settings.Global#DEVICE_PROVISIONED} instead
         */
+37 −9
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import static android.view.contentcapture.ContentCaptureHelper.VERBOSE;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.UiThread;
import android.content.ComponentName;
@@ -108,9 +109,7 @@ public final class ContentCaptureManager {
            if (mMainSession == null) {
                mMainSession = new MainContentCaptureSession(mContext, mHandler, mService,
                        mDisabled);
                if (VERBOSE) {
                    Log.v(TAG, "getDefaultContentCaptureSession(): created " + mMainSession);
                }
                if (VERBOSE) Log.v(TAG, "getMainContentCaptureSession(): created " + mMainSession);
            }
            return mMainSession;
        }
@@ -147,13 +146,9 @@ public final class ContentCaptureManager {
     */
    @Nullable
    public ComponentName getServiceComponentName() {
        if (!isContentCaptureEnabled()) {
            return null;
        }
        // Wait for system server to return the component name.
        final SyncResultReceiver resultReceiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS);

        if (!isContentCaptureEnabled()) return null;

        final SyncResultReceiver resultReceiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS);
        try {
            mService.getServiceComponentName(resultReceiver);
            return resultReceiver.getParcelableResult();
@@ -164,6 +159,17 @@ public final class ContentCaptureManager {

    /**
     * Checks whether content capture is enabled for this activity.
     *
     * <p>There are many reasons it could be disabled, such as:
     * <ul>
     *   <li>App itself disabled content capture through {@link #setContentCaptureEnabled(boolean)}.
     *   <li>Service disabled content capture for this specific activity.
     *   <li>Service disabled content capture for all activities of this package.
     *   <li>Service disabled content capture globally.
     *   <li>User disabled content capture globally (through Settings).
     *   <li>OEM disabled content capture globally.
     *   <li>Transient errors.
     * </ul>
     */
    public boolean isContentCaptureEnabled() {
        synchronized (mLock) {
@@ -183,6 +189,28 @@ public final class ContentCaptureManager {
        }
    }

    /**
     * Gets whether Content Capture is enabled for the given user.
     *
     * <p>This method is typically used by the Content Capture Service settings page, so it can
     * provide a toggle to enable / disable it.
     *
     * @hide
     */
    @SystemApi
    public boolean isContentCaptureFeatureEnabled() {
        if (mService == null) return false;

        final SyncResultReceiver resultReceiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS);
        try {
            mService.isContentCaptureFeatureEnabled(resultReceiver);
            return resultReceiver.getIntResult() == 1;
        } catch (RemoteException e) {
            // Unable to retrieve component name in a reasonable amount of time.
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Called by the app to request the Content Capture service to remove user-data associated with
     * some context.
+2 −1
Original line number Diff line number Diff line
@@ -99,7 +99,8 @@ public abstract class ContentCaptureSession implements AutoCloseable {
    public static final int STATE_FLAG_SECURE = 0x20;

    /**
     * Session is disabled manually by the specific app.
     * Session is disabled manually by the specific app
     * (through {@link ContentCaptureManager#setContentCaptureEnabled(boolean)}).
     *
     * @hide
     */
Loading