Android4.4 SystemUI analysis-PowerUI

Source: Internet
Author: User

Android4.4 SystemUI analysis-PowerUI

The following analysis shows a slight difference between the native SystemUI of MTK Android4.4 and the SystemUI of Google, but the overall framework of the two is similar.

This is the first article to analyze SystemUI. First, start with the simplest PowerUI. The source code path:/frameworks/base/packages/SystemUI directory structure is as follows:

When I import the Eclipse editor, the error is reported because some packages and resources on the Framework cannot be found, which does not matter. After the modification, I compile it using the mmm module and then push it to the mobile phone (eng version) for debugging. After the push operation, it must be restarted to take effect.

No Activity registration on AndroidManifest. xml

 

                                 
              
  
 
Therefore, the whole program starts SystemUIService from the outside. So how does one start SystemUIService? Check this file:/frameworks/base/services/java/com/android/server/SystemServer. java. You can find

 

 

    static final void startSystemUi(Context context) {        Intent intent = new Intent();        intent.setComponent(new ComponentName("com.android.systemui",                    "com.android.systemui.SystemUIService"));        //Slog.d(TAG, "Starting service: " + intent);        context.startServiceAsUser(intent, UserHandle.OWNER);    }
Therefore, SystemUI is called when SystemService is started.

 

The key code of SystemUIService is as follows:

 

package com.android.systemui;import android.app.Service;import android.content.Intent;import android.content.res.Configuration;import android.os.IBinder;import android.util.Log;import java.io.FileDescriptor;import java.io.PrintWriter;import java.util.HashMap;public class SystemUIService extends Service {    private static final String TAG = "SystemUIService";    /**     * The classes of the stuff to start.     */    private final Class
 [] SERVICES = new Class[] {            com.android.systemui.recent.Recents.class,            com.android.systemui.statusbar.SystemBars.class,            com.android.systemui.usb.StorageNotification.class,            com.android.systemui.power.PowerUI.class,            com.android.systemui.media.RingtonePlayer.class,            com.android.systemui.settings.SettingsUI.class,        };    /**     * Hold a reference on the stuff we start.     */    private final SystemUI[] mServices = new SystemUI[SERVICES.length];    @Override    public void onCreate() {        HashMap
 
  , Object> components = new HashMap
  
   , Object>();        final int N = SERVICES.length;        for (int i=0; i
   
     cl = SERVICES[i];            Log.d(TAG, "loading: " + cl);            Log.d("dzt", "loading: " + cl);            try {                mServices[i] = (SystemUI)cl.newInstance();            } catch (IllegalAccessException ex) {                throw new RuntimeException(ex);            } catch (InstantiationException ex) {                throw new RuntimeException(ex);            }            mServices[i].mContext = this;            mServices[i].mComponents = components;            Log.d(TAG, "running: " + mServices[i]);            Log.d("dzt", "running: " + mServices[i]);            mServices[i].start();        }    }}
   
  
 
These classes

 

 

com.android.systemui.recent.Recents.class,            com.android.systemui.statusbar.SystemBars.class,            com.android.systemui.usb.StorageNotification.class,            com.android.systemui.power.PowerUI.class,            com.android.systemui.media.RingtonePlayer.class,            com.android.systemui.settings.SettingsUI.class,

All are inherited from: SystemUI. Instances are created in the OnCreate () function of SystemUIService and mServices [I]. start (); method is called.

 

Next we will analyze the simplest com. android. systemui. power. PowerUI. class

Register some listeners in the start () method of PowerUI.

 

public void start() {        mLowBatteryAlertCloseLevel = mContext.getResources().getInteger(                com.android.internal.R.integer.config_lowBatteryCloseWarningLevel);        mLowBatteryReminderLevels[0] = mContext.getResources().getInteger(                com.android.internal.R.integer.config_lowBatteryWarningLevel);        mLowBatteryReminderLevels[1] = mContext.getResources().getInteger(                com.android.internal.R.integer.config_criticalBatteryWarningLevel);        final PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);        mScreenOffTime = pm.isScreenOn() ? -1 : SystemClock.elapsedRealtime();        // Register for Intent broadcasts for...        IntentFilter filter = new IntentFilter();        filter.addAction(Intent.ACTION_BATTERY_CHANGED);        filter.addAction(Intent.ACTION_SCREEN_OFF);        filter.addAction(Intent.ACTION_SCREEN_ON);        /// M: Support show battery level when configuration changed. @{        filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);        /// M: Support show battery level when configuration changed. @}        /// M: Hide low battery dialog when PowerOffAlarm ring. @{        filter.addAction("android.intent.action.normal.boot");        filter.addAction("android.intent.action.ACTION_SHUTDOWN_IPO");        /// M: Hide low battery dialog when PowerOffAlarm ring. @}        mContext.registerReceiver(mIntentReceiver, filter, null, mHandler);    }
For example, you can listen to ACTION_BATTERY_CHANGED to determine the power usage. If the power consumption is low, a prompt is sent to the user. Other actions are broadcast-based to handle specific tasks, if you need to customize or add new listeners for power-related functions, you can modify them in this class.

 

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.