The following analysis is based on the MTK Android4.4 native Systemui and Google's systemui there is a slight difference, but the overall framework is similar.
This is the first analysis of Systemui, first from the simplest Powerui, source path:/frameworks/base/packages/systemui program directory structure as follows:
I import Eclipse Editor, the reason for the error is because there is no framework to find some packages and resources, this does not matter, after the modification in the use of the MMM module compiled, and then push to the mobile phone (Eng version) for debugging, push requires a restart to take effect.
No activity registration on Androidmanifest.xml
<intent-filter> <action android:name= "Android.intent.action.MAIN"/> <category android: Name= "Android.intent.category.LAUNCHER"/> </intent-filter>
So the entire program starts up systemuiservice from the outside. So how does it start systemuiservice? Look at this file:/frameworks/base/services/java/com/android/server/systemserver.java can be found in this file
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); }
So Systemui was called when the Systemservice started.
The key code for 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 FINA L 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<class<?>, object> components = new Hashmap<class<?>, object> (); Final int N = services.length; for (int i=0; i<n; i++) {class<?> 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,
are inherited from: Systemui, the instance is created in the Systemuiservice OnCreate () function, and the Mservices[i].start () method is called.
The simplest com.android.systemui.power.PowerUI.class is analyzed below.
In the start () method of Powerui, register some listeners
public void Start () {mlowbatteryalertcloselevel = Mcontext.getresources (). Getinteger (com.android.i Nternal. R.integer.config_lowbatteryclosewarninglevel); Mlowbatteryreminderlevels[0] = Mcontext.getresources (). Getinteger (Com.android.internal.r.integer.config_lo Wbatterywarninglevel); MLOWBATTERYREMINDERLEVELS[1] = Mcontext.getresources (). Getinteger (COM.ANDROID.INTERNAL.R.INTEGER.CONFIG_CR Iticalbatterywarninglevel); Final PowerManager PM = (powermanager) mcontext.getsystemservice (Context.power_service); Mscreenofftime = Pm.isscreenon ()? -1:systemclock.elapsedrealtime (); Register for Intent broadcasts ... 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, listen to action_battery_changed determine the size of the power, if the low power to a prompt to the user, the other action is based on the broadcast to deal with some specific things, if the power-related functions need to be customized or add new listeners can be modified in this class.
The Powerui of Android4.4 systemui analysis