# 如何在OpenHarmony 4.1R上设置系统默认不锁屏 **Repository Path**: xjluo/applications_screenlock-OpenHarmony-v4.1-Release ## Basic Information - **Project Name**: 如何在OpenHarmony 4.1R上设置系统默认不锁屏 - **Description**: 在OpenHarmony 4.1R上设置系统默认不锁屏(修改系统锁屏应用) - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2025-01-02 - **Last Updated**: 2025-01-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 如何在OpenHarmony 4.1R上设置系统默认不锁屏 本文介绍如何修改系统锁屏应用,从而实现在OpenHarmony 4.1R上设置系统默认不锁屏。 ## 环境配置 1.DevEco Studio 4.1 Release,[下载链接地址](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_package_901_9/ee/v3/HqJ-6O2FQny86xtk_dg9HQ/devecostudio-windows-4.1.0.400.zip?HW-CC-KV=V1&HW-CC-Date=20240409T033730Z&HW-CC-Expire=315360000&HW-CC-Sign=BFA444BC43A041331E695AE2CFA9035A957AF107E06C97E793FD3D31D7096A0D) 2. API10 Full SDK,[安装教程](https://ost.51cto.com/posts/26752) ## 步骤 1.首先下载4.1r分支的系统锁屏应用[applications_screenlock](https://gitee.com/openharmony/applications_screenlock/tree/OpenHarmony-v4.1-Release/) 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](https://gitee.com/openharmony/developtools_hapsigner/tree/OpenHarmony-v4.1-Release)仓库,进入 dist 目录,点击下载[OpenHarmony.p12](https://gitee.com/openharmony/developtools_hapsigner/blob/OpenHarmony-v4.1-Release/dist/OpenHarmony.p12)和[OpenHarmonyApplication.pem](https://gitee.com/openharmony/developtools_hapsigner/blob/OpenHarmony-v4.1-Release/dist/OpenHarmonyApplication.pem)(pem文件若无法直接下载,可直接在目录中创建文件然后将内容拷贝到文件中)。 ![image.png](https://dl-harmonyos.51cto.com/images/202408/d240c4c819e1b1d1e62957674563b248015f06.png?x-oss-process=image/resize,w_820,h_552) - 把下载好的文件放入工程目录的 signature 中。 ![image.png](https://dl-harmonyos.51cto.com/images/202408/63a7dca6519b5b686d0442c3721be8815829ad.png?x-oss-process=image/resize,w_681,h_198) - 签名文件配置: DevEco Studio 4.0 Release 版本界面化配置签名时,秘钥不允许配置8位以下纯数字秘钥,而标准签名文件的秘钥为123456 ,所以无法通过DevEco Studio 界面进行签名的配置。仅能使用手动配置build-profile.json5 文件方式,进行签名信息的配置。下载[material](https://ost.51cto.com/resource/2546?login=from_csdn)包解压后放入signature 目录中,material 文件夹中存放的为加密盐文件,此包将给予签名工具验证秘钥时使用。 ![image.png](https://dl-harmonyos.51cto.com/images/202408/579ee0027b054eafa6f3588d4f06f38c6b30b2.png?x-oss-process=image/resize,w_616,h_280) - 配置工程根路径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" } }], ``` ![image.png](https://dl-harmonyos.51cto.com/images/202408/b8a382033192dad655d078337d9ed496bc4e2d.png?x-oss-process=image/resize,w_820,h_834) - 构建安装验证 单击 Build >Build Hap(s)/APP(s) > Build APP(s) 构建 SystemUI 工程HAP包。 ![image.png](https://dl-harmonyos.51cto.com/images/202408/e8b2c29060db9a2aa7d591bd9ad4cdd9adb422.png?x-oss-process=image/resize,w_553,h_250) 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 ``` ![image.png](https://dl-harmonyos.51cto.com/images/202408/d4dd6d19355f2a6dfdc7133bd1fbfa7f8744f1.png?x-oss-process=image/resize,w_820,h_169) ## 实现效果 [实现效果.mp4](https://gitee.com/from-north-to-north/applications_screenlock-OpenHarmony-v4.1-Release/blob/master/%E5%AE%9E%E7%8E%B0%E6%95%88%E6%9E%9C.mp4) [ 修改好的不锁屏的系统锁屏应用](https://gitee.com/from-north-to-north/applications_screenlock-OpenHarmony-v4.1-Release/blob/master/applications_screenlock-OpenHarmony-v4.1-Release.zip) [编译好的不锁屏的hap包](https://gitee.com/from-north-to-north/applications_screenlock-OpenHarmony-v4.1-Release/blob/master/phone-entry-default-signed.hap) 设置屏幕不息屏 ``` hdc shell power-shell setmode 602 ``` 参考链接:https://laval.csdn.net/657aaa786901917cd68b1f45.html