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

Commit 72e83d8c authored by Felipe Leme's avatar Felipe Leme
Browse files

Changed ContentCaptureManager API so service can only disable itself.

To re-enable, it will need to launch a Settings intent
(Settings.ACTION_REQUEST_ENABLE_CONTENT_CAPTURE).

Bug: 123286662
Test: atest CtsContentCaptureServiceTestCases

Change-Id: I0dd03013aba645c188af4034e530492d8294180e
parent 1ca52f00
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -6355,6 +6355,7 @@ package android.service.contentcapture {
  public abstract class ContentCaptureService extends android.app.Service {
    ctor public ContentCaptureService();
    method public final void disableContentCaptureServices();
    method public void onActivitySnapshot(@NonNull android.view.contentcapture.ContentCaptureSessionId, @NonNull android.service.contentcapture.SnapshotData);
    method public void onConnected();
    method public void onContentCaptureEvent(@NonNull android.view.contentcapture.ContentCaptureSessionId, @NonNull android.view.contentcapture.ContentCaptureEvent);
@@ -9372,7 +9373,6 @@ package android.view.contentcapture {
  public final class ContentCaptureManager {
    method public boolean isContentCaptureFeatureEnabled();
    method public void setContentCaptureFeatureEnabled(boolean);
  }
  public final class ViewNode extends android.app.assist.AssistStructure.ViewNode {
+1 −1
Original line number Diff line number Diff line
@@ -2114,6 +2114,7 @@ package android.service.contentcapture {

  public abstract class ContentCaptureService extends android.app.Service {
    ctor public ContentCaptureService();
    method public final void disableContentCaptureServices();
    method public void onActivitySnapshot(@NonNull android.view.contentcapture.ContentCaptureSessionId, @NonNull android.service.contentcapture.SnapshotData);
    method public void onConnected();
    method public void onContentCaptureEvent(@NonNull android.view.contentcapture.ContentCaptureSessionId, @NonNull android.view.contentcapture.ContentCaptureEvent);
@@ -2758,7 +2759,6 @@ 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_IDLE_FLUSH_FREQUENCY = "idle_flush_frequency";
    field public static final String DEVICE_CONFIG_PROPERTY_LOGGING_LEVEL = "logging_level";
    field public static final String DEVICE_CONFIG_PROPERTY_LOG_HISTORY_SIZE = "log_history_size";
+18 −0
Original line number Diff line number Diff line
@@ -283,6 +283,24 @@ public abstract class ContentCaptureService extends Service {
        if (VERBOSE) Log.v(TAG, "onDestroyContentCaptureSession(id=" + sessionId + ")");
    }

    /**
     * Disables the Content Capture service for the given user.
     */
    public final void disableContentCaptureServices() {
        if (DEBUG) Log.d(TAG, "disableContentCaptureServices()");

        final IContentCaptureServiceCallback callback = mCallback;
        if (callback == null) {
            Log.w(TAG, "disableContentCaptureServices(): no server callback");
            return;
        }
        try {
            callback.disableSelf();
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
        }
    }

    /**
     * Called when the Android system disconnects from the service.
     *
+2 −2
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package android.service.contentcapture;

import android.content.ComponentName;
import com.android.internal.os.IResultReceiver;

import java.util.List;

@@ -28,4 +27,5 @@ import java.util.List;
 */
oneway interface IContentCaptureServiceCallback {
    void setContentCaptureWhitelist(in List<String> packages, in List<ComponentName> activities);
    void disableSelf();
 }
+2 −33
Original line number Diff line number Diff line
@@ -327,39 +327,8 @@ public final class ContentCaptureManager {
            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
    @TestApi
    public void setContentCaptureFeatureEnabled(boolean enabled) {
        if (sDebug) 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);
                Log.wtf(TAG, "received invalid result: " + resultCode);
                return false;
        }
    }

Loading