diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index 4abf924b4a43a..2914f6c5abf2b 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -126,7 +126,6 @@ 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.view.contentcapture.ContentCaptureManager.ContentCaptureClient; import android.widget.AdapterView; @@ -840,7 +839,7 @@ public class Activity extends ContextThemeWrapper /** The autofill manager. Always access via {@link #getAutofillManager()}. */ @Nullable private AutofillManager mAutofillManager; - /** The content capture manager. Always access via {@link #getContentCaptureManager()}. */ + /** The content capture manager. Access via {@link #getContentCaptureManager()}. */ @Nullable private ContentCaptureManager mContentCaptureManager; private final ArrayList mActivityLifecycleCallbacks = @@ -1092,12 +1091,11 @@ public class Activity extends ContextThemeWrapper case CONTENT_CAPTURE_START: //TODO(b/111276913): decide whether the InteractionSessionId should be // saved / restored in the activity bundle - probably not - int flags = 0; - if ((getWindow().getAttributes().flags - & WindowManager.LayoutParams.FLAG_SECURE) != 0) { - flags |= ContentCaptureContext.FLAG_DISABLED_BY_FLAG_SECURE; + final Window window = getWindow(); + if (window != null) { + cm.updateWindowAttributes(window.getAttributes()); } - cm.onActivityCreated(mToken, getComponentName(), flags); + cm.onActivityCreated(mToken, getComponentName()); break; case CONTENT_CAPTURE_RESUME: cm.onActivityResumed(); @@ -3785,6 +3783,9 @@ public class Activity extends ContextThemeWrapper View decor = mDecor; if (decor != null && decor.getParent() != null) { getWindowManager().updateViewLayout(decor, params); + if (mContentCaptureManager != null) { + mContentCaptureManager.updateWindowAttributes(params); + } } } } diff --git a/core/java/android/view/contentcapture/ContentCaptureManager.java b/core/java/android/view/contentcapture/ContentCaptureManager.java index 84608406061aa..e3c2bd1b2a26d 100644 --- a/core/java/android/view/contentcapture/ContentCaptureManager.java +++ b/core/java/android/view/contentcapture/ContentCaptureManager.java @@ -37,6 +37,7 @@ import android.os.ServiceManager; import android.util.Log; import android.view.View; import android.view.ViewStructure; +import android.view.WindowManager; import android.view.contentcapture.ContentCaptureSession.FlushReason; import com.android.internal.annotations.GuardedBy; @@ -343,10 +344,9 @@ public final class ContentCaptureManager { /** @hide */ @UiThread public void onActivityCreated(@NonNull IBinder applicationToken, - @NonNull ComponentName activityComponent, int flags) { + @NonNull ComponentName activityComponent) { if (mOptions.lite) return; synchronized (mLock) { - mFlags |= flags; getMainContentCaptureSession().start(applicationToken, activityComponent, mFlags); } } @@ -498,6 +498,32 @@ public final class ContentCaptureManager { } } + /** + * Called by apps to update flag secure when window attributes change. + * + * @hide + */ + public void updateWindowAttributes(@NonNull WindowManager.LayoutParams params) { + if (sDebug) { + Log.d(TAG, "updateWindowAttributes(): window flags=" + params.flags); + } + final boolean flagSecureEnabled = + (params.flags & WindowManager.LayoutParams.FLAG_SECURE) != 0; + + MainContentCaptureSession mainSession; + synchronized (mLock) { + if (flagSecureEnabled) { + mFlags |= ContentCaptureContext.FLAG_DISABLED_BY_FLAG_SECURE; + } else { + mFlags &= ~ContentCaptureContext.FLAG_DISABLED_BY_FLAG_SECURE; + } + mainSession = mMainSession; + } + if (mainSession != null) { + mainSession.setDisabled(flagSecureEnabled); + } + } + /** * Gets whether content capture is enabled for the given user. * diff --git a/core/java/android/view/contentcapture/MainContentCaptureSession.java b/core/java/android/view/contentcapture/MainContentCaptureSession.java index 8673fbe630913..7241664602e9d 100644 --- a/core/java/android/view/contentcapture/MainContentCaptureSession.java +++ b/core/java/android/view/contentcapture/MainContentCaptureSession.java @@ -593,7 +593,7 @@ public final class MainContentCaptureSession extends ContentCaptureSession { } /** - * Called by ContentCaptureManager.setContentCaptureEnabled + * Sets the disabled state of content capture. * * @return whether disabled state was changed. */