diff options
| author | 2020-05-07 15:13:47 +0800 | |
|---|---|---|
| committer | 2020-08-03 11:36:54 +0800 | |
| commit | 6591174401e9011ebae147f8d65acb6814d6130a (patch) | |
| tree | 37343436ce82828c135d464c01b8c8449c255b1a | |
| parent | e8e0cac6faf9a31b5cc4c3a20014507d50566c7b (diff) | |
Annotating context in framework base
Bug: 151414704
Test: build & run
Change-Id: I42c8ab699433c51158a1af201da0521413d74dcd
| -rw-r--r-- | core/java/android/app/Activity.java | 2 | ||||
| -rw-r--r-- | core/java/android/app/Dialog.java | 15 | ||||
| -rw-r--r-- | core/java/android/app/WallpaperManager.java | 5 | ||||
| -rw-r--r-- | core/java/android/app/WindowContext.java | 2 | ||||
| -rw-r--r-- | core/java/android/content/Context.java | 10 | ||||
| -rw-r--r-- | core/java/android/inputmethodservice/InputMethodService.java | 2 | ||||
| -rw-r--r-- | core/java/android/view/GestureDetector.java | 10 | ||||
| -rw-r--r-- | core/java/android/view/LayoutInflater.java | 4 | ||||
| -rw-r--r-- | core/java/android/view/View.java | 3 | ||||
| -rw-r--r-- | core/java/android/view/ViewConfiguration.java | 6 | ||||
| -rw-r--r-- | core/java/android/view/ViewRootImpl.java | 6 | ||||
| -rw-r--r-- | core/java/android/view/Window.java | 5 | ||||
| -rw-r--r-- | core/java/android/view/WindowManagerImpl.java | 2 | ||||
| -rw-r--r-- | core/java/android/view/inputmethod/InputMethodManager.java | 3 | ||||
| -rw-r--r-- | core/java/com/android/internal/policy/PhoneWindow.java | 5 |
15 files changed, 59 insertions, 21 deletions
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index 107fb26357aa..dfe1c158dd6b 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -35,6 +35,7 @@ import android.annotation.RequiresPermission; import android.annotation.StyleRes; import android.annotation.SystemApi; import android.annotation.TestApi; +import android.annotation.UiContext; import android.app.VoiceInteractor.Request; import android.app.admin.DevicePolicyManager; import android.app.assist.AssistContent; @@ -727,6 +728,7 @@ import java.util.function.Consumer; * upload, independent of whether the original activity is paused, stopped, * or finished. */ +@UiContext public class Activity extends ContextThemeWrapper implements LayoutInflater.Factory2, Window.Callback, KeyEvent.Callback, diff --git a/core/java/android/app/Dialog.java b/core/java/android/app/Dialog.java index 5e05506eb416..9833ed60fe46 100644 --- a/core/java/android/app/Dialog.java +++ b/core/java/android/app/Dialog.java @@ -24,6 +24,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.StringRes; import android.annotation.StyleRes; +import android.annotation.UiContext; import android.compat.annotation.UnsupportedAppUsage; import android.content.ComponentName; import android.content.Context; @@ -101,6 +102,7 @@ public class Dialog implements DialogInterface, Window.Callback, private final WindowManager mWindowManager; @UnsupportedAppUsage + @UiContext final Context mContext; @UnsupportedAppUsage final Window mWindow; @@ -158,7 +160,7 @@ public class Dialog implements DialogInterface, Window.Callback, * @param context the context in which the dialog should run * @see android.R.styleable#Theme_dialogTheme */ - public Dialog(@NonNull Context context) { + public Dialog(@UiContext @NonNull Context context) { this(context, 0, true); } @@ -177,11 +179,12 @@ public class Dialog implements DialogInterface, Window.Callback, * @param themeResId a style resource describing the theme to use for the * window, or {@code 0} to use the default dialog theme */ - public Dialog(@NonNull Context context, @StyleRes int themeResId) { + public Dialog(@UiContext @NonNull Context context, @StyleRes int themeResId) { this(context, themeResId, true); } - Dialog(@NonNull Context context, @StyleRes int themeResId, boolean createContextThemeWrapper) { + Dialog(@UiContext @NonNull Context context, @StyleRes int themeResId, + boolean createContextThemeWrapper) { if (createContextThemeWrapper) { if (themeResId == Resources.ID_NULL) { final TypedValue outValue = new TypedValue(); @@ -222,7 +225,7 @@ public class Dialog implements DialogInterface, Window.Callback, mCancelMessage = cancelCallback; } - protected Dialog(@NonNull Context context, boolean cancelable, + protected Dialog(@UiContext @NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) { this(context); mCancelable = cancelable; @@ -234,7 +237,9 @@ public class Dialog implements DialogInterface, Window.Callback, * * @return Context The Context used by the Dialog. */ - public final @NonNull Context getContext() { + @UiContext + @NonNull + public final Context getContext() { return mContext; } diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java index c5d343d168ca..0a80ccc13487 100644 --- a/core/java/android/app/WallpaperManager.java +++ b/core/java/android/app/WallpaperManager.java @@ -26,6 +26,7 @@ import android.annotation.SdkConstant.SdkConstantType; import android.annotation.SystemApi; import android.annotation.SystemService; import android.annotation.TestApi; +import android.annotation.UiContext; import android.compat.annotation.UnsupportedAppUsage; import android.content.ComponentName; import android.content.ContentResolver; @@ -213,7 +214,6 @@ public class WallpaperManager { private static final Object sSync = new Object[0]; @UnsupportedAppUsage private static Globals sGlobals; - private final Context mContext; private final boolean mWcgEnabled; private final ColorManagementProxy mCmProxy; @@ -539,7 +539,8 @@ public class WallpaperManager { } } - /*package*/ WallpaperManager(IWallpaperManager service, Context context, Handler handler) { + /*package*/ WallpaperManager(IWallpaperManager service, @UiContext Context context, + Handler handler) { mContext = context; if (service != null) { initGlobals(service, context.getMainLooper()); diff --git a/core/java/android/app/WindowContext.java b/core/java/android/app/WindowContext.java index cb416c923c60..5f72bac89d7b 100644 --- a/core/java/android/app/WindowContext.java +++ b/core/java/android/app/WindowContext.java @@ -20,6 +20,7 @@ import static android.view.WindowManagerGlobal.ADD_TOO_MANY_TOKENS; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.UiContext; import android.content.Context; import android.content.ContextWrapper; import android.os.Bundle; @@ -42,6 +43,7 @@ import java.lang.ref.Reference; * @see Context#createWindowContext(int, Bundle) * @hide */ +@UiContext public class WindowContext extends ContextWrapper { private final WindowManagerImpl mWindowManager; private final IWindowManager mWms; diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index 6f8923ffaf59..cb0c255fa2dc 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -21,6 +21,7 @@ import android.annotation.CallbackExecutor; import android.annotation.CheckResult; import android.annotation.ColorInt; import android.annotation.ColorRes; +import android.annotation.DisplayContext; import android.annotation.DrawableRes; import android.annotation.IntDef; import android.annotation.NonNull; @@ -33,6 +34,7 @@ import android.annotation.StyleableRes; import android.annotation.SuppressLint; import android.annotation.SystemApi; import android.annotation.TestApi; +import android.annotation.UiContext; import android.annotation.UserIdInt; import android.app.ActivityManager; import android.app.IApplicationThread; @@ -3750,6 +3752,7 @@ public abstract class Context { * @see #getSystemService(String) * @see android.view.WindowManager */ + @UiContext public static final String WINDOW_SERVICE = "window"; /** @@ -3760,6 +3763,7 @@ public abstract class Context { * @see #getSystemService(String) * @see android.view.LayoutInflater */ + @UiContext public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater"; /** @@ -3932,6 +3936,7 @@ public abstract class Context { * * @see #getSystemService(String) */ + @UiContext public static final String WALLPAPER_SERVICE = "wallpaper"; /** @@ -5779,6 +5784,7 @@ public abstract class Context { * * @return A {@link Context} for the display. */ + @DisplayContext public abstract Context createDisplayContext(@NonNull Display display); /** @@ -5843,7 +5849,9 @@ public abstract class Context { * the current number of window contexts without adding any view by * {@link WindowManager#addView} <b>exceeds five</b>. */ - public @NonNull Context createWindowContext(@WindowType int type, @Nullable Bundle options) { + @UiContext + @NonNull + public Context createWindowContext(@WindowType int type, @Nullable Bundle options) { throw new RuntimeException("Not implemented. Must override in a subclass."); } diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java index c5a11abe1136..7250801eec81 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -32,6 +32,7 @@ import android.annotation.IntDef; import android.annotation.MainThread; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.UiContext; import android.app.ActivityManager; import android.app.Dialog; import android.compat.annotation.UnsupportedAppUsage; @@ -258,6 +259,7 @@ import java.util.Collections; * @attr ref android.R.styleable#InputMethodService_imeExtractEnterAnimation * @attr ref android.R.styleable#InputMethodService_imeExtractExitAnimation */ +@UiContext public class InputMethodService extends AbstractInputMethodService { static final String TAG = "InputMethodService"; static final boolean DEBUG = false; diff --git a/core/java/android/view/GestureDetector.java b/core/java/android/view/GestureDetector.java index 55c527ba6fa6..8a722184eb77 100644 --- a/core/java/android/view/GestureDetector.java +++ b/core/java/android/view/GestureDetector.java @@ -25,6 +25,7 @@ import static com.android.internal.util.FrameworkStatsLog.TOUCH_GESTURE_CLASSIFI import static com.android.internal.util.FrameworkStatsLog.TOUCH_GESTURE_CLASSIFIED__CLASSIFICATION__SINGLE_TAP; import static com.android.internal.util.FrameworkStatsLog.TOUCH_GESTURE_CLASSIFIED__CLASSIFICATION__UNKNOWN_CLASSIFICATION; +import android.annotation.UiContext; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.os.Build; @@ -393,7 +394,7 @@ public class GestureDetector { * * @throws NullPointerException if {@code listener} is null. */ - public GestureDetector(Context context, OnGestureListener listener) { + public GestureDetector(@UiContext Context context, OnGestureListener listener) { this(context, listener, null); } @@ -412,7 +413,8 @@ public class GestureDetector { * * @throws NullPointerException if {@code listener} is null. */ - public GestureDetector(Context context, OnGestureListener listener, Handler handler) { + public GestureDetector(@UiContext Context context, OnGestureListener listener, + Handler handler) { if (handler != null) { mHandler = new GestureHandler(handler); } else { @@ -442,12 +444,12 @@ public class GestureDetector { * * @throws NullPointerException if {@code listener} is null. */ - public GestureDetector(Context context, OnGestureListener listener, Handler handler, + public GestureDetector(@UiContext Context context, OnGestureListener listener, Handler handler, boolean unused) { this(context, listener, handler); } - private void init(Context context) { + private void init(@UiContext Context context) { if (mListener == null) { throw new NullPointerException("OnGestureListener must not be null"); } diff --git a/core/java/android/view/LayoutInflater.java b/core/java/android/view/LayoutInflater.java index 1afe11ea1acf..b925b492c04b 100644 --- a/core/java/android/view/LayoutInflater.java +++ b/core/java/android/view/LayoutInflater.java @@ -21,6 +21,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemService; import android.annotation.TestApi; +import android.annotation.UiContext; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.content.pm.ApplicationInfo; @@ -94,6 +95,7 @@ public abstract class LayoutInflater { * {@hide} */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) + @UiContext protected final Context mContext; // these are optional, set by the caller @@ -277,7 +279,7 @@ public abstract class LayoutInflater { /** * Obtains the LayoutInflater from the given context. */ - public static LayoutInflater from(Context context) { + public static LayoutInflater from(@UiContext Context context) { LayoutInflater LayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (LayoutInflater == null) { diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 2168fe331972..c362dde097c3 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -43,6 +43,7 @@ import android.annotation.Nullable; import android.annotation.Size; import android.annotation.StyleRes; import android.annotation.TestApi; +import android.annotation.UiContext; import android.annotation.UiThread; import android.compat.annotation.UnsupportedAppUsage; import android.content.AutofillOptions; @@ -4867,6 +4868,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ @ViewDebug.ExportedProperty(deepExport = true) @UnsupportedAppUsage + @UiContext protected Context mContext; @UnsupportedAppUsage @@ -14991,6 +14993,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @return The view's Context. */ @ViewDebug.CapturedViewProperty + @UiContext public final Context getContext() { return mContext; } diff --git a/core/java/android/view/ViewConfiguration.java b/core/java/android/view/ViewConfiguration.java index ffeeb806ba54..ccf1fb07d0bb 100644 --- a/core/java/android/view/ViewConfiguration.java +++ b/core/java/android/view/ViewConfiguration.java @@ -20,6 +20,7 @@ import static android.os.StrictMode.vmIncorrectContextUseEnabled; import android.annotation.FloatRange; import android.annotation.TestApi; +import android.annotation.UiContext; import android.app.Activity; import android.app.AppGlobals; import android.compat.annotation.UnsupportedAppUsage; @@ -391,7 +392,7 @@ public class ViewConfiguration { * @see #get(android.content.Context) * @see android.util.DisplayMetrics */ - private ViewConfiguration(Context context) { + private ViewConfiguration(@UiContext Context context) { mConstructedWithContext = true; final Resources res = context.getResources(); final DisplayMetrics metrics = res.getDisplayMetrics(); @@ -498,7 +499,8 @@ public class ViewConfiguration { * be {@link Activity} or other {@link Context} created with * {@link Context#createWindowContext(int, Bundle)}. */ - public static ViewConfiguration get(Context context) { + + public static ViewConfiguration get(@UiContext Context context) { if (!context.isUiContext() && vmIncorrectContextUseEnabled()) { final String errorMessage = "Tried to access UI constants from a non-visual Context:" + context; diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index f2cec250d47f..33ba47e14c36 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -64,6 +64,7 @@ import android.animation.LayoutTransition; import android.annotation.AnyThread; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.UiContext; import android.app.ActivityManager; import android.app.ActivityThread; import android.app.ResourcesManager; @@ -349,6 +350,7 @@ public final class ViewRootImpl implements ViewParent, @GuardedBy("mWindowCallbacks") final ArrayList<WindowCallbacks> mWindowCallbacks = new ArrayList<>(); @UnsupportedAppUsage + @UiContext public final Context mContext; @UnsupportedAppUsage @@ -719,11 +721,11 @@ public final class ViewRootImpl implements ViewParent, false /* useSfChoreographer */); } - public ViewRootImpl(Context context, Display display, IWindowSession session) { + public ViewRootImpl(@UiContext Context context, Display display, IWindowSession session) { this(context, display, session, false /* useSfChoreographer */); } - public ViewRootImpl(Context context, Display display, IWindowSession session, + public ViewRootImpl(@UiContext Context context, Display display, IWindowSession session, boolean useSfChoreographer) { mContext = context; mWindowSession = session; diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java index 446e7aa67bc5..1dbf37aca689 100644 --- a/core/java/android/view/Window.java +++ b/core/java/android/view/Window.java @@ -27,6 +27,7 @@ import android.annotation.Nullable; import android.annotation.StyleRes; import android.annotation.SystemApi; import android.annotation.TestApi; +import android.annotation.UiContext; import android.app.WindowConfiguration; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; @@ -280,6 +281,7 @@ public abstract class Window { public static final int DECOR_CAPTION_SHADE_DARK = 2; @UnsupportedAppUsage + @UiContext private final Context mContext; @UnsupportedAppUsage @@ -722,7 +724,7 @@ public abstract class Window { } - public Window(Context context) { + public Window(@UiContext Context context) { mContext = context; mFeatures = mLocalFeatures = getDefaultFeatures(context); } @@ -733,6 +735,7 @@ public abstract class Window { * * @return Context The Context that was supplied to the constructor. */ + @UiContext public final Context getContext() { return mContext; } diff --git a/core/java/android/view/WindowManagerImpl.java b/core/java/android/view/WindowManagerImpl.java index 28a18da37b3e..69301ad6f7b4 100644 --- a/core/java/android/view/WindowManagerImpl.java +++ b/core/java/android/view/WindowManagerImpl.java @@ -25,6 +25,7 @@ import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING; import android.annotation.NonNull; +import android.annotation.UiContext; import android.app.ResourcesManager; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; @@ -70,6 +71,7 @@ import java.util.List; public final class WindowManagerImpl implements WindowManager { @UnsupportedAppUsage private final WindowManagerGlobal mGlobal = WindowManagerGlobal.getInstance(); + @UiContext @VisibleForTesting public final Context mContext; private final Window mParentWindow; diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java index 599a7c24e8aa..7533ec4ab7e9 100644 --- a/core/java/android/view/inputmethod/InputMethodManager.java +++ b/core/java/android/view/inputmethod/InputMethodManager.java @@ -22,6 +22,7 @@ import static android.Manifest.permission.WRITE_SECURE_SETTINGS; import static com.android.internal.inputmethod.StartInputReason.WINDOW_FOCUS_GAIN_REPORT_WITHOUT_EDITOR; import static com.android.internal.inputmethod.StartInputReason.WINDOW_FOCUS_GAIN_REPORT_WITH_SAME_EDITOR; +import android.annotation.DisplayContext; import android.annotation.DrawableRes; import android.annotation.NonNull; import android.annotation.Nullable; @@ -1198,7 +1199,7 @@ public final class InputMethodManager { * @hide */ @NonNull - public static InputMethodManager forContext(Context context) { + public static InputMethodManager forContext(@DisplayContext Context context) { final int displayId = context.getDisplayId(); // For better backward compatibility, we always use Looper.getMainLooper() for the default // display case. diff --git a/core/java/com/android/internal/policy/PhoneWindow.java b/core/java/com/android/internal/policy/PhoneWindow.java index 0a3fe096279d..053b06f3d407 100644 --- a/core/java/com/android/internal/policy/PhoneWindow.java +++ b/core/java/com/android/internal/policy/PhoneWindow.java @@ -35,6 +35,7 @@ import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_DRAW_BA import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.UiContext; import android.app.ActivityManager; import android.app.KeyguardManager; import android.app.SearchManager; @@ -342,7 +343,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { static final RotationWatcher sRotationWatcher = new RotationWatcher(); @UnsupportedAppUsage - public PhoneWindow(Context context) { + public PhoneWindow(@UiContext Context context) { super(context); mLayoutInflater = LayoutInflater.from(context); mRenderShadowsInCompositor = Settings.Global.getInt(context.getContentResolver(), @@ -352,7 +353,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { /** * Constructor for main window of an activity. */ - public PhoneWindow(Context context, Window preservedWindow, + public PhoneWindow(@UiContext Context context, Window preservedWindow, ActivityConfigCallback activityConfigCallback) { this(context); // Only main activity windows use decor context, all the other windows depend on whatever |