Start implementing background restrictions for eph apps.

This implements the additional intended path for checking
allowed background operations, APP_START_MODE_DISABLED, which
doesn't allow an app to launch in the background at all.

Also change the semantics of delivering broadcasts to manifest
receivers to always restrict those, not changing based on
whether the app is currently idle.  This is the desired intended
behavior for apps as they explicitly update to work with
bg check.

And now that we have ephemerality associated with the uid state
in the activity manager, we can propagate this through the
relevant callbacks in IUidObserver so things watching these
changes can immediately determine whether they should do their
more aggressive shut down work for the uid rather than having
to walk through all their state looking for package associated
with that uid and whether they should be shut down.

Also remove the "lenient" bg check mode, since that was
just an early experiment that we won't actually use.

Add a new "make-idle" activity manager command to immediately
put a uid into the idle state (if possible) to make it easier
to test.

Test: manually against an eph app
Change-Id: I43a138ff281f69a9251d3f29ab6e13f48cff8ad6
diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java
index df970a4..4a39e4a 100644
--- a/core/java/android/app/ActivityManager.java
+++ b/core/java/android/app/ActivityManager.java
@@ -102,7 +102,7 @@
         }
 
         @Override
-        public void onUidGone(int uid) {
+        public void onUidGone(int uid, boolean disabled) {
             mListener.onUidImportance(uid, RunningAppProcessInfo.IMPORTANCE_GONE);
         }
 
@@ -111,7 +111,7 @@
         }
 
         @Override
-        public void onUidIdle(int uid) {
+        public void onUidIdle(int uid, boolean disabled) {
         }
     }
 
diff --git a/core/java/android/app/IActivityManager.aidl b/core/java/android/app/IActivityManager.aidl
index 80267205..5e3c028 100644
--- a/core/java/android/app/IActivityManager.aidl
+++ b/core/java/android/app/IActivityManager.aidl
@@ -499,7 +499,7 @@
     boolean supportsLocalVoiceInteraction() = 365;
     void notifyPinnedStackAnimationEnded() = 366;
     void removeStack(int stackId) = 367;
-    void setLenientBackgroundCheck(boolean enabled) = 368;
+    void makePackageIdle(String packageName, int userId) = 368;
     int getMemoryTrimLevel() = 369;
     /**
      * Resizes the pinned stack.
diff --git a/core/java/android/app/IUidObserver.aidl b/core/java/android/app/IUidObserver.aidl
index fa8d0c9..64cb9b1 100644
--- a/core/java/android/app/IUidObserver.aidl
+++ b/core/java/android/app/IUidObserver.aidl
@@ -26,7 +26,7 @@
     /**
      * Report that there are no longer any processes running for a uid.
      */
-    void onUidGone(int uid);
+    void onUidGone(int uid, boolean disabled);
 
     /**
      * Report that a uid is now active (no longer idle).
@@ -37,5 +37,5 @@
      * Report that a uid is idle -- it has either been running in the background for
      * a sufficient period of time, or all of its processes have gone away.
      */
-    void onUidIdle(int uid);
+    void onUidIdle(int uid, boolean disabled);
 }
diff --git a/core/java/android/content/pm/PackageManagerInternal.java b/core/java/android/content/pm/PackageManagerInternal.java
index 1f013ae..2aa7ac6 100644
--- a/core/java/android/content/pm/PackageManagerInternal.java
+++ b/core/java/android/content/pm/PackageManagerInternal.java
@@ -162,6 +162,12 @@
     public abstract boolean isPackageDataProtected(int userId, String packageName);
 
     /**
+     * Returns {@code true} if a given package is installed as ephemeral. Otherwise, returns
+     * {@code false}.
+     */
+    public abstract boolean isPackageEphemeral(int userId, String packageName);
+
+    /**
      * Gets whether the package was ever launched.
      * @param packageName The package name.
      * @param userId The user for which to check.
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 07538dd..79b42ba 100755
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -8629,13 +8629,6 @@
         public static final String ALWAYS_FINISH_ACTIVITIES = "always_finish_activities";
 
         /**
-         * @hide
-         * If not 0, the activity manager will implement a looser version of background
-         * check that is more compatible with existing apps.
-         */
-        public static final String LENIENT_BACKGROUND_CHECK = "lenient_background_check";
-
-        /**
          * Use Dock audio output for media:
          *      0 = disabled
          *      1 = enabled