Loading services/core/java/com/android/server/am/ActivityManagerService.java +43 −15 Original line number Original line Diff line number Diff line Loading @@ -735,11 +735,11 @@ public class ActivityManagerService extends IActivityManager.Stub * <p>NOTE: Callers should avoid acquiring the mPidsSelfLocked lock before calling this * <p>NOTE: Callers should avoid acquiring the mPidsSelfLocked lock before calling this * method. * method. */ */ void put(int key, ProcessRecord value) { void put(ProcessRecord app) { synchronized (this) { synchronized (this) { mPidMap.put(key, value); mPidMap.put(app.pid, app); } } mAtmInternal.onProcessMapped(key, value.getWindowProcessController()); mAtmInternal.onProcessMapped(app.pid, app.getWindowProcessController()); } } /** /** Loading @@ -747,11 +747,18 @@ public class ActivityManagerService extends IActivityManager.Stub * <p>NOTE: Callers should avoid acquiring the mPidsSelfLocked lock before calling this * <p>NOTE: Callers should avoid acquiring the mPidsSelfLocked lock before calling this * method. * method. */ */ void remove(int pid) { void remove(ProcessRecord app) { boolean removed = false; synchronized (this) { synchronized (this) { mPidMap.remove(pid); final ProcessRecord existingApp = mPidMap.get(app.pid); if (existingApp != null && existingApp.startSeq == app.startSeq) { mPidMap.remove(app.pid); removed = true; } } if (removed) { mAtmInternal.onProcessUnMapped(app.pid); } } mAtmInternal.onProcessUnMapped(pid); } } /** /** Loading @@ -759,17 +766,18 @@ public class ActivityManagerService extends IActivityManager.Stub * <p>NOTE: Callers should avoid acquiring the mPidsSelfLocked lock before calling this * <p>NOTE: Callers should avoid acquiring the mPidsSelfLocked lock before calling this * method. * method. */ */ boolean removeIfNoThread(int pid) { boolean removeIfNoThread(ProcessRecord app) { boolean removed = false; boolean removed = false; synchronized (this) { synchronized (this) { final ProcessRecord app = get(pid); final ProcessRecord existingApp = get(app.pid); if (app != null && app.thread == null) { if (existingApp != null && existingApp.startSeq == app.startSeq mPidMap.remove(pid); && app.thread == null) { mPidMap.remove(app.pid); removed = true; removed = true; } } } } if (removed) { if (removed) { mAtmInternal.onProcessUnMapped(pid); mAtmInternal.onProcessUnMapped(app.pid); } } return removed; return removed; } } Loading Loading @@ -1970,7 +1978,7 @@ public class ActivityManagerService extends IActivityManager.Stub app.getWindowProcessController().setPid(MY_PID); app.getWindowProcessController().setPid(MY_PID); app.maxAdj = ProcessList.SYSTEM_ADJ; app.maxAdj = ProcessList.SYSTEM_ADJ; app.makeActive(mSystemThread.getApplicationThread(), mProcessStats); app.makeActive(mSystemThread.getApplicationThread(), mProcessStats); mPidsSelfLocked.put(app.pid, app); mPidsSelfLocked.put(app); mProcessList.updateLruProcessLocked(app, false, null); mProcessList.updateLruProcessLocked(app, false, null); updateOomAdjLocked(OomAdjuster.OOM_ADJ_REASON_NONE); updateOomAdjLocked(OomAdjuster.OOM_ADJ_REASON_NONE); } } Loading Loading @@ -4601,7 +4609,7 @@ public class ActivityManagerService extends IActivityManager.Stub @GuardedBy("this") @GuardedBy("this") private final void processStartTimedOutLocked(ProcessRecord app) { private final void processStartTimedOutLocked(ProcessRecord app) { final int pid = app.pid; final int pid = app.pid; boolean gone = mPidsSelfLocked.removeIfNoThread(pid); boolean gone = mPidsSelfLocked.removeIfNoThread(app); if (gone) { if (gone) { Slog.w(TAG, "Process " + app + " failed to attach"); Slog.w(TAG, "Process " + app + " failed to attach"); Loading Loading @@ -4658,6 +4666,26 @@ public class ActivityManagerService extends IActivityManager.Stub synchronized (mPidsSelfLocked) { synchronized (mPidsSelfLocked) { app = mPidsSelfLocked.get(pid); app = mPidsSelfLocked.get(pid); } } if (app != null && (app.startUid != callingUid || app.startSeq != startSeq)) { String processName = null; final ProcessRecord pending = mProcessList.mPendingStarts.get(startSeq); if (pending != null) { processName = pending.processName; } final String msg = "attachApplicationLocked process:" + processName + " startSeq:" + startSeq + " pid:" + pid + " belongs to another existing app:" + app.processName + " startSeq:" + app.startSeq; Slog.wtf(TAG, msg); // SafetyNet logging for b/131105245. EventLog.writeEvent(0x534e4554, "131105245", app.startUid, msg); // If there is already an app occupying that pid that hasn't been cleaned up cleanUpApplicationRecordLocked(app, false, false, -1, true /*replacingPid*/); mPidsSelfLocked.remove(app); app = null; } } else { } else { app = null; app = null; } } Loading @@ -4666,7 +4694,7 @@ public class ActivityManagerService extends IActivityManager.Stub // update the internal state. // update the internal state. if (app == null && startSeq > 0) { if (app == null && startSeq > 0) { final ProcessRecord pending = mProcessList.mPendingStarts.get(startSeq); final ProcessRecord pending = mProcessList.mPendingStarts.get(startSeq); if (pending != null && pending.startUid == callingUid if (pending != null && pending.startUid == callingUid && pending.startSeq == startSeq && mProcessList.handleProcessStartedLocked(pending, pid, pending && mProcessList.handleProcessStartedLocked(pending, pid, pending .isUsingWrapper(), .isUsingWrapper(), startSeq, true)) { startSeq, true)) { Loading Loading @@ -13642,7 +13670,7 @@ public class ActivityManagerService extends IActivityManager.Stub return true; return true; } else if (app.pid > 0 && app.pid != MY_PID) { } else if (app.pid > 0 && app.pid != MY_PID) { // Goodbye! // Goodbye! mPidsSelfLocked.remove(app.pid); mPidsSelfLocked.remove(app); mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app); mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app); mBatteryStatsService.noteProcessFinish(app.processName, app.info.uid); mBatteryStatsService.noteProcessFinish(app.processName, app.info.uid); if (app.isolated) { if (app.isolated) { services/core/java/com/android/server/am/ProcessList.java +17 −5 Original line number Original line Diff line number Diff line Loading @@ -1445,10 +1445,11 @@ public final class ProcessList { long startTime = SystemClock.elapsedRealtime(); long startTime = SystemClock.elapsedRealtime(); if (app.pid > 0 && app.pid != ActivityManagerService.MY_PID) { if (app.pid > 0 && app.pid != ActivityManagerService.MY_PID) { checkSlow(startTime, "startProcess: removing from pids map"); checkSlow(startTime, "startProcess: removing from pids map"); mService.mPidsSelfLocked.remove(app.pid); mService.mPidsSelfLocked.remove(app); mService.mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app); mService.mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app); checkSlow(startTime, "startProcess: done removing from pids map"); checkSlow(startTime, "startProcess: done removing from pids map"); app.setPid(0); app.setPid(0); app.startSeq = 0; } } if (DEBUG_PROCESSES && mService.mProcessesOnHold.contains(app)) Slog.v( if (DEBUG_PROCESSES && mService.mProcessesOnHold.contains(app)) Slog.v( Loading Loading @@ -1656,6 +1657,14 @@ public final class ProcessList { app.killedByAm = false; app.killedByAm = false; app.removed = false; app.removed = false; app.killed = false; app.killed = false; if (app.startSeq != 0) { Slog.wtf(TAG, "startProcessLocked processName:" + app.processName + " with non-zero startSeq:" + app.startSeq); } if (app.pid != 0) { Slog.wtf(TAG, "startProcessLocked processName:" + app.processName + " with non-zero pid:" + app.pid); } final long startSeq = app.startSeq = ++mProcStartSeqCounter; final long startSeq = app.startSeq = ++mProcStartSeqCounter; app.setStartParams(uid, hostingRecord, seInfo, startTime); app.setStartParams(uid, hostingRecord, seInfo, startTime); app.setUsingWrapper(invokeWith != null app.setUsingWrapper(invokeWith != null Loading Loading @@ -2063,12 +2072,15 @@ public final class ProcessList { // If there is already an app occupying that pid that hasn't been cleaned up // If there is already an app occupying that pid that hasn't been cleaned up if (oldApp != null && !app.isolated) { if (oldApp != null && !app.isolated) { // Clean up anything relating to this pid first // Clean up anything relating to this pid first Slog.w(TAG, "Reusing pid " + pid Slog.wtf(TAG, "handleProcessStartedLocked process:" + app.processName + " while app is still mapped to it"); + " startSeq:" + app.startSeq + " pid:" + pid + " belongs to another existing app:" + oldApp.processName + " startSeq:" + oldApp.startSeq); mService.cleanUpApplicationRecordLocked(oldApp, false, false, -1, mService.cleanUpApplicationRecordLocked(oldApp, false, false, -1, true /*replacingPid*/); true /*replacingPid*/); } } mService.mPidsSelfLocked.put(pid, app); mService.mPidsSelfLocked.put(app); synchronized (mService.mPidsSelfLocked) { synchronized (mService.mPidsSelfLocked) { if (!procAttached) { if (!procAttached) { Message msg = mService.mHandler.obtainMessage(PROC_START_TIMEOUT_MSG); Message msg = mService.mHandler.obtainMessage(PROC_START_TIMEOUT_MSG); Loading Loading @@ -2241,7 +2253,7 @@ public final class ProcessList { .pendingStart)) { .pendingStart)) { int pid = app.pid; int pid = app.pid; if (pid > 0) { if (pid > 0) { mService.mPidsSelfLocked.remove(pid); mService.mPidsSelfLocked.remove(app); mService.mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app); mService.mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app); mService.mBatteryStatsService.noteProcessFinish(app.processName, app.info.uid); mService.mBatteryStatsService.noteProcessFinish(app.processName, app.info.uid); if (app.isolated) { if (app.isolated) { Loading Loading
services/core/java/com/android/server/am/ActivityManagerService.java +43 −15 Original line number Original line Diff line number Diff line Loading @@ -735,11 +735,11 @@ public class ActivityManagerService extends IActivityManager.Stub * <p>NOTE: Callers should avoid acquiring the mPidsSelfLocked lock before calling this * <p>NOTE: Callers should avoid acquiring the mPidsSelfLocked lock before calling this * method. * method. */ */ void put(int key, ProcessRecord value) { void put(ProcessRecord app) { synchronized (this) { synchronized (this) { mPidMap.put(key, value); mPidMap.put(app.pid, app); } } mAtmInternal.onProcessMapped(key, value.getWindowProcessController()); mAtmInternal.onProcessMapped(app.pid, app.getWindowProcessController()); } } /** /** Loading @@ -747,11 +747,18 @@ public class ActivityManagerService extends IActivityManager.Stub * <p>NOTE: Callers should avoid acquiring the mPidsSelfLocked lock before calling this * <p>NOTE: Callers should avoid acquiring the mPidsSelfLocked lock before calling this * method. * method. */ */ void remove(int pid) { void remove(ProcessRecord app) { boolean removed = false; synchronized (this) { synchronized (this) { mPidMap.remove(pid); final ProcessRecord existingApp = mPidMap.get(app.pid); if (existingApp != null && existingApp.startSeq == app.startSeq) { mPidMap.remove(app.pid); removed = true; } } if (removed) { mAtmInternal.onProcessUnMapped(app.pid); } } mAtmInternal.onProcessUnMapped(pid); } } /** /** Loading @@ -759,17 +766,18 @@ public class ActivityManagerService extends IActivityManager.Stub * <p>NOTE: Callers should avoid acquiring the mPidsSelfLocked lock before calling this * <p>NOTE: Callers should avoid acquiring the mPidsSelfLocked lock before calling this * method. * method. */ */ boolean removeIfNoThread(int pid) { boolean removeIfNoThread(ProcessRecord app) { boolean removed = false; boolean removed = false; synchronized (this) { synchronized (this) { final ProcessRecord app = get(pid); final ProcessRecord existingApp = get(app.pid); if (app != null && app.thread == null) { if (existingApp != null && existingApp.startSeq == app.startSeq mPidMap.remove(pid); && app.thread == null) { mPidMap.remove(app.pid); removed = true; removed = true; } } } } if (removed) { if (removed) { mAtmInternal.onProcessUnMapped(pid); mAtmInternal.onProcessUnMapped(app.pid); } } return removed; return removed; } } Loading Loading @@ -1970,7 +1978,7 @@ public class ActivityManagerService extends IActivityManager.Stub app.getWindowProcessController().setPid(MY_PID); app.getWindowProcessController().setPid(MY_PID); app.maxAdj = ProcessList.SYSTEM_ADJ; app.maxAdj = ProcessList.SYSTEM_ADJ; app.makeActive(mSystemThread.getApplicationThread(), mProcessStats); app.makeActive(mSystemThread.getApplicationThread(), mProcessStats); mPidsSelfLocked.put(app.pid, app); mPidsSelfLocked.put(app); mProcessList.updateLruProcessLocked(app, false, null); mProcessList.updateLruProcessLocked(app, false, null); updateOomAdjLocked(OomAdjuster.OOM_ADJ_REASON_NONE); updateOomAdjLocked(OomAdjuster.OOM_ADJ_REASON_NONE); } } Loading Loading @@ -4601,7 +4609,7 @@ public class ActivityManagerService extends IActivityManager.Stub @GuardedBy("this") @GuardedBy("this") private final void processStartTimedOutLocked(ProcessRecord app) { private final void processStartTimedOutLocked(ProcessRecord app) { final int pid = app.pid; final int pid = app.pid; boolean gone = mPidsSelfLocked.removeIfNoThread(pid); boolean gone = mPidsSelfLocked.removeIfNoThread(app); if (gone) { if (gone) { Slog.w(TAG, "Process " + app + " failed to attach"); Slog.w(TAG, "Process " + app + " failed to attach"); Loading Loading @@ -4658,6 +4666,26 @@ public class ActivityManagerService extends IActivityManager.Stub synchronized (mPidsSelfLocked) { synchronized (mPidsSelfLocked) { app = mPidsSelfLocked.get(pid); app = mPidsSelfLocked.get(pid); } } if (app != null && (app.startUid != callingUid || app.startSeq != startSeq)) { String processName = null; final ProcessRecord pending = mProcessList.mPendingStarts.get(startSeq); if (pending != null) { processName = pending.processName; } final String msg = "attachApplicationLocked process:" + processName + " startSeq:" + startSeq + " pid:" + pid + " belongs to another existing app:" + app.processName + " startSeq:" + app.startSeq; Slog.wtf(TAG, msg); // SafetyNet logging for b/131105245. EventLog.writeEvent(0x534e4554, "131105245", app.startUid, msg); // If there is already an app occupying that pid that hasn't been cleaned up cleanUpApplicationRecordLocked(app, false, false, -1, true /*replacingPid*/); mPidsSelfLocked.remove(app); app = null; } } else { } else { app = null; app = null; } } Loading @@ -4666,7 +4694,7 @@ public class ActivityManagerService extends IActivityManager.Stub // update the internal state. // update the internal state. if (app == null && startSeq > 0) { if (app == null && startSeq > 0) { final ProcessRecord pending = mProcessList.mPendingStarts.get(startSeq); final ProcessRecord pending = mProcessList.mPendingStarts.get(startSeq); if (pending != null && pending.startUid == callingUid if (pending != null && pending.startUid == callingUid && pending.startSeq == startSeq && mProcessList.handleProcessStartedLocked(pending, pid, pending && mProcessList.handleProcessStartedLocked(pending, pid, pending .isUsingWrapper(), .isUsingWrapper(), startSeq, true)) { startSeq, true)) { Loading Loading @@ -13642,7 +13670,7 @@ public class ActivityManagerService extends IActivityManager.Stub return true; return true; } else if (app.pid > 0 && app.pid != MY_PID) { } else if (app.pid > 0 && app.pid != MY_PID) { // Goodbye! // Goodbye! mPidsSelfLocked.remove(app.pid); mPidsSelfLocked.remove(app); mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app); mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app); mBatteryStatsService.noteProcessFinish(app.processName, app.info.uid); mBatteryStatsService.noteProcessFinish(app.processName, app.info.uid); if (app.isolated) { if (app.isolated) {
services/core/java/com/android/server/am/ProcessList.java +17 −5 Original line number Original line Diff line number Diff line Loading @@ -1445,10 +1445,11 @@ public final class ProcessList { long startTime = SystemClock.elapsedRealtime(); long startTime = SystemClock.elapsedRealtime(); if (app.pid > 0 && app.pid != ActivityManagerService.MY_PID) { if (app.pid > 0 && app.pid != ActivityManagerService.MY_PID) { checkSlow(startTime, "startProcess: removing from pids map"); checkSlow(startTime, "startProcess: removing from pids map"); mService.mPidsSelfLocked.remove(app.pid); mService.mPidsSelfLocked.remove(app); mService.mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app); mService.mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app); checkSlow(startTime, "startProcess: done removing from pids map"); checkSlow(startTime, "startProcess: done removing from pids map"); app.setPid(0); app.setPid(0); app.startSeq = 0; } } if (DEBUG_PROCESSES && mService.mProcessesOnHold.contains(app)) Slog.v( if (DEBUG_PROCESSES && mService.mProcessesOnHold.contains(app)) Slog.v( Loading Loading @@ -1656,6 +1657,14 @@ public final class ProcessList { app.killedByAm = false; app.killedByAm = false; app.removed = false; app.removed = false; app.killed = false; app.killed = false; if (app.startSeq != 0) { Slog.wtf(TAG, "startProcessLocked processName:" + app.processName + " with non-zero startSeq:" + app.startSeq); } if (app.pid != 0) { Slog.wtf(TAG, "startProcessLocked processName:" + app.processName + " with non-zero pid:" + app.pid); } final long startSeq = app.startSeq = ++mProcStartSeqCounter; final long startSeq = app.startSeq = ++mProcStartSeqCounter; app.setStartParams(uid, hostingRecord, seInfo, startTime); app.setStartParams(uid, hostingRecord, seInfo, startTime); app.setUsingWrapper(invokeWith != null app.setUsingWrapper(invokeWith != null Loading Loading @@ -2063,12 +2072,15 @@ public final class ProcessList { // If there is already an app occupying that pid that hasn't been cleaned up // If there is already an app occupying that pid that hasn't been cleaned up if (oldApp != null && !app.isolated) { if (oldApp != null && !app.isolated) { // Clean up anything relating to this pid first // Clean up anything relating to this pid first Slog.w(TAG, "Reusing pid " + pid Slog.wtf(TAG, "handleProcessStartedLocked process:" + app.processName + " while app is still mapped to it"); + " startSeq:" + app.startSeq + " pid:" + pid + " belongs to another existing app:" + oldApp.processName + " startSeq:" + oldApp.startSeq); mService.cleanUpApplicationRecordLocked(oldApp, false, false, -1, mService.cleanUpApplicationRecordLocked(oldApp, false, false, -1, true /*replacingPid*/); true /*replacingPid*/); } } mService.mPidsSelfLocked.put(pid, app); mService.mPidsSelfLocked.put(app); synchronized (mService.mPidsSelfLocked) { synchronized (mService.mPidsSelfLocked) { if (!procAttached) { if (!procAttached) { Message msg = mService.mHandler.obtainMessage(PROC_START_TIMEOUT_MSG); Message msg = mService.mHandler.obtainMessage(PROC_START_TIMEOUT_MSG); Loading Loading @@ -2241,7 +2253,7 @@ public final class ProcessList { .pendingStart)) { .pendingStart)) { int pid = app.pid; int pid = app.pid; if (pid > 0) { if (pid > 0) { mService.mPidsSelfLocked.remove(pid); mService.mPidsSelfLocked.remove(app); mService.mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app); mService.mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app); mService.mBatteryStatsService.noteProcessFinish(app.processName, app.info.uid); mService.mBatteryStatsService.noteProcessFinish(app.processName, app.info.uid); if (app.isolated) { if (app.isolated) { Loading