Android 5.1-Status bar charging flag issue

Source: Internet
Author: User

Android 5.1 Ubuntu14.04 Sourceinsigh

Power is full, plug in the USB head, observe the settings-battery, the power is 100%, the status is fully, but still have the charge icon rust

I have read the code about StatusBar before. This time, I found Statusbarheaderview.java directly with Sourceinsight.

There's a way about the battery.

    @Override    publicvoid onbatterylevelchanged (intboolean  Boolean  charging) {        = numberformat.getpercentinstance (). Format (double) level/100.0 );        Mbatterylevel.settext (percentage);    }

Doesn't seem to help, we're looking for an icon, not a number.

Guess, when the battery is changing, it's going to be a notification.

Search the battery directly with Sourceinsight, find some files about battery

/** Batterymanager.java (Base/core/java/android/os) */    // values for ' status ' field in the action_battery_changed Intent     Public Static Final int Battery_status_full = 5;    // defines the status value

In Batteryservice.java , you can find a way to get the icon

/***/privateint geticonlocked (int level )        {if (Mbatteryprops.batterystatus = = batterymanager.battery_status_charging)            {return Com.android.internal.r.drawable.stat_sys_battery_charge;

According to Stat_sys_battery_charge, you can find stat_sys_battery_charge.xml (framework/base/core/res/res/drawable)

Find will be worth the icon stored in frameworks/base/core/res/res/drawable-mdpi/and other directories

Modify the judging condition or return value in Batteryservice.java geticonlocked

Found a lot of resource files, modify the return value. Like what:

if (Mbatteryprops.batterystatus = = batterymanager.battery_status_charging)            {return Com.android.internal.r.drawable.stat_sys_battery;    // Show non-rechargeable icons

After compiling push in, found no effect

Not successful, why? No one received the broadcast? ICON was stuffed into the batterymanager.extra_icon_small.

int icon = geticonlocked (mbatteryprops.batterylevel); Intent.putextra (Batterymanager.extra_icon_small , icon);

grep a bit extra_icon_small, found no place to receive. No one is receiving the broadcast, so how does the battery icon rust go up?

Another way of looking for ideas

I know the status bar belongs to Systemui, observe Systemui's file directory; open Androidmanifest.xml see

<android:name= "Systemuiservice"  android:exported= "true" />

Next find and open the Systemuiservice.java ; in OnCreate () mention the Systemuiapplication

Systemuiapplication.java launched a series of services, including

Com.android.systemui.statusbar.SystemBars.class

Open Systembars.java frameworks/base/packages/systemui/src/com/android/systemui/statusbar

Can see Basestatusbar

Mstatusbar = (basestatusbar) cls.newinstance ();

Shuntengmogua

Search for r.layout in Basestatusbar.java , but find only notification related

Basestatusbar is the basic status bar meaning, will there be other classes to inherit it? grep, find out.

Tvstatusbar and Phonestatusbar inherit from Basestatusbar

Search for "r.layout." In Phonestatusbar.java and get a few layout:

R.layout.super_status_bar

R.layout.heads_up

R.layout.navigation_bar

R.layout.status_bar_notification_keyguard_overflow, wait.

Mstatusbarwindow = (Statusbarwindowview) view.inflate (context,                null);

Focus on Super_status_bar, which is loaded with a lot of sub-layouts, such as Status_bar

Open status_bar.xml , find System_icon_area; it has system_icons

Open System_icons.xml We found that there is a custom control Com.android.systemui.BatteryMeterView

Now I know the battery icon is drawn.

(Framework/base/packages/systemui/src/com/android/systemui )public class    extendsimplements  Demomode,        batterycontroller.batterystatechangecallback

Batterycontroller.batterystatechangecallback interface is implemented, battery status changes, battery icon is updated

Private class extends Broadcastreceiver {

Receive the broadcast, remove the battery information; get the battery information to update the icon

Observe the draw method, which is useful tracker to judge

        if (tracker.plugged) {            //  define the bolt shape

If the USB header is plugged in, the lightning sign will be drawn;

So many add a judgment, when full of electricity, do not draw lightning signs

        if (Tracker.plugged && (batterystatus! = batterymanager.battery_status_full))            {// define the bolt shape

Batterystatus is a self-defined int variable from rust that removes the battery status from the Batterytracker and is then used to determine

Recompile burn-write, found after full power, no charge flag

The original sign of the charge rust was painted.

Android 5.1-Status bar charging flag issue

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.