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

Commit 842dd79e authored by Alex Mang's avatar Alex Mang
Browse files

Propagate ContentCaptureManager allowlist update to activities

Ref Doc: go/propagate-ccm-allowlist

BYPASS_INCLUSIVE_LANGUAGE_REASON=logging existing function call name
Tested: manually on device
Bug: 177345035
Bug: 165025636

Change-Id: I46c41a1e3e8a91a08889f5505e5bc1510776e253
parent 94691f3c
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
@@ -176,6 +176,8 @@ import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManagerGlobal;
import android.view.autofill.AutofillId;
import android.view.contentcapture.IContentCaptureManager;
import android.view.contentcapture.IContentCaptureOptionsCallback;
import android.view.translation.TranslationSpec;
import android.webkit.WebView;
import android.window.SplashScreen;
@@ -512,6 +514,8 @@ public final class ActivityThread extends ClientTransactionHandler {

    boolean mHasImeComponent = false;

    private IContentCaptureOptionsCallback.Stub mContentCaptureOptionsCallback = null;

    /** Activity client record, used for bookkeeping for the real {@link Activity} instance. */
    public static final class ActivityClientRecord {
        @UnsupportedAppUsage
@@ -1934,6 +1938,7 @@ public final class ActivityThread extends ClientTransactionHandler {
        public static final int PURGE_RESOURCES = 161;
        public static final int ATTACH_STARTUP_AGENTS = 162;
        public static final int UPDATE_UI_TRANSLATION_STATE = 163;
        public static final int SET_CONTENT_CAPTURE_OPTIONS_CALLBACK = 164;

        public static final int INSTRUMENT_WITHOUT_RESTART = 170;
        public static final int FINISH_INSTRUMENTATION_WITHOUT_RESTART = 171;
@@ -1983,6 +1988,8 @@ public final class ActivityThread extends ClientTransactionHandler {
                    case PURGE_RESOURCES: return "PURGE_RESOURCES";
                    case ATTACH_STARTUP_AGENTS: return "ATTACH_STARTUP_AGENTS";
                    case UPDATE_UI_TRANSLATION_STATE: return "UPDATE_UI_TRANSLATION_STATE";
                    case SET_CONTENT_CAPTURE_OPTIONS_CALLBACK:
                        return "SET_CONTENT_CAPTURE_OPTIONS_CALLBACK";
                    case INSTRUMENT_WITHOUT_RESTART: return "INSTRUMENT_WITHOUT_RESTART";
                    case FINISH_INSTRUMENTATION_WITHOUT_RESTART:
                        return "FINISH_INSTRUMENTATION_WITHOUT_RESTART";
@@ -2175,6 +2182,9 @@ public final class ActivityThread extends ClientTransactionHandler {
                            (TranslationSpec) args.arg3, (TranslationSpec) args.arg4,
                            (List<AutofillId>) args.arg5);
                    break;
                case SET_CONTENT_CAPTURE_OPTIONS_CALLBACK:
                    handleSetContentCaptureOptionsCallback((String) msg.obj);
                    break;
                case INSTRUMENT_WITHOUT_RESTART:
                    handleInstrumentWithoutRestart((AppBindData) msg.obj);
                    break;
@@ -6788,6 +6798,7 @@ public final class ActivityThread extends ClientTransactionHandler {

            // Propagate Content Capture options
            app.setContentCaptureOptions(data.contentCaptureOptions);
            sendMessage(H.SET_CONTENT_CAPTURE_OPTIONS_CALLBACK, data.appInfo.packageName);

            mInitialApplication = app;

@@ -6849,6 +6860,36 @@ public final class ActivityThread extends ClientTransactionHandler {
        }
    }

    private void handleSetContentCaptureOptionsCallback(String packageName) {
        if (mContentCaptureOptionsCallback != null) {
            return;
        }

        IBinder b = ServiceManager.getService(Context.CONTENT_CAPTURE_MANAGER_SERVICE);
        if (b == null) {
            return;
        }

        IContentCaptureManager service = IContentCaptureManager.Stub.asInterface(b);
        mContentCaptureOptionsCallback = new IContentCaptureOptionsCallback.Stub() {
            @Override
            public void setContentCaptureOptions(ContentCaptureOptions options)
                    throws RemoteException {
                if (mInitialApplication != null) {
                    mInitialApplication.setContentCaptureOptions(options);
                }
            }
        };
        try {
            service.registerContentCaptureOptionsCallback(packageName,
                    mContentCaptureOptionsCallback);
        } catch (RemoteException e)  {
            Slog.w(TAG, "registerContentCaptureOptionsCallback() failed: "
                    + packageName, e);
            mContentCaptureOptionsCallback = null;
        }
    }

    private void handleInstrumentWithoutRestart(AppBindData data) {
        try {
            data.compatInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;
+7 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.view.contentcapture.ContentCaptureEvent;
import android.view.contentcapture.DataRemovalRequest;
import android.view.contentcapture.DataShareRequest;
import android.view.contentcapture.IDataShareWriteAdapter;
import android.view.contentcapture.IContentCaptureOptionsCallback;
import android.os.IBinder;
import android.os.ICancellationSignal;

@@ -100,4 +101,10 @@ oneway interface IContentCaptureManager {
     * Sets whether the default service should be used.
     */
    void setDefaultServiceEnabled(int userId, boolean enabled);

    /**
     * Registers a listener to handle updates ContentCaptureOptions from server.
     */
    void registerContentCaptureOptionsCallback(String packageName,
                                               in IContentCaptureOptionsCallback callback);
}
+31 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2021, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.view.contentcapture;

import android.content.ContentCaptureOptions;

/**
  * Callback for changes to content capture options made by ContentCaptureService.
  * Callback interface used by IContentCaptureManager to send asynchronous
  * notifications back to its clients.  Note that this is a
  * one-way interface so the server does not block waiting for the client.
  *
  * @hide
  */
oneway interface IContentCaptureOptionsCallback {
    void setContentCaptureOptions(in ContentCaptureOptions options);
}
+12 −0
Original line number Diff line number Diff line
@@ -98,6 +98,18 @@ public class GlobalWhitelistState {
        }
    }

    /**
     * Gets packages that are either entirely allowlisted or have components that are allowlisted
     * for the given user.
     */
    public ArraySet<String> getWhitelistedPackages(@UserIdInt int userId) {
        synchronized (mGlobalWhitelistStateLock) {
            if (mWhitelisterHelpers == null) return null;
            final WhitelistHelper helper = mWhitelisterHelpers.get(userId);
            return helper == null ? null : helper.getWhitelistedPackages();
        }
    }

    /**
     * Resets the allowlist for the given user.
     */
+9 −0
Original line number Diff line number Diff line
@@ -140,6 +140,15 @@ public final class WhitelistHelper {
        return mWhitelistedPackages == null ? null : mWhitelistedPackages.get(packageName);
    }

    /**
     * Returns a set of all packages that are either entirely allowlisted or have components that
     * are allowlisted.
     */
    @Nullable
    public ArraySet<String> getWhitelistedPackages() {
        return mWhitelistedPackages == null ? null : new ArraySet<>(mWhitelistedPackages.keySet());
    }

    @Override
    public String toString() {
        return "WhitelistHelper[" + mWhitelistedPackages + ']';
Loading