summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/view/contentcapture/ContentCaptureManager.java11
-rw-r--r--core/java/android/view/contentcapture/MainContentCaptureSession.java23
-rw-r--r--services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java11
-rw-r--r--services/contentcapture/java/com/android/server/contentcapture/ContentCaptureServerSession.java19
4 files changed, 61 insertions, 3 deletions
diff --git a/core/java/android/view/contentcapture/ContentCaptureManager.java b/core/java/android/view/contentcapture/ContentCaptureManager.java
index c2ad82fd5c5f..84608406061a 100644
--- a/core/java/android/view/contentcapture/ContentCaptureManager.java
+++ b/core/java/android/view/contentcapture/ContentCaptureManager.java
@@ -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);
}
}
diff --git a/core/java/android/view/contentcapture/MainContentCaptureSession.java b/core/java/android/view/contentcapture/MainContentCaptureSession.java
index 784cf9c32557..8673fbe63091 100644
--- a/core/java/android/view/contentcapture/MainContentCaptureSession.java
+++ b/core/java/android/view/contentcapture/MainContentCaptureSession.java
@@ -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
diff --git a/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java b/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java
index a7921b5f3892..4399e4267fda 100644
--- a/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java
+++ b/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java
@@ -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);
}
diff --git a/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureServerSession.java b/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureServerSession.java
index d38dfd409439..2643db1d5851 100644
--- a/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureServerSession.java
+++ b/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureServerSession.java
@@ -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;
@@ -108,6 +113,20 @@ final class ContentCaptureServerSession {
}
/**
+ * 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.
*/
@GuardedBy("mLock")