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

}

}

}

}

//*/

相关推荐
阿pin8 分钟前
Android随笔-kotlin Flow
android·kotlin·flow
阳光予你19 分钟前
App 启动流程:从 Launcher 点击到 Activity 创建
android
小孔龙40 分钟前
BufferQueue 对象交接与同步
android
XiaoLeisj1 小时前
Kotlin Flow 常用操作符:数据变换 map、filter、onEach,时间控制 debounce、sample,终端聚合 reduce、fold
android·kotlin·android jetpack·协程·响应式编程·flow
EQ-雪梨蛋花汤1 小时前
Android 3D 开发教程(三):Sceneform-EQR 配置 PBR 材质、光照、相机与实时阴影
android·3d·材质
Dovis(誓平步青云)2 小时前
《 固井工程软件 Cemsol 的数据管理与国产化适配实践》
android·java·开发语言·人工智能
Kapaseker2 小时前
小白都看得懂的 Skill 教程 - 创建第一个 Skill
android·kotlin·vibecoding
zhangphil2 小时前
Android BitmapFactory实现AOSP ContentResolver.loadThumbnail快速取小缩略图,Kotlin
android·kotlin
weixin_440784112 小时前
【OkHttp实现原理】
android·java·okhttp
恋猫de小郭2 小时前
Jetpack Compose 8 月版正式发布,核心模块 1.12
android·前端·flutter