pipa: Add Xiaomi Peripheral Manager
* right now keyboardutils just does disable the keyboard input device after boot Change-Id: I7020b043e9e643d125e9641b18f3f0e71d8343b1
This commit is contained in:
committed by
Abdulwahab Isam
parent
37a8902077
commit
bf214c5b8a
@@ -34,6 +34,10 @@ DEVICE_PACKAGE_OVERLAYS += \
|
||||
$(LOCAL_PATH)/overlay \
|
||||
$(LOCAL_PATH)/overlay-lineage
|
||||
|
||||
# Peripheral Manager
|
||||
PRODUCT_PACKAGES += \
|
||||
XiaomiPeripheralManager
|
||||
|
||||
# Permissions
|
||||
PRODUCT_COPY_FILES += \
|
||||
frameworks/native/data/etc/handheld_core_hardware.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/handheld_core_hardware.xml
|
||||
|
||||
17
peripheralmanager/Android.bp
Normal file
17
peripheralmanager/Android.bp
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// Copyright (C) 2023 The LineageOS Project
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
android_app {
|
||||
name: "XiaomiPeripheralManager",
|
||||
certificate: "platform",
|
||||
srcs: ["src/**/*.java"],
|
||||
platform_apis: true,
|
||||
privileged: true,
|
||||
system_ext_specific: true,
|
||||
static_libs: [
|
||||
"androidx.core_core",
|
||||
],
|
||||
}
|
||||
34
peripheralmanager/AndroidManifest.xml
Normal file
34
peripheralmanager/AndroidManifest.xml
Normal file
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2023 The LineageOS Project
|
||||
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.lineageos.xiaomiperipheralmanager"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0"
|
||||
android:sharedUserId="android.uid.system">
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="31"
|
||||
android:targetSdkVersion="31"/>
|
||||
|
||||
<application
|
||||
android:label="@string/app_name"
|
||||
android:persistent="true"
|
||||
android:defaultToDeviceProtectedStorage="true"
|
||||
android:directBootAware="true">
|
||||
|
||||
<receiver
|
||||
android:name=".BootCompletedReceiver"
|
||||
android:exported="true"
|
||||
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
</application>
|
||||
</manifest>
|
||||
10
peripheralmanager/res/values/strings.xml
Normal file
10
peripheralmanager/res/values/strings.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2023 The LineageOS Project
|
||||
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
||||
<!-- App Name -->
|
||||
<string name="app_name">Xiaomi Peripheral Manager</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package org.lineageos.xiaomiperipheralmanager;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
public class BootCompletedReceiver extends BroadcastReceiver {
|
||||
|
||||
private static final String TAG = "XiaomiPeripheralManager";
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
@Override
|
||||
public void onReceive(final Context context, Intent intent) {
|
||||
if (DEBUG) Log.d(TAG, "Received boot completed intent");
|
||||
KeyboardUtils.setup(context);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package org.lineageos.xiaomiperipheralmanager;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.input.InputManager;
|
||||
import android.util.Log;
|
||||
import android.view.InputDevice;
|
||||
|
||||
public class KeyboardUtils {
|
||||
|
||||
private static final String TAG = "XiaomiPeripheralManagerKeyboardUtils";
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private static final int kbVendorId = 5593;
|
||||
private static final int kbProductId = 163;
|
||||
|
||||
private static InputManager mInputManager;
|
||||
|
||||
public static void setup(Context context) {
|
||||
if (mInputManager == null) {
|
||||
mInputManager = (InputManager) context.getSystemService(Context.INPUT_SERVICE);
|
||||
}
|
||||
setKeyboardEnabled(false);
|
||||
}
|
||||
|
||||
public static void setKeyboardEnabled(boolean enabled) {
|
||||
if (DEBUG) Log.d(TAG, "setKeyboardEnabled: " + enabled);
|
||||
for (int id : mInputManager.getInputDeviceIds()) {
|
||||
if (isDeviceXiaomiKeyboard(id)) {
|
||||
if (DEBUG) Log.d(TAG, "setKeyboardEnabled: Found Xiaomi Keyboard with id: " + id);
|
||||
if (enabled) {
|
||||
if (DEBUG) Log.d(TAG, "setKeyboardEnabled: Enabling Xiaomi Keyboard");
|
||||
mInputManager.enableInputDevice(id);
|
||||
} else {
|
||||
if (DEBUG) Log.d(TAG, "setKeyboardEnabled: Disabling Xiaomi Keyboard");
|
||||
mInputManager.disableInputDevice(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isDeviceXiaomiKeyboard(int id) {
|
||||
InputDevice inputDevice = mInputManager.getInputDevice(id);
|
||||
return inputDevice.getVendorId() == kbVendorId && inputDevice.getProductId() == kbProductId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user