Android Q AppCompactor and LowMemDetector
16lz
2021-01-23
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 获得当前进程PackageName
- android LayoutInflater.inflate()的参数及其功能
- appium启动APP配置参数:
- android中AudioRecord采集音频的参数说明
- 穿针引线,帮你回忆, 汇总:Android系统启动流程 & 应用程序'进程'启
- android 查看其他进程内存数据
- Android 消息机制 进程调度问题
- Android进程间通信(IPC)