@@ -8,87 +8,62 @@ import android.util.Log
88import com.openlist.mobile.config.AppConfig
99
1010/* *
11- * 开机启动接收器 - 处理开机启动和包更新事件
11+ * Boot receiver - handles device boot and package update events
1212 */
1313class BootReceiver : BroadcastReceiver () {
1414 companion object {
1515 private const val TAG = " BootReceiver"
1616 }
1717
18- override fun onReceive (context : Context , intent : Intent ) {
19- val action = intent.action
20- Log .d(TAG , " Received broadcast: $action " )
18+ override fun onReceive (context : Context ? , intent : Intent ? ) {
19+ if (context == null || intent?.action == null ) return
20+
21+ Log .d(TAG , " Received broadcast: ${intent.action} " )
2122
22- try {
23- when (action) {
24- Intent .ACTION_BOOT_COMPLETED ,
25- " android.intent.action.QUICKBOOT_POWERON" ,
26- " com.htc.intent.action.QUICKBOOT_POWERON" -> {
27- Log .d(TAG , " Boot completed" )
28- handleBootCompleted(context)
29- }
30-
31- Intent .ACTION_MY_PACKAGE_REPLACED ,
32- Intent .ACTION_PACKAGE_REPLACED -> {
33- Log .d(TAG , " Package replaced" )
34- handlePackageReplaced(context, intent)
35- }
36-
37- else -> {
38- Log .d(TAG , " Unknown action: $action " )
39- }
23+ when (intent.action) {
24+ Intent .ACTION_BOOT_COMPLETED -> {
25+ handleBootCompleted(context)
26+ }
27+ Intent .ACTION_MY_PACKAGE_REPLACED -> {
28+ handlePackageReplaced(context)
4029 }
41- } catch (e: Exception ) {
42- Log .e(TAG , " Error handling boot broadcast" , e)
4330 }
4431 }
4532
46- /* *
47- * 处理开机完成事件
48- */
4933 private fun handleBootCompleted (context : Context ) {
5034 if (! AppConfig .isStartAtBootEnabled) {
51- Log .d(TAG , " Auto start is disabled" )
35+ Log .d(TAG , " Auto- start disabled, skipping " )
5236 return
5337 }
5438
55- // 开机时清除手动停止标志,因为设备重启了
39+ // Clear manual stop flag on boot
5640 AppConfig .isManuallyStoppedByUser = false
57- Log .d(TAG , " Manual stop flag cleared on boot" )
58-
59- Log .d(TAG , " Starting services after boot" )
60- startServices(context)
41+
42+ Log .d(TAG , " Starting OpenList service" )
43+ startService(context)
6144 }
6245
63- /* *
64- * 处理包更新事件
65- */
66- private fun handlePackageReplaced (context : Context , intent : Intent ) {
67- val packageName = intent.dataString
68- if (packageName?.contains(context.packageName) == true ) {
69- Log .d(TAG , " Our package was replaced, restarting services" )
70- if (AppConfig .isStartAtBootEnabled) {
71- startServices(context)
72- }
46+ private fun handlePackageReplaced (context : Context ) {
47+ if (! AppConfig .isStartAtBootEnabled) {
48+ Log .d(TAG , " Auto-start disabled, skipping package update restart" )
49+ return
7350 }
51+
52+ Log .d(TAG , " Starting OpenList service after package update" )
53+ startService(context)
7454 }
7555
76- /* *
77- * 启动所有必要的服务
78- */
79- private fun startServices (context : Context ) {
56+ private fun startService (context : Context ) {
8057 try {
81- // 启动主服务
82- val mainServiceIntent = Intent (context, OpenListService ::class .java)
58+ val serviceIntent = Intent (context, OpenListService ::class .java)
8359 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
84- context.startForegroundService(mainServiceIntent )
60+ context.startForegroundService(serviceIntent )
8561 } else {
86- context.startService(mainServiceIntent )
62+ context.startService(serviceIntent )
8763 }
88- Log .d(TAG , " Main service start command sent" )
89-
64+ Log .d(TAG , " Service start command sent" )
9065 } catch (e: Exception ) {
91- Log .e(TAG , " Failed to start services " , e)
66+ Log .e(TAG , " Failed to start service " , e)
9267 }
9368 }
9469}
0 commit comments