1、双击屏幕时,tp报上来的事件设定为KeyEvent.KEYCODE_U,则在PhoneWindowManager中可以增加监听,只要正常上报该事件,按以下的执行则能实现双击亮屏的功能。
ALPS_R0MP1/frameworks / base/services/core/java/com/android/server/policy/PhoneWindowManager.java
@Override
public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
......
case KeyEvent.KEYCODE_U:{
if (SystemProperties.getBoolean("ro.hct_double_click_brighten_screen_support", false)) {
result &= ~ACTION_PASS_TO_USER;
if (down) {
isWakeKey = true;
}
}
break;
}
}
2、实现功能后则需要添加按钮控制,以达到不需要时关闭该功能后节省点的目的,UI具体实现代码如下:
ALPS_R0MP1/vendor/mediatek/proprietary/packages / apps/MtkSettings/src/com/android/settings/gestures/WakeUpSwitchController.java
package com.android.settings.gestures;
import android.content.Context;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.Settings;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import com.android.settings.core.TogglePreferenceController;
public class WakeUpSwitchController extends TogglePreferenceController {
private final Context mContext;
private static final int MY_USER_ID = UserHandle.myUserId();
private final String WAKE_UP_SWITHCH_MOD = "wake_up_switch_mod";
public WakeUpSwitchController(Context context, String preferenceKey) {
super(context, preferenceKey);
mContext = context;
}
@Override
public boolean isChecked() {
return Settings.System.getIntForUser(mContext.getContentResolver(),
WAKE_UP_SWITHCH_MOD,
0, MY_USER_ID) != 0;
}
@Override
public boolean setChecked(boolean isChecked) {
Settings.System.putIntForUser(mContext.getContentResolver(), WAKE_UP_SWITHCH_MOD,
isChecked ? 1 : 0, MY_USER_ID);
SystemProperties.set("persist.vendor.hct.gesturewake", isChecked ? "1" : "0");
return true;
}
@Override
public int getAvailabilityStatus() {
return SystemProperties.getBoolean("ro.hct_double_click_brighten_screen_support", false) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
}
3、通过对目标prop值的监听来控制tp的节点,具体实现如下:
ALPS_R0MP1/device / mediatek/mt6779/init.mt6779.rc
#gesturewake
chown root system /sys/bus/i2c/devices/0-0038/fts_gesture_mode
chmod 0777 /sys/bus/i2c/devices/0-0038/fts_gesture_mode
on property:persist.vendor.hct.gesturewake=*
write /sys/bus/i2c/devices/0-0038/fts_gesture_mode ${persist.vendor.hct.gesturewake}
----------
ALPS_R0MP1/device / mediatek/sepolicy/basic/non_plat/file.te
#gesturewake
type hct_gesture_mode, fs_type, sysfs_type;
----------
ALPS_R0MP1/device / mediatek/sepolicy/basic/non_plat/file_contexts
#gesturewake
/sys/bus/i2c/devices/0-0038/fts_gesture_mode u:object_r:hct_gesture_mode:s0
----------
ALPS_R0MP1/device / mediatek/sepolicy/basic/non_plat/property_contexts
#=============gesture wake==============
persist.vendor.hct.gesturewake u:object_r:system_prop:s0
----------
ALPS_R0MP1/device / mediatek/sepolicy/basic/non_plat/system_app.te
#gesturewake
allow system_app system_prop:property_service set;
allow system_app hct_gesture_mode:file { write read getattr open };
|