SP91的待机功耗大到42mA(com.android.deskclock.ON_QUARTER_HOUR)

2024-02-06 17:40

本文主要是介绍SP91的待机功耗大到42mA(com.android.deskclock.ON_QUARTER_HOUR),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

CPU 休眠偶尔平均电流 42 mA

  • 现象如下
    这里写图片描述

  • 发生时刻:PC时间 11:06 ,PowerMonitor 1026~1032秒

  • MtkLog 时间点
11-28 11:05:45.118827   950  1112 E ActivityManager: Sending non-protected broadcast com.android.deskclock.ON_QUARTER_HOUR from system uid 1000 pkg com.android.deskclock
11-28 11:05:45.118827   950  1112 E ActivityManager: java.lang.Throwable
11-28 11:05:45.118827   950  1112 E ActivityManager:    at com.android.server.am.ActivityManagerService.checkBroadcastFromSystem(ActivityManagerService.java:19338)
11-28 11:05:45.118827   950  1112 E ActivityManager:    at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:19942)
11-28 11:05:45.118827   950  1112 E ActivityManager:    at com.android.server.am.ActivityManagerService.broadcastIntentInPackage(ActivityManagerService.java:20130)
11-28 11:05:45.118827   950  1112 E ActivityManager:    at com.android.server.am.PendingIntentRecord.sendInner(PendingIntentRecord.java:325)
11-28 11:05:45.118827   950  1112 E ActivityManager:    at com.android.server.am.PendingIntentRecord.sendWithResult(PendingIntentRecord.java:222)
11-28 11:05:45.118827   950  1112 E ActivityManager:    at com.android.server.am.ActivityManagerService.sendIntentSender(ActivityManagerService.java:8169)
11-28 11:05:45.118827   950  1112 E ActivityManager:    at android.app.PendingIntent.send(PendingIntent.java:836)
11-28 11:05:45.118827   950  1112 E ActivityManager:    at com.android.server.AlarmManagerService$DeliveryTracker.deliverLocked(AlarmManagerService.java:3565)
11-28 11:05:45.118827   950  1112 E ActivityManager:    at com.android.server.AlarmManagerService.deliverAlarmsLocked(AlarmManagerService.java:2938)
11-28 11:05:45.118827   950  1112 E ActivityManager:    at com.android.server.AlarmManagerService$AlarmThread.run(AlarmManagerService.java:3086)
11-28 11:05:45.129578   950   978 D AppOps  : startOperation: allowing code 40 uid 1000 package android
11-28 11:05:45.130176   950  1112 D AES     : onEndOfErrorDumpThread: system_server_wtf Process: system_server
11-28 11:05:45.130176   950  1112 D AES     : Subject: ActivityManager
11-28 11:05:45.130176   950  1112 D AES     : Build: LAVA/Z91/Z91:7.1.1/N6F26Q/1514365452:user/release-keys
11-28 11:05:45.130176   950  1112 D AES     : 
11-28 11:05:45.130176   950  1112 D AES     : android.util.Log$TerribleFailure: Sending non-protected broadcast com.android.deskclock.ON_QUARTER_HOUR from system uid 1000 pkg com.android.deskclock
11-28 11:05:45.130176   950  1112 D AES     :   at android.util.Log.wtf(Log.java:295)
11-28 11:05:45.130176   950  1112 D AES     :   at android.util.Log.wtf(Log.java:290)
11-28 11:05:45.130176   950  1112 D AES     :   at com.android.server.am.ActivityManagerService.checkBroadcastFromSystem(ActivityManagerService.java:19335)
11-28 11:05:45.130176   950  1112 D AES     :   at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:19942)
11-28 11:05:45.130176   950  1112 D AES     :   at com.android.server.am.ActivityManagerService.broadcastIntentInPackage(ActivityManagerService.java:20130)
11-28 11:05:45.130176   950  1112 D AES     :   at com.android.server.am.PendingIntentRecord.sendInner(PendingIntentRecord.java:325)
11-28 11:05:45.130176   950  1112 D AES     :   at com.android.server.am.PendingIntentRecord.sendWithResult(PendingIntentRecord.java:222)
11-28 11:05:45.130176   950  1112 D AES     :   at com.android.server.am.ActivityManagerService.sendIntentSender(ActivityManagerService.java:8169)
11-28 11:05:45.130176   950  1112 D AES     :   at android.app.PendingIntent.send(PendingIntent.java:836)
11-28 11:05:45.130176   950  1112 D AES     :   at com.android.server.AlarmManagerService$DeliveryTracker.deliverLocked(AlarmManagerService.java:3565)
11-28 11:05:45.130176   950  1112 D AES     :   at com.android.server.AlarmManagerService.deliverAlarmsLocked(AlarmManagerService.java:2938)
11-28 11:05:45.130176   950  1112 D AES     :   at com.android.server.AlarmManagerService$AlarmThread.run(AlarmManagerService.java:3086)
11-28 11:05:45.130176   950  1112 D AES     : Caused by: java.lang.Throwable
11-28 11:05:45.130176   950  1112 D AES     :   at com.android.server.am.ActivityManagerService.checkBroadcastFromSystem(ActivityManagerService.java:19338)
11-28 11:05:45.130176   950  1112 D AES     :   ... 9 more
11-28 11:05:45.130176   950  1112 D AES     :  950
11-28 11:05:45.130366   950  1112 W AES     : Exception Log handling...
11-28 11:05:45.130829   950  1169 D AppOps  : startOperation: allowing code 40 uid 1000 package android
11-28 11:05:45.137684  1223  1223 D KeyguardUpdateMonitor: received broadcast android.intent.action.TIME_TICK
11-28 11:05:45.138396  1223  1223 D KeyguardUpdateMonitor: handleTimeUpdate
11-28 11:05:45.272902  1223  1223 V Clock   : onReceive: Intent { act=android.intent.action.TIME_TICK flg=0x50000014 (has extras) }
11-28 11:05:45.293306   950  1472 D AES     : AEEIOCTL_GET/SET_SF_STATE IOCTL,cmd= 1074294797, lParam=0. 
11-28 11:05:45.294011   950  1472 D AES     : AEEIOCTL_RT_MON_Kick IOCTL,cmd= 2147774474, lParam=300. 
11-28 11:05:45.294107  1223  1223 V Clock   : onReceive: Intent { act=android.intent.action.TIME_TICK flg=0x50000014 (has extras) }

分析

首先查看系统唤醒
如果是 RTC 唤醒,要找上层的 alarm 也很简单,在 main log 或者 sys log 里面搜索下面的关键字即可
关键字 AlarmManager: sending alarm Alarm

查询结果如下:

11-28 11:05:45.134589   950  1112 V AlarmManager: sending alarm Alarm{b982fb4 type 1 when 1480302001000 com.android.deskclock} success具体细节:
4,381: 11-28 11:05:45.134589   950  1112 V AlarmManager: sending alarm Alarm{b982fb4 type 1 when 1480302001000 com.android.deskclock} success 
4,399: 11-28 11:05:45.389511   950  1783 V AlarmManager: APP set(PendingIntent{9e1ef52: PendingIntentRecord{78a1223 com.android.deskclock broadcastIntent}}) : type=1 triggerAtTime=1480302901000 win=0 tElapsed=4190256 maxElapsed=4190256 interval=0 flags=0x9 由于该AlarmManager.RTC 没有实际唤醒CPU,故kenalLog不显示
11-28 11:05:45.426971     0     0 I [ 1084.519376]-(1)[0:swapper/1]: [SPM] wake up by  R12_APXGPT1_EVENT_B, timer_out = 375, r13 = 0xe860200, debug_flag = 0x200110ff 0x0, r12 = 0x10, r12_ext = 0x100, raw_sta = 0x0, idle_sta = 0xfb, req_sta =  0x1800, event_reg = 0x90100000, isr = 0x0, raw_ext_sta = 0x4402a3aa, wake_misc = 0x0, pcm_flag = 0x180 0x0, req = 0x0

上述确定 com.android.deskclock 设置定时进行广播com.android.deskclock.ON_QUARTER_HOUR唤醒 type 1 表示AlarmManager.RTC

AlarmManager.RTC,硬件闹钟,不唤醒手机(也可能是其它设备)休眠;当手机休眠时不发射闹钟。

xref: /frameworks/base/core/java/android/app/AlarmManager.java
83public class AlarmManager {92    /**
93     * Alarm time in {@link System#currentTimeMillis System.currentTimeMillis()}
94     * (wall clock time in UTC).  This alarm does not wake the
95     * device up; if it goes off while the device is asleep, it will not be
96     * delivered until the next time the device wakes up.
97     */
98    public static final int RTC = 1;

分析结果

com.android.deskclock 休眠下执行的com.android.deskclock.ON_QUARTER_HOUR导致平均电流被拉高

查看 com.android.deskclock 相关源码

AndroidManifest.xml

        <!-- #endif --><!--  add start by  for MultiClock Widget  --><receiver android:name="com.android.alarmclock.MultiColckWidgetProvider" android:label="@string/multi_gadget"android:icon="@drawable/ic_launcher_alarmclock"><intent-filter><action android:name="android.appwidget.action.APPWIDGET_UPDATE" /><action android:name="com.android.deskclock.ON_QUARTER_HOUR" /><action android:name="android.intent.action.DATE_CHANGED" /><action android:name="android.intent.action.TIMEZONE_CHANGED" /><action android:name="android.intent.action.TIME_SET" /><action android:name="android.intent.action.LOCALE_CHANGED" /><action android:name="com.android.deskclock.worldclock.update" /><action android:name="android.intent.action.DATE_FORMAT_CHANGED" /></intent-filter><meta-data android:name="android.appwidget.provider" android:resource="@xml/multiclock_appwidget" /></receiver><!-- #endif -->
package com.android.alarmclock;public class MultiColckWidgetProvider extends AppWidgetProvider {/*** Intent to be used for checking if a world clock's date has changed. Must be every fifteen* minutes because not all time zones are hour-locked.**/public static final String ACTION_ON_QUARTER_HOUR = "com.android.deskclock.ON_QUARTER_HOUR";@Overridepublic void onReceive(Context context, Intent intent) {String action = intent.getAction();Log.d(TAG, "onReceive: " + action);super.onReceive(context, intent);if (ACTION_ON_QUARTER_HOUR.equals(action)|| Intent.ACTION_DATE_CHANGED.equals(action)|| Intent.ACTION_TIMEZONE_CHANGED.equals(action)|| Intent.ACTION_TIME_CHANGED.equals(action)|| Intent.ACTION_LOCALE_CHANGED.equals(action)|| Cities.WORLDCLOCK_UPDATE_INTENT.equals(action)) {AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);if (appWidgetManager != null) {int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context));for (int appWidgetId : appWidgetIds) {updateClock(context, appWidgetManager, appWidgetId);}if(!ACTION_ON_QUARTER_HOUR.equals(action)) {cancelAlarmOnQuarterHour(context);}startAlarmOnQuarterHour(context);}}}/*** Start an alarm that fires on the next quarter hour to update the world clock city* day when the local time or the world city crosses midnight.** @param context The context in which the PendingIntent should perform the broadcast.*/private void startAlarmOnQuarterHour(Context context) {if (context != null) {final long onQuarterHour = Utils.getAlarmOnQuarterHour();final PendingIntent quarterlyIntent = getOnQuarterHourPendingIntent(context);final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);am.setExact(AlarmManager.RTC, onQuarterHour, quarterlyIntent);Log.v(TAG, "startAlarmOnQuarterHour " + context.toString());}}

上述确认无误了

写一个Demo 验证

定时器进行AlarmManager.RTC休眠下唤醒
代码如下

调用
===============================================================================
package com.android.wakeupdemo;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;public class MainActivity extends Activity {private Intent mIntent;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mIntent = new Intent(this, MyBroadcast.class);mIntent.setAction(MyBroadcast.ACITON);AlarmTaskUtil.starRepeatAlarmTaskBroadcast(this, 5 * 1000 /* 5秒钟 */, mIntent);Log.d("suhuazhi", "starRepeatAlarmTaskBroadcast " + MyBroadcast.ACITON);}@Overrideprotected void onDestroy() {super.onDestroy();AlarmTaskUtil.stopAlarmTaskByBroadcast(this, mIntent);Log.d("suhuazhi", "onDestroy");}
}
定时器
===============================================================================
package com.android.wakeupdemo;import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;public class AlarmTaskUtil {public static void starRepeatAlarmTaskBroadcast(Context context, long intervalMillis, Intent intent) {AlarmManager mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);PendingIntent operation = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);mAlarmManager.setRepeating(AlarmManager.RTC, System.currentTimeMillis(), intervalMillis, operation);}public static void stopAlarmTaskByBroadcast(Context context, Intent intent) {AlarmManager mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);PendingIntent operation = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);mAlarmManager.cancel(operation);}
}
广播
===============================================================================
package com.android.wakeupdemo;import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;public class MyBroadcast extends BroadcastReceiver {public final static String ACITON = "com.su.wakeupdemo.ON_QUARTER_HOUR";@Overridepublic void onReceive(Context context, Intent intent) {if (ACITON.equals(intent.getAction())) {Log.d("suhuazhi", "I am here " + ACITON);}}}

捕获台阶电流

这里写图片描述

Log关键字
sending alarm Alarm

3,687: 11-28 15:46:40.163016   920  1090 V AlarmManager: sending alarm Alarm{92ddf3e type 1 when 1511855198951 com.android.wakeupdemo} success 
3,681: 11-28 15:46:40.122116   920  1090 V AlarmManager: sending alarm Alarm{e4b4fd type 1 when 1511854898951 com.android.wakeupdemo} success 

解决方案

本测试是在飞行模式下测试,要求平均待机电流在 4mA 下,该广播的主要作用是刷新时间控件,解决思路,没有联网的情况下,不进行定时设置或者延迟更新时间,不要太频繁。如果影响不大,甚至可以去除自定义广播

这篇关于SP91的待机功耗大到42mA(com.android.deskclock.ON_QUARTER_HOUR)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/685065

相关文章

Android实现在线预览office文档的示例详解

《Android实现在线预览office文档的示例详解》在移动端展示在线Office文档(如Word、Excel、PPT)是一项常见需求,这篇文章为大家重点介绍了两种方案的实现方法,希望对大家有一定的... 目录一、项目概述二、相关技术知识三、实现思路3.1 方案一:WebView + Office Onl

Android实现两台手机屏幕共享和远程控制功能

《Android实现两台手机屏幕共享和远程控制功能》在远程协助、在线教学、技术支持等多种场景下,实时获得另一部移动设备的屏幕画面,并对其进行操作,具有极高的应用价值,本项目旨在实现两台Android手... 目录一、项目概述二、相关知识2.1 MediaProjection API2.2 Socket 网络

Android实现悬浮按钮功能

《Android实现悬浮按钮功能》在很多场景中,我们希望在应用或系统任意界面上都能看到一个小的“悬浮按钮”(FloatingButton),用来快速启动工具、展示未读信息或快捷操作,所以本文给大家介绍... 目录一、项目概述二、相关技术知识三、实现思路四、整合代码4.1 Java 代码(MainActivi

Android Mainline基础简介

《AndroidMainline基础简介》AndroidMainline是通过模块化更新Android核心组件的框架,可能提高安全性,本文给大家介绍AndroidMainline基础简介,感兴趣的朋... 目录关键要点什么是 android Mainline?Android Mainline 的工作原理关键

如何解决idea的Module:‘:app‘platform‘android-32‘not found.问题

《如何解决idea的Module:‘:app‘platform‘android-32‘notfound.问题》:本文主要介绍如何解决idea的Module:‘:app‘platform‘andr... 目录idea的Module:‘:app‘pwww.chinasem.cnlatform‘android-32

Android实现打开本地pdf文件的两种方式

《Android实现打开本地pdf文件的两种方式》在现代应用中,PDF格式因其跨平台、稳定性好、展示内容一致等特点,在Android平台上,如何高效地打开本地PDF文件,不仅关系到用户体验,也直接影响... 目录一、项目概述二、相关知识2.1 PDF文件基本概述2.2 android 文件访问与存储权限2.

Android Studio 配置国内镜像源的实现步骤

《AndroidStudio配置国内镜像源的实现步骤》本文主要介绍了AndroidStudio配置国内镜像源的实现步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,... 目录一、修改 hosts,解决 SDK 下载失败的问题二、修改 gradle 地址,解决 gradle

在Android平台上实现消息推送功能

《在Android平台上实现消息推送功能》随着移动互联网应用的飞速发展,消息推送已成为移动应用中不可或缺的功能,在Android平台上,实现消息推送涉及到服务端的消息发送、客户端的消息接收、通知渠道(... 目录一、项目概述二、相关知识介绍2.1 消息推送的基本原理2.2 Firebase Cloud Me

Android中Dialog的使用详解

《Android中Dialog的使用详解》Dialog(对话框)是Android中常用的UI组件,用于临时显示重要信息或获取用户输入,本文给大家介绍Android中Dialog的使用,感兴趣的朋友一起... 目录android中Dialog的使用详解1. 基本Dialog类型1.1 AlertDialog(

Android Kotlin 高阶函数详解及其在协程中的应用小结

《AndroidKotlin高阶函数详解及其在协程中的应用小结》高阶函数是Kotlin中的一个重要特性,它能够将函数作为一等公民(First-ClassCitizen),使得代码更加简洁、灵活和可... 目录1. 引言2. 什么是高阶函数?3. 高阶函数的基础用法3.1 传递函数作为参数3.2 Lambda