-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sdm845-common: Implement keyhandler for fingerprint shutter
* 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
1 parent
b69059d
commit 1ccd52f
Showing
8 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
overlay/AOSPBerylliumFrameworksOverlay/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
24
overlay/AOSPBerylliumFrameworksOverlay/res/values/config.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -234,6 +234,11 @@ PRODUCT_PACKAGES += \ | |
PRODUCT_PACKAGES += \ | ||
[email protected] | ||
|
||
# Keyhandler | ||
PRODUCT_PACKAGES += \ | ||
AOSPBerylliumFrameworksOverlay \ | ||
KeyHandler | ||
|
||
# Lights | ||
PRODUCT_PACKAGES += \ | ||
[email protected]_sdm845 | ||
|