編輯:關於Android編程
正文
為防止某些進程被low memory意外殺掉,可以將其加入白名單,降低誤傷的概率; 一般來說,low memory killer會首先選擇adj value徘徊在9~15的process去結束生命; 1.在ActivityManagerService.java 增加如下代碼: static final String[] mThirdPartyAppWhiteList = { android.process.media}; static final int [] mThirdPartyAppAdj = {7}; 2.在ActivityManagerService.java修改如下代碼: private final boolean updateOomAdjLocked(ProcessRecord app, int hiddenAdj, int clientHiddenAdj, int emptyAdj, ProcessRecord TOP_APP, boolean doingAll) { app.hiddenAdj = hiddenAdj; app.clientHiddenAdj = clientHiddenAdj; app.emptyAdj = emptyAdj; if (app.thread == null) { return false; } final boolean wasKeeping = app.keeping; boolean success = true; boolean isWLProc = false; /// M: ALPS00497111 [Volunteer free] LCA Memory Optimized boolean isThirdPartyAppWhiteProcess = false; //add int mThirdPartyAdj = ProcessList.HIDDEN_APP_MIN_ADJ; computeOomAdjLocked(app, hiddenAdj, clientHiddenAdj, emptyAdj, TOP_APP, false, doingAll); if (app.curRawAdj != app.setRawAdj) { if (wasKeeping && !app.keeping) { // This app is no longer something we want to keep. Note // its current wake lock time to later know to kill it if // it is not behaving well. BatteryStatsImpl stats = mBatteryStatsService.getActiveStatistics(); synchronized (stats) { app.lastWakeTime = stats.getProcessWakeTime(app.info.uid, app.pid, SystemClock.elapsedRealtime()); } app.lastCpuTime = app.curCpuTime; } app.setRawAdj = app.curRawAdj; } if (app.curAdj != app.setAdj) { /// M: LTK @{ if (FeatureOption.MTK_MEMORY_COMPRESSION_SUPPORT) { if(app.curAdj > app.setAdj && (app.curAdj >= ProcessList.PREVIOUS_APP_ADJ) && app.hasShownUi) { try { IAmsPlus amsplus = MediatekClassFactory.createInstance(IAmsPlus.class); amsplus.afterAdjAdjustment(mMainStack.convertProcessRecord(app), app.setAdj, app.curAdj, mMainStack.convertLaunchRecord(mMainStack.topRunningActivityLocked(null))); } catch (Exception e) { Log.w(TAG, [LTK] Exception thrown during afterAdjAdjustment failed:, e); } } } /// @} /// M: ALPS00497111 [Volunteer free] LCA Memory Optimized @{ if(FeatureOption.MTK_LCA_RAM_OPTIMIZE) { for(int num = 0; num <= WL_PROCNAME.length -1 ;num++) { if(WL_PROCNAME[num].equals(app.processName) && app.curAdj > ProcessList.HIDDEN_APP_MIN_ADJ) { isWLProc = true; break; } } } //add 如下的code if(FeatureOption.MTK_LCA_RAM_OPTIMIZE) { if (mThirdPartyAppWhiteList.length != mThirdPartyAppAdj.length) { throw new Exception(mThirdPartyAppWhiteList is not match mThirdPartyAppAdj); } for(int num = 0; num <= mThirdPartyAppWhiteList.length -1 ;num++) { if(mThirdPartyAppWhiteList[num].equals(app.processName) && app.curAdj > mThirdPartyAppAdj[num]) { isThirdPartyAppWhiteProcess = true; mThirdPartyAdj = mThirdPartyAppAdj[num]; } } } //add code end if(isWLProc) { if (Process.setOomAdj(app.pid, ProcessList.HIDDEN_APP_MIN_ADJ)) { if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v( TAG, Set + app.pid + + app.processName + adj + ProcessList.HIDDEN_APP_MIN_ADJ + : + app.adjType); app.setAdj = ProcessList.HIDDEN_APP_MIN_ADJ; } else { success = false; Slog.w(TAG, Failed setting oom adj of + app + to + ProcessList.HIDDEN_APP_MIN_ADJ); } } //添加如下的判斷: else if(isThirdPartyAppWhiteProcess) { if (Process.setOomAdj(app.pid, mThirdPartyAdj)) { if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v( TAG, Set + app.pid + + app.processName + adj + mThirdPartyAdj + : + app.adjType); app.setAdj = mThirdPartyAdj; } else { success = false; Slog.w(TAG, Failed setting oom adj of + app + to + mThirdPartyAdj); } } else { if (Process.setOomAdj(app.pid, app.curAdj)) { if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v( TAG, Set + app.pid + + app.processName + adj + app.curAdj + : + app.adjType); app.setAdj = app.curAdj; } else { success = false; Slog.w(TAG, Failed setting oom adj of + app + to + app.curAdj); } } /// @} } if (app.setSchedGroup != app.curSchedGroup) { app.setSchedGroup = app.curSchedGroup; if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v(TAG, Setting process group of + app.processName + to + app.curSchedGroup); if (app.waitingToKill != null && app.setSchedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE) { Slog.i(TAG, Killing + app.toShortString() + : + app.waitingToKill); EventLog.writeEvent(EventLogTags.AM_KILL, app.userId, app.pid, app.processName, app.setAdj, app.waitingToKill); app.killedBackground = true; Process.killProcessQuiet(app.pid); success = false; } else { if (true) { long oldId = Binder.clearCallingIdentity(); try { Process.setProcessGroup(app.pid, app.curSchedGroup); } catch (Exception e) { Slog.w(TAG, Failed setting process group of + app.pid + to + app.curSchedGroup); e.printStackTrace(); } finally { Binder.restoreCallingIdentity(oldId); } } else { if (app.thread != null) { try { app.thread.setSchedulingGroup(app.curSchedGroup); } catch (RemoteException e) { } } } } } return success; }
0x00為了避免我們的so文件被動態分析,我們通常在so中加入一些反調試代碼,常見的Android native反調試方法有以下幾種。1、直接調用ptrace(PTRAC
在Android中,每個應用程序都有自己的進程,當需要在不同的進程之間傳遞對象時,該如何實現呢?顯然, Java中是不支持跨進程內存共享的。因此要傳遞對象,需要把
我們知道Intent的應用,可以啟動別一個Activity,那麼是否可以啟動別外的一個應用程序呢,答案是可以的。1、首先我們新建一個Android應用,名為Another
昨天將框架整合完成,現在我主要實現昨天的需求,實現商品的列表查詢,這時要涉及到jsp和serveilet知識,不清楚的朋友可以趕緊去補充下知識。1、商品列表的實現1.1、