1 Commits
v1.0 ... v1.1

6 changed files with 221 additions and 38 deletions

View File

@@ -1,8 +1,22 @@
# 变更记录 # 变更记录
## 2026-11-29 · 锁屏权限引导:设置页新增锁屏显示权限入口一键跳应用启动管理,版本 1.0 ## 2026-11-29 · 锁屏倒计时改灭屏投递拉起不再出横幅;沉浸式遮状态栏;横屏专属排版;版本 1.1
- 同步源码更新 3 个文件(新增/修改 3,删除 0)。 - 同步源码更新 5 个文件(新增/修改 5,删除 0)。
## 2026-11-29 · 锁屏倒计时改灭屏投递拉起(不再出通知横幅);沉浸式遮状态栏;横屏专属排版(v1.1)
- 拉起流程重构:实测鸿蒙 4.0 即使开了"后台弹出界面"等全部权限,亮屏后服务 startActivity 仍被静默拦截,而全屏意图亮屏后投递只出横幅。改为**灭屏瞬间投递**全屏意图(鸿蒙只在"锁屏+灭屏"投递时才直接拉页):LockScreenActivity 悄悄盖在锁屏底下、屏幕保持熄灭(去掉 turnScreenOn 防止自动亮屏耗电),用户按电源键亮屏直接看到倒计时,全程无横幅
- TimerService:SCREEN_OFF → 灭屏投递;SCREEN_ON → 只补结算 + 清抽屉触发通知;页面未拉起时保留"服务直启 + 横幅通知"双兜底;计时停止时自动清触发通知
- LockScreenActivity:沉浸式全屏(IMMERSIVE_STICKY + LAYOUT_NO_LIMITS),顶部时间/信号/电池彻底遮掉;onWindowFocusChanged 重套沉浸式;监听 USER_PRESENT 解锁即退出;新增 showing 静态标记供服务判断页面是否已在锁屏上
- 横屏专属排版:新增 layout-land/activity_lock_screen.xml 左右分栏——左侧大号倒计时(120sp)+ 任务名,细竖线分隔,右侧信息栏纵向排日期/时钟/状态;清单去掉 configChanges 使旋转时重建切换布局,launchMode=singleTask 防重复实例
- 版本 1.0 → 1.1(versionCode 35)
## 2026-11-29 · 华为锁屏权限引导:设置页新增「锁屏显示权限」入口,一键跳应用启动管理(v1.0)
- 根因:鸿蒙/EMUI 默认拦截"后台弹出界面",前台服务直接 startActivity 被**静默**拦截(runCatching 不报错),只剩全屏意图通知——亮屏后投递只显示横幅,这就是"还是弹出通知"的真正原因。该权限无公开 API 可查询/授予,只能引导手动开启
- 设置页「提醒」区「锁屏全屏倒计时」开关下方新增「锁屏显示权限 · 去开启」入口:弹窗说明开启路径,点「去设置」直达华为手机管家应用启动管理页,失败退回系统应用详情页
- 新增 util/HuaweiPerms.kt;版本号规则调整为十进制进位:0.9 → 1.0,本次 0.17 → 1.0(versionCode 34)
## 2026-11-29 · 华为锁屏权限引导:设置页新增「锁屏显示权限」入口,一键跳应用启动管理(v1.0) ## 2026-11-29 · 华为锁屏权限引导:设置页新增「锁屏显示权限」入口,一键跳应用启动管理(v1.0)

View File

@@ -44,13 +44,12 @@
<activity <activity
android:name=".ui.lockscreen.LockScreenActivity" android:name=".ui.lockscreen.LockScreenActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:excludeFromRecents="true" android:excludeFromRecents="true"
android:exported="false" android:exported="false"
android:launchMode="singleTask"
android:showWhenLocked="true" android:showWhenLocked="true"
android:taskAffinity="" android:taskAffinity=""
android:theme="@style/LockScreenTheme" android:theme="@style/LockScreenTheme" />
android:turnScreenOn="true" />
<service <service
android:name=".service.TimerService" android:name=".service.TimerService"

View File

@@ -11,6 +11,7 @@ import android.os.IBinder
import android.os.Looper import android.os.Looper
import android.os.PowerManager import android.os.PowerManager
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import com.focusbox.app.ui.lockscreen.LockScreenActivity
import com.focusbox.app.util.Prefs import com.focusbox.app.util.Prefs
/** /**
@@ -75,37 +76,55 @@ class TimerService : Service() {
private val screenReceiver = object : BroadcastReceiver() { private val screenReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
when (intent.action) { when (intent.action) {
Intent.ACTION_SCREEN_ON -> showLockPeek() Intent.ACTION_SCREEN_ON -> onScreenOn()
Intent.ACTION_SCREEN_OFF -> Notif.cancelFullscreen(context) Intent.ACTION_SCREEN_OFF -> onScreenOff()
} }
} }
} }
private fun showLockPeek() { /**
// 先补结算:EMUI 冻结进程后到点闹钟可能被推迟,用户按电源键亮屏 * 灭屏瞬间投递全屏意图通知——这是鸿蒙唯一会直接拉起 LockScreenActivity 的窗口。
// 这一瞬进程已解冻,正好把过期的倒计时立刻结算掉, * 鸿蒙 4.0 的规则:全屏意图只在「锁屏 + 灭屏」时投递才直接把页面盖在锁屏上;
// 通知/锁屏卡片就不会再滚负数 * 亮屏后投递永远只出横幅;服务直接 startActivity 则被"后台弹出界面"策略静默拦截
TimerCore.tick() * (实测开了权限也一样)。所以改成灭屏时就投递:页面(turnScreenOn=false)
if (!Prefs.lockFullscreen) return * 悄悄盖在锁屏底下、屏幕保持熄灭,用户按电源键亮屏就直接看到倒计时,
* 不会再出现任何通知横幅。
*/
private fun onScreenOff() {
if (!Prefs.lockFullscreen || !TimerCore.running) return
TimerCore.tick() // 灭屏一瞬先补结算,避免到点边界上拉出 00:00 的空页面
if (!TimerCore.running) return if (!TimerCore.running) return
val km = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager val km = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
// 只有真在锁屏界面才拉全屏页;用户正在用手机时不打扰 if (!km.isKeyguardLocked()) return
if (!km.inKeyguardRestrictedInputMode()) return
// 鸿蒙上全屏意图只在"锁屏且灭屏时投递"才会直接拉起 Activity,
// 亮屏后投递只会出横幅通知——所以直接从服务启动页面(鸿蒙允许
// 前台服务拉起自己的 Activity),全屏意图通知保留作兜底
runCatching {
startActivity(
Intent(this, com.focusbox.app.ui.lockscreen.LockScreenActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
)
}
Notif.updateFullscreen(this) Notif.updateFullscreen(this)
} }
/** 亮屏:先补结算(冻结进程的到点闹钟被推迟时,靠这一下止损,不再滚负数) */
private fun onScreenOn() {
TimerCore.tick()
if (LockScreenActivity.showing) {
// 页面已经盖在锁屏上(灭屏投递拉起的),抽屉里的触发通知清掉
Notif.cancelFullscreen(this)
} else if (Prefs.lockFullscreen && TimerCore.running) {
val km = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
if (km.isKeyguardLocked()) {
// 灭屏投递没拉起来(个别 ROM 拦全屏意图)的兜底:
// 先试服务直启,再留一条全屏意图通知让用户点进同一页面
runCatching {
startActivity(
Intent(this, LockScreenActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
)
}
Notif.updateFullscreen(this)
}
}
}
private val onStateChanged: () -> Unit = { private val onStateChanged: () -> Unit = {
Notif.updateOngoing(this) Notif.updateOngoing(this)
// 暂停/结束时同步停掉 1 秒轮询,别让 Handler 空转 // 计时结束/暂停时清掉锁屏触发通知,抽屉里不留垃圾
if (!TimerCore.running) Notif.cancelFullscreen(this)
syncTicker() syncTicker()
syncWakeLock() syncWakeLock()
} }

View File

@@ -1,16 +1,22 @@
package com.focusbox.app.ui.lockscreen package com.focusbox.app.ui.lockscreen
import android.app.KeyguardManager import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import android.text.format.DateFormat import android.text.format.DateFormat
import android.view.View
import android.view.WindowManager import android.view.WindowManager
import android.widget.TextView import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.focusbox.app.R import com.focusbox.app.R
import com.focusbox.app.data.Store import com.focusbox.app.data.Store
import com.focusbox.app.service.Notif
import com.focusbox.app.service.TimerCore import com.focusbox.app.service.TimerCore
import com.focusbox.app.util.Dates import com.focusbox.app.util.Dates
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
@@ -20,15 +26,26 @@ import java.util.Locale
/** /**
* 锁屏全屏倒计时页。 * 锁屏全屏倒计时页。
* *
* 触发链路:计时中按电源键亮屏 → TimerService 收到 SCREEN_ON → * 触发链路:计时中用户锁屏(灭屏)→ TimerService 灭屏瞬间发全屏意图通知 →
* 检查处于锁屏后发一条全屏意图通知 → 系统把本页直接盖在锁屏上展示。 * 鸿蒙直接把本页盖在锁屏上(屏幕保持熄灭,本页不设 turnScreenOn)→
* 用户按电源键亮屏即见倒计时,全程不出通知横幅。
* *
* 交互极简:黑底上只有日期、时钟、大号倒计时和任务名, * 交互极简:黑底上只有日期、时钟、大号倒计时和任务名,
* 点按任意处退出;倒计时本身在前台服务里走,退出/熄屏都不受影响, * 点按任意处退出、解锁时自动退出;倒计时本身在前台服务里走,
* 计时结束后本页在下一次刷新时自动关闭。 * 退出/熄屏都不受影响,计时结束后本页在下一次刷新时自动关闭。
*
* 沉浸式:STATUS_BAR_HIDDEN + LAYOUT_NO_LIMITS 把顶部的时间/信号/电池
* 一起遮掉,整块屏幕只有页面内容。
*/ */
class LockScreenActivity : AppCompatActivity() { class LockScreenActivity : AppCompatActivity() {
companion object {
/** 服务用来判断页面是否已盖在锁屏上(避免重复拉起/多报通知) */
@Volatile
var showing: Boolean = false
private set
}
private val handler = Handler(Looper.getMainLooper()) private val handler = Handler(Looper.getMainLooper())
private lateinit var tvDate: TextView private lateinit var tvDate: TextView
@@ -46,18 +63,23 @@ class LockScreenActivity : AppCompatActivity() {
} }
} }
/** 用户解锁(输密码/指纹进系统)后页面没有存在意义,立即退出 */
private val unlockReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action == Intent.ACTION_USER_PRESENT) finish()
}
}
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
// 盖在锁屏上显示(API 27+ 用官方方法,清单里的 showWhenLocked/turnScreenOn 双保险) // 盖在锁屏上显示(API 27+ 用官方方法,清单里的 showWhenLocked 双保险)。
// 注意不能开 turnScreenOn:灭屏投递拉起本页时屏幕要保持熄灭,
// 等用户按电源键才亮,否则每次锁屏都会自动亮屏耗电
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
setShowWhenLocked(true) setShowWhenLocked(true)
setTurnScreenOn(true)
} else { } else {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
window.addFlags( window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED)
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
or WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
)
} }
setContentView(R.layout.activity_lock_screen) setContentView(R.layout.activity_lock_screen)
@@ -67,19 +89,60 @@ class LockScreenActivity : AppCompatActivity() {
tvMode = findViewById(R.id.tvLockMode) tvMode = findViewById(R.id.tvLockMode)
tvTask = findViewById(R.id.tvLockTask) tvTask = findViewById(R.id.tvLockTask)
findViewById<android.view.View>(R.id.lockRoot).setOnClickListener { finish() } findViewById<View>(R.id.lockRoot).setOnClickListener { finish() }
ContextCompat.registerReceiver(
this,
unlockReceiver,
IntentFilter(Intent.ACTION_USER_PRESENT),
ContextCompat.RECEIVER_NOT_EXPORTED,
)
} }
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
showing = true
// 页面已经实际盖到锁屏上了,抽屉里那条触发通知清掉
Notif.cancelFullscreen(this)
applyImmersive()
handler.post(tick) handler.post(tick)
} }
override fun onStop() { override fun onStop() {
showing = false
handler.removeCallbacks(tick) handler.removeCallbacks(tick)
super.onStop() super.onStop()
} }
override fun onDestroy() {
runCatching { unregisterReceiver(unlockReceiver) }
super.onDestroy()
}
/** 沉浸式全屏:状态栏/导航栏全隐藏,且布局延伸到状态栏底下(时间信号电池彻底不见) */
private fun applyImmersive() {
@Suppress("DEPRECATION")
window.setFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
)
@Suppress("DEPRECATION")
window.decorView.systemUiVisibility = (
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_FULLSCREEN
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
)
}
/** 从别的窗口/通知横幅抢回焦点后,沉浸式标记会被系统清掉,重新套一遍 */
override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
if (hasFocus) applyImmersive()
}
private fun render() { private fun render() {
val now = TimerCore.displayNow() val now = TimerCore.displayNow()
// 计时已结束且没有剩余读数:页面使命完成,自动关闭 // 计时已结束且没有剩余读数:页面使命完成,自动关闭

View File

@@ -431,6 +431,6 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
} }
companion object { companion object {
const val VERSION = "1.0" const val VERSION = "1.1"
} }
} }

View File

@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
锁屏全屏倒计时·横屏专属排版(区别于竖屏的纯纵向堆叠):
左右分栏 —— 左侧主角是大号倒计时 + 任务名,细竖线分隔,
右侧信息栏纵向排日期/时钟/状态,重心靠左、信息靠右。
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lockRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:clickable="true"
android:focusable="true"
android:gravity="center_vertical"
android:orientation="horizontal">
<!-- 左:倒计时 + 任务名(主角区) -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.2"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/tvLockCountdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:textColor="#FFFFFF"
android:textSize="120sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tvLockTask"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:ellipsize="end"
android:maxWidth="360dp"
android:maxLines="1"
android:textColor="#CCFFFFFF"
android:textSize="17sp" />
</LinearLayout>
<!-- 中:细分隔线 -->
<View
android:layout_width="1dp"
android:layout_height="180dp"
android:background="#26FFFFFF" />
<!-- 右:信息栏(日期 / 时钟 / 状态) -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/tvLockDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:letterSpacing="0.08"
android:textColor="#99FFFFFF"
android:textSize="15sp" />
<TextView
android:id="@+id/tvLockClock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:includeFontPadding="false"
android:textColor="#CCFFFFFF"
android:textSize="64sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tvLockMode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:letterSpacing="0.2"
android:textColor="#66FFFFFF"
android:textSize="13sp" />
</LinearLayout>
</LinearLayout>