Android 10 系统源码 锁屏状态下,设备接收蓝牙传送消息,屏幕未亮屏

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 {

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值