本文主要是介绍12 展讯Sprd设置-电池-AppStateInfoCollector.handleProcStateChanged 代码走读,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1. AppStateInfoCollector.handleProcStateChanged
重点监听UID状态变化,来改变uid的状态
// return true: for new app state// false: for otherspublic boolean reportAppProcStateInfo(String packageName, int uid, int procState) {int userId = UserHandle.getUserId(uid);ArrayMap<String, AppState> mAppStateInfoList = getAppStateInfoList(userId);//update mAppStateInfoListint index = mAppStateInfoList.indexOfKey(packageName);AppState appState = null;boolean ret = true;if (DEBUG) Slog.d(TAG, "- reportAppProcStateInfo() E -");if (index >= 0) {appState = mAppStateInfoList.valueAt(index);// update procStateappState.mProcState = procState;if (uid != appState.mUid) appState.mUid = uid;ret = false;} else {if (DEBUG) Slog.d(TAG, "reportAppProcStateInfo: appName:" + packageName + " uid:" + uid + " is not exist, create it");appState = buildAppState(packageName, userId, Event.NONE);mAppStateInfoList.put(packageName, appState);}return ret;}
2. PowerController.handleProcStateChanged
private void handleProcStateChanged(String appName, int uid, int procState) {if (DEBUG) Slog.d(TAG, "- handleProcstateChanged() E - packageName:" + appName+ " uid:" + uid + " procState:" + Util.ProcState2Str(procState));if (mAppStateInfoCollector.reportAppProcStateInfo(appName, uid, procState)) {// Note: Bug 698133 appIdle cts fail -->BEG// Ugly: we have to check if doing cts/gts test// is cts/gts test, thencheckCtsGtsTesting(appName);// Note: Bug 698133 appIdle cts fail <--END}
3. PowerController.updateUidStateLocked
static final int MSG_UID_STATE_CHANGED = 5;switch (msg.what) {...case MSG_UID_STATE_CHANGED:handleProcStateChanged((String)msg.obj, msg.arg1, msg.arg2);break;.../*** Process state of UID changed; if needed, will trigger*/private void updateUidStateLocked(int uid, int uidState) {...//Add for bug 884770 ENDif ((null != appName) ) {msgHandler.sendMessage(msgHandler.obtainMessage(MSG_UID_STATE_CHANGED, uid, uidState, appName));}private void removeUidStateLocked(int uid) {.....if ((null != appName) ) {msgHandler.sendMessage(msgHandler.obtainMessage(MSG_UID_STATE_CHANGED, uid, ActivityManager.PROCESS_STATE_CACHED_EMPTY, appName));...
4. PowerController.IUidObserver.onUidStateChanged
final private IUidObserver mUidObserver = new IUidObserver.Stub() {@Override public void onUidStateChanged(int uid, int procState, long procStateSeq) throws RemoteException {synchronized (mUidStateLock) {updateUidStateLocked(uid, procState);}mAppStateInfoCollector.updateUidState(uid, procState);}
5. registerUidObserver.(ActivityManager.UID_OBSERVER_PROCSTATE)
private void registerUidObserver() {try {if (mActivityManager != null)mActivityManager.registerUidObserver(mUidObserver, ActivityManager.UID_OBSERVER_PROCSTATE| ActivityManager.UID_OBSERVER_GONE/*| ActivityManager.UID_OBSERVER_IDLE| ActivityManager.UID_OBSERVER_ACTIVE*/,ActivityManager.PROCESS_STATE_UNKNOWN, null);} catch (RemoteException e) {// ignored; both services live in system_server}}
监听UID变化状态,重点uid隐藏、状态变更
package android.app;@SystemService(Context.ACTIVITY_SERVICE)
public class ActivityManager {/** @hide Flag for registerUidObserver: report changes in process state. */public static final int UID_OBSERVER_PROCSTATE = 1<<0;/** @hide Flag for registerUidObserver: report uid gone. */public static final int UID_OBSERVER_GONE = 1<<1;/** @hide Flag for registerUidObserver: report uid has become idle. */public static final int UID_OBSERVER_IDLE = 1<<2;/** @hide Flag for registerUidObserver: report uid has become active. */public static final int UID_OBSERVER_ACTIVE = 1<<3;/** @hide Flag for registerUidObserver: report uid cached state has changed. */public static final int UID_OBSERVER_CACHED = 1<<4;
这篇关于12 展讯Sprd设置-电池-AppStateInfoCollector.handleProcStateChanged 代码走读的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!