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

Commit e82f16f8 authored by Adam He's avatar Adam He Committed by android-build-merger
Browse files

Merge "Propogate disabled state to content capture session after changing user...

Merge "Propogate disabled state to content capture session after changing user restrictions or on ccm.setContentCaptureEnabled()." into qt-dev
am: 9f590ef1

Change-Id: I5fedb104718c3fd22a54f7c5caec1dc18cb3a2e7
parents d05b02a5 9f590ef1
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -484,8 +484,17 @@ public final class ContentCaptureManager {
            Log.d(TAG, "setContentCaptureEnabled(): setting to " + enabled + " for " + mContext);
        }

        MainContentCaptureSession mainSession;
        synchronized (mLock) {
            mFlags |= enabled ? 0 : ContentCaptureContext.FLAG_DISABLED_BY_APP;
            if (enabled) {
                mFlags &= ~ContentCaptureContext.FLAG_DISABLED_BY_APP;
            } else {
                mFlags |= ContentCaptureContext.FLAG_DISABLED_BY_APP;
            }
            mainSession = mMainSession;
        }
        if (mainSession != null) {
            mainSession.setDisabled(!enabled);
        }
    }

+23 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import static android.view.contentcapture.ContentCaptureEvent.TYPE_VIEW_TREE_APP
import static android.view.contentcapture.ContentCaptureHelper.getSanitizedString;
import static android.view.contentcapture.ContentCaptureHelper.sDebug;
import static android.view.contentcapture.ContentCaptureHelper.sVerbose;
import static android.view.contentcapture.ContentCaptureManager.RESULT_CODE_FALSE;

import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -80,6 +81,12 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
     */
    public static final String EXTRA_BINDER = "binder";

    /**
     * Name of the {@link IResultReceiver} extra used to pass the content capture enabled state.
     * @hide
     */
    public static final String EXTRA_ENABLED_STATE = "enabled";

    @NonNull
    private final AtomicBoolean mDisabled = new AtomicBoolean(false);

@@ -155,6 +162,13 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
            public void send(int resultCode, Bundle resultData) {
                final IBinder binder;
                if (resultData != null) {
                    // Change in content capture enabled.
                    final boolean hasEnabled = resultData.getBoolean(EXTRA_ENABLED_STATE);
                    if (hasEnabled) {
                        final boolean disabled = (resultCode == RESULT_CODE_FALSE);
                        mDisabled.set(disabled);
                        return;
                    }
                    binder = resultData.getBinder(EXTRA_BINDER);
                    if (binder == null) {
                        Log.wtf(TAG, "No " + EXTRA_BINDER + " extra result");
@@ -578,6 +592,15 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
        return mDisabled.get();
    }

    /**
     * Called by ContentCaptureManager.setContentCaptureEnabled
     *
     * @return whether disabled state was changed.
     */
    boolean setDisabled(boolean disabled) {
        return mDisabled.compareAndSet(!disabled, disabled);
    }

    // TODO(b/122454205): refactor "notifyXXXX" methods below to a common "Buffer" object that is
    // shared between ActivityContentCaptureSession and ChildContentCaptureSession objects. Such
    // change should also get get rid of the "internalNotifyXXXX" methods above
+9 −2
Original line number Diff line number Diff line
@@ -161,8 +161,14 @@ final class ContentCapturePerUserService
    @Override // from PerUserSystemService
    @GuardedBy("mLock")
    protected boolean updateLocked(boolean disabled) {
        destroyLocked();
        final boolean disabledStateChanged = super.updateLocked(disabled);
        if (disabledStateChanged) {
            // update session content capture enabled state.
            for (int i = 0; i < mSessions.size(); i++) {
                mSessions.valueAt(i).setContentCaptureEnabledLocked(!disabled);
            }
        }
        destroyLocked();
        updateRemoteServiceLocked(disabled);
        return disabledStateChanged;
    }
@@ -542,7 +548,8 @@ final class ContentCapturePerUserService
                Slog.v(TAG, "setContentCaptureWhitelist(" + (packages == null
                        ? "null_packages" : packages.size() + " packages")
                        + ", " + (activities == null
                        ? "null_activities" : activities.size() + " activities") + ")");
                        ? "null_activities" : activities.size() + " activities") + ")"
                        + " for user " + mUserId);
            }
            mMaster.mGlobalContentCaptureOptions.setWhitelist(mUserId, packages, activities);
        }
+19 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@
package com.android.server.contentcapture;

import static android.service.contentcapture.ContentCaptureService.setClientState;
import static android.view.contentcapture.ContentCaptureManager.RESULT_CODE_FALSE;
import static android.view.contentcapture.ContentCaptureManager.RESULT_CODE_TRUE;
import static android.view.contentcapture.ContentCaptureSession.NO_SESSION_ID;
import static android.view.contentcapture.ContentCaptureSession.STATE_ACTIVE;
import static android.view.contentcapture.ContentCaptureSession.STATE_DISABLED;
@@ -24,13 +26,16 @@ import static android.view.contentcapture.ContentCaptureSession.STATE_SERVICE_UP

import android.annotation.NonNull;
import android.content.ComponentName;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.service.contentcapture.ContentCaptureService;
import android.service.contentcapture.SnapshotData;
import android.util.LocalLog;
import android.util.Slog;
import android.view.contentcapture.ContentCaptureContext;
import android.view.contentcapture.ContentCaptureSessionId;
import android.view.contentcapture.MainContentCaptureSession;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.os.IResultReceiver;
@@ -107,6 +112,20 @@ final class ContentCaptureServerSession {
                STATE_ACTIVE);
    }

    /**
     * Changes the {@link ContentCaptureService} enabled state.
     */
    @GuardedBy("mLock")
    public void setContentCaptureEnabledLocked(boolean enabled) {
        try {
            final Bundle extras = new Bundle();
            extras.putBoolean(MainContentCaptureSession.EXTRA_ENABLED_STATE, true);
            mSessionStateReceiver.send(enabled ? RESULT_CODE_TRUE : RESULT_CODE_FALSE, extras);
        } catch (RemoteException e) {
            Slog.w(TAG, "Error async reporting result to client: " + e);
        }
    }

    /**
     * Notifies the {@link ContentCaptureService} of a snapshot of an activity.
     */