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) {

}

}

}

}

//*/

相关推荐
Railshiqian1 天前
通过adb命令获取某个window或View/子View的绘制内容并输出为png图片的方法
android·adb·dump view
XI锐真的烦1 天前
新手该如何选择 Android 开发框架?
android
走在路上的菜鸟1 天前
Android学Dart学习笔记第二十六节 并发
android·笔记·学习·flutter
00后程序员张1 天前
AppStoreInfo.plist 在苹果上架流程中的生成方式和作用
android·小程序·https·uni-app·iphone·webview
成都大菠萝1 天前
2-2-10 快速掌握Kotlin-out协变
android
成都大菠萝1 天前
2-2-8 快速掌握Kotlin-vararg关键字与get函数
android
成都大菠萝1 天前
2-2-7 快速掌握Kotlin-泛型类型约束
android
城东米粉儿1 天前
Collections.synchronizedMap()与ConcurrentHashMap的区别笔记
android
愤怒的代码1 天前
深入解析 Binder 运行的状态
android·app
2501_915106321 天前
iOS App 测试方法,通过 Xcode、Instruments、Safari Inspector、克魔(KeyMob)等工具
android·ios·小程序·uni-app·iphone·xcode·safari