refactor(service): 将广播接收从静态注册改为动态注册
- 移除 AndroidManifest 中 ManagerService 的静态 intent-filter 声明 - 将 SCREEN_ON、SCREEN_OFF、USER_PRESENT 等广播改为代码中动态注册 - 在 onStartCommand 中添加 action 日志便于调试 - 启用 Gradle 并行同步以提升构建性能
This commit is contained in:
1 parent
513447ec7a
commit
d1fa9a8a08
3 files changed
+9
-13
No files matched your search
@@ -135,17 +135,9 @@
|
|||||||
android:name=".runtime.service.SocketService"
|
android:name=".runtime.service.SocketService"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
|
|
||||||
<service android:name=".runtime.service.ManagerService">
|
<service
|
||||||
<intent-filter android:priority="1000">
|
android:name=".runtime.service.ManagerService"
|
||||||
<action android:name="android.intent.action.USER_PRESENT" />
|
android:exported="false" />
|
||||||
<action android:name="android.intent.action.SCREEN_ON" />
|
|
||||||
<action android:name="android.intent.action.SCREEN_OFF" />
|
|
||||||
<action android:name="android.intent.action.DATE_CHANGED" />
|
|
||||||
<action android:name="android.intent.action.TIME_SET" />
|
|
||||||
<action android:name="android.intent.action.TIMEZONE_CHANGED" />
|
|
||||||
<action android:name="android.intent.action.TIME_TICK" />
|
|
||||||
</intent-filter>
|
|
||||||
</service>
|
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
android:name=".runtime.receiver.BootReceiver"
|
android:name=".runtime.receiver.BootReceiver"
|
||||||
|
|||||||
@@ -4,13 +4,11 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.PixelFormat;
|
import android.graphics.PixelFormat;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.DisplayMetrics;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -133,6 +131,7 @@ public class ManagerService extends BaseService implements NetworkUtils.OnNetwor
|
|||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
super.onStartCommand(intent, flags, startId);
|
super.onStartCommand(intent, flags, startId);
|
||||||
|
Log.e(TAG, "onStartCommand: " + intent.getAction());
|
||||||
startEvent.onNext(System.currentTimeMillis());
|
startEvent.onNext(System.currentTimeMillis());
|
||||||
return START_STICKY;
|
return START_STICKY;
|
||||||
}
|
}
|
||||||
@@ -405,6 +404,9 @@ public class ManagerService extends BaseService implements NetworkUtils.OnNetwor
|
|||||||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
||||||
filter.addAction(ACTION_LOCK);
|
filter.addAction(ACTION_LOCK);
|
||||||
filter.addAction(ACTION_UNLOCK);
|
filter.addAction(ACTION_UNLOCK);
|
||||||
|
filter.addAction(Intent.ACTION_SCREEN_OFF);
|
||||||
|
filter.addAction(Intent.ACTION_SCREEN_ON);
|
||||||
|
filter.addAction(Intent.ACTION_USER_PRESENT);
|
||||||
ReceiverCompat.registerReceiver(this, lockScreenReceiver, filter, ReceiverCompat.RECEIVER_NOT_EXPORTED);
|
ReceiverCompat.registerReceiver(this, lockScreenReceiver, filter, ReceiverCompat.RECEIVER_NOT_EXPORTED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,3 +18,5 @@ org.gradle.parallel=true
|
|||||||
org.gradle.caching=true
|
org.gradle.caching=true
|
||||||
android.useAndroidX=true
|
android.useAndroidX=true
|
||||||
MATRIX_VERSION=2.0.0
|
MATRIX_VERSION=2.0.0
|
||||||
|
# Enabled parallel sync for Gradle 9.4+
|
||||||
|
org.gradle.tooling.parallel=true
|
||||||
Reference in new issue
Block a user