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中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

Android自定义Scrollbar的两种实现方式

《Android自定义Scrollbar的两种实现方式》本文介绍两种实现自定义滚动条的方法,分别通过ItemDecoration方案和独立View方案实现滚动条定制化,文章通过代码示例讲解的非常详细,... 目录方案一:ItemDecoration实现(推荐用于RecyclerView)实现原理完整代码实现

Android App安装列表获取方法(实践方案)

《AndroidApp安装列表获取方法(实践方案)》文章介绍了Android11及以上版本获取应用列表的方案调整,包括权限配置、白名单配置和action配置三种方式,并提供了相应的Java和Kotl... 目录前言实现方案         方案概述一、 androidManifest 三种配置方式

Android WebView无法加载H5页面的常见问题和解决方法

《AndroidWebView无法加载H5页面的常见问题和解决方法》AndroidWebView是一种视图组件,使得Android应用能够显示网页内容,它基于Chromium,具备现代浏览器的许多功... 目录1. WebView 简介2. 常见问题3. 网络权限设置4. 启用 JavaScript5. D

Android如何获取当前CPU频率和占用率

《Android如何获取当前CPU频率和占用率》最近在优化App的性能,需要获取当前CPU视频频率和占用率,所以本文小编就来和大家总结一下如何在Android中获取当前CPU频率和占用率吧... 最近在优化 App 的性能,需要获取当前 CPU视频频率和占用率,通过查询资料,大致思路如下:目前没有标准的

Android开发中gradle下载缓慢的问题级解决方法

《Android开发中gradle下载缓慢的问题级解决方法》本文介绍了解决Android开发中Gradle下载缓慢问题的几种方法,本文给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧... 目录一、网络环境优化二、Gradle版本与配置优化三、其他优化措施针对android开发中Gradle下载缓慢的问

Android 悬浮窗开发示例((动态权限请求 | 前台服务和通知 | 悬浮窗创建 )

《Android悬浮窗开发示例((动态权限请求|前台服务和通知|悬浮窗创建)》本文介绍了Android悬浮窗的实现效果,包括动态权限请求、前台服务和通知的使用,悬浮窗权限需要动态申请并引导... 目录一、悬浮窗 动态权限请求1、动态请求权限2、悬浮窗权限说明3、检查动态权限4、申请动态权限5、权限设置完毕后

Android里面的Service种类以及启动方式

《Android里面的Service种类以及启动方式》Android中的Service分为前台服务和后台服务,前台服务需要亮身份牌并显示通知,后台服务则有启动方式选择,包括startService和b... 目录一句话总结:一、Service 的两种类型:1. 前台服务(必须亮身份牌)2. 后台服务(偷偷干

Android kotlin语言实现删除文件的解决方案

《Androidkotlin语言实现删除文件的解决方案》:本文主要介绍Androidkotlin语言实现删除文件的解决方案,在项目开发过程中,尤其是需要跨平台协作的项目,那么删除用户指定的文件的... 目录一、前言二、适用环境三、模板内容1.权限申请2.Activity中的模板一、前言在项目开发过程中,尤