Fix issue #5321282: Force Stop Button in Battery Screen Not disabled correctly

If the app had activities still finishing, when we checked whether it was
now stopped we would get told no.  Also some other improvements:

- Schedule an idle as part of the force stop, to get any finishing
  activities out of the stack soon rather than waiting for some activity
  to idle.
- Don't filter out stopped system apps.  This is dangerous because
  system apps may have no way for the user to explicitly launch them,
  so they could get put into a stopped state for which there is no way
  to get them out.  Also if the user really wants a system app to not
  run, the new disabling mechanism is more appropriate.

Change-Id: I34003f21dac29e2ca0f66a23b88c710de41bab99
diff --git a/services/java/com/android/server/am/ActivityStack.java b/services/java/com/android/server/am/ActivityStack.java
index a0aedf9..35dee3c 100644
--- a/services/java/com/android/server/am/ActivityStack.java
+++ b/services/java/com/android/server/am/ActivityStack.java
@@ -765,9 +765,7 @@
                 // Still need to tell some activities to stop; can't sleep yet.
                 if (DEBUG_PAUSE) Slog.v(TAG, "Sleep still need to stop "
                         + mStoppingActivities.size() + " activities");
-                Message msg = Message.obtain();
-                msg.what = IDLE_NOW_MSG;
-                mHandler.sendMessage(msg);
+                scheduleIdleLocked();
                 return;
             }
 
@@ -978,9 +976,7 @@
                         // then give up on things going idle and start clearing
                         // them out.
                         if (DEBUG_PAUSE) Slog.v(TAG, "To many pending stops, forcing idle");
-                        Message msg = Message.obtain();
-                        msg.what = IDLE_NOW_MSG;
-                        mHandler.sendMessage(msg);
+                        scheduleIdleLocked();
                     } else {
                         checkReadyForSleepLocked();
                     }
@@ -3103,6 +3099,12 @@
         return stops;
     }
 
+    final void scheduleIdleLocked() {
+        Message msg = Message.obtain();
+        msg.what = IDLE_NOW_MSG;
+        mHandler.sendMessage(msg);
+    }
+
     final ActivityRecord activityIdleInternal(IBinder token, boolean fromTimeout,
             Configuration config) {
         if (localLOGV) Slog.v(TAG, "Activity idle: " + token);
@@ -3413,9 +3415,7 @@
                     // If we already have a few activities waiting to stop,
                     // then give up on things going idle and start clearing
                     // them out.
-                    Message msg = Message.obtain();
-                    msg.what = IDLE_NOW_MSG;
-                    mHandler.sendMessage(msg);
+                    scheduleIdleLocked();
                 } else {
                     checkReadyForSleepLocked();
                 }