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

 

 

更多相关文章

  1. Android 获得当前进程PackageName
  2. android LayoutInflater.inflate()的参数及其功能
  3. appium启动APP配置参数:
  4. android中AudioRecord采集音频的参数说明
  5. 穿针引线,帮你回忆, 汇总:Android系统启动流程 & 应用程序'进程'启
  6. android 查看其他进程内存数据
  7. Android 消息机制 进程调度问题
  8. Android进程间通信(IPC)

随机推荐

  1. Android程序安装后图标不显示
  2. Android中分页滑动实现总结
  3. Android(安卓)启动性能优化 - kernel篇
  4. 加快Android离线文档的访问速度
  5. android离开一个页面时关闭子线程
  6. 转换 iOS 用户界面到 Android(安卓)的 5
  7. 从初学android到现在每天收入50块,收入还
  8. android平台yuv缩放相关
  9. 【Android】UI设计之界面布局
  10. 单击事件(onClick())与触摸事件(onTouch())的