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

Commit b278ec38 authored by Adam He's avatar Adam He Committed by Android (Google) Code Review
Browse files

Merge changes from topics "dsiable_settings_2", "disable_cc_settings"

* changes:
  Added new APIs to let ContentCaptureService enable / disable the feature.
  Added new APIs to let Settings enable / disable ContentCapture
parents 0f878e30 bb0c2a2a
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -6028,6 +6028,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";
@@ -9365,6 +9366,11 @@ package android.view.contentcapture {
    field public static final int TYPE_VIEW_TEXT_CHANGED = 3; // 0x3
  }
  public final class ContentCaptureManager {
    method public boolean isContentCaptureFeatureEnabled();
    method public void setContentCaptureFeatureEnabled(boolean);
  }
  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
@@ -1698,6 +1698,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
@@ -5687,6 +5687,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
         */
+93 −9
Original line number Diff line number Diff line
@@ -15,10 +15,12 @@
 */
package android.view.contentcapture;

import static android.view.contentcapture.ContentCaptureHelper.DEBUG;
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;
@@ -51,6 +53,13 @@ public final class ContentCaptureManager {

    private static final String TAG = ContentCaptureManager.class.getSimpleName();

    /** @hide */
    public static final int RESULT_CODE_TRUE = 1;
    /** @hide */
    public static final int RESULT_CODE_FALSE = 2;
    /** @hide */
    public static final int RESULT_CODE_NOT_SERVICE = -1;

    /**
     * Timeout for calls to system_server.
     */
@@ -108,9 +117,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 +154,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 +167,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) {
@@ -178,11 +192,81 @@ public final class ContentCaptureManager {
     * it on {@link android.app.Activity#onCreate(android.os.Bundle, android.os.PersistableBundle)}.
     */
    public void setContentCaptureEnabled(boolean enabled) {
        if (DEBUG) {
            Log.d(TAG, "setContentCaptureEnabled(): setting to " + enabled + " for " + mContext);
        }

        synchronized (mLock) {
            mFlags |= enabled ? 0 : ContentCaptureContext.FLAG_DISABLED_BY_APP;
        }
    }

    /**
     * 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.
     *
     * @throws SecurityException if caller is not the app that owns the Content Capture service
     * associated with the user.
     *
     * @hide
     */
    @SystemApi
    public boolean isContentCaptureFeatureEnabled() {
        if (mService == null) return false;

        final SyncResultReceiver resultReceiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS);
        final int resultCode;
        try {
            mService.isContentCaptureFeatureEnabled(resultReceiver);
            resultCode = resultReceiver.getIntResult();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
        switch (resultCode) {
            case RESULT_CODE_TRUE:
                return true;
            case RESULT_CODE_FALSE:
                return false;
            case RESULT_CODE_NOT_SERVICE:
                throw new SecurityException("caller is not user's ContentCapture service");
            default:
                throw new IllegalStateException("received invalid result: " + resultCode);
        }
    }

    /**
     * Sets whether Content Capture is enabled for the given user.
     *
     * @throws SecurityException if caller is not the app that owns the Content Capture service
     * associated with the user.
     *
     * @hide
     */
    @SystemApi
    public void setContentCaptureFeatureEnabled(boolean enabled) {
        if (DEBUG) Log.d(TAG, "setContentCaptureFeatureEnabled(): setting to " + enabled);

        final SyncResultReceiver resultReceiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS);
        final int resultCode;
        try {
            mService.setContentCaptureFeatureEnabled(enabled, resultReceiver);
            resultCode = resultReceiver.getIntResult();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
        switch (resultCode) {
            case RESULT_CODE_TRUE:
                // Our work is done here, in our void existance...
                return;
            case RESULT_CODE_NOT_SERVICE:
                throw new SecurityException("caller is not user's ContentCapture service");
            default:
                throw new IllegalStateException("received invalid result: " + resultCode);
        }
    }

    /**
     * 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