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

Commit 326f15a3 authored by Felipe Leme's avatar Felipe Leme
Browse files

Optimized Content Capture workflow by caching some state at the application level.

Content Capture for an activity and/or package is only available when the Content Capture service
explicitly whitelists it. As the whitelist is kept at system-server level, it's better to fetch that
info when the application is started and cache it locally, so we can optimize the
ContentCaptureManager APIs to return quickly when it's disabled.

This CL also caches other values such as the buffer parameters.

Test: atest CtsContentCaptureServiceTestCases

Bug: 120494182
Bug: 121202151

Change-Id: I9d5211bca496ffa85ba9efc2a7bb32411834b787
parent 98ab00f9
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -483,6 +483,20 @@ package android.bluetooth {

package android.content {

  public final class ContentCaptureOptions implements android.os.Parcelable {
    ctor public ContentCaptureOptions(int, int, int, int, int, @Nullable android.util.ArraySet<android.content.ComponentName>);
    method public int describeContents();
    method public static android.content.ContentCaptureOptions forWhitelistingItself();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.content.ContentCaptureOptions> CREATOR;
    field public final int idleFlushingFrequencyMs;
    field public final int logHistorySize;
    field public final int loggingLevel;
    field public final int maxBufferSize;
    field public final int textChangeFlushingFrequencyMs;
    field @Nullable public final android.util.ArraySet<android.content.ComponentName> whitelistedComponents;
  }

  public class ContentProviderClient implements java.lang.AutoCloseable {
    method @RequiresPermission(android.Manifest.permission.REMOVE_TASKS) public void setDetectNotResponding(long);
  }
@@ -496,6 +510,7 @@ package android.content {
    method public android.os.UserHandle getUser();
    method public int getUserId();
    method public void setAutofillCompatibilityEnabled(boolean);
    method public void setContentCaptureOptions(@Nullable android.content.ContentCaptureOptions);
  }

}
+2 −7
Original line number Diff line number Diff line
@@ -1110,7 +1110,7 @@ public class Activity extends ContextThemeWrapper
        super.attachBaseContext(newBase);
        if (newBase != null) {
            newBase.setAutofillClient(this);
            newBase.setContentCaptureSupported(true);
            newBase.setContentCaptureOptions(getContentCaptureOptions());
        }
    }

@@ -1120,12 +1120,6 @@ public class Activity extends ContextThemeWrapper
        return this;
    }

    /** @hide */
    @Override
    public boolean isContentCaptureSupported() {
        return true;
    }

    /**
     * Register an {@link Application.ActivityLifecycleCallbacks} instance that receives
     * lifecycle callbacks for only this Activity.
@@ -7615,6 +7609,7 @@ public class Activity extends ContextThemeWrapper
        mWindow.setColorMode(info.colorMode);

        setAutofillCompatibilityEnabled(application.isAutofillCompatibilityEnabled());
        setContentCaptureOptions(application.getContentCaptureOptions());
    }

    private void enableAutofillCompatibilityIfNeeded() {
+15 −1
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import android.app.servertransaction.TransactionExecutorHelper;
import android.content.BroadcastReceiver;
import android.content.ComponentCallbacks2;
import android.content.ComponentName;
import android.content.ContentCaptureOptions;
import android.content.ContentProvider;
import android.content.ContentResolver;
import android.content.Context;
@@ -746,6 +747,14 @@ public final class ActivityThread extends ClientTransactionHandler {

        boolean autofillCompatibilityEnabled;

        /**
         * Content capture options for the application - when null, it means ContentCapture is not
         * enabled for the package.
         */
        @Nullable
        ContentCaptureOptions contentCaptureOptions;

        @Override
        public String toString() {
            return "AppBindData{appInfo=" + appInfo + "}";
        }
@@ -966,7 +975,8 @@ public final class ActivityThread extends ClientTransactionHandler {
                boolean enableBinderTracking, boolean trackAllocation,
                boolean isRestrictedBackupMode, boolean persistent, Configuration config,
                CompatibilityInfo compatInfo, Map services, Bundle coreSettings,
                String buildSerial, boolean autofillCompatibilityEnabled) {
                String buildSerial, boolean autofillCompatibilityEnabled,
                ContentCaptureOptions contentCaptureOptions) {

            if (services != null) {
                if (false) {
@@ -1014,6 +1024,7 @@ public final class ActivityThread extends ClientTransactionHandler {
            data.initProfilerInfo = profilerInfo;
            data.buildSerial = buildSerial;
            data.autofillCompatibilityEnabled = autofillCompatibilityEnabled;
            data.contentCaptureOptions = contentCaptureOptions;
            sendMessage(H.BIND_APPLICATION, data);
        }

@@ -6155,6 +6166,9 @@ public final class ActivityThread extends ClientTransactionHandler {
            // Propagate autofill compat state
            app.setAutofillCompatibilityEnabled(data.autofillCompatibilityEnabled);

            // Propagate Content Capture options
            app.setContentCaptureOptions(data.contentCaptureOptions);

            mInitialApplication = app;

            // don't bring up providers in restricted mode; they may depend on the
+6 −5
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.annotation.TestApi;
import android.annotation.UnsupportedAppUsage;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentCaptureOptions;
import android.content.ContentProvider;
import android.content.ContentResolver;
import android.content.Context;
@@ -217,7 +218,7 @@ class ContextImpl extends Context {
    private AutofillClient mAutofillClient = null;
    private boolean mIsAutofillCompatEnabled;

    private boolean mIsContentCaptureSupported = false;
    private ContentCaptureOptions mContentCaptureOptions = null;

    private final Object mSync = new Object();

@@ -2388,14 +2389,14 @@ class ContextImpl extends Context {

    /** @hide */
    @Override
    public boolean isContentCaptureSupported() {
        return mIsContentCaptureSupported;
    public ContentCaptureOptions getContentCaptureOptions() {
        return mContentCaptureOptions;
    }

    /** @hide */
    @Override
    public void setContentCaptureSupported(boolean supported) {
        mIsContentCaptureSupported = supported;
    public void setContentCaptureOptions(ContentCaptureOptions options) {
        mContentCaptureOptions = options;
    }

    @UnsupportedAppUsage
+3 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.app.ProfilerInfo;
import android.app.ResultInfo;
import android.app.servertransaction.ClientTransaction;
import android.content.ComponentName;
import android.content.ContentCaptureOptions;
import android.content.IIntentReceiver;
import android.content.Intent;
import android.content.pm.ActivityInfo;
@@ -68,7 +69,8 @@ oneway interface IApplicationThread {
            int debugMode, boolean enableBinderTracking, boolean trackAllocation,
            boolean restrictedBackupMode, boolean persistent, in Configuration config,
            in CompatibilityInfo compatInfo, in Map services,
            in Bundle coreSettings, in String buildSerial, boolean isAutofillCompatEnabled);
            in Bundle coreSettings, in String buildSerial, boolean isAutofillCompatEnabled,
            in ContentCaptureOptions contentCaptureOptions);
    void runIsolatedEntryPoint(in String entryPoint, in String[] entryPointArgs);
    void scheduleExit();
    void scheduleServiceArgs(IBinder token, in ParceledListSlice args);
Loading