diff options
5 files changed, 44 insertions, 25 deletions
diff --git a/core/java/android/hardware/input/InputManager.java b/core/java/android/hardware/input/InputManager.java index 2fec02f91e39..a0cceae98ba9 100644 --- a/core/java/android/hardware/input/InputManager.java +++ b/core/java/android/hardware/input/InputManager.java @@ -39,7 +39,6 @@ import android.os.InputEventInjectionSync; import android.os.RemoteException; import android.os.SystemClock; import android.os.Vibrator; -import android.sysprop.InputProperties; import android.util.Log; import android.view.Display; import android.view.InputDevice; @@ -1038,9 +1037,7 @@ public final class InputManager { */ public boolean isStylusPointerIconEnabled() { if (mIsStylusPointerIconEnabled == null) { - mIsStylusPointerIconEnabled = mContext.getResources() - .getBoolean(com.android.internal.R.bool.config_enableStylusPointerIcon) - || InputProperties.force_enable_stylus_pointer_icon().orElse(false); + mIsStylusPointerIconEnabled = InputSettings.isStylusPointerIconEnabled(mContext); } return mIsStylusPointerIconEnabled; } diff --git a/core/java/android/hardware/input/InputManagerGlobal.java b/core/java/android/hardware/input/InputManagerGlobal.java index 5462171be7e1..c0877d3ad8e2 100644 --- a/core/java/android/hardware/input/InputManagerGlobal.java +++ b/core/java/android/hardware/input/InputManagerGlobal.java @@ -1252,7 +1252,7 @@ public final class InputManagerGlobal { /** * @see InputManager#requestPointerCapture(IBinder, boolean) */ - void requestPointerCapture(IBinder windowToken, boolean enable) { + public void requestPointerCapture(IBinder windowToken, boolean enable) { try { mIm.requestPointerCapture(windowToken, enable); } catch (RemoteException ex) { diff --git a/core/java/android/hardware/input/InputSettings.java b/core/java/android/hardware/input/InputSettings.java index cdf9ea5131ba..6cd32ff1e8e5 100644 --- a/core/java/android/hardware/input/InputSettings.java +++ b/core/java/android/hardware/input/InputSettings.java @@ -25,6 +25,7 @@ import android.annotation.TestApi; import android.content.Context; import android.os.UserHandle; import android.provider.Settings; +import android.sysprop.InputProperties; /** * InputSettings encapsulates reading and writing settings related to input @@ -316,4 +317,15 @@ public class InputSettings { Settings.System.TOUCHPAD_RIGHT_CLICK_ZONE, enabled ? 1 : 0, UserHandle.USER_CURRENT); } + + /** + * Whether a pointer icon will be shown over the location of a + * stylus pointer. + * @hide + */ + public static boolean isStylusPointerIconEnabled(@NonNull Context context) { + return context.getResources() + .getBoolean(com.android.internal.R.bool.config_enableStylusPointerIcon) + || InputProperties.force_enable_stylus_pointer_icon().orElse(false); + } } diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 86e7fb09c5ea..2b29e7878a5d 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -133,7 +133,9 @@ import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; import android.hardware.display.DisplayManager; import android.hardware.display.DisplayManager.DisplayListener; -import android.hardware.input.InputManager; +import android.hardware.display.DisplayManagerGlobal; +import android.hardware.input.InputManagerGlobal; +import android.hardware.input.InputSettings; import android.media.AudioManager; import android.os.Binder; import android.os.Build; @@ -443,9 +445,7 @@ public final class ViewRootImpl implements ViewParent, @UnsupportedAppUsage final IWindowSession mWindowSession; @NonNull Display mDisplay; - final DisplayManager mDisplayManager; final String mBasePackageName; - final InputManager mInputManager; final int[] mTmpLocation = new int[2]; @@ -550,6 +550,9 @@ public final class ViewRootImpl implements ViewParent, // Whether to draw this surface as DISPLAY_DECORATION. boolean mDisplayDecorationCached = false; + // Is the stylus pointer icon enabled + private final boolean mIsStylusPointerIconEnabled; + /** * Update the Choreographer's FrameInfo object with the timing information for the current * ViewRootImpl instance. Erase the data in the current ViewFrameInfo to prepare for the next @@ -994,14 +997,14 @@ public final class ViewRootImpl implements ViewParent, mFallbackEventHandler = new PhoneFallbackEventHandler(context); // TODO(b/222696368): remove getSfInstance usage and use vsyncId for transactions mChoreographer = Choreographer.getInstance(); - mDisplayManager = (DisplayManager)context.getSystemService(Context.DISPLAY_SERVICE); - mInputManager = context.getSystemService(InputManager.class); mInsetsController = new InsetsController(new ViewRootInsetsControllerHost(this)); mHandwritingInitiator = new HandwritingInitiator( mViewConfiguration, mContext.getSystemService(InputMethodManager.class)); mViewBoundsSandboxingEnabled = getViewBoundsSandboxingEnabled(); + mIsStylusPointerIconEnabled = + InputSettings.isStylusPointerIconEnabled(mContext); String processorOverrideName = context.getResources().getString( R.string.config_inputEventCompatProcessorOverrideClassName); @@ -1488,7 +1491,14 @@ public final class ViewRootImpl implements ViewParent, mAccessibilityInteractionConnectionManager, mHandler); mAccessibilityManager.addHighTextContrastStateChangeListener( mHighContrastTextManager, mHandler); - mDisplayManager.registerDisplayListener(mDisplayListener, mHandler); + DisplayManagerGlobal + .getInstance() + .registerDisplayListener( + mDisplayListener, + mHandler, + DisplayManager.EVENT_FLAG_DISPLAY_ADDED + | DisplayManager.EVENT_FLAG_DISPLAY_CHANGED + | DisplayManager.EVENT_FLAG_DISPLAY_REMOVED); } /** @@ -1499,7 +1509,9 @@ public final class ViewRootImpl implements ViewParent, mAccessibilityInteractionConnectionManager); mAccessibilityManager.removeHighTextContrastStateChangeListener( mHighContrastTextManager); - mDisplayManager.unregisterDisplayListener(mDisplayListener); + DisplayManagerGlobal + .getInstance() + .unregisterDisplayListener(mDisplayListener); } private void setTag() { @@ -5382,7 +5394,9 @@ public final class ViewRootImpl implements ViewParent, Log.e(mTag, "No input channel to request Pointer Capture."); return; } - mInputManager.requestPointerCapture(inputToken, enabled); + InputManagerGlobal + .getInstance() + .requestPointerCapture(inputToken, enabled); } private void handlePointerCaptureChanged(boolean hasCapture) { @@ -6947,7 +6961,7 @@ public final class ViewRootImpl implements ViewParent, } final boolean needsStylusPointerIcon = event.isStylusPointer() && event.isHoverEvent() - && mInputManager.isStylusPointerIconEnabled(); + && mIsStylusPointerIconEnabled; if (needsStylusPointerIcon || event.isFromSource(InputDevice.SOURCE_MOUSE)) { if (event.getActionMasked() == MotionEvent.ACTION_HOVER_ENTER || event.getActionMasked() == MotionEvent.ACTION_HOVER_EXIT) { @@ -7018,8 +7032,7 @@ public final class ViewRootImpl implements ViewParent, } PointerIcon pointerIcon = null; - - if (event.isStylusPointer() && mInputManager.isStylusPointerIconEnabled()) { + if (event.isStylusPointer() && mIsStylusPointerIconEnabled) { pointerIcon = mHandwritingInitiator.onResolvePointerIcon(mContext, event); } @@ -7034,14 +7047,18 @@ public final class ViewRootImpl implements ViewParent, mPointerIconType = pointerType; mCustomPointerIcon = null; if (mPointerIconType != PointerIcon.TYPE_CUSTOM) { - mInputManager.setPointerIconType(pointerType); + InputManagerGlobal + .getInstance() + .setPointerIconType(pointerType); return true; } } if (mPointerIconType == PointerIcon.TYPE_CUSTOM && !pointerIcon.equals(mCustomPointerIcon)) { mCustomPointerIcon = pointerIcon; - mInputManager.setCustomPointerIcon(mCustomPointerIcon); + InputManagerGlobal + .getInstance() + .setCustomPointerIcon(mCustomPointerIcon); } return true; } diff --git a/core/java/com/android/internal/policy/DecorContext.java b/core/java/com/android/internal/policy/DecorContext.java index 134a91710c0b..efaedd1073d6 100644 --- a/core/java/com/android/internal/policy/DecorContext.java +++ b/core/java/com/android/internal/policy/DecorContext.java @@ -82,13 +82,6 @@ public class DecorContext extends ContextThemeWrapper { } return mContentCaptureManager; } - // TODO(b/154191411): Try to revisit this issue in S. - // We use application to get DisplayManager here because ViewRootImpl holds reference of - // DisplayManager and implicitly holds reference of mContext, which makes activity cannot - // be GC'd even after destroyed if mContext is an activity object. - if (Context.DISPLAY_SERVICE.equals(name)) { - return super.getSystemService(name); - } // LayoutInflater and WallpaperManagerService should also be obtained from visual context // instead of base context. return (context != null) ? context.getSystemService(name) : super.getSystemService(name); |