Loading services/core/java/com/android/server/am/ActiveServices.java +66 −1 Original line number Diff line number Diff line Loading @@ -121,6 +121,10 @@ public final class ActiveServices { // at the same time. final int mMaxStartingBackground; // Flag to reschedule the services during app launch. Disable by default. private static final boolean SERVICE_RESCHEDULE = SystemProperties.getBoolean("ro.am.reschedule_service", false); final SparseArray<ServiceMap> mServiceMap = new SparseArray<>(); /** Loading Loading @@ -1229,6 +1233,14 @@ public final class ActiveServices { r.pendingStarts.add(0, si); long dur = SystemClock.uptimeMillis() - si.deliveredTime; dur *= 2; if (SERVICE_RESCHEDULE && DEBUG_DELAYED_SERVICE) { Slog.w(TAG,"Can add more delay !!!" +" si.deliveredTime "+si.deliveredTime +" dur "+dur +" si.deliveryCount "+si.deliveryCount +" si.doneExecutingCount "+si.doneExecutingCount +" allowCancel "+allowCancel); } if (minDuration < dur) minDuration = dur; if (resetTime < dur) resetTime = dur; } else { Loading @@ -1241,6 +1253,13 @@ public final class ActiveServices { } r.totalRestartCount++; if (SERVICE_RESCHEDULE && DEBUG_DELAYED_SERVICE) { Slog.w(TAG,"r.name "+r.name+" N "+N+" minDuration "+minDuration +" resetTime "+resetTime+" now "+now +" r.restartDelay "+r.restartDelay +" r.restartTime+resetTime "+(r.restartTime+resetTime) +" allowCancel "+allowCancel); } if (r.restartDelay == 0) { r.restartCount++; r.restartDelay = minDuration; Loading @@ -1262,6 +1281,14 @@ public final class ActiveServices { } r.nextRestartTime = now + r.restartDelay; if (SERVICE_RESCHEDULE && DEBUG_DELAYED_SERVICE) { Slog.w(TAG,"r.name "+r.name+" N "+N+" minDuration "+minDuration +" resetTime "+resetTime+" now "+now +" r.restartDelay "+r.restartDelay +" r.restartTime+resetTime "+(r.restartTime+resetTime) +" r.nextRestartTime "+r.nextRestartTime +" allowCancel "+allowCancel); } // Make sure that we don't end up restarting a bunch of services // all at the same time. Loading Loading @@ -1304,6 +1331,15 @@ public final class ActiveServices { r.nextRestartTime = SystemClock.uptimeMillis() + r.restartDelay; Slog.w(TAG, "Scheduling restart of crashed service " + r.shortName + " in " + r.restartDelay + "ms"); if (SERVICE_RESCHEDULE && DEBUG_DELAYED_SERVICE) { for (int i=mRestartingServices.size()-1; i>=0; i--) { ServiceRecord r2 = mRestartingServices.get(i); Slog.w(TAG,"Restarting list - i "+i+" r2.nextRestartTime " +r2.nextRestartTime+" r2.name "+r2.name); } } EventLog.writeEvent(EventLogTags.AM_SCHEDULE_SERVICE_RESTART, r.userId, r.shortName, r.restartDelay); Loading @@ -1315,7 +1351,31 @@ public final class ActiveServices { return; } try { if(SERVICE_RESCHEDULE == true) { boolean shouldDelay = false; ActivityRecord top_rc = null; ActivityStack stack = mAm.getFocusedStack(); if(stack != null) { top_rc = stack.topRunningActivityLocked(null); } if(top_rc != null) { if(!top_rc.nowVisible && !r.shortName.contains(top_rc.packageName)) { shouldDelay = true; } } if(!shouldDelay) { bringUpServiceLocked(r, r.intent.getIntent().getFlags(), r.createdFromFg, true); } else { if (DEBUG_DELAYED_SERVICE) { Slog.v(TAG, "Reschedule service restart due to app launch" +" r.shortName "+r.shortName+" r.app = "+r.app); } r.resetRestartCounter(); scheduleServiceRestartLocked(r, true); } } else { bringUpServiceLocked(r, r.intent.getIntent().getFlags(), r.createdFromFg, true); } } catch (TransactionTooLargeException e) { // Ignore, it's been logged and nothing upstack cares. } Loading Loading @@ -1538,6 +1598,11 @@ public final class ActiveServices { if (newService) { app.services.remove(r); r.app = null; if (SERVICE_RESCHEDULE && DEBUG_DELAYED_SERVICE) { Slog.w(TAG, " Failed to create Service !!!! ." +"This will introduce huge delay... " +r.shortName + " in " + r.restartDelay + "ms"); } } // Retry. Loading Loading
services/core/java/com/android/server/am/ActiveServices.java +66 −1 Original line number Diff line number Diff line Loading @@ -121,6 +121,10 @@ public final class ActiveServices { // at the same time. final int mMaxStartingBackground; // Flag to reschedule the services during app launch. Disable by default. private static final boolean SERVICE_RESCHEDULE = SystemProperties.getBoolean("ro.am.reschedule_service", false); final SparseArray<ServiceMap> mServiceMap = new SparseArray<>(); /** Loading Loading @@ -1229,6 +1233,14 @@ public final class ActiveServices { r.pendingStarts.add(0, si); long dur = SystemClock.uptimeMillis() - si.deliveredTime; dur *= 2; if (SERVICE_RESCHEDULE && DEBUG_DELAYED_SERVICE) { Slog.w(TAG,"Can add more delay !!!" +" si.deliveredTime "+si.deliveredTime +" dur "+dur +" si.deliveryCount "+si.deliveryCount +" si.doneExecutingCount "+si.doneExecutingCount +" allowCancel "+allowCancel); } if (minDuration < dur) minDuration = dur; if (resetTime < dur) resetTime = dur; } else { Loading @@ -1241,6 +1253,13 @@ public final class ActiveServices { } r.totalRestartCount++; if (SERVICE_RESCHEDULE && DEBUG_DELAYED_SERVICE) { Slog.w(TAG,"r.name "+r.name+" N "+N+" minDuration "+minDuration +" resetTime "+resetTime+" now "+now +" r.restartDelay "+r.restartDelay +" r.restartTime+resetTime "+(r.restartTime+resetTime) +" allowCancel "+allowCancel); } if (r.restartDelay == 0) { r.restartCount++; r.restartDelay = minDuration; Loading @@ -1262,6 +1281,14 @@ public final class ActiveServices { } r.nextRestartTime = now + r.restartDelay; if (SERVICE_RESCHEDULE && DEBUG_DELAYED_SERVICE) { Slog.w(TAG,"r.name "+r.name+" N "+N+" minDuration "+minDuration +" resetTime "+resetTime+" now "+now +" r.restartDelay "+r.restartDelay +" r.restartTime+resetTime "+(r.restartTime+resetTime) +" r.nextRestartTime "+r.nextRestartTime +" allowCancel "+allowCancel); } // Make sure that we don't end up restarting a bunch of services // all at the same time. Loading Loading @@ -1304,6 +1331,15 @@ public final class ActiveServices { r.nextRestartTime = SystemClock.uptimeMillis() + r.restartDelay; Slog.w(TAG, "Scheduling restart of crashed service " + r.shortName + " in " + r.restartDelay + "ms"); if (SERVICE_RESCHEDULE && DEBUG_DELAYED_SERVICE) { for (int i=mRestartingServices.size()-1; i>=0; i--) { ServiceRecord r2 = mRestartingServices.get(i); Slog.w(TAG,"Restarting list - i "+i+" r2.nextRestartTime " +r2.nextRestartTime+" r2.name "+r2.name); } } EventLog.writeEvent(EventLogTags.AM_SCHEDULE_SERVICE_RESTART, r.userId, r.shortName, r.restartDelay); Loading @@ -1315,7 +1351,31 @@ public final class ActiveServices { return; } try { if(SERVICE_RESCHEDULE == true) { boolean shouldDelay = false; ActivityRecord top_rc = null; ActivityStack stack = mAm.getFocusedStack(); if(stack != null) { top_rc = stack.topRunningActivityLocked(null); } if(top_rc != null) { if(!top_rc.nowVisible && !r.shortName.contains(top_rc.packageName)) { shouldDelay = true; } } if(!shouldDelay) { bringUpServiceLocked(r, r.intent.getIntent().getFlags(), r.createdFromFg, true); } else { if (DEBUG_DELAYED_SERVICE) { Slog.v(TAG, "Reschedule service restart due to app launch" +" r.shortName "+r.shortName+" r.app = "+r.app); } r.resetRestartCounter(); scheduleServiceRestartLocked(r, true); } } else { bringUpServiceLocked(r, r.intent.getIntent().getFlags(), r.createdFromFg, true); } } catch (TransactionTooLargeException e) { // Ignore, it's been logged and nothing upstack cares. } Loading Loading @@ -1538,6 +1598,11 @@ public final class ActiveServices { if (newService) { app.services.remove(r); r.app = null; if (SERVICE_RESCHEDULE && DEBUG_DELAYED_SERVICE) { Slog.w(TAG, " Failed to create Service !!!! ." +"This will introduce huge delay... " +r.shortName + " in " + r.restartDelay + "ms"); } } // Retry. Loading