Merge "Create InputManagerGlobal class" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
f950c81209
@@ -48,8 +48,6 @@ import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.Process;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.ServiceManager.ServiceNotFoundException;
|
||||
import android.os.SystemClock;
|
||||
import android.os.VibrationEffect;
|
||||
import android.os.Vibrator;
|
||||
@@ -305,8 +303,11 @@ public final class InputManager {
|
||||
|
||||
private static String sVelocityTrackerStrategy;
|
||||
|
||||
private InputManager(IInputManager im) {
|
||||
mIm = im;
|
||||
private InputManagerGlobal mGlobal;
|
||||
|
||||
private InputManager() {
|
||||
mGlobal = InputManagerGlobal.getInstance();
|
||||
mIm = mGlobal.getInputManagerService();
|
||||
try {
|
||||
sVelocityTrackerStrategy = mIm.getVelocityTrackerStrategy();
|
||||
} catch (RemoteException ex) {
|
||||
@@ -324,7 +325,8 @@ public final class InputManager {
|
||||
@VisibleForTesting
|
||||
public static InputManager resetInstance(IInputManager inputManagerService) {
|
||||
synchronized (InputManager.class) {
|
||||
sInstance = new InputManager(inputManagerService);
|
||||
InputManagerGlobal.resetInstance(inputManagerService);
|
||||
sInstance = new InputManager();
|
||||
return sInstance;
|
||||
}
|
||||
}
|
||||
@@ -337,6 +339,7 @@ public final class InputManager {
|
||||
@VisibleForTesting
|
||||
public static void clearInstance() {
|
||||
synchronized (InputManager.class) {
|
||||
InputManagerGlobal.clearInstance();
|
||||
sInstance = null;
|
||||
}
|
||||
}
|
||||
@@ -364,13 +367,7 @@ public final class InputManager {
|
||||
public static InputManager getInstance(Context context) {
|
||||
synchronized (InputManager.class) {
|
||||
if (sInstance == null) {
|
||||
try {
|
||||
sInstance = new InputManager(IInputManager.Stub
|
||||
.asInterface(ServiceManager.getServiceOrThrow(Context.INPUT_SERVICE)));
|
||||
|
||||
} catch (ServiceNotFoundException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
sInstance = new InputManager();
|
||||
}
|
||||
if (sInstance.mWeakContext == null || sInstance.mWeakContext.get() == null) {
|
||||
sInstance.mWeakContext = new WeakReference(context);
|
||||
|
||||
82
core/java/android/hardware/input/InputManagerGlobal.java
Normal file
82
core/java/android/hardware/input/InputManagerGlobal.java
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.hardware.input;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.IBinder;
|
||||
import android.os.ServiceManager;
|
||||
|
||||
/**
|
||||
* Manages communication with the input manager service on behalf of
|
||||
* an application process. You're probably looking for {@link InputManager}.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public final class InputManagerGlobal {
|
||||
private static final String TAG = "InputManagerGlobal";
|
||||
|
||||
private static InputManagerGlobal sInstance;
|
||||
|
||||
private final IInputManager mIm;
|
||||
|
||||
public InputManagerGlobal(IInputManager im) {
|
||||
mIm = im;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an instance of the input manager global singleton.
|
||||
*
|
||||
* @return The display manager instance, may be null early in system startup
|
||||
* before the display manager has been fully initialized.
|
||||
*/
|
||||
public static InputManagerGlobal getInstance() {
|
||||
synchronized (InputManagerGlobal.class) {
|
||||
if (sInstance == null) {
|
||||
IBinder b = ServiceManager.getService(Context.INPUT_SERVICE);
|
||||
if (b != null) {
|
||||
sInstance = new InputManagerGlobal(IInputManager.Stub.asInterface(b));
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
}
|
||||
|
||||
public IInputManager getInputManagerService() {
|
||||
return mIm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an instance of the input manager.
|
||||
*
|
||||
* @return The input manager instance.
|
||||
*/
|
||||
public static InputManagerGlobal resetInstance(IInputManager inputManagerService) {
|
||||
synchronized (InputManager.class) {
|
||||
sInstance = new InputManagerGlobal(inputManagerService);
|
||||
return sInstance;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the instance of the input manager.
|
||||
*/
|
||||
public static void clearInstance() {
|
||||
synchronized (InputManagerGlobal.class) {
|
||||
sInstance = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user