violet: Implement keyhandler for fingerprint shutter

* Prevents fp from triggering other events such as
   vibrate on long press

Fixes: 7b74e3d8fef912c35f6d48f69c951af290414d73 ("keylayout: Redirect keycode 96 to CAMERA")
Co-authored-by: Adithya R <gh0strider.2k18.reborn@gmail.com>
Signed-off-by: Adithya R <gh0strider.2k18.reborn@gmail.com>
Signed-off-by: Joker-V2 <nipinna0@gmail.com>
This commit is contained in:
Henrique Silva
2018-07-30 20:06:19 -03:00
committed by Joker-V2
parent cb737a71a5
commit 2613cc3f9c
6 changed files with 123 additions and 0 deletions

View File

@@ -286,6 +286,10 @@ PRODUCT_PACKAGES += \
PRODUCT_COPY_FILES += \
$(LOCAL_PATH)/configs/sec_config:$(TARGET_COPY_OUT_VENDOR)/etc/sec_config
# Keyhandler
PRODUCT_PACKAGES += \
KeyHandler
# Keylayouts
PRODUCT_COPY_FILES += \
$(LOCAL_PATH)/configs/keylayout/sm6150-idp-snd-card_Button_Jack.kl:$(TARGET_COPY_OUT_SYSTEM)/usr/keylayout/sm6150-idp-snd-card_Button_Jack.kl \

19
keyhandler/Android.bp Normal file
View File

@@ -0,0 +1,19 @@
//
// Copyright (C) 2021 WaveOS
//
// SPDX-License-Identifier: Apache-2.0
//
android_app {
name: "KeyHandler",
srcs: ["src/**/*.java"],
certificate: "platform",
platform_apis: true,
privileged: true,
optimize: {
proguard_flags_files: ["proguard.flags"],
},
}

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2021 WaveOS
SPDX-License-Identifier: Apache-2.0
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:sharedUserId="android.uid.system"
package="me.superioros.keyhandler" />

View File

@@ -0,0 +1,4 @@
# Keep keyhandler constructor
-keep public class * implements com.android.internal.os.DeviceKeyHandler {
public <init>(android.content.Context);
}

View File

@@ -0,0 +1,77 @@
/*
* Copyright (C) 2021 WaveOS
*
* SPDX-License-Identifier: Apache-2.0
*/
package me.superioros.keyhandler;
import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.view.KeyEvent;
import android.util.Log;
import com.android.internal.os.DeviceKeyHandler;
import java.util.List;
public class KeyHandler implements DeviceKeyHandler {
private static final int FP_SCANCODE = 96;
private static final int FP_KEYCODE = KeyEvent.KEYCODE_CAMERA;
private static final String MIUI_CAMERA_PACKAGE_NAME = "com.android.camera";
private static final String TAG = "KeyHandler";
private static final boolean DEBUG = false;
private static ActivityManager am;
private static PackageManager pm;
public KeyHandler(Context context) {
am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
pm = context.getPackageManager();
}
public KeyEvent handleKeyEvent(KeyEvent event) {
int keyCode = event.getKeyCode();
int scanCode = event.getScanCode();
int action = event.getAction();
if (DEBUG)
Log.i(TAG, String.format("Received event keyCode=%d scanCode=%d action=%d", keyCode, scanCode, action));
if (keyCode == FP_KEYCODE && scanCode == FP_SCANCODE) {
if (action != KeyEvent.ACTION_DOWN) {
return null;
}
ActivityInfo runningActivity = getRunningActivityInfo();
if (runningActivity != null && runningActivity.packageName.equals(MIUI_CAMERA_PACKAGE_NAME)) {
if (DEBUG) Log.i(TAG, "Miui camera running, returning event");
return event;
} else {
if (DEBUG) Log.i(TAG, "Miui camera not running, returning null");
return null;
}
}
return event;
}
private static ActivityInfo getRunningActivityInfo() {
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) {
// Do nothing
}
}
return null;
}
}

View File

@@ -519,4 +519,14 @@
<!-- Pocket Lock -->
<bool name="config_pocketModeSupported">true</bool>
<!-- Paths to the libraries that contain device specific key handlers -->
<string-array name="config_deviceKeyHandlerLibs" translatable="false">
<item>/system/priv-app/KeyHandler/KeyHandler.apk</item>
</string-array>
<!-- Names of the key handler classes -->
<string-array name="config_deviceKeyHandlerClasses" translatable="false">
<item>me.superioros.keyhandler.KeyHandler</item>
</string-array>
</resources>