`
Leif_冬
  • 浏览: 47550 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

Android Q BatterySaver Owner/Guest在点击”Based on percentage“的区别

 
阅读更多

经过加Code debug发现Owner/Guest 下 Secure.LOW_POWER_WARNING_ACKNOWLEDGED 这个值会有区别. 

Owner 和 Guest模式下第一次(刷完OS后,reboot不算)都会弹出“About Battery Saver“的警告对话框[Secure.LOW_POWER_WARNING_ACKNOWLEDGED 这个初始值应该是0],后面Owner不会再弹出,后来Guest/Owner为什么会有区别还要分析,应该是Secure.LOW_POWER_WARNING_ACKNOWLEDGED 这个值在Guest下发生了变化,下一步看Code里哪边有对这个值有修改.

 

点击 ”Based on percentage“这个 Button无论Owner或Guest都会对下面的Seekbar值进行初始化赋值(设置成5%),Guest 状态下Secure.getInt(context.getContentResolver(),

                Secure.LOW_POWER_WARNING_ACKNOWLEDGED, 0) 的值会是0 ,会将triggerLevel 设置为0,继而threshold为0,Button下面的Seekbar就会隐藏(mSeekBarPreference.setVisible(false);)并发送广播弹出“About Battery Saver“警告对话框.

下面是相关的Code.

 

#################点击RadioButton触发部分#######################
package/app/Settings/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleRadioButtonsController.java
        Log.i("TD","key 值是: "+key);
        if (!TextUtils.equals(key, KEY_NO_SCHEDULE)
                && BatterySaverUtils.maybeShowBatterySaverConfirmation(
                mContext, confirmationExtras)) {
            // reset this if we need to show the confirmation message
            Log.i("TD","------------------------->怀疑就是给triggerLevel赋值");
            mode = PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE;
            triggerLevel = 0;
        }
        // Trigger level is intentionally left alone when going between dynamic and percentage modes
        // so that a users percentage based schedule is preserved when they toggle between the two.
        Settings.Global.putInt(resolver, Global.AUTOMATIC_POWER_SAVE_MODE, mode);
        if (mode != PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC) {
            Log.i("TD","------------------------->怀疑就是这修改了triggerLevel值");
            Settings.Global.putInt(resolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, triggerLevel);
        }else{
            Log.i("TD","mode就是PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC");
        }
        mSeekBarController.updateSeekBar();
#################发送广播部分#######################
frameworks/base/packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatterySaverUtils.java
public static boolean maybeShowBatterySaverConfirmation(Context context, Bundle extras) {
        if (Secure.getInt(context.getContentResolver(),
                Secure.LOW_POWER_WARNING_ACKNOWLEDGED, 0) != 0) {
            Log.i("TD","------->结束没有发广播");
            return false; // Already shown.
        }
        Log.i("TD","------->发射广播");
        context.sendBroadcast(
                getSystemUiBroadcast(ACTION_SHOW_START_SAVER_CONFIRMATION, extras));
        return true;
    }

  

#################更新SeekBar框部分#######################
pacakage/app/Settings/src/com/android/settings/fuelgauge/batterysaver/BatterySaverScheduleSeekBarController.java
public void updateSeekBar() {
        .......
        if (mode == PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE) {
            final int threshold =
                    Settings.Global.getInt(resolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0);
            if (threshold <= 0) {
                mSeekBarPreference.setVisible(false);
            } else {
                Log.i("TD","#2--------------->mSeekBarPreference setVisible false-=-=-=->threshold: "+threshold);
                final int currentSeekbarValue = Math.max(threshold / 5, MIN_SEEKBAR_VALUE);
               .......
    }

 

#################接受广播-弹出对话框部分#######################
/frameworks/base/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java
       @Override
        public void onReceive(Context context, Intent intent) {
         ....
         else if (action.equals(ACTION_SHOW_START_SAVER_CONFIRMATION)) {
                Log.i("TD","------------------->ACTION_SHOW_START_SAVER_CONFIRMATION");
                dismissLowBatteryNotification();
                showStartSaverConfirmation(intent.getExtras());
       
        private void showStartSaverConfirmation(Bundle extras) {
        if (mSaverConfirmation != null) {
            Log.i("TD","----------------------->mSaverConfirmation isn't null");
        }else{
            Log.i("TD","----------------------->mSaverConfirmation is null");
        }
        if (mSaverConfirmation != null) return;
        final SystemUIDialog d = new SystemUIDialog(mContext);
        final boolean confirmOnly = extras.getBoolean(BatterySaverUtils.EXTRA_CONFIRM_TEXT_ONLY);
        final int batterySaverTriggerMode =
                extras.getInt(BatterySaverUtils.EXTRA_POWER_SAVE_MODE_TRIGGER,
                        PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
        final int batterySaverTriggerLevel =
                extras.getInt(BatterySaverUtils.EXTRA_POWER_SAVE_MODE_TRIGGER_LEVEL, 0);
        Log.i("TD","---->batterySaverTriggerMode: "+batterySaverTriggerMode);
        Log.i("TD","---->batterySaverTriggerLevel: "+batterySaverTriggerLevel);
        d.setMessage(getBatterySaverDescription());
        .......

    

写道
通过adb shell 指令修改low_power_warning_acknowledged值(即LOW_POWER_WARNING_ACKNOWLEDGED)结合BatterySaverUtils.java&&PowerNotificationWarnings.java里的所加Log分析如下:

    

[Step0]MC93C:/ $ settings get secure low_power_warning_acknowledged
null
[Step1]MC93C:/ $ settings get secure low_power_warning_acknowledged
1
[Step2]MC93C:/ $ settings put secure low_power_warning_acknowledged 0                                                                                        
[Step3]MC93C:/ $ settings get secure low_power_warning_acknowledged                                                                                                  
0
[Step4]MC93C:/ $ settings get secure low_power_warning_acknowledged
null
[Step5]MC93C:/ $ settings get secure low_power_warning_acknowledged
null                                                                                                    
[Step6]MC93C:/ $ settings get secure low_power_warning_acknowledged                                                                                                     
null
[Step7]MC93C:/ $ settings get secure low_power_warning_acknowledged                                                                                                     
1
[Step8]MC93C:/ $ settings put secure low_power_warning_acknowledged  0                                                                
[Step9]MC93C:/ $ settings get secure low_power_warning_acknowledged                                                                                                   
0

    

写道
Step0是刷机或做factoryreset后进入"Battery Saver"->"Set a schedule"得到的结果
Step1是在Owner下点击一次"Based on percentage"后得到的结果
LOG1:--->Secure.LOW_POWER_WARNING_ACKNOWLEDGED value is: 0
LOG2------->LOW_POWER_WARNING_ACKNOWLEDGED value is: 0
LOG3------->LOW_POWER_WARNING_ACKNOWLEDGED value is: 1
Step2手动将low_power_warning_acknowledged值修改成0
Step3查看low_power_warning_acknowledged是否修改成功
Step4将状态切到Guest,进入"Battery Saver"->"Set a schedule"得到的结果
Step5是在Guest下点击一次"Based on percentage"后得到的结果
LOG1:--->Secure.LOW_POWER_WARNING_ACKNOWLEDGED value is: 0[此后这边的值会一直为0,具体原因下面会解释]
LOG2------->LOW_POWER_WARNING_ACKNOWLEDGED value is: 0 [因为Step2有做过手动修改,如果没有的话,这边的值会是1]
LOG3------->LOW_POWER_WARNING_ACKNOWLEDGED value is: 1
Step6是在Guest下再一次点击"Based on percentage"后得到的结果
LOG1:--->Secure.LOW_POWER_WARNING_ACKNOWLEDGED value is: 0
LOG2------->LOW_POWER_WARNING_ACKNOWLEDGED value is: 1
LOG3------->LOW_POWER_WARNING_ACKNOWLEDGED value is: 1
Step7是切到Owner状态下没有做任何操作得到的值
Step8,Step9是重复过程(Step2,Step3)
如果切到Guest状态不做如何操作就切回Owner状态,那么用指令获取low_power_warning_acknowledged值,仍然为0.[Step0~Step4&&Step7]
说明PartI是读取本状态下(Owner/Guest)的数据库里的内容,PartII读写的是公共区域数据库里的内容,在Guest状态下没有权限访问公共区域的值(LOW_POWER_WARNING_ACKNOWLEDGED),
导致PartI部分的判断条件(LOW_POWER_WARNING_ACKNOWLEDGED==0)所以就会一直发送广播去弹出对话框及隐藏下面的Seekbar.

    

PartI.#################发送广播部分#######################
frameworks/base/packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatterySaverUtils.java
public static boolean maybeShowBatterySaverConfirmation(Context context, Bundle extras) {
         Log.i("TD","LOG1:--->Secure.LOW_POWER_WARNING_ACKNOWLEDGED value is:  "+Secure.getInt(context.getContentResolver(),
                Secure.LOW_POWER_WARNING_ACKNOWLEDGED, 0));
        if (Secure.getInt(context.getContentResolver(),
                Secure.LOW_POWER_WARNING_ACKNOWLEDGED, 0) != 0) {
            Log.i("TD","------->结束没有发广播");
            return false; // Already shown.
        }
        Log.i("TD","------->发射广播");
        context.sendBroadcast(
                getSystemUiBroadcast(ACTION_SHOW_START_SAVER_CONFIRMATION, extras));
        return true;
    }

PartII./frameworks/base/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java

     if (confirmOnly) {
                ......
                        Log.i("TD","LOG2------->LOW_POWER_WARNING_ACKNOWLEDGED value is:  "+Secure.getInt(mContext.getContentResolver(), Secure.LOW_POWER_WARNING_ACKNOWLEDGED, 0));
                                Settings.Global.putInt(
                                resolver,
                                Global.AUTOMATIC_POWER_SAVE_MODE,
                                batterySaverTriggerMode);
                        Settings.Global.putInt(
                                resolver,
                                Global.LOW_POWER_MODE_TRIGGER_LEVEL,
                                batterySaverTriggerLevel);
                        boolean jg = Secure.putInt(
                                resolver,
                                Secure.LOW_POWER_WARNING_ACKNOWLEDGED,
                                1);
                        Log.i("TD","------>putInt 结果为 : "+jg); //确实每次都能写LOW_POWER_WARNING_ACKNOWLEDGED成功
                        Log.i("TD","LOG3------->LOW_POWER_WARNING_ACKNOWLEDGED value is:  "+Secure.getInt(mContext.getContentResolver(), Secure.LOW_POWER_WARNING_ACKNOWLEDGED, 0));

                    });
        }

    

写道
在网络上有找到一个与此相关的文章,请参考https://www.guidingtech.com/guest-mode-android/
其中关于数据访问部分说明:"PROTECT PERSONAL DATA
Similar to user profiles, the primary users' installed apps, personal data (such as photos, audio, video, contacts), app data (call history, web history, chats, and messages), settings and customizations will be unavailable in the guest mode. Even notifications from the admin’s account will be blocked on the guest profile. However, you can access all those things when you switch to an admin profile.

The guest mode gives a feeling of a fresh device where you are offered only the pre-installed apps."

 

 

 

分享到:
评论

相关推荐

    360BatterySaver.apk

    360省电王,可以通过调整手机系统级省手机耗电量

    Buoy:内置Android Battery Saver的扩展

    浮标内置Android Battery Saver的扩展描述内置的Android省电模式实际上非常强大。 唯一令人失望的是,没有一个是开箱即用的配置。 这就是Buoy的用武之地。Buoy使得在任何情况下都可以使用内置的节电器。 如果您希望...

    SystemUI新增图标demo

    SystemUI新增图标demo,模拟源码添加一个BatterySaver图标

    Win10系统如何使用URI.docx

    在Windows 10操作系统中,URI(Uniform Resource Identifier)是一种用于唯一标识资源的字符串。URI可以被用来启动特定的应用程序或打开特定的设置页面。以下是如何在Win10系统中使用URI的详细步骤和相关知识点: 1...

    GP88写频软件使用方法

    - BatterySaver:设置省电模式。 - TxSignallingName:选择信令类型,对于GP88可能没有此选项,需要使用GP300IVG软件添加信令。 5. 写入信道信息: 在主菜单下按F3开始编写信息到一个信道,编写完毕后按F4选择下一...

    GP88写频教程

    - **BatterySaver**:省电模式。 - **TxSignallingName**:信令类型。需要注意的是,如果GP88设备没有此选项,则可能需要使用GP300IVG软件添加信令。 3. **保存信道设置**: - 编辑完单个信道后,可以通过按F4键...

Global site tag (gtag.js) - Google Analytics