frameworks/base/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -163,6 +163,7 @@ import android.os.IDeviceIdleController;
import android.os.IInterface;
import android.os.Looper;
import android.os.Message;
+import android.os.PowerManager;
import android.os.Process;
import android.os.RemoteException;
import android.os.ResultReceiver;
@@ -370,6 +371,8 @@ public class NotificationManagerService extends SystemService {
private UriGrantsManagerInternal mUgmInternal;
private RoleObserver mRoleObserver;
private UserManager mUm;
+ private PowerManager mPowerManager;
+ private PowerManager.WakeLock mWakeLock;
final IBinder mForegroundToken = new Binder();
private WorkerHandler mHandler;
@@ -4843,9 +4846,34 @@ public class NotificationManagerService extends SystemService {
}
}
+ wakeUpScreen(pkg, r);
mHandler.post(new EnqueueNotificationRunnable(userId, r));
}
+ private void wakeUpScreen(final String pkg, final NotificationRecord r) {
+ if ("com.android.bluetooth".equals(pkg)) {
+ Context context = getContext();
+ if (mPowerManager == null) {
+ mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
+ }
+ boolean isScreenOn = mPowerManager.isScreenOn();
+ boolean isDozeEnable = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.DOZE_ENABLED, 1) == 1;
+ android.util.Log.i(TAG, "wakeUpScreen isScreenOn:" + isScreenOn + " isDozeEnable:" + isDozeEnable);
+ if (!isScreenOn && isDozeEnable) {
+ if (mWakeLock == null) {
+ mWakeLock = mPowerManager.newWakeLock((PowerManager.ACQUIRE_CAUSES_WAKEUP
+ | PowerManager.SCREEN_BRIGHT_WAKE_LOCK), "Notification");
+ mWakeLock.setReferenceCounted(false);
+ }
+ final StatusBarNotification sn = r.sbn;
+ NotificationRecord old = mNotificationsByKey.get(sn.getKey());
+ if (old == null) {
+ mWakeLock.acquire(3 * 1000);
+ }
+ }
+ }
+ }
+
@VisibleForTesting
protected void fixNotification(Notification notification, String pkg, int userId)
throws NameNotFoundException {
Android 10 系统源码 锁屏状态下,设备接收蓝牙传送消息,屏幕未亮屏
最新推荐文章于 2024-08-12 00:15:00 发布
这个博客主要讨论了Android系统中`NotificationManagerService`如何与`PowerManager`进行交互来唤醒屏幕。当特定包名如`com.android.bluetooth`的通知到来时,服务会检查屏幕状态和Doze模式,并在必要时使用`WakeLock`保持屏幕亮起3秒,确保用户能看到通知。

533

被折叠的 条评论
为什么被折叠?



