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

Commit 62b92261 authored by Charles Chen's avatar Charles Chen Committed by Android (Google) Code Review
Browse files

Merge "Release detectIncorrectContextUse"

parents 2e444eda 7d77103f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -35794,6 +35794,7 @@ package android.os {
    method @NonNull public android.os.StrictMode.VmPolicy.Builder detectCredentialProtectedWhileLocked();
    method @NonNull public android.os.StrictMode.VmPolicy.Builder detectFileUriExposure();
    method @NonNull public android.os.StrictMode.VmPolicy.Builder detectImplicitDirectBoot();
    method @NonNull public android.os.StrictMode.VmPolicy.Builder detectIncorrectContextUse();
    method @NonNull public android.os.StrictMode.VmPolicy.Builder detectLeakedClosableObjects();
    method @NonNull public android.os.StrictMode.VmPolicy.Builder detectLeakedRegistrationObjects();
    method @NonNull public android.os.StrictMode.VmPolicy.Builder detectLeakedSqlLiteObjects();
+0 −1
Original line number Diff line number Diff line
@@ -1227,7 +1227,6 @@ package android.os {
  }

  public static final class StrictMode.VmPolicy.Builder {
    method @NonNull public android.os.StrictMode.VmPolicy.Builder detectIncorrectContextUse();
    method @NonNull public android.os.StrictMode.VmPolicy.Builder permitIncorrectContextUse();
  }

+8 −1
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ import android.os.HandlerExecutor;
import android.os.IBinder;
import android.os.Looper;
import android.os.StatFs;
import android.os.StrictMode;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.storage.StorageManager;
@@ -6289,13 +6290,19 @@ public abstract class Context {
    /**
     * Returns {@code true} if the context is a UI context which can access UI components such as
     * {@link WindowManager}, {@link android.view.LayoutInflater LayoutInflater} or
     * {@link android.app.WallpaperManager WallpaperManager}.
     * {@link android.app.WallpaperManager WallpaperManager}. Accessing UI components from non-UI
     * contexts throws {@link android.os.strictmode.Violation} if
     * {@link StrictMode.VmPolicy.Builder#detectIncorrectContextUse()} is enabled.
     * <p>
     * Examples of UI contexts are
     * an {@link android.app.Activity Activity}, a context created from
     * {@link #createWindowContext(int, Bundle)} or
     * {@link android.inputmethodservice.InputMethodService InputMethodService}
     * </p>
     *
     * @see #getDisplay()
     * @see #getSystemService(String)
     * @see StrictMode.VmPolicy.Builder#detectIncorrectContextUse()
     */
    public static boolean isUiContext(@NonNull Context context) {
        return context.isUiContext();
+4 −6
Original line number Diff line number Diff line
@@ -85,8 +85,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.atomic.AtomicInteger;
@@ -1045,22 +1043,22 @@ public final class StrictMode {
            /**
             * Detect attempts to invoke a method on a {@link Context} that is not suited for such
             * operation.
             * <p>An example of this is trying to obtain an instance of visual service (e.g.
             * <p>An example of this is trying to obtain an instance of UI service (e.g.
             * {@link android.view.WindowManager}) from a non-visual {@link Context}. This is not
             * allowed, since a non-visual {@link Context} is not adjusted to any visual area, and
             * therefore can report incorrect metrics or resources.
             * @see Context#getDisplay()
             * @see Context#getSystemService(String)
             * @hide
             */
            @TestApi
            public @NonNull Builder detectIncorrectContextUse() {
                return enable(DETECT_VM_INCORRECT_CONTEXT_USE);
            }

            /**
             * Disable detection of incorrect context use.
             * TODO(b/149790106): Fix usages and remove.
             *
             * @see #detectIncorrectContextUse()
             *
             * @hide
             */
            @TestApi