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

Commit 8171d774 authored by mrulhania's avatar mrulhania
Browse files

Add (displays) sensitive content concept to the View

Adding a new property/state to track whether the
view displays sensitive content. The property
can be explicitly set by the developer or can be
determined based on fallbacks.

Bug: 322886920
Test: atest android.sensitivecontentprotection.cts.ViewUnitTest
Change-Id: I76aa38c51d907dbfce2d522fdda901867db81ff5
parent 60fdaef6
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -52202,6 +52202,7 @@ package android.view {
    method public final boolean getClipToOutline();
    method @Nullable public final android.view.contentcapture.ContentCaptureSession getContentCaptureSession();
    method public CharSequence getContentDescription();
    method @FlaggedApi("android.view.flags.sensitive_content_app_protection_api") public final int getContentSensitivity();
    method @UiContext public final android.content.Context getContext();
    method protected android.view.ContextMenu.ContextMenuInfo getContextMenuInfo();
    method public final boolean getDefaultFocusHighlightEnabled();
@@ -52381,6 +52382,7 @@ package android.view {
    method public boolean isAttachedToWindow();
    method public boolean isAutoHandwritingEnabled();
    method public boolean isClickable();
    method @FlaggedApi("android.view.flags.sensitive_content_app_protection_api") public final boolean isContentSensitive();
    method public boolean isContextClickable();
    method public boolean isCredential();
    method public boolean isDirty();
@@ -52585,6 +52587,7 @@ package android.view {
    method public void setClipToOutline(boolean);
    method public void setContentCaptureSession(@Nullable android.view.contentcapture.ContentCaptureSession);
    method public void setContentDescription(CharSequence);
    method @FlaggedApi("android.view.flags.sensitive_content_app_protection_api") public final void setContentSensitivity(int);
    method public void setContextClickable(boolean);
    method public void setDefaultFocusHighlightEnabled(boolean);
    method @Deprecated public void setDrawingCacheBackgroundColor(@ColorInt int);
@@ -52769,6 +52772,9 @@ package android.view {
    field public static final int AUTOFILL_TYPE_NONE = 0; // 0x0
    field public static final int AUTOFILL_TYPE_TEXT = 1; // 0x1
    field public static final int AUTOFILL_TYPE_TOGGLE = 2; // 0x2
    field @FlaggedApi("android.view.flags.sensitive_content_app_protection_api") public static final int CONTENT_SENSITIVITY_AUTO = 0; // 0x0
    field @FlaggedApi("android.view.flags.sensitive_content_app_protection_api") public static final int CONTENT_SENSITIVITY_NOT_SENSITIVE = 2; // 0x2
    field @FlaggedApi("android.view.flags.sensitive_content_app_protection_api") public static final int CONTENT_SENSITIVITY_SENSITIVE = 1; // 0x1
    field public static final int DRAG_FLAG_ACCESSIBILITY_ACTION = 1024; // 0x400
    field public static final int DRAG_FLAG_GLOBAL = 256; // 0x100
    field public static final int DRAG_FLAG_GLOBAL_PERSISTABLE_URI_PERMISSION = 64; // 0x40
+94 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import static android.view.displayhash.DisplayHashResultCallback.DISPLAY_HASH_ER
import static android.view.displayhash.DisplayHashResultCallback.DISPLAY_HASH_ERROR_UNKNOWN;
import static android.view.displayhash.DisplayHashResultCallback.EXTRA_DISPLAY_HASH;
import static android.view.displayhash.DisplayHashResultCallback.EXTRA_DISPLAY_HASH_ERROR_CODE;
import static android.view.flags.Flags.FLAG_SENSITIVE_CONTENT_APP_PROTECTION_API;
import static android.view.flags.Flags.FLAG_TOOLKIT_SET_FRAME_RATE_READ_ONLY;
import static android.view.flags.Flags.FLAG_VIEW_VELOCITY_API;
import static android.view.flags.Flags.enableUseMeasureCacheDuringForceLayout;
@@ -1945,6 +1946,41 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     */
    static final int TOOLTIP = 0x40000000;
    /** @hide */
    @IntDef(prefix = { "CONTENT_SENSITIVITY_" }, value = {
            CONTENT_SENSITIVITY_AUTO,
            CONTENT_SENSITIVITY_SENSITIVE,
            CONTENT_SENSITIVITY_NOT_SENSITIVE
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface ContentSensitivity {}
    /**
     * Automatically determine whether a view displays sensitive content. For example, available
     * autofill hints (or some other signal) can be used to determine if this view
     * displays sensitive content.
     *
     * @see #getContentSensitivity()
     */
    @FlaggedApi(FLAG_SENSITIVE_CONTENT_APP_PROTECTION_API)
    public static final int CONTENT_SENSITIVITY_AUTO = 0x0;
    /**
     * The view displays sensitive content.
     *
     * @see #getContentSensitivity()
     */
    @FlaggedApi(FLAG_SENSITIVE_CONTENT_APP_PROTECTION_API)
    public static final int CONTENT_SENSITIVITY_SENSITIVE = 0x1;
    /**
     * The view doesn't display sensitive content.
     *
     * @see #getContentSensitivity()
     */
    @FlaggedApi(FLAG_SENSITIVE_CONTENT_APP_PROTECTION_API)
    public static final int CONTENT_SENSITIVITY_NOT_SENSITIVE = 0x2;
    /** @hide */
    @IntDef(flag = true, prefix = { "FOCUSABLES_" }, value = {
            FOCUSABLES_ALL,
@@ -3646,6 +3682,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     *           1                      PFLAG4_ROTARY_HAPTICS_ENABLED
     *          1                       PFLAG4_ROTARY_HAPTICS_SCROLL_SINCE_LAST_ROTARY_INPUT
     *         1                        PFLAG4_ROTARY_HAPTICS_WAITING_FOR_SCROLL_EVENT
     *       11                         PFLAG4_CONTENT_SENSITIVITY_MASK
     * |-------|-------|-------|-------|
     */
@@ -3762,6 +3799,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     */
    private static final int PFLAG4_ROTARY_HAPTICS_WAITING_FOR_SCROLL_EVENT = 0x800000;
    private static final int PFLAG4_CONTENT_SENSITIVITY_SHIFT = 24;
    /**
     * Mask for obtaining the bits which specify how to determine whether a view
     * displays sensitive content or not.
     */
    private static final int PFLAG4_CONTENT_SENSITIVITY_MASK =
            (CONTENT_SENSITIVITY_AUTO | CONTENT_SENSITIVITY_SENSITIVE
                    | CONTENT_SENSITIVITY_NOT_SENSITIVE) << PFLAG4_CONTENT_SENSITIVITY_SHIFT;
    /* End of masks for mPrivateFlags4 */
    /** @hide */
@@ -10149,6 +10195,54 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        return false;
    }
    /**
     * Sets content sensitivity mode to determine whether this view displays sensitive content.
     *
     * @param mode {@link #CONTENT_SENSITIVITY_AUTO}, {@link #CONTENT_SENSITIVITY_NOT_SENSITIVE}
     *                                            or {@link #CONTENT_SENSITIVITY_SENSITIVE}
     */
    @FlaggedApi(FLAG_SENSITIVE_CONTENT_APP_PROTECTION_API)
    public final void setContentSensitivity(@ContentSensitivity int mode)  {
        mPrivateFlags4 &= ~PFLAG4_CONTENT_SENSITIVITY_MASK;
        mPrivateFlags4 |= ((mode << PFLAG4_CONTENT_SENSITIVITY_SHIFT)
                & PFLAG4_CONTENT_SENSITIVITY_MASK);
    }
    /**
     * Gets content sensitivity mode to determine whether this view displays sensitive content.
     *
     * <p>See {@link #setContentSensitivity(int)} and
     * {@link #isContentSensitive()} for more info about this mode.
     *
     * @return {@link #CONTENT_SENSITIVITY_AUTO} by default, or value passed to
     * {@link #setContentSensitivity(int)}.
     */
    @FlaggedApi(FLAG_SENSITIVE_CONTENT_APP_PROTECTION_API)
    public @ContentSensitivity
    final int getContentSensitivity() {
        return (mPrivateFlags4 & PFLAG4_CONTENT_SENSITIVITY_MASK)
                >> PFLAG4_CONTENT_SENSITIVITY_SHIFT;
    }
    /**
     * Returns whether this view displays sensitive content, based
     * on the value explicitly set by {@link #setContentSensitivity(int)}.
     *
     * @return whether the view displays sensitive content.
     *
     * @see #setContentSensitivity(int)
     * @see #CONTENT_SENSITIVITY_AUTO
     * @see #CONTENT_SENSITIVITY_SENSITIVE
     * @see #CONTENT_SENSITIVITY_NOT_SENSITIVE
     */
    @FlaggedApi(FLAG_SENSITIVE_CONTENT_APP_PROTECTION_API)
    public final boolean isContentSensitive() {
        if (getContentSensitivity() == CONTENT_SENSITIVITY_SENSITIVE) {
            return true;
        }
        return false;
    }
    /**
     * Gets the mode for determining whether this view is important for content capture.
     *