Android(安卓)Q AppCompactor and LowMemDetector
16lz
2022-04-21
1、在ActivityManagerService.java 中
OomAdjuster mOomAdjuster;final LowMemDetector mLowMemDetector;
mProcessList.init(this, activeUids);mLowMemDetector = null;mOomAdjuster = new OomAdjuster(this, mProcessList, activeUids);
2、在OomAdjuster.java 中
OomAdjuster(ActivityManagerService service, ProcessList processList, ActiveUids activeUids) { mService = service; mProcessList = processList; mActiveUids = activeUids; mLocalPowerManager = LocalServices.getService(PowerManagerInternal.class); mConstants = mService.mConstants; mAppCompact = new AppCompactor(mService); // The process group is usually critical to the response time of foreground app, so the // setter should apply it as soon as possible. final ServiceThread adjusterThread = new ServiceThread(TAG, TOP_APP_PRIORITY_BOOST, false /* allowIo */); adjusterThread.start(); Process.setThreadGroupAndCpuset(adjusterThread.getThreadId(), THREAD_GROUP_TOP_APP); mProcessGroupHandler = new Handler(adjusterThread.getLooper(), msg -> { Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "setProcessGroup"); final int pid = msg.arg1; final int group = msg.arg2; try { setProcessGroup(pid, group); } catch (Exception e) { if (DEBUG_ALL) { Slog.w(TAG, "Failed setting process group of " + pid + " to " + group, e); } } finally { Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); } return true; });}
这里创建了mAppCompact 对象,及创建了一个服务进程用于oom 调节时设置进程cpu group 组
3、AppCompactor.java
public AppCompactor(ActivityManagerService am) { mAm = am; mCompactionThread = new ServiceThread("CompactionThread", THREAD_PRIORITY_FOREGROUND, true); mProcStateThrottle = new HashSet<>();}
4、初始化
mOomAdjuster.initSettings();
void initSettings() { mAppCompact.init();}
/** * Reads phenotype config to determine whether app compaction is enabled or not and * starts the background thread if necessary. */public void init() { DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, ActivityThread.currentApplication().getMainExecutor(), mOnFlagsChangedListener); synchronized (mPhenotypeFlagLock) { updateUseCompaction();//参加handle updateCompactionActions(); updateCompactionThrottles(); updateStatsdSampleRate(); updateFullRssThrottle(); updateFullDeltaRssThrottle(); updateProcStateThrottle(); } Process.setThreadGroupAndCpuset(mCompactionThread.getThreadId(), Process.THREAD_GROUP_SYSTEM);}
/** * Reads the flag value from DeviceConfig to determine whether app compaction * should be enabled, and starts the compaction thread if needed. */@GuardedBy("mPhenotypeFlagLock")private void updateUseCompaction() { mUseCompaction = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, KEY_USE_COMPACTION, DEFAULT_USE_COMPACTION); if (mUseCompaction && !mCompactionThread.isAlive()) { mCompactionThread.start(); mCompactionHandler = new MemCompactionHandler(); //handle }}
创建handle,设置参数,监听数据库字段参数,这些参数用户压缩时使用
https://www.jianshu.com/p/ae4ca096201a
更多相关文章
- Android创建和删除桌面快捷方式
- Android(安卓)Timer,TimerTask简单的使用
- Android(安卓)通过findViewById方式创建TabHost
- Android(安卓)开发技巧集合
- android 6.0系统 make otapackage 错误
- Android短信发送器
- android创建数据库(SQLite)保存图片示例
- mybatisplus的坑 insert标签insert into select无参数问题的解决
- Python技巧匿名函数、回调函数和高阶函数