Skip to content

Commit

Permalink
sdm845-common: Implement keyhandler for fingerprint shutter
Browse files Browse the repository at this point in the history
 * prevents fp from triggering other events such as
   vibrate on long press

Fixes: d0e76759b64987e3af18a3290a8b6125ac53f789 ("keylayout: Redirect keycode 96 to CAMERA")
Co-authored-by: Adithya R <[email protected]>
Signed-off-by: Adithya R <[email protected]>
Change-Id: Ic7fec6d37d42b3d5fa8ff78935eaa85e212d64f5
  • Loading branch information
RahulGorai0206 and adithya2306 committed Feb 16, 2024
1 parent b69059d commit 1ccd52f
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 0 deletions.
19 changes: 19 additions & 0 deletions keyhandler/Android.bp
Original file line number Diff line number Diff line change
@@ -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"],
},
}
9 changes: 9 additions & 0 deletions keyhandler/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -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="com.pixelos.keyhandler" />
4 changes: 4 additions & 0 deletions keyhandler/proguard.flags
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Keep keyhandler constructor
-keep public class * implements com.android.internal.os.DeviceKeyHandler {
public <init>(android.content.Context);
}
77 changes: 77 additions & 0 deletions keyhandler/src/com/pixelos/keyhandler/KeyHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (C) 2021 WaveOS
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.pixelos.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;
}

}
11 changes: 11 additions & 0 deletions overlay/AOSPBerylliumFrameworksOverlay/Android.bp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// Copyright (C) 2023 PixelOS
//
// SPDX-License-Identifier: Apache-2.0
//

runtime_resource_overlay {
name: "AOSPBerylliumFrameworksOverlay",
sdk_version: "current",
vendor: true,
}
14 changes: 14 additions & 0 deletions overlay/AOSPBerylliumFrameworksOverlay/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2023 PixelOS
SPDX-License-Identifier: Apache-2.0
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pixel.android.beryllium">

<overlay
android:isStatic="true"
android:priority="800"
android:targetPackage="android" />
</manifest>
24 changes: 24 additions & 0 deletions overlay/AOSPBerylliumFrameworksOverlay/res/values/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2023 PixelOS
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.
-->
<resources>
<!-- 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>com.pixelos.keyhandler.KeyHandler</item>
</string-array>
</resources>
5 changes: 5 additions & 0 deletions sdm845.mk
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ PRODUCT_PACKAGES += \
PRODUCT_PACKAGES += \
[email protected]

# Keyhandler
PRODUCT_PACKAGES += \
AOSPBerylliumFrameworksOverlay \
KeyHandler

# Lights
PRODUCT_PACKAGES += \
[email protected]_sdm845
Expand Down

0 comments on commit 1ccd52f

Please sign in to comment.