如何在OpenHarmony 4.1R上设置系统默认不锁屏(修改系统锁屏应用)
本文介绍如何修改系统锁屏应用,从而实现在OpenHarmony 4.1R上设置系统默认不锁屏。 环境配置 1.DevEco Studio 4.1 Release,下载链接地址 API10 Full SDK,安装教程 步骤 1.首先下载4.1r分支的系统锁屏应用applications_screenlock 2.修改系统锁屏应用代码,applications
本文介绍如何修改系统锁屏应用,从而实现在OpenHarmony 4.1R上设置系统默认不锁屏。
环境配置
1.DevEco Studio 4.1 Release,下载链接地址
- API10 Full SDK,安装教程
步骤
1.首先下载4.1r分支的系统锁屏应用applications_screenlock
2.修改系统锁屏应用代码,applications_screenlock-OpenHarmony-v4.1-Release\features\screenlock\src\main\ets\com\ohos\model\screenLockService.ts文件中
将monitorEvents方法修改为
monitorEvents() {
Log.showDebug(TAG, 'registered events start');
this.screenLockModel.eventListener((typeName: String) => {
switch (typeName) {
// System ready on device boot
case EVENT_SYSTEM_READY:
Log.showInfo(TAG, `EVENT_SYSTEM_READY event`);
this.lockScreen();
break;
//Bright screen
case EVENT_END_SCREEN_ON:
Log.showInfo(TAG, `EVENT_END_SCREEN_ON event`);
this.authUserByFace()
AppStorage.SetOrCreate('deviceStatus', EVENT_END_SCREEN_ON);
break;
//The device is going to sleep
case EVENT_BEGIN_SLEEP:
Trace.start(Trace.CORE_METHOD_SLEEP_TO_LOCK_SCREEN);
Log.showInfo(TAG, `EVENT_BEGIN_SLEEP event`);
this.unlockScreen();//修改
this.accountModel.updateAllUsers()
AppStorage.SetOrCreate('deviceStatus', EVENT_END_SCREEN_ON);//修改
break;
//unlock request was received
case EVENT_UNLOCK_SCREEN:
Log.showInfo(TAG, `EVENT_UNLOCK_SCREEN event`);
this.unlockScreen();
break;
//lock request was received
case EVENT_LOCK_SCREEN:
Log.showInfo(TAG, `EVENT_LOCK_SCREEN event`);
this.unlockScreen();//修改
break;
case SERVICE_RESTART:
setTimeout(() => {
this.monitorEvents();
this.unlockScreen();//修改
}, 2000);
break;
default:
Log.showError(TAG, `eventListener:typeName ${typeName}`)
}
})
将lockScreen方法修改为
lockScreen() {
Trace.start(Trace.CORE_METHOD_SHOW_LOCK_SCREEN);
Log.showDebug(TAG, `lockScreen`);
let length = parseInt(Router.getLength())
Log.showDebug(TAG, `Router.getLength: ${length}`)
for (let index = 1; index < length; index++) {
Log.showInfo(TAG, `back to index`);
Router.back();
}
//lock the screen
this.screenLockModel.showScreenLockWindow(() => {
Log.showInfo(TAG, `showScreenLockWindow finish`);
this.checkPinAuthProperty(() => {
});
Log.showInfo(TAG, `screenlock status:${this.currentLockStatus}, userId : ${this.accountModel.getCurrentUserId()}`);
if (this.currentLockStatus == ScreenLockStatus.Locking) {
Log.showInfo(TAG, `had locked, no need to publish lock_screen`);
} else {
this.notifyLockScreenResult(LockResult.Success)
systemParameter.set('bootevent.lockscreen.ready','true')
this.currentLockStatus = ScreenLockStatus.Locking;
this.unlocking();//修改
}
});
}
3.使用DevEco Studio 4.1 Release和 API10 Full SDK对系统应用进行签名,默认工程是未配置签名的状态,所构建的包均为 unsigned 标记的HAP包,无法安装到 OpenHarmony 系统中。
打开developtools_hapsigner仓库,进入 dist 目录,点击下载OpenHarmony.p12和OpenHarmonyApplication.pem(pem文件若无法直接下载,可直接在目录中创建文件然后将内容拷贝到文件中)。
把下载好的文件放入工程目录的 signature 中。
签名文件配置:
DevEco Studio 4.0 Release 版本界面化配置签名时,秘钥不允许配置8位以下纯数字秘钥,而标准签名文件的秘钥为123456 ,所以无法通过DevEco Studio 界面进行签名的配置。仅能使用手动配置build-profile.json5 文件方式,进行签名信息的配置。下载material包解压后放入signature 目录中,material 文件夹中存放的为加密盐文件,此包将给予签名工具验证秘钥时使用。
- 配置工程根路径build-profile.json5 文件,拷贝以下签名信息到配置文件中,其中storePassword 和keyPassword 为material 包与秘钥加密生成的数据,keyAlias 为固定值"OpenHarmony Application Release"。
"signingConfigs": [{ "name": "release", "material": { "storePassword": "00000016D9DCF063F0FC4BBD0E7FE1E3B06A67C07BECE1BDD4E2A3EFDAE20F890810EC02AA2A", "certpath": "signature/OpenHarmonyApplication.pem", "keyAlias": "OpenHarmony Application Release", "keyPassword": "00000016FD3897FD4C46940ED39FFC652872B7B18BEDCCA07400A6EBEE307C9C41B96DB6B64D", "profile": "signature/systemui.p7b", "signAlg": "SHA256withECDSA", "storeFile": "signature/OpenHarmony.p12" } }],
- 构建安装验证
单击 Build >Build Hap(s)/APP(s) > Build APP(s) 构建 SystemUI 工程HAP包。
4.安装编译好的锁屏应用
编译好的应用在product\phone\build\default\outputs\default\phone-entry-default-signed.hap
将应用包推送到开发板
hdc file send "\你的路径\applications_screenlock-OpenHarmony-v4.1-Release\product\phone\build\default\outputs\default\phone-entry-default-signed.hap" /data
安装hap
hdc shell bm install -p /data/phone-entry-default-signed.hap -u 0
实现效果
设置屏幕不息屏
1.临时性
hdc shell power-shell setmode 602
2.修改power_mode_config.xml(永久性),将id为102的value改为-1
更多推荐
所有评论(0)