Merge "resolve merge conflicts of 7e0769b219 to rvc-dev" into rvc-dev

This commit is contained in:
TreeHugger Robot
2020-03-22 00:36:07 +00:00
committed by Android (Google) Code Review
3 changed files with 54 additions and 5 deletions

View File

@@ -23,7 +23,6 @@ import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context; import android.content.Context;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Point;
import android.os.Build; import android.os.Build;
import android.os.RemoteException; import android.os.RemoteException;
import android.provider.Settings; import android.provider.Settings;
@@ -66,8 +65,9 @@ public class ViewConfiguration {
/** /**
* Defines the default duration in milliseconds before a press turns into * Defines the default duration in milliseconds before a press turns into
* a long press * a long press
* @hide
*/ */
private static final int DEFAULT_LONG_PRESS_TIMEOUT = 500; public static final int DEFAULT_LONG_PRESS_TIMEOUT = 400;
/** /**
* Defines the default duration in milliseconds between the first tap's up event and the second * Defines the default duration in milliseconds between the first tap's up event and the second

View File

@@ -60,6 +60,7 @@ import android.os.MessageQueue;
import android.os.Process; import android.os.Process;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.UserHandle; import android.os.UserHandle;
import android.provider.DeviceConfig;
import android.provider.Settings; import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException; import android.provider.Settings.SettingNotFoundException;
import android.text.TextUtils; import android.text.TextUtils;
@@ -126,6 +127,9 @@ public class InputManagerService extends IInputManager.Stub
private static final String EXCLUDED_DEVICES_PATH = "etc/excluded-input-devices.xml"; private static final String EXCLUDED_DEVICES_PATH = "etc/excluded-input-devices.xml";
private static final String PORT_ASSOCIATIONS_PATH = "etc/input-port-associations.xml"; private static final String PORT_ASSOCIATIONS_PATH = "etc/input-port-associations.xml";
// Feature flag name for the deep press feature
private static final String DEEP_PRESS_ENABLED = "deep_press_enabled";
private static final int MSG_DELIVER_INPUT_DEVICES_CHANGED = 1; private static final int MSG_DELIVER_INPUT_DEVICES_CHANGED = 1;
private static final int MSG_SWITCH_KEYBOARD_LAYOUT = 2; private static final int MSG_SWITCH_KEYBOARD_LAYOUT = 2;
private static final int MSG_RELOAD_KEYBOARD_LAYOUTS = 3; private static final int MSG_RELOAD_KEYBOARD_LAYOUTS = 3;
@@ -246,6 +250,7 @@ public class InputManagerService extends IInputManager.Stub
private static native void nativeSetPointerCapture(long ptr, boolean detached); private static native void nativeSetPointerCapture(long ptr, boolean detached);
private static native boolean nativeCanDispatchToDisplay(long ptr, int deviceId, int displayId); private static native boolean nativeCanDispatchToDisplay(long ptr, int deviceId, int displayId);
private static native void nativeNotifyPortAssociationsChanged(long ptr); private static native void nativeNotifyPortAssociationsChanged(long ptr);
private static native void nativeSetMotionClassifierEnabled(long ptr, boolean enabled);
// Input event injection constants defined in InputDispatcher.h. // Input event injection constants defined in InputDispatcher.h.
private static final int INPUT_EVENT_INJECTION_SUCCEEDED = 0; private static final int INPUT_EVENT_INJECTION_SUCCEEDED = 0;
@@ -356,6 +361,7 @@ public class InputManagerService extends IInputManager.Stub
registerPointerSpeedSettingObserver(); registerPointerSpeedSettingObserver();
registerShowTouchesSettingObserver(); registerShowTouchesSettingObserver();
registerAccessibilityLargePointerSettingObserver(); registerAccessibilityLargePointerSettingObserver();
registerLongPressTimeoutObserver();
mContext.registerReceiver(new BroadcastReceiver() { mContext.registerReceiver(new BroadcastReceiver() {
@Override @Override
@@ -363,12 +369,14 @@ public class InputManagerService extends IInputManager.Stub
updatePointerSpeedFromSettings(); updatePointerSpeedFromSettings();
updateShowTouchesFromSettings(); updateShowTouchesFromSettings();
updateAccessibilityLargePointerFromSettings(); updateAccessibilityLargePointerFromSettings();
updateDeepPressStatusFromSettings("user switched");
} }
}, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler); }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler);
updatePointerSpeedFromSettings(); updatePointerSpeedFromSettings();
updateShowTouchesFromSettings(); updateShowTouchesFromSettings();
updateAccessibilityLargePointerFromSettings(); updateAccessibilityLargePointerFromSettings();
updateDeepPressStatusFromSettings("just booted");
} }
// TODO(BT) Pass in parameter for bluetooth system // TODO(BT) Pass in parameter for bluetooth system
@@ -1600,7 +1608,7 @@ public class InputManagerService extends IInputManager.Stub
setPointerSpeedUnchecked(speed); setPointerSpeedUnchecked(speed);
} }
public void updatePointerSpeedFromSettings() { private void updatePointerSpeedFromSettings() {
int speed = getPointerSpeedSetting(); int speed = getPointerSpeedSetting();
setPointerSpeedUnchecked(speed); setPointerSpeedUnchecked(speed);
} }
@@ -1632,7 +1640,7 @@ public class InputManagerService extends IInputManager.Stub
return speed; return speed;
} }
public void updateShowTouchesFromSettings() { private void updateShowTouchesFromSettings() {
int setting = getShowTouchesSetting(0); int setting = getShowTouchesSetting(0);
nativeSetShowTouches(mPtr, setting != 0); nativeSetShowTouches(mPtr, setting != 0);
} }
@@ -1648,7 +1656,7 @@ public class InputManagerService extends IInputManager.Stub
}, UserHandle.USER_ALL); }, UserHandle.USER_ALL);
} }
public void updateAccessibilityLargePointerFromSettings() { private void updateAccessibilityLargePointerFromSettings() {
final int accessibilityConfig = Settings.Secure.getIntForUser( final int accessibilityConfig = Settings.Secure.getIntForUser(
mContext.getContentResolver(), Settings.Secure.ACCESSIBILITY_LARGE_POINTER_ICON, mContext.getContentResolver(), Settings.Secure.ACCESSIBILITY_LARGE_POINTER_ICON,
0, UserHandle.USER_CURRENT); 0, UserHandle.USER_CURRENT);
@@ -1667,6 +1675,34 @@ public class InputManagerService extends IInputManager.Stub
}, UserHandle.USER_ALL); }, UserHandle.USER_ALL);
} }
private void updateDeepPressStatusFromSettings(String reason) {
// Not using ViewConfiguration.getLongPressTimeout here because it may return a stale value
final int timeout = Settings.Secure.getIntForUser(mContext.getContentResolver(),
Settings.Secure.LONG_PRESS_TIMEOUT, ViewConfiguration.DEFAULT_LONG_PRESS_TIMEOUT,
UserHandle.USER_CURRENT);
final boolean featureEnabledFlag =
DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_INPUT_NATIVE_BOOT,
DEEP_PRESS_ENABLED, true /* default */);
final boolean enabled =
featureEnabledFlag && timeout <= ViewConfiguration.DEFAULT_LONG_PRESS_TIMEOUT;
Log.i(TAG,
(enabled ? "Enabling" : "Disabling") + " motion classifier because " + reason
+ ": feature " + (featureEnabledFlag ? "enabled" : "disabled")
+ ", long press timeout = " + timeout);
nativeSetMotionClassifierEnabled(mPtr, enabled);
}
private void registerLongPressTimeoutObserver() {
mContext.getContentResolver().registerContentObserver(
Settings.Secure.getUriFor(Settings.Secure.LONG_PRESS_TIMEOUT), true,
new ContentObserver(mHandler) {
@Override
public void onChange(boolean selfChange) {
updateDeepPressStatusFromSettings("timeout changed");
}
}, UserHandle.USER_ALL);
}
private int getShowTouchesSetting(int defaultValue) { private int getShowTouchesSetting(int defaultValue) {
int result = defaultValue; int result = defaultValue;
try { try {

View File

@@ -220,6 +220,7 @@ public:
void reloadPointerIcons(); void reloadPointerIcons();
void setCustomPointerIcon(const SpriteIcon& icon); void setCustomPointerIcon(const SpriteIcon& icon);
void setPointerCapture(bool enabled); void setPointerCapture(bool enabled);
void setMotionClassifierEnabled(bool enabled);
/* --- InputReaderPolicyInterface implementation --- */ /* --- InputReaderPolicyInterface implementation --- */
@@ -1295,6 +1296,10 @@ int32_t NativeInputManager::getCustomPointerIconId() {
return POINTER_ICON_STYLE_CUSTOM; return POINTER_ICON_STYLE_CUSTOM;
} }
void NativeInputManager::setMotionClassifierEnabled(bool enabled) {
mInputManager->setMotionClassifierEnabled(enabled);
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
static jlong nativeInit(JNIEnv* env, jclass /* clazz */, static jlong nativeInit(JNIEnv* env, jclass /* clazz */,
@@ -1774,6 +1779,13 @@ static void nativeNotifyPortAssociationsChanged(JNIEnv* env, jclass /* clazz */,
InputReaderConfiguration::CHANGE_DISPLAY_INFO); InputReaderConfiguration::CHANGE_DISPLAY_INFO);
} }
static void nativeSetMotionClassifierEnabled(JNIEnv* /* env */, jclass /* clazz */, jlong ptr,
jboolean enabled) {
NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
im->setMotionClassifierEnabled(enabled);
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
static const JNINativeMethod gInputManagerMethods[] = { static const JNINativeMethod gInputManagerMethods[] = {
@@ -1832,6 +1844,7 @@ static const JNINativeMethod gInputManagerMethods[] = {
(void*)nativeSetCustomPointerIcon}, (void*)nativeSetCustomPointerIcon},
{"nativeCanDispatchToDisplay", "(JII)Z", (void*)nativeCanDispatchToDisplay}, {"nativeCanDispatchToDisplay", "(JII)Z", (void*)nativeCanDispatchToDisplay},
{"nativeNotifyPortAssociationsChanged", "(J)V", (void*)nativeNotifyPortAssociationsChanged}, {"nativeNotifyPortAssociationsChanged", "(J)V", (void*)nativeNotifyPortAssociationsChanged},
{"nativeSetMotionClassifierEnabled", "(JZ)V", (void*)nativeSetMotionClassifierEnabled},
}; };
#define FIND_CLASS(var, className) \ #define FIND_CLASS(var, className) \