sanders: KeyHandler: Cleanup code
This commit is contained in:
@@ -19,20 +19,18 @@ package org.lineageos.settings.device;
|
|||||||
|
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.ActivityManagerNative;
|
import android.app.ActivityManagerNative;
|
||||||
|
import android.app.ISearchManager;
|
||||||
import android.app.KeyguardManager;
|
import android.app.KeyguardManager;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.ISearchManager;
|
|
||||||
import android.widget.Toast;
|
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.ContentObserver;
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.provider.MediaStore;
|
import android.content.res.Resources;
|
||||||
|
import android.database.ContentObserver;
|
||||||
import android.hardware.Sensor;
|
import android.hardware.Sensor;
|
||||||
import android.hardware.SensorEvent;
|
import android.hardware.SensorEvent;
|
||||||
import android.hardware.SensorEventListener;
|
import android.hardware.SensorEventListener;
|
||||||
@@ -43,8 +41,8 @@ import android.hardware.camera2.CameraManager;
|
|||||||
import android.hardware.input.InputManager;
|
import android.hardware.input.InputManager;
|
||||||
import android.media.AudioAttributes;
|
import android.media.AudioAttributes;
|
||||||
import android.media.session.MediaSessionLegacyHelper;
|
import android.media.session.MediaSessionLegacyHelper;
|
||||||
import android.os.Bundle;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
@@ -54,26 +52,24 @@ import android.os.RemoteException;
|
|||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.Vibrator;
|
|
||||||
import android.os.VibrationEffect;
|
import android.os.VibrationEffect;
|
||||||
import android.util.Log;
|
import android.os.Vibrator;
|
||||||
|
import android.provider.MediaStore;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.InputDevice;
|
import android.view.InputDevice;
|
||||||
import android.view.KeyCharacterMap;
|
import android.view.KeyCharacterMap;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.ViewConfiguration;
|
import android.view.ViewConfiguration;
|
||||||
import android.view.IWindowManager;
|
import android.widget.Toast;
|
||||||
import android.view.WindowManagerGlobal;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.Manifest;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.android.internal.os.DeviceKeyHandler;
|
import com.android.internal.os.DeviceKeyHandler;
|
||||||
import com.android.internal.util.ArrayUtils;
|
import com.android.internal.util.ArrayUtils;
|
||||||
|
|
||||||
import org.lineageos.settings.device.util.FileUtils;
|
import org.lineageos.settings.device.util.FileUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static org.lineageos.settings.device.actions.Constants.*;
|
import static org.lineageos.settings.device.actions.Constants.*;
|
||||||
|
|
||||||
public class KeyHandler implements DeviceKeyHandler {
|
public class KeyHandler implements DeviceKeyHandler {
|
||||||
@@ -88,10 +84,14 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
|
|
||||||
private static final String GESTURE_WAKEUP_REASON = "keyhandler-gesture-wakeup";
|
private static final String GESTURE_WAKEUP_REASON = "keyhandler-gesture-wakeup";
|
||||||
private static final int GESTURE_WAKELOCK_DURATION = 3000;
|
private static final int GESTURE_WAKELOCK_DURATION = 3000;
|
||||||
|
private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
|
||||||
|
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
||||||
|
.setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
|
||||||
|
.build();
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final PowerManager mPowerManager;
|
private final PowerManager mPowerManager;
|
||||||
private final NotificationManager mNotificationManager;
|
private final NotificationManager mNotificationManager;
|
||||||
|
public boolean mIsHapticFeedbackEnabledOnSystem;
|
||||||
WakeLock mProximityWakeLock;
|
WakeLock mProximityWakeLock;
|
||||||
WakeLock mGestureWakeLock;
|
WakeLock mGestureWakeLock;
|
||||||
private KeyguardManager mKeyguardManager;
|
private KeyguardManager mKeyguardManager;
|
||||||
@@ -105,49 +105,37 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
private Vibrator mVibrator;
|
private Vibrator mVibrator;
|
||||||
private int mProximityTimeOut;
|
private int mProximityTimeOut;
|
||||||
private boolean mProximityWakeSupported;
|
private boolean mProximityWakeSupported;
|
||||||
|
|
||||||
private ISearchManager mSearchManagerService;
|
private ISearchManager mSearchManagerService;
|
||||||
|
|
||||||
private Handler mHandler;
|
private Handler mHandler;
|
||||||
private int fpTapCounts = 0;
|
private int fpTapCounts = 0;
|
||||||
private boolean fpTapPending = false;
|
private boolean fpTapPending = false;
|
||||||
private boolean screenOffGesturePending = false;
|
private boolean screenOffGesturePending = false;
|
||||||
|
|
||||||
public boolean mIsHapticFeedbackEnabledOnSystem;
|
|
||||||
|
|
||||||
private SettingsObserver mSettingsObserver;
|
private SettingsObserver mSettingsObserver;
|
||||||
|
private Runnable doubleTapRunnable = new Runnable() {
|
||||||
private class SettingsObserver extends ContentObserver {
|
public void run() {
|
||||||
SettingsObserver(Handler handler) {
|
int action = 0;
|
||||||
super(handler);
|
if (fpTapCounts > 1) {
|
||||||
}
|
action = str2int(FileUtils.readOneLine(getFPNodeBasedOnScreenState(FP_KEY_DBLTAP_NODE)));
|
||||||
|
} else {
|
||||||
|
if (isSingleTapEnabledOnFP()) {
|
||||||
|
action = str2int(FileUtils.readOneLine(getFPNodeBasedOnScreenState(FP_KEYS_NODE)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void observe() {
|
if (action != 0) {
|
||||||
mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(
|
boolean isActionSupported = ArrayUtils.contains(mPowerManager.isScreenOn() ? sFPSupportedActions : sFPSupportedActionsScreenOff, action);
|
||||||
Settings.System.HAPTIC_FEEDBACK_ENABLED), false, this, UserHandle.USER_ALL);
|
if (isActionSupported) {
|
||||||
update();
|
fireFPAction(action, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resetDoubleTapOnFP();
|
||||||
}
|
}
|
||||||
|
};
|
||||||
@Override
|
private Runnable screenOffGestureRunnable = new Runnable() {
|
||||||
public void onChange(boolean selfChange) {
|
public void run() {
|
||||||
update();
|
resetScreenOffGestureDelay();
|
||||||
}
|
}
|
||||||
|
};
|
||||||
public void update() {
|
|
||||||
mIsHapticFeedbackEnabledOnSystem = Settings.System.getIntForUser(mContext.getContentResolver(),
|
|
||||||
Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setHapticFeedbackEnabledOnSystem(boolean enabled){
|
|
||||||
Settings.System.putIntForUser(mContext.getContentResolver(),
|
|
||||||
Settings.System.HAPTIC_FEEDBACK_ENABLED, enabled ? 1 : 0, UserHandle.USER_CURRENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
|
|
||||||
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
|
||||||
.setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
public KeyHandler(Context context) {
|
public KeyHandler(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@@ -197,12 +185,43 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
long[] out = new long[ar.length];
|
long[] out = new long[ar.length];
|
||||||
for (int i=0; i<ar.length; i++) {
|
for (int i = 0; i < ar.length; i++) {
|
||||||
out[i] = ar[i];
|
out[i] = ar[i];
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ActivityInfo getRunningActivityInfo(Context context) {
|
||||||
|
final ActivityManager am = (ActivityManager) context
|
||||||
|
.getSystemService(Context.ACTIVITY_SERVICE);
|
||||||
|
final PackageManager pm = context.getPackageManager();
|
||||||
|
|
||||||
|
List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
|
||||||
|
if (tasks != null && !tasks.isEmpty()) {
|
||||||
|
ActivityManager.RunningTaskInfo top = tasks.get(0);
|
||||||
|
try {
|
||||||
|
return pm.getActivityInfo(top.topActivity, 0);
|
||||||
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void dispatchMediaKeyWithWakeLock(int keycode, Context context) {
|
||||||
|
if (ActivityManagerNative.isSystemReady()) {
|
||||||
|
KeyEvent event = new KeyEvent(SystemClock.uptimeMillis(),
|
||||||
|
SystemClock.uptimeMillis(), KeyEvent.ACTION_DOWN, keycode, 0);
|
||||||
|
MediaSessionLegacyHelper.getHelper(context).sendMediaButtonEvent(event, true);
|
||||||
|
event = KeyEvent.changeAction(event, KeyEvent.ACTION_UP);
|
||||||
|
MediaSessionLegacyHelper.getHelper(context).sendMediaButtonEvent(event, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setHapticFeedbackEnabledOnSystem(boolean enabled) {
|
||||||
|
Settings.System.putIntForUser(mContext.getContentResolver(),
|
||||||
|
Settings.System.HAPTIC_FEEDBACK_ENABLED, enabled ? 1 : 0, UserHandle.USER_CURRENT);
|
||||||
|
}
|
||||||
|
|
||||||
private String getRearCameraId() {
|
private String getRearCameraId() {
|
||||||
if (mRearCameraId == null) {
|
if (mRearCameraId == null) {
|
||||||
try {
|
try {
|
||||||
@@ -231,7 +250,7 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
return pm.getLaunchIntentForPackage(resInfo.get(0).activityInfo.packageName);
|
return pm.getLaunchIntentForPackage(resInfo.get(0).activityInfo.packageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void triggerCameraAction(){
|
private void triggerCameraAction() {
|
||||||
ensureKeyguardManager();
|
ensureKeyguardManager();
|
||||||
WakeLock wl = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "GestureWakeLock");
|
WakeLock wl = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "GestureWakeLock");
|
||||||
wl.acquire(500);
|
wl.acquire(500);
|
||||||
@@ -258,11 +277,11 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
Intent normalIntent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
|
Intent normalIntent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
|
||||||
normalIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
normalIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
normalIntent.addFlags(Intent.FLAG_FROM_BACKGROUND);
|
normalIntent.addFlags(Intent.FLAG_FROM_BACKGROUND);
|
||||||
|
|
||||||
Intent secureIntent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
|
Intent secureIntent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
|
||||||
secureIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
secureIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
secureIntent.addFlags(Intent.FLAG_FROM_BACKGROUND);
|
secureIntent.addFlags(Intent.FLAG_FROM_BACKGROUND);
|
||||||
|
|
||||||
ActivityInfo normalActivity = getBestActivityInfo(normalIntent);
|
ActivityInfo normalActivity = getBestActivityInfo(normalIntent);
|
||||||
ActivityInfo secureActivity = getBestActivityInfo(secureIntent, normalActivity);
|
ActivityInfo secureActivity = getBestActivityInfo(secureIntent, normalActivity);
|
||||||
if (secureActivity != null) {
|
if (secureActivity != null) {
|
||||||
@@ -284,13 +303,13 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
|
|
||||||
private ActivityInfo getBestActivityInfo(Intent intent, ActivityInfo match) {
|
private ActivityInfo getBestActivityInfo(Intent intent, ActivityInfo match) {
|
||||||
PackageManager pm = mContext.getPackageManager();
|
PackageManager pm = mContext.getPackageManager();
|
||||||
List <ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
|
List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
|
||||||
ActivityInfo best = null;
|
ActivityInfo best = null;
|
||||||
if (activities.size() > 0) {
|
if (activities.size() > 0) {
|
||||||
best = activities.get(0).activityInfo;
|
best = activities.get(0).activityInfo;
|
||||||
if (match != null) {
|
if (match != null) {
|
||||||
String packageName = match.applicationInfo.packageName;
|
String packageName = match.applicationInfo.packageName;
|
||||||
for (int i = activities.size()-1; i >= 0; i--) {
|
for (int i = activities.size() - 1; i >= 0; i--) {
|
||||||
ActivityInfo activityInfo = activities.get(i).activityInfo;
|
ActivityInfo activityInfo = activities.get(i).activityInfo;
|
||||||
if (packageName.equals(activityInfo.applicationInfo.packageName)) {
|
if (packageName.equals(activityInfo.applicationInfo.packageName)) {
|
||||||
best = activityInfo;
|
best = activityInfo;
|
||||||
@@ -336,7 +355,7 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toggleFlashlight(){
|
private void toggleFlashlight() {
|
||||||
String rearCameraId = getRearCameraId();
|
String rearCameraId = getRearCameraId();
|
||||||
if (rearCameraId != null) {
|
if (rearCameraId != null) {
|
||||||
mGestureWakeLock.acquire(GESTURE_WAKELOCK_DURATION);
|
mGestureWakeLock.acquire(GESTURE_WAKELOCK_DURATION);
|
||||||
@@ -362,33 +381,12 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
mHandler.removeCallbacks(doubleTapRunnable);
|
mHandler.removeCallbacks(doubleTapRunnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Runnable doubleTapRunnable = new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
int action = 0;
|
|
||||||
if (fpTapCounts > 1){
|
|
||||||
action = str2int(FileUtils.readOneLine(getFPNodeBasedOnScreenState(FP_KEY_DBLTAP_NODE)));
|
|
||||||
}else{
|
|
||||||
if (isSingleTapEnabledOnFP()){
|
|
||||||
action = str2int(FileUtils.readOneLine(getFPNodeBasedOnScreenState(FP_KEYS_NODE)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (action != 0){
|
|
||||||
boolean isActionSupported = ArrayUtils.contains(mPowerManager.isScreenOn() ? sFPSupportedActions : sFPSupportedActionsScreenOff, action);
|
|
||||||
if (isActionSupported){
|
|
||||||
fireFPAction(action, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resetDoubleTapOnFP();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private void detectDoubleTapOnFP() {
|
private void detectDoubleTapOnFP() {
|
||||||
fpTapCounts++;
|
fpTapCounts++;
|
||||||
if (fpTapCounts == 1 || fpTapCounts == 2){
|
if (fpTapCounts == 1 || fpTapCounts == 2) {
|
||||||
doHapticFeedbackFP(false);
|
doHapticFeedbackFP(false);
|
||||||
}
|
}
|
||||||
if (!fpTapPending){
|
if (!fpTapPending) {
|
||||||
fpTapPending = true;
|
fpTapPending = true;
|
||||||
mHandler.postDelayed(doubleTapRunnable, ViewConfiguration.getDoubleTapTimeout());
|
mHandler.postDelayed(doubleTapRunnable, ViewConfiguration.getDoubleTapTimeout());
|
||||||
}
|
}
|
||||||
@@ -406,8 +404,8 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
return !FileUtils.readOneLine(getFPNodeBasedOnScreenState(FP_HAPTIC_NODE)).equals("0");
|
return !FileUtils.readOneLine(getFPNodeBasedOnScreenState(FP_HAPTIC_NODE)).equals("0");
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getFPNodeBasedOnScreenState(String node){
|
private String getFPNodeBasedOnScreenState(String node) {
|
||||||
if (mPowerManager.isScreenOn()){
|
if (mPowerManager.isScreenOn()) {
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
switch (node) {
|
switch (node) {
|
||||||
@@ -430,7 +428,7 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
public boolean handleKeyEvent(KeyEvent event) {
|
public boolean handleKeyEvent(KeyEvent event) {
|
||||||
int scanCode = event.getScanCode();
|
int scanCode = event.getScanCode();
|
||||||
|
|
||||||
if (DEBUG){
|
if (DEBUG) {
|
||||||
Log.d(TAG, "DEBUG: action=" + event.getAction()
|
Log.d(TAG, "DEBUG: action=" + event.getAction()
|
||||||
+ ", flags=" + event.getFlags()
|
+ ", flags=" + event.getFlags()
|
||||||
+ ", keyCode=" + event.getKeyCode()
|
+ ", keyCode=" + event.getKeyCode()
|
||||||
@@ -455,27 +453,27 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scanCode != FP_TAP_SCANCODE){
|
if (scanCode != FP_TAP_SCANCODE) {
|
||||||
resetDoubleTapOnFP();
|
resetDoubleTapOnFP();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFPScanCode) {
|
if (isFPScanCode) {
|
||||||
if((!isFPGestureEnabled) || (!isScreenOn && !isFPGestureEnabledOnScreenOff)){
|
if ((!isFPGestureEnabled) || (!isScreenOn && !isFPGestureEnabledOnScreenOff)) {
|
||||||
resetDoubleTapOnFP();
|
resetDoubleTapOnFP();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!isScreenOn && isFPGestureEnabledOnScreenOff){
|
if (!isScreenOn && isFPGestureEnabledOnScreenOff) {
|
||||||
processFPScreenOffScancode(scanCode);
|
processFPScreenOffScancode(scanCode);
|
||||||
}else{
|
} else {
|
||||||
processFPScancode(scanCode);
|
processFPScancode(scanCode);
|
||||||
}
|
}
|
||||||
}else if (isScreenOffGesturesScanCode) {
|
} else if (isScreenOffGesturesScanCode) {
|
||||||
processScreenOffScancode(scanCode);
|
processScreenOffScancode(scanCode);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processFPScancode(int scanCode){
|
private void processFPScancode(int scanCode) {
|
||||||
int action = 0;
|
int action = 0;
|
||||||
boolean isScreenOn = mPowerManager.isScreenOn();
|
boolean isScreenOn = mPowerManager.isScreenOn();
|
||||||
switch (scanCode) {
|
switch (scanCode) {
|
||||||
@@ -483,7 +481,7 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
if (isDoubleTapEnabledOnFP()) {
|
if (isDoubleTapEnabledOnFP()) {
|
||||||
detectDoubleTapOnFP();
|
detectDoubleTapOnFP();
|
||||||
return;
|
return;
|
||||||
}else{
|
} else {
|
||||||
resetDoubleTapOnFP();
|
resetDoubleTapOnFP();
|
||||||
action = str2int(FileUtils.readOneLine(getFPNodeBasedOnScreenState(FP_KEYS_NODE)));
|
action = str2int(FileUtils.readOneLine(getFPNodeBasedOnScreenState(FP_KEYS_NODE)));
|
||||||
}
|
}
|
||||||
@@ -499,23 +497,23 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
boolean isActionSupported = ArrayUtils.contains(isScreenOn ? sFPSupportedActions : sFPSupportedActionsScreenOff, action);
|
boolean isActionSupported = ArrayUtils.contains(isScreenOn ? sFPSupportedActions : sFPSupportedActionsScreenOff, action);
|
||||||
if (isActionSupported){
|
if (isActionSupported) {
|
||||||
fireFPAction(action, true);
|
fireFPAction(action, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireFPAction(int action, boolean haptic){
|
private void fireFPAction(int action, boolean haptic) {
|
||||||
ensureKeyguardManager();
|
ensureKeyguardManager();
|
||||||
boolean isHapticFeedbackEnabledOnFP = isHapticFeedbackEnabledOnFP();
|
boolean isHapticFeedbackEnabledOnFP = isHapticFeedbackEnabledOnFP();
|
||||||
if (!haptic){
|
if (!haptic) {
|
||||||
isHapticFeedbackEnabledOnFP = false;
|
isHapticFeedbackEnabledOnFP = false;
|
||||||
}
|
}
|
||||||
if (isHapticFeedbackEnabledOnFP && (action == ACTION_CAMERA || action == ACTION_FLASHLIGHT)){
|
if (isHapticFeedbackEnabledOnFP && (action == ACTION_CAMERA || action == ACTION_FLASHLIGHT)) {
|
||||||
vibrate(action == ACTION_CAMERA ? 500 : 250);
|
vibrate(action == ACTION_CAMERA ? 500 : 250);
|
||||||
}
|
}
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case ACTION_HOME:
|
case ACTION_HOME:
|
||||||
if (!mKeyguardManager.inKeyguardRestrictedInputMode()){
|
if (!mKeyguardManager.inKeyguardRestrictedInputMode()) {
|
||||||
triggerVirtualKeypress(mHandler, KeyEvent.KEYCODE_HOME);
|
triggerVirtualKeypress(mHandler, KeyEvent.KEYCODE_HOME);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -526,7 +524,7 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
triggerVirtualKeypress(mHandler, KeyEvent.KEYCODE_BACK);
|
triggerVirtualKeypress(mHandler, KeyEvent.KEYCODE_BACK);
|
||||||
break;
|
break;
|
||||||
case ACTION_RECENTS:
|
case ACTION_RECENTS:
|
||||||
if (!mKeyguardManager.inKeyguardRestrictedInputMode()){
|
if (!mKeyguardManager.inKeyguardRestrictedInputMode()) {
|
||||||
triggerVirtualKeypress(mHandler, KeyEvent.KEYCODE_APP_SWITCH);
|
triggerVirtualKeypress(mHandler, KeyEvent.KEYCODE_APP_SWITCH);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -537,7 +535,7 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
triggerVirtualKeypress(mHandler, KeyEvent.KEYCODE_VOLUME_DOWN);
|
triggerVirtualKeypress(mHandler, KeyEvent.KEYCODE_VOLUME_DOWN);
|
||||||
break;
|
break;
|
||||||
case ACTION_VOICE_ASSISTANT:
|
case ACTION_VOICE_ASSISTANT:
|
||||||
if (!mKeyguardManager.inKeyguardRestrictedInputMode()){
|
if (!mKeyguardManager.inKeyguardRestrictedInputMode()) {
|
||||||
fireGoogleNowOnTap();
|
fireGoogleNowOnTap();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -560,24 +558,24 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
triggerVirtualKeypress(mHandler, KeyEvent.KEYCODE_SYSRQ);
|
triggerVirtualKeypress(mHandler, KeyEvent.KEYCODE_SYSRQ);
|
||||||
break;
|
break;
|
||||||
case ACTION_PIP:
|
case ACTION_PIP:
|
||||||
if (!mKeyguardManager.inKeyguardRestrictedInputMode()){
|
if (!mKeyguardManager.inKeyguardRestrictedInputMode()) {
|
||||||
goToPipMode();
|
goToPipMode();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (isHapticFeedbackEnabledOnFP && action != ACTION_VOICE_ASSISTANT && action != ACTION_CAMERA && action != ACTION_FLASHLIGHT){ // prevent double vibration
|
if (isHapticFeedbackEnabledOnFP && action != ACTION_VOICE_ASSISTANT && action != ACTION_CAMERA && action != ACTION_FLASHLIGHT) { // prevent double vibration
|
||||||
doHapticFeedbackFP(false);
|
doHapticFeedbackFP(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void vibrate(int intensity){
|
private void vibrate(int intensity) {
|
||||||
if (mVibrator == null) {
|
if (mVibrator == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mVibrator.vibrate(intensity);
|
mVibrator.vibrate(intensity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void goToPipMode(){
|
private void goToPipMode() {
|
||||||
ActivityInfo ai = getRunningActivityInfo(mContext);
|
ActivityInfo ai = getRunningActivityInfo(mContext);
|
||||||
if (ai != null && !ai.supportsPictureInPicture()) {
|
if (ai != null && !ai.supportsPictureInPicture()) {
|
||||||
try {
|
try {
|
||||||
@@ -597,43 +595,17 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
triggerVirtualKeypress(mHandler, 171);
|
triggerVirtualKeypress(mHandler, 171);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ActivityInfo getRunningActivityInfo(Context context) {
|
private void toggleScreenState() {
|
||||||
final ActivityManager am = (ActivityManager) context
|
if (mPowerManager.isScreenOn()) {
|
||||||
.getSystemService(Context.ACTIVITY_SERVICE);
|
|
||||||
final PackageManager pm = context.getPackageManager();
|
|
||||||
|
|
||||||
List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
|
|
||||||
if (tasks != null && !tasks.isEmpty()) {
|
|
||||||
ActivityManager.RunningTaskInfo top = tasks.get(0);
|
|
||||||
try {
|
|
||||||
return pm.getActivityInfo(top.topActivity, 0);
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void toggleScreenState(){
|
|
||||||
if(mPowerManager.isScreenOn()){
|
|
||||||
mPowerManager.goToSleep(SystemClock.uptimeMillis());
|
mPowerManager.goToSleep(SystemClock.uptimeMillis());
|
||||||
}else{
|
} else {
|
||||||
mPowerManager.wakeUp(SystemClock.uptimeMillis());
|
mPowerManager.wakeUp(SystemClock.uptimeMillis());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void dispatchMediaKeyWithWakeLock(int keycode, Context context) {
|
|
||||||
if (ActivityManagerNative.isSystemReady()) {
|
|
||||||
KeyEvent event = new KeyEvent(SystemClock.uptimeMillis(),
|
|
||||||
SystemClock.uptimeMillis(), KeyEvent.ACTION_DOWN, keycode, 0);
|
|
||||||
MediaSessionLegacyHelper.getHelper(context).sendMediaButtonEvent(event, true);
|
|
||||||
event = KeyEvent.changeAction(event, KeyEvent.ACTION_UP);
|
|
||||||
MediaSessionLegacyHelper.getHelper(context).sendMediaButtonEvent(event, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void triggerVirtualKeypress(final Handler handler, final int keyCode) {
|
private void triggerVirtualKeypress(final Handler handler, final int keyCode) {
|
||||||
final boolean mIsHapticFeedbackEnabledOnSystem_ = mIsHapticFeedbackEnabledOnSystem;
|
final boolean mIsHapticFeedbackEnabledOnSystem_ = mIsHapticFeedbackEnabledOnSystem;
|
||||||
if (mIsHapticFeedbackEnabledOnSystem_){
|
if (mIsHapticFeedbackEnabledOnSystem_) {
|
||||||
setHapticFeedbackEnabledOnSystem(false);
|
setHapticFeedbackEnabledOnSystem(false);
|
||||||
}
|
}
|
||||||
final InputManager im = InputManager.getInstance();
|
final InputManager im = InputManager.getInstance();
|
||||||
@@ -646,29 +618,22 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
KeyEvent.ACTION_UP);
|
KeyEvent.ACTION_UP);
|
||||||
|
|
||||||
// add a small delay to make sure everything behind got focus
|
// add a small delay to make sure everything behind got focus
|
||||||
handler.postDelayed(new Runnable(){
|
handler.postDelayed(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
im.injectInputEvent(downEvent,InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
|
im.injectInputEvent(downEvent, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
|
||||||
}}, 10);
|
}
|
||||||
|
}, 10);
|
||||||
|
|
||||||
handler.postDelayed(new Runnable(){
|
handler.postDelayed(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
im.injectInputEvent(upEvent, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
|
im.injectInputEvent(upEvent, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
|
||||||
if (mIsHapticFeedbackEnabledOnSystem_){
|
if (mIsHapticFeedbackEnabledOnSystem_) {
|
||||||
setHapticFeedbackEnabledOnSystem(true);
|
setHapticFeedbackEnabledOnSystem(true);
|
||||||
}
|
}
|
||||||
}}, 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void sendCloseSystemWindows(String reason) {
|
|
||||||
if (ActivityManagerNative.isSystemReady()) {
|
|
||||||
try {
|
|
||||||
ActivityManagerNative.getDefault().closeSystemDialogs(reason);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
}
|
}
|
||||||
}
|
}, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireGoogleNowOnTap() {
|
private void fireGoogleNowOnTap() {
|
||||||
@@ -682,8 +647,8 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int str2int(String str){
|
private int str2int(String str) {
|
||||||
if (str == null || str.isEmpty()){
|
if (str == null || str.isEmpty()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -693,7 +658,7 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processFPScreenOffScancode(int scanCode){
|
private void processFPScreenOffScancode(int scanCode) {
|
||||||
if (!mFPScreenOffGesturesHandler.hasMessages(FP_ACTION_REQUEST)) {
|
if (!mFPScreenOffGesturesHandler.hasMessages(FP_ACTION_REQUEST)) {
|
||||||
Message msg = mFPScreenOffGesturesHandler.obtainMessage(FP_ACTION_REQUEST);
|
Message msg = mFPScreenOffGesturesHandler.obtainMessage(FP_ACTION_REQUEST);
|
||||||
msg.arg1 = scanCode;
|
msg.arg1 = scanCode;
|
||||||
@@ -706,7 +671,7 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
if (mProximityWakeSupported && proximityWakeCheckEnabled && mProximitySensor != null) {
|
if (mProximityWakeSupported && proximityWakeCheckEnabled && mProximitySensor != null) {
|
||||||
mFPScreenOffGesturesHandler.sendMessageDelayed(msg, mProximityTimeOut);
|
mFPScreenOffGesturesHandler.sendMessageDelayed(msg, mProximityTimeOut);
|
||||||
registerFPScreenOffListener(scanCode);
|
registerFPScreenOffListener(scanCode);
|
||||||
}else{
|
} else {
|
||||||
mFPScreenOffGesturesHandler.sendMessage(msg);
|
mFPScreenOffGesturesHandler.sendMessage(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -739,147 +704,102 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void resetScreenOffGestureDelay() {
|
private void resetScreenOffGestureDelay() {
|
||||||
screenOffGesturePending = false;
|
screenOffGesturePending = false;
|
||||||
mHandler.removeCallbacks(screenOffGestureRunnable);
|
mHandler.removeCallbacks(screenOffGestureRunnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Runnable screenOffGestureRunnable = new Runnable() {
|
private void processScreenOffScancode(int scanCode) {
|
||||||
public void run() {
|
if (screenOffGesturePending) {
|
||||||
resetScreenOffGestureDelay();
|
return;
|
||||||
}
|
} else {
|
||||||
};
|
resetScreenOffGestureDelay();
|
||||||
|
screenOffGesturePending = true;
|
||||||
private void processScreenOffScancode(int scanCode){
|
mHandler.postDelayed(screenOffGestureRunnable, 500);
|
||||||
if (screenOffGesturePending){
|
}
|
||||||
return;
|
if (!mScreenOffGesturesHandler.hasMessages(GESTURE_REQUEST)) {
|
||||||
}else{
|
Message msg = mScreenOffGesturesHandler.obtainMessage(GESTURE_REQUEST);
|
||||||
resetScreenOffGestureDelay();
|
msg.arg1 = scanCode;
|
||||||
screenOffGesturePending = true;
|
|
||||||
mHandler.postDelayed(screenOffGestureRunnable, 500);
|
|
||||||
}
|
|
||||||
if (!mScreenOffGesturesHandler.hasMessages(GESTURE_REQUEST)) {
|
|
||||||
Message msg = mScreenOffGesturesHandler.obtainMessage(GESTURE_REQUEST);
|
|
||||||
msg.arg1 = scanCode;
|
|
||||||
/* boolean defaultProximity = mContext.getResources().getBoolean(
|
/* boolean defaultProximity = mContext.getResources().getBoolean(
|
||||||
com.android.internal.R.bool.config_proximityCheckOnWakeEnabledByDefault);
|
com.android.internal.R.bool.config_proximityCheckOnWakeEnabledByDefault);
|
||||||
boolean proximityWakeCheckEnabled = Settings.System.getInt(mContext.getContentResolver(),
|
boolean proximityWakeCheckEnabled = Settings.System.getInt(mContext.getContentResolver(),
|
||||||
Settings.System.PROXIMITY_ON_WAKE, defaultProximity ? 1 : 0) == 1;*/
|
Settings.System.PROXIMITY_ON_WAKE, defaultProximity ? 1 : 0) == 1;*/
|
||||||
boolean defaultProximity = true;
|
boolean defaultProximity = true;
|
||||||
boolean proximityWakeCheckEnabled = true;
|
boolean proximityWakeCheckEnabled = true;
|
||||||
if (mProximityWakeSupported && proximityWakeCheckEnabled && mProximitySensor != null) {
|
if (mProximityWakeSupported && proximityWakeCheckEnabled && mProximitySensor != null) {
|
||||||
mScreenOffGesturesHandler.sendMessageDelayed(msg, mProximityTimeOut);
|
mScreenOffGesturesHandler.sendMessageDelayed(msg, mProximityTimeOut);
|
||||||
registerScreenOffGesturesListener(scanCode);
|
registerScreenOffGesturesListener(scanCode);
|
||||||
} else {
|
} else {
|
||||||
mScreenOffGesturesHandler.sendMessage(msg);
|
mScreenOffGesturesHandler.sendMessage(msg);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerScreenOffGesturesListener(final int scanCode) {
|
|
||||||
mProximityWakeLock.acquire();
|
|
||||||
mSensorManager.registerListener(new SensorEventListener() {
|
|
||||||
@Override
|
|
||||||
public void onSensorChanged(SensorEvent event) {
|
|
||||||
mProximityWakeLock.release();
|
|
||||||
mSensorManager.unregisterListener(this);
|
|
||||||
if (!mScreenOffGesturesHandler.hasMessages(GESTURE_REQUEST)) {
|
|
||||||
// The sensor took to long, ignoring.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mScreenOffGesturesHandler.removeMessages(GESTURE_REQUEST);
|
|
||||||
if (event.values[0] == mProximitySensor.getMaximumRange()) {
|
|
||||||
Message msg = mScreenOffGesturesHandler.obtainMessage(GESTURE_REQUEST);
|
|
||||||
msg.arg1 = scanCode;
|
|
||||||
mScreenOffGesturesHandler.sendMessage(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
|
||||||
}
|
|
||||||
|
|
||||||
}, mProximitySensor, SensorManager.SENSOR_DELAY_FASTEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ScreenOffGesturesHandler extends Handler {
|
|
||||||
@Override
|
|
||||||
public void handleMessage(Message msg) {
|
|
||||||
int scanCode = msg.arg1;
|
|
||||||
int action = 0;
|
|
||||||
switch (scanCode) {
|
|
||||||
case GESTURE_SWIPE_RIGHT_SCANCODE:
|
|
||||||
action = str2int(FileUtils.readOneLine(GESTURE_SWIPE_RIGHT_NODE));
|
|
||||||
break;
|
|
||||||
case GESTURE_SWIPE_LEFT_SCANCODE:
|
|
||||||
action = str2int(FileUtils.readOneLine(GESTURE_SWIPE_LEFT_NODE));
|
|
||||||
break;
|
|
||||||
case GESTURE_SWIPE_DOWN_SCANCODE:
|
|
||||||
action = str2int(FileUtils.readOneLine(GESTURE_SWIPE_DOWN_NODE));
|
|
||||||
break;
|
|
||||||
case GESTURE_SWIPE_UP_SCANCODE:
|
|
||||||
action = str2int(FileUtils.readOneLine(GESTURE_SWIPE_UP_NODE));
|
|
||||||
break;
|
|
||||||
case GESTURE_DOUBLE_TAP_SCANCODE:
|
|
||||||
action = str2int(FileUtils.readOneLine(GESTURE_DOUBLE_TAP_NODE));
|
|
||||||
if (action != 0){
|
|
||||||
action = ACTION_POWER;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
boolean isActionSupported = ArrayUtils.contains(sScreenOffSupportedActions, action);
|
|
||||||
if(isActionSupported){
|
|
||||||
fireScreenOffAction(action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void fireScreenOffAction(int action){
|
|
||||||
boolean haptic = Settings.System.getInt(mContext.getContentResolver(), KEY_GESTURE_ENABLE_HAPTIC_FEEDBACK, 1) != 0;
|
|
||||||
if (haptic && (action == ACTION_CAMERA || action == ACTION_FLASHLIGHT)){
|
|
||||||
vibrate(action == ACTION_CAMERA ? 500 : 250);
|
|
||||||
}
|
|
||||||
switch (action) {
|
|
||||||
case ACTION_POWER:
|
|
||||||
toggleScreenState();
|
|
||||||
break;
|
|
||||||
case ACTION_PLAY_PAUSE:
|
|
||||||
dispatchMediaKeyWithWakeLock(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, mContext);
|
|
||||||
break;
|
|
||||||
case ACTION_PREVIOUS_TRACK:
|
|
||||||
dispatchMediaKeyWithWakeLock(KeyEvent.KEYCODE_MEDIA_PREVIOUS, mContext);
|
|
||||||
break;
|
|
||||||
case ACTION_NEXT_TRACK:
|
|
||||||
dispatchMediaKeyWithWakeLock(KeyEvent.KEYCODE_MEDIA_NEXT, mContext);
|
|
||||||
break;
|
|
||||||
case ACTION_FLASHLIGHT:
|
|
||||||
toggleFlashlight();
|
|
||||||
break;
|
|
||||||
case ACTION_CAMERA:
|
|
||||||
triggerCameraAction();
|
|
||||||
break;
|
|
||||||
case ACTION_BROWSER:
|
|
||||||
openBrowser();
|
|
||||||
break;
|
|
||||||
case ACTION_DIALER:
|
|
||||||
openDialer();
|
|
||||||
break;
|
|
||||||
case ACTION_EMAIL:
|
|
||||||
openEmail();
|
|
||||||
break;
|
|
||||||
case ACTION_MESSAGES:
|
|
||||||
openMessages();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (action != ACTION_FLASHLIGHT && action != ACTION_CAMERA){
|
|
||||||
doHapticFeedbackScreenOff();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class FPScreenOffGesturesHandler extends Handler {
|
private void registerScreenOffGesturesListener(final int scanCode) {
|
||||||
@Override
|
mProximityWakeLock.acquire();
|
||||||
public void handleMessage(Message msg) {
|
mSensorManager.registerListener(new SensorEventListener() {
|
||||||
processFPScancode(msg.arg1);
|
@Override
|
||||||
|
public void onSensorChanged(SensorEvent event) {
|
||||||
|
mProximityWakeLock.release();
|
||||||
|
mSensorManager.unregisterListener(this);
|
||||||
|
if (!mScreenOffGesturesHandler.hasMessages(GESTURE_REQUEST)) {
|
||||||
|
// The sensor took to long, ignoring.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mScreenOffGesturesHandler.removeMessages(GESTURE_REQUEST);
|
||||||
|
if (event.values[0] == mProximitySensor.getMaximumRange()) {
|
||||||
|
Message msg = mScreenOffGesturesHandler.obtainMessage(GESTURE_REQUEST);
|
||||||
|
msg.arg1 = scanCode;
|
||||||
|
mScreenOffGesturesHandler.sendMessage(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}, mProximitySensor, SensorManager.SENSOR_DELAY_FASTEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fireScreenOffAction(int action) {
|
||||||
|
boolean haptic = Settings.System.getInt(mContext.getContentResolver(), KEY_GESTURE_ENABLE_HAPTIC_FEEDBACK, 1) != 0;
|
||||||
|
if (haptic && (action == ACTION_CAMERA || action == ACTION_FLASHLIGHT)) {
|
||||||
|
vibrate(action == ACTION_CAMERA ? 500 : 250);
|
||||||
|
}
|
||||||
|
switch (action) {
|
||||||
|
case ACTION_POWER:
|
||||||
|
toggleScreenState();
|
||||||
|
break;
|
||||||
|
case ACTION_PLAY_PAUSE:
|
||||||
|
dispatchMediaKeyWithWakeLock(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, mContext);
|
||||||
|
break;
|
||||||
|
case ACTION_PREVIOUS_TRACK:
|
||||||
|
dispatchMediaKeyWithWakeLock(KeyEvent.KEYCODE_MEDIA_PREVIOUS, mContext);
|
||||||
|
break;
|
||||||
|
case ACTION_NEXT_TRACK:
|
||||||
|
dispatchMediaKeyWithWakeLock(KeyEvent.KEYCODE_MEDIA_NEXT, mContext);
|
||||||
|
break;
|
||||||
|
case ACTION_FLASHLIGHT:
|
||||||
|
toggleFlashlight();
|
||||||
|
break;
|
||||||
|
case ACTION_CAMERA:
|
||||||
|
triggerCameraAction();
|
||||||
|
break;
|
||||||
|
case ACTION_BROWSER:
|
||||||
|
openBrowser();
|
||||||
|
break;
|
||||||
|
case ACTION_DIALER:
|
||||||
|
openDialer();
|
||||||
|
break;
|
||||||
|
case ACTION_EMAIL:
|
||||||
|
openEmail();
|
||||||
|
break;
|
||||||
|
case ACTION_MESSAGES:
|
||||||
|
openMessages();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (action != ACTION_FLASHLIGHT && action != ACTION_CAMERA) {
|
||||||
|
doHapticFeedbackScreenOff();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -901,9 +821,9 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boolean enabled = Settings.System.getInt(mContext.getContentResolver(), KEY_GESTURE_ENABLE_HAPTIC_FEEDBACK, 1) != 0;
|
boolean enabled = Settings.System.getInt(mContext.getContentResolver(), KEY_GESTURE_ENABLE_HAPTIC_FEEDBACK, 1) != 0;
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
mVibrator.vibrate(50);
|
mVibrator.vibrate(50);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doHapticFeedbackFP(boolean longpress) {
|
private void doHapticFeedbackFP(boolean longpress) {
|
||||||
@@ -918,10 +838,10 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
owningUid = android.os.Process.myUid();
|
owningUid = android.os.Process.myUid();
|
||||||
owningPackage = mContext.getOpPackageName();
|
owningPackage = mContext.getOpPackageName();
|
||||||
VibrationEffect effect;
|
VibrationEffect effect;
|
||||||
if (longpress){
|
if (longpress) {
|
||||||
pattern = getLongIntArray(mContext.getResources(),com.android.internal.R.array.config_longPressVibePattern);
|
pattern = getLongIntArray(mContext.getResources(), com.android.internal.R.array.config_longPressVibePattern);
|
||||||
}else{
|
} else {
|
||||||
pattern = getLongIntArray(mContext.getResources(),com.android.internal.R.array.config_virtualKeyVibePattern);
|
pattern = getLongIntArray(mContext.getResources(), com.android.internal.R.array.config_virtualKeyVibePattern);
|
||||||
}
|
}
|
||||||
if (pattern.length == 0) {
|
if (pattern.length == 0) {
|
||||||
// No vibration
|
// No vibration
|
||||||
@@ -937,6 +857,67 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class SettingsObserver extends ContentObserver {
|
||||||
|
SettingsObserver(Handler handler) {
|
||||||
|
super(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
void observe() {
|
||||||
|
mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(
|
||||||
|
Settings.System.HAPTIC_FEEDBACK_ENABLED), false, this, UserHandle.USER_ALL);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChange(boolean selfChange) {
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update() {
|
||||||
|
mIsHapticFeedbackEnabledOnSystem = Settings.System.getIntForUser(mContext.getContentResolver(),
|
||||||
|
Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ScreenOffGesturesHandler extends Handler {
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message msg) {
|
||||||
|
int scanCode = msg.arg1;
|
||||||
|
int action = 0;
|
||||||
|
switch (scanCode) {
|
||||||
|
case GESTURE_SWIPE_RIGHT_SCANCODE:
|
||||||
|
action = str2int(FileUtils.readOneLine(GESTURE_SWIPE_RIGHT_NODE));
|
||||||
|
break;
|
||||||
|
case GESTURE_SWIPE_LEFT_SCANCODE:
|
||||||
|
action = str2int(FileUtils.readOneLine(GESTURE_SWIPE_LEFT_NODE));
|
||||||
|
break;
|
||||||
|
case GESTURE_SWIPE_DOWN_SCANCODE:
|
||||||
|
action = str2int(FileUtils.readOneLine(GESTURE_SWIPE_DOWN_NODE));
|
||||||
|
break;
|
||||||
|
case GESTURE_SWIPE_UP_SCANCODE:
|
||||||
|
action = str2int(FileUtils.readOneLine(GESTURE_SWIPE_UP_NODE));
|
||||||
|
break;
|
||||||
|
case GESTURE_DOUBLE_TAP_SCANCODE:
|
||||||
|
action = str2int(FileUtils.readOneLine(GESTURE_DOUBLE_TAP_NODE));
|
||||||
|
if (action != 0) {
|
||||||
|
action = ACTION_POWER;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
boolean isActionSupported = ArrayUtils.contains(sScreenOffSupportedActions, action);
|
||||||
|
if (isActionSupported) {
|
||||||
|
fireScreenOffAction(action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class FPScreenOffGesturesHandler extends Handler {
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message msg) {
|
||||||
|
processFPScancode(msg.arg1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class MyTorchCallback extends CameraManager.TorchCallback {
|
private class MyTorchCallback extends CameraManager.TorchCallback {
|
||||||
@Override
|
@Override
|
||||||
public void onTorchModeChanged(String cameraId, boolean enabled) {
|
public void onTorchModeChanged(String cameraId, boolean enabled) {
|
||||||
@@ -952,4 +933,4 @@ public class KeyHandler implements DeviceKeyHandler {
|
|||||||
mTorchEnabled = false;
|
mTorchEnabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user