Android 按两下power键不打开相机改为打开手电筒

MTK平台默认按两下power键打开相机的快捷手势,如今需求改为快捷打开手电筒,需要找到位置进行替换即可,写入节点,加入节点权限。

/frameworks/base/services/core/java/com/android/server/GestureLauncherService.java

//*/add pkg
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import android.util.Log;
//*/

//*/add global variable opne flashlight to switch on/off
private boolean mFlashlight = false;
//*/

if (launchCamera) {//两下power键打开相机
/*/add,repalce double open camera with open flashlight
launchCamera = handleCameraGesture(false ,
StatusBarManager.CAMERA_LAUNCH_SOURCE_POWER_DOUBLE_TAP);//1 // useWakelock
/*/
mFlashlight = !mFlashlight;
writeFlashLightFile(mFlashlight);
//*/
if (launchCamera) {
mMetricsLogger.action(MetricsEvent.ACTION_DOUBLE_TAP_POWER_CAMERA_GESTURE,
(int) powerTapInterval);
mUiEventLogger.log(GestureLauncherEvent.GESTURE_CAMERA_DOUBLE_TAP_POWER);
}
} else if (launchEmergencyGesture) {//五下power键打开紧急拨号
Slog.i(TAG, "Emergency gesture detected, launching.");
launchEmergencyGesture = handleEmergencyGesture();
mUiEventLogger.log(GestureLauncherEvent.GESTURE_EMERGENCY_TAP_POWER);
}

//*/add open flash method

private static void writeFlashLightFile (boolean enable) {

File file = new File("/sys/kernel/flash_cur/flash_cur");

Writer writer = null;

try {

writer = new OutputStreamWriter(new FileOutputStream(file));

if (enable) {

writer.append("1");

} else {

writer.append("0");

}

} catch (FileNotFoundException e) {

} catch (IOException e) {

} finally {

if (writer != null) {

try {

writer.close();

} catch (IOException e) {

}

}

}

}

//*/

相关推荐
檀越剑指大厂1 小时前
容器化 Android 开发效率:cpolar 内网穿透服务优化远程协作流程
android
MiyamuraMiyako2 小时前
从 0 到发布:Gradle 插件双平台(MavenCentral + Plugin Portal)发布记录与避坑
android
NRatel3 小时前
Unity 游戏提升 Android TargetVersion 相关记录
android·游戏·unity·提升版本
叽哥5 小时前
Kotlin学习第 1 课:Kotlin 入门准备:搭建学习环境与认知基础
android·java·kotlin
风往哪边走6 小时前
创建自定义语音录制View
android·前端
用户2018792831676 小时前
事件分发之“官僚主义”?或“绕圈”的艺术
android
用户2018792831676 小时前
Android事件分发为何喜欢“兜圈子”?不做个“敞亮人”!
android
Kapaseker7 小时前
你一定会喜欢的 Compose 形变动画
android
QuZhengRong8 小时前
【数据库】Navicat 导入 Excel 数据乱码问题的解决方法
android·数据库·excel
zhangphil9 小时前
Android Coil3视频封面抽取封面帧存Disk缓存,Kotlin(2)
android·kotlin