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

Commit 000e9572 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Integrate content capture with FLAG_SECURE"

parents 4e536b85 328c0e38
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -121,6 +121,7 @@ import android.view.autofill.AutofillManager;
import android.view.autofill.AutofillManager.AutofillClient;
import android.view.autofill.AutofillPopupWindow;
import android.view.autofill.IAutofillWindowPresenter;
import android.view.contentcapture.ContentCaptureContext;
import android.view.contentcapture.ContentCaptureManager;
import android.widget.AdapterView;
import android.widget.Toast;
@@ -1045,14 +1046,19 @@ public class Activity extends ContextThemeWrapper

    private void notifyContentCaptureManagerIfNeeded(@ContentCaptureNotificationType int type) {
        final ContentCaptureManager cm = getContentCaptureManager();
        if (cm == null || !cm.isContentCaptureEnabled()) {
        if (cm == null) {
            return;
        }
        switch (type) {
            case CONTENT_CAPTURE_START:
                //TODO(b/111276913): decide whether the InteractionSessionId should be
                // saved / restored in the activity bundle - probably not
                cm.onActivityStarted(mToken, getComponentName());
                int flags = 0;
                if ((getWindow().getAttributes().flags
                        & WindowManager.LayoutParams.FLAG_SECURE) != 0) {
                    flags |= ContentCaptureContext.FLAG_DISABLED_BY_FLAG_SECURE;
                }
                cm.onActivityStarted(mToken, getComponentName(), flags);
                break;
            case CONTENT_CAPTURE_FLUSH:
                cm.flush();
+12 −3
Original line number Diff line number Diff line
@@ -311,6 +311,14 @@ public abstract class ContentCaptureService extends Service {
            @NonNull String sessionId, int uid, IResultReceiver clientReceiver) {
        mSessionUids.put(sessionId, uid);
        onCreateContentCaptureSession(context, new ContentCaptureSessionId(sessionId));

        final int flags = context.getFlags();
        if ((flags & ContentCaptureContext.FLAG_DISABLED_BY_FLAG_SECURE) != 0) {
            setClientState(clientReceiver, ContentCaptureSession.STATE_DISABLED_BY_FLAG_SECURE,
                    mClientInterface.asBinder());
            return;
        }

        setClientState(clientReceiver, ContentCaptureSession.STATE_ACTIVE,
                mClientInterface.asBinder());
    }
@@ -392,15 +400,16 @@ public abstract class ContentCaptureService extends Service {
    }

    /**
     * Sends the state of the {@link ContentCaptureManager} in the cleint app.
     * Sends the state of the {@link ContentCaptureManager} in the client app.
     *
     * @param clientReceiver receiver in the client app.
     * @param sessionState state of the session
     * @param binder handle to the {@code IContentCaptureDirectManager} object that resides in the
     * service.
     * @hide
     */
    public static void setClientState(@NonNull IResultReceiver clientReceiver,
            int sessionStatus, @Nullable IBinder binder) {
            int sessionState, @Nullable IBinder binder) {
        try {
            final Bundle extras;
            if (binder != null) {
@@ -409,7 +418,7 @@ public abstract class ContentCaptureService extends Service {
            } else {
                extras = null;
            }
            clientReceiver.send(sessionStatus, extras);
            clientReceiver.send(sessionState, extras);
        } catch (RemoteException e) {
            Slog.w(TAG, "Error async reporting result to client: " + e);
        }
+2 −2
Original line number Diff line number Diff line
@@ -126,8 +126,8 @@ public final class ContentCaptureManager {

    /** @hide */
    public void onActivityStarted(@NonNull IBinder applicationToken,
            @NonNull ComponentName activityComponent) {
        getMainContentCaptureSession().start(applicationToken, activityComponent);
            @NonNull ComponentName activityComponent, int flags) {
        getMainContentCaptureSession().start(applicationToken, activityComponent, flags);
    }

    /** @hide */
+9 −0
Original line number Diff line number Diff line
@@ -86,6 +86,13 @@ public abstract class ContentCaptureSession implements AutoCloseable {
     */
    public static final int STATE_DISABLED_DUPLICATED_ID = 4;

    /**
     * Session is disabled by FLAG_SECURE
     *
     * @hide
     */
    public static final int STATE_DISABLED_BY_FLAG_SECURE = 5;

    private static final int INITIAL_CHILDREN_CAPACITY = 5;

    private final CloseGuard mCloseGuard = CloseGuard.get();
@@ -356,6 +363,8 @@ public abstract class ContentCaptureSession implements AutoCloseable {
                return "DISABLED_NO_SERVICE";
            case STATE_DISABLED_DUPLICATED_ID:
                return "DISABLED_DUPLICATED_ID";
            case STATE_DISABLED_BY_FLAG_SECURE:
                return "DISABLED_FLAG_SECURE";
            default:
                return "INVALID:" + state;
        }
+10 −5
Original line number Diff line number Diff line
@@ -157,7 +157,8 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
     *
     * @hide
     */
    void start(@NonNull IBinder applicationToken, @NonNull ComponentName activityComponent) {
    void start(@NonNull IBinder applicationToken, @NonNull ComponentName activityComponent,
            int flags) {
        if (!isContentCaptureEnabled()) return;

        if (VERBOSE) {
@@ -166,7 +167,7 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
        }

        mHandler.sendMessage(obtainMessage(MainContentCaptureSession::handleStartSession, this,
                applicationToken, activityComponent));
                applicationToken, activityComponent, flags));
    }

    @Override
@@ -181,7 +182,8 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
                obtainMessage(MainContentCaptureSession::handleDestroySession, this));
    }

    private void handleStartSession(@NonNull IBinder token, @NonNull ComponentName componentName) {
    private void handleStartSession(@NonNull IBinder token, @NonNull ComponentName componentName,
            int flags) {
        if (mState != STATE_UNKNOWN) {
            // TODO(b/111276913): revisit this scenario
            Log.w(TAG, "ignoring handleStartSession(" + token + ") while on state "
@@ -196,7 +198,6 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
            Log.v(TAG, "handleStartSession(): token=" + token + ", act="
                    + getActivityDebugName() + ", id=" + mId);
        }
        final int flags = 0; // TODO(b/111276913): get proper flags

        try {
            if (mSystemServerInterface == null) return;
@@ -245,7 +246,11 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
                Log.w(TAG, "Failed to link to death on " + binder + ": " + e);
            }
        }
        if (resultCode == STATE_DISABLED_NO_SERVICE || resultCode == STATE_DISABLED_DUPLICATED_ID) {

        // TODO(b/111276913): change the resultCode to use flags so there's just one flag for
        // disabled stuff
        if (resultCode == STATE_DISABLED_NO_SERVICE || resultCode == STATE_DISABLED_DUPLICATED_ID
                || resultCode == STATE_DISABLED_BY_FLAG_SECURE) {
            mDisabled.set(true);
            handleResetSession(/* resetState= */ false);
        } else {