平台 MTK
android版本 8.1
谷歌在android 6.0之后有一个主动显示的功能,如果设备支持这个功能的话,直接设置这个功能默认打开就可以了,因为正常唤醒屏幕的操作是会影响手机功耗的.
对应的Setting属性
(./base/core/java/android/provider/Settings.java)
在定制的时候默认打开就可以,这种显示,手机在收到短信(或其他)通知后,不会完全亮屏,谷歌自家的手机就是默认打开该功能,设置项在"setting>display>Ambient dispaly"
/**
* Whether the device should doze if configured.
* @hide
*/
public static final String DOZE_ENABLED = "doze_enabled";
/**
* Whether doze should be always on.
* @hide
*/
public static final String DOZE_ALWAYS_ON = "doze_always_on";
/**
* Whether the device should pulse on pick up gesture.
* @hide
*/
public static final String DOZE_PULSE_ON_PICK_UP = "doze_pulse_on_pick_up";
有的项目不支持主动显示功能,如果还需要心亮屏,就只能完全唤醒,当显示通知的时候,亮屏到锁屏界面
参照MTK online上的修改,不过由于是7.0,代码有点差异,我们需要修改一下。
[FAQ20202] 当手机灭屏时,定制来短信或者微信亮屏时间
内容 (2017-07-25)
[DESCRIPTION]
手机灭屏之后,来短信或者信息亮屏7s之后再黑屏。
[SOLUTION]
Android N上验证:
这个修改为客制化的需求,可以在BaseStatusBar.java定义一个wakelock,并初始化:
import android.os.PowerManager;
private PowerManager.WakeLock mNotificationWakeLock;
mNotificationWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, TAG);
mNotificationWakeLock.setReferenceCounted(false);
方案一:
在addNotificationViews和updateNotificationViews里面添加如下亮屏请求。当来了一条新通知或者更新一条通知的时候都会走到这两个逻辑:
//added MTK
if (!mPowerManager.isScreenOn() && entry.key != null && entry.key.contains(“com.android.mms”)){//可以根据需要亮屏的应用,增加不同的包名判断。
mNotificationWakeLock.acquire(5000);
Log.d(TAG, “special app notification turn screen on”);
}
//added end
android 8.1 修改一下
+ private PowerManager.WakeLock mNotificationWakeLock;
+ private void screenWakeUp(Entry entry) {
+ if(mNotificationWakeLock == null){
+ mNotificationWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, TAG);
+ mNotificationWakeLock.setReferenceCounted(false);
+ }
+ if (!mPowerManager.isScreenOn() && entry.key != null && entry.key.contains("com.google.android.apps.messaging")) {
+ mNotificationWakeLock.acquire(5000);
+ Log.d(TAG, "special app notification turn screen on");
+ }
+ }
+
protected void addNotificationViews(Entry entry) {
if (entry == null) {
return;
}
// Add the expanded view and icon.
mNotificationData.add(entry);
+ screenWakeUp(entry);
updateNotifications();
}
protected void updateRowStates() {
final int N = mStackScroller.getChildCount();
int visibleNotifications = 0;
boolean onKeyguard = mState == StatusBarState.KEYGUARD;
int maxNotifications = -1;
if (onKeyguard) {
maxNotifications = getMaxKeyguardNotifications(true /* recompute */);
}
mStackScroller.setMaxDisplayedNotifications(maxNotifications);
Stack stack = new Stack<>();
for (int i = N - 1; i >= 0; i--) {
@@ -7605,36 +7619,37 @@ public class StatusBar extends SystemUI implements DemoMode,
Notification n = notification.getNotification();
mNotificationData.updateRanking(ranking);
final StatusBarNotification oldNotification = entry.notification;
entry.notification = notification;
mGroupManager.onEntryUpdated(entry, oldNotification);
entry.updateIcons(mContext, notification);
inflateViews(entry, mStackScroller);
mForegroundServiceController.updateNotification(notification,
mNotificationData.getImportance(key));
boolean shouldPeek = shouldPeek(entry, notification);
boolean alertAgain = alertAgain(entry, n);
updateHeadsUp(key, entry, shouldPeek, alertAgain);
+ screenWakeUp(entry);
updateNotifications();
if (!notification.isClearable()) {
// The user may have performed a dismiss action on the notification, since it's
// not clearable we should snap it back.
mStackScroller.snapViewIfNeeded(entry.row);
}
if (DEBUG) {
// Is this for you?
boolean isForCurrentUser = isNotificationForCurrentProfiles(notification);
Log.d(TAG, "notification is " + (isForCurrentUser ? "" : "not ") + "for you");
}
setAreThereNotifications();
}