本帖最后由 七个柚子多少钱 于 2021-10-12 15:25 编辑
需求:
产品工作在低温环境,电池输出电流较小,期望工作启动峰值电流小于1A以下,最好在500ma; 验证:
测试过程为电源键开机起到系统进入到安卓桌面
1. 开发板启动峰值电流约1.2A左右(无显示屏) 2. 对于使用SIM和不使用SIM卡情况测试峰值电流约1.2A左右 3. 对于飞行模式和正常模式下开机测试峰值电流约1.2A左右
使用SIM卡正常模式启动电流记录:
解决思路:
测试的峰值电流主要发生在开机10S时间段,此时系统启动了android init程序,使用低频低核数启动系统,来减小峰值电流,在系统正常启动完后恢复正常的CPU频率和核数
步骤1:
在device/mediatek/mt6771/init.mt6771.rc文件修改CPU频率和核数 - on early-init
- + # highly freq
- + write proc/ppm/enabled "1"
- + write proc/ppm/policy/ut_fix_core_num "1 1"
- + write proc/ppm/policy/ut_fix_freq_idx "15 15"
- on init
复制代码
注意:
修改CPU频率和核数需要在on init之前,建议在写on early-init和on init之间即可;.rc类似于.xml文件,system/core/init/init.c文件main函数会解析.rc文件,on early-init、on init等代表触发器,在特定的条件下会执行触发器后编写的命令。 格式 | 含义 | on early-init | 在初始化早期阶段触发 | on init | 在初始化阶段触发 | on late-init | 在初始化晚期阶段触发 | on boot/charger | 当系统启动/充电时触发 | on property | 当属性值满足条件时触发 |
参考链接:Android系统启动之init.rc文件解析过程
步骤2:
在接收到系统开机广播后恢复正常的CPU频率和核数;在任意系统服务,系统应用源码注册开机广播接收器; 示例1:
在系统设置应用代码内添加开机广播接收 路径:静态方式注册广播 - vendor/mediatek/proprietary/packages/apps/MtkSettings/AndroidManifest.xml
复制代码添加声明 - <receiver android:name="com.mediatek.settings.RestoreRotationReceiver">
- <intent-filter>
- <action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
- + <action android:name="android.intent.action.BOOT_COMPLETED"/>
- </intent-filter>
- </receiver>
复制代码- vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/mediatek/settings/RestoreRotationReceiver.java
复制代码在收到开机广播后,恢复正常的cpu频率和核数 - import java.io.BufferedReader;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.PrintStream;
- public class RestoreRotationReceiver extends BroadcastReceiver {
-
- private static final String ACTION_BOOT = "android.intent.action.BOOT_COMPLETED";
- private String cpuPath="proc/ppm/enabled"; //多核控制开关
- private String cpuHz="proc/ppm/policy/ut_fix_freq_idx";//cpu频率
- private String cpuNum="/proc/ppm/policy/ut_fix_core_num"; //cpu核数
- @Override
- public void onReceive(Context context, Intent intent) {
- if (intent.getAction().equals(ACTION_BOOT)) {
- wirteValue(cpuNum,"-1 -1");
- wirteValue(cpuHz,"-1 1");
- wirteValue(cpuHz,"0");
- }
- }
-
- public void wirteValue(String path,String value) {
- BufferedWriter bw = null;
- try {
- bw = new BufferedWriter(new FileWriter(new File(path)));
- bw.write(value);
- } catch (IOException e) {
- e.printStackTrace();
- }finally{
- if (bw!=null) {
- try {
- bw.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
复制代码
示例2:
添加自定义服务并注册开机广播接收 在路径下frameworks/base/core/java/android/home/创建IHomeService.aidl文件 - frameworks/base/core/java/android/home/IHomeService.aidl
复制代码- package android.home;
- interface IHomeService {
- }
复制代码 将IHomeService.aidl加入编译
- frameworks/base/Android.bp b/frameworks/base/Android.bp
复制代码- + "core/java/android/home/IHomeService.aidl",
复制代码
在路径下frameworks/base/services/core/java/com/android/server/home/创建HomeService.java文件,在动态方式注册开机广播接收,收到广播后恢复正常cpu频率和核数
- frameworks/base/services/core/java/com/android/server/home/HomeService.java
复制代码- package com.android.server.home;
- import com.android.server.IoThread;
- import android.content.pm.PackageManager;
- import android.content.Context;
- import android.home.IHomeService;
- import android.util.Log;
- import android.content.BroadcastReceiver;
- import android.content.Intent;
- import android.content.IntentFilter;
- import android.os.BatteryManager;
- import java.util.List;
- import android.app.ActivityManager;
- import android.app.ActivityManager.RunningTaskInfo;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.File;
- public class HomeService extends IHomeService.Stub {
- private static final String TAG = "HomeService";
- private Context mContext;
- private String packagename1 = "com.android.gallery3d";
- private String packagename2 = "com.mxtech.videoplayer.ad";
- private String cpuPath="proc/ppm/enabled"; //多核控制开关
- private String cpuHz="proc/ppm/policy/ut_fix_freq_idx";//cpu频率
- private String cpuNum="/proc/ppm/policy/ut_fix_core_num"; //cpu核数
- private boolean flag1=true;
- private boolean flag2=true;
- private boolean oldflag=false;
- private int defaultlevel=35;
- private CpuInfoReceiver cpuInfoReceiver;
- public HomeService(Context context) {
- super();
- Log.d(TAG, "HomeService context");
- mContext = context;
- IntentFilter intentFilter = new IntentFilter();
- intentFilter.addAction("android.intent.action.BOOT_COMPLETED");
- cpuInfoReceiver = new CpuInfoReceiver();
- context.registerReceiver(cpuInfoReceiver, intentFilter);
- }
- public void wirteValue(String path,String value) {
- BufferedWriter bw=null;
- try {
- bw=new BufferedWriter(new FileWriter(new File(path)));
- bw.write(value);
- } catch (IOException e) {
- e.printStackTrace();
- }finally{
- if (bw!=null) {
- try {
- bw.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
- class CpuInfoReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- wirteValue(cpuNum,"-1 -1");
- wirteValue(cpuHz,"-1 -1");
- wirteValue(cpuPath,"0");
- }
- }
- }
复制代码 注册系统服务- frameworks/base/services/java/com/android/server/SystemServer.java
复制代码
- import com.android.server.home.HomeService;
- public final class SystemServer {
-
- traceBeginAndSlog("StartHomeService");
- try {
- ServiceManager.addService("ctrlcpu", new HomeService(context));
- } catch (Throwable e) {
- reportWtf("starting Home Service", e);
- }
- traceEnd();
- }
复制代码 修改后编译代码:make update-api
修改后:
使用SIM卡正常模式启动电流记录:
|