sdm845-common: Add a KeyHandler for tri-state-key events
Change-Id: I22a7ee5b7eec5667b14f1a587a6d0138e77dc0f3
This commit is contained in:
parent
89203b453e
commit
3c7edbc4a3
5 changed files with 136 additions and 0 deletions
30
KeyHandler/Android.mk
Normal file
30
KeyHandler/Android.mk
Normal file
|
@ -0,0 +1,30 @@
|
|||
#
|
||||
# Copyright (C) 2018 The LineageOS Project
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, src)
|
||||
LOCAL_PACKAGE_NAME := KeyHandler
|
||||
|
||||
LOCAL_CERTIFICATE := platform
|
||||
LOCAL_PRIVILEGED_MODULE := true
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
|
||||
LOCAL_PROGUARD_ENABLED := disabled
|
||||
|
||||
include $(BUILD_PACKAGE)
|
20
KeyHandler/AndroidManifest.xml
Normal file
20
KeyHandler/AndroidManifest.xml
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2018 The LineageOS Project
|
||||
|
||||
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.
|
||||
-->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:sharedUserId="android.uid.system"
|
||||
package="org.lineageos.settings.device">
|
||||
</manifest>
|
73
KeyHandler/src/org/lineageos/settings/device/KeyHandler.java
Normal file
73
KeyHandler/src/org/lineageos/settings/device/KeyHandler.java
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (C) 2018 The LineageOS Project
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.lineageos.settings.device;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Vibrator;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import com.android.internal.os.DeviceKeyHandler;
|
||||
|
||||
public class KeyHandler implements DeviceKeyHandler {
|
||||
private static final String TAG = KeyHandler.class.getSimpleName();
|
||||
|
||||
// Slider key codes
|
||||
private static final int MODE_NORMAL = 601;
|
||||
private static final int MODE_VIBRATION = 602;
|
||||
private static final int MODE_SILENCE = 603;
|
||||
|
||||
private final Context mContext;
|
||||
private final AudioManager mAudioManager;
|
||||
private final Vibrator mVibrator;
|
||||
|
||||
public KeyHandler(Context context) {
|
||||
mContext = context;
|
||||
|
||||
mAudioManager = mContext.getSystemService(AudioManager.class);
|
||||
mVibrator = mContext.getSystemService(Vibrator.class);
|
||||
}
|
||||
|
||||
public KeyEvent handleKeyEvent(KeyEvent event) {
|
||||
int scanCode = event.getScanCode();
|
||||
|
||||
switch (scanCode) {
|
||||
case MODE_NORMAL:
|
||||
mAudioManager.setRingerModeInternal(AudioManager.RINGER_MODE_NORMAL);
|
||||
break;
|
||||
case MODE_VIBRATION:
|
||||
mAudioManager.setRingerModeInternal(AudioManager.RINGER_MODE_VIBRATE);
|
||||
break;
|
||||
case MODE_SILENCE:
|
||||
mAudioManager.setRingerModeInternal(AudioManager.RINGER_MODE_SILENT);
|
||||
break;
|
||||
default:
|
||||
return event;
|
||||
}
|
||||
doHapticFeedback();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void doHapticFeedback() {
|
||||
if (mVibrator == null || !mVibrator.hasVibrator()) {
|
||||
return;
|
||||
}
|
||||
|
||||
mVibrator.vibrate(50);
|
||||
}
|
||||
}
|
|
@ -105,6 +105,7 @@ PRODUCT_COPY_FILES += \
|
|||
|
||||
# tri-state-key
|
||||
PRODUCT_PACKAGES += \
|
||||
KeyHandler \
|
||||
tri-state-key_daemon
|
||||
|
||||
# Update engine
|
||||
|
|
|
@ -20,6 +20,18 @@
|
|||
<integer name="config_proximityCheckTimeout">100</integer>
|
||||
<bool name="config_proximityCheckOnWakeEnabledByDefault">true</bool>
|
||||
|
||||
<!-- Paths to the libraries that contain device specific key handlers -->
|
||||
<string-array name="config_deviceKeyHandlerLibs" translatable="false">
|
||||
<item>/system/priv-app/LineageParts/LineageParts.apk</item>
|
||||
<item>/system/priv-app/KeyHandler/KeyHandler.apk</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Names of the key handler classes -->
|
||||
<string-array name="config_deviceKeyHandlerClasses" translatable="false">
|
||||
<item>org.lineageos.lineageparts.gestures.KeyHandler</item>
|
||||
<item>org.lineageos.settings.device.KeyHandler</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Hardware keys present on the device, stored as a bit field.
|
||||
This integer should equal the sum of the corresponding value for each
|
||||
of the following keys present:
|
||||
|
|
Loading…
Reference in a new issue