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-03-21 11:48:58 发布