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创建和删除桌面快捷方式
  2. Android(安卓)Timer,TimerTask简单的使用
  3. Android(安卓)通过findViewById方式创建TabHost
  4. Android(安卓)开发技巧集合
  5. android 6.0系统 make otapackage 错误
  6. Android短信发送器
  7. android创建数据库(SQLite)保存图片示例
  8. mybatisplus的坑 insert标签insert into select无参数问题的解决
  9. Python技巧匿名函数、回调函数和高阶函数

随机推荐

  1. Android(安卓)使用MediaPlayer播放assets
  2. Android开机动画 (boot animation)制作
  3. android(NDK+JNI)---NDK开发 环境配置
  4. PANIC: Could not open the file(安卓环境
  5. Android(安卓)ORM数据库框架之-greenDao(
  6. Android(安卓)java.lang.UnsatisfiedLink
  7. android wifi驱动开发日记(二)
  8. android studio 使用备忘
  9. Alibaba-AndFix Bug热修复框架原理及源码
  10. GreenDao使用心得