Fix issue #3001368: API REVIEW: android.app.Activity

Bye bye, lots of junk.

Change-Id: Idd72fc525851277362b2a1ff3bb0f7865fe655fd
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index 72bf825..2c4babb 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -1631,35 +1631,11 @@
     }
 
     /**
-     * @deprecated This functionality will be removed in the future; please do
-     * not use.
-     *
-     * Control whether this activity is required to be persistent.  By default
-     * activities are not persistent; setting this to true will prevent the
-     * system from stopping this activity or its process when running low on
-     * resources.
-     * 
-     * <p><em>You should avoid using this method</em>, it has severe negative
-     * consequences on how well the system can manage its resources.  A better
-     * approach is to implement an application service that you control with
-     * {@link Context#startService} and {@link Context#stopService}.
-     * 
-     * @param isPersistent Control whether the current activity must be
-     *                     persistent, true if so, false for the normal
-     *                     behavior.
+     * @deprecated As of {@link android.os.Build.VERSION_CODES#GINGERBREAD}
+     * this is a no-op.
      */
     @Deprecated
     public void setPersistent(boolean isPersistent) {
-        if (mParent == null) {
-            try {
-                ActivityManagerNative.getDefault()
-                    .setPersistent(mToken, isPersistent);
-            } catch (RemoteException e) {
-                // Empty
-            }
-        } else {
-            throw new RuntimeException("setPersistent() not yet supported for embedded activities");
-        }
     }
 
     /**
diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java
index 89812ab..d6231ea 100644
--- a/core/java/android/app/ActivityManagerNative.java
+++ b/core/java/android/app/ActivityManagerNative.java
@@ -345,17 +345,6 @@
             return true;
         }
 
-        case SET_PERSISTENT_TRANSACTION: {
-            data.enforceInterface(IActivityManager.descriptor);
-            IBinder token = data.readStrongBinder();
-            boolean isPersistent = data.readInt() != 0;
-            if (token != null) {
-                setPersistent(token, isPersistent);
-            }
-            reply.writeNoException();
-            return true;
-        }
-
         case ATTACH_APPLICATION_TRANSACTION: {
             data.enforceInterface(IActivityManager.descriptor);
             IApplicationThread app = ApplicationThreadNative.asInterface(
@@ -1589,18 +1578,6 @@
         data.recycle();
         reply.recycle();
     }
-    public void setPersistent(IBinder token, boolean isPersistent) throws RemoteException
-    {
-        Parcel data = Parcel.obtain();
-        Parcel reply = Parcel.obtain();
-        data.writeInterfaceToken(IActivityManager.descriptor);
-        data.writeStrongBinder(token);
-        data.writeInt(isPersistent ? 1 : 0);
-        mRemote.transact(SET_PERSISTENT_TRANSACTION, data, reply, 0);
-        reply.readException();
-        data.recycle();
-        reply.recycle();
-    }
     public void attachApplication(IApplicationThread app) throws RemoteException
     {
         Parcel data = Parcel.obtain();
diff --git a/core/java/android/app/IActivityManager.java b/core/java/android/app/IActivityManager.java
index 28af0d3..83d422e 100644
--- a/core/java/android/app/IActivityManager.java
+++ b/core/java/android/app/IActivityManager.java
@@ -116,7 +116,6 @@
     public void unbroadcastIntent(IApplicationThread caller, Intent intent) throws RemoteException;
     /* oneway */
     public void finishReceiver(IBinder who, int resultCode, String resultData, Bundle map, boolean abortBroadcast) throws RemoteException;
-    public void setPersistent(IBinder token, boolean isPersistent) throws RemoteException;
     public void attachApplication(IApplicationThread app) throws RemoteException;
     /* oneway */
     public void activityIdle(IBinder token, Configuration config) throws RemoteException;
@@ -444,7 +443,7 @@
     int REPORT_THUMBNAIL_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+27;
     int GET_CONTENT_PROVIDER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+28;
     int PUBLISH_CONTENT_PROVIDERS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+29;
-    int SET_PERSISTENT_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+30;
+    
     int FINISH_SUB_ACTIVITY_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+31;
     int GET_RUNNING_SERVICE_CONTROL_PANEL_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+32;
     int START_SERVICE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+33;
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index 50054bd..9c06c33 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -2993,84 +2993,6 @@
         }
     }
     
-    final void decPersistentCountLocked(ProcessRecord app) {
-        app.persistentActivities--;
-        if (app.persistentActivities > 0) {
-            // Still more of 'em...
-            return;
-        }
-        if (app.persistent) {
-            // Ah, but the application itself is persistent.  Whatever!
-            return;
-        }
-
-        // App is no longer persistent...  make sure it and the ones
-        // following it in the LRU list have the correc oom_adj.
-        updateOomAdjLocked();
-    }
-
-    public void setPersistent(IBinder token, boolean isPersistent) {
-        if (checkCallingPermission(android.Manifest.permission.PERSISTENT_ACTIVITY)
-                != PackageManager.PERMISSION_GRANTED) {
-            String msg = "Permission Denial: setPersistent() from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid()
-                    + " requires " + android.Manifest.permission.PERSISTENT_ACTIVITY;
-            Slog.w(TAG, msg);
-            throw new SecurityException(msg);
-        }
-
-        synchronized(this) {
-            int index = mMainStack.indexOfTokenLocked(token);
-            if (index < 0) {
-                return;
-            }
-            ActivityRecord r = (ActivityRecord)mMainStack.mHistory.get(index);
-            ProcessRecord app = r.app;
-
-            if (localLOGV) Slog.v(
-                TAG, "Setting persistence " + isPersistent + ": " + r);
-
-            if (isPersistent) {
-                if (r.persistent) {
-                    // Okay okay, I heard you already!
-                    if (localLOGV) Slog.v(TAG, "Already persistent!");
-                    return;
-                }
-                r.persistent = true;
-                app.persistentActivities++;
-                if (localLOGV) Slog.v(TAG, "Num persistent now: " + app.persistentActivities);
-                if (app.persistentActivities > 1) {
-                    // We aren't the first...
-                    if (localLOGV) Slog.v(TAG, "Not the first!");
-                    return;
-                }
-                if (app.persistent) {
-                    // This would be redundant.
-                    if (localLOGV) Slog.v(TAG, "App is persistent!");
-                    return;
-                }
-
-                // App is now persistent...  make sure it and the ones
-                // following it now have the correct oom_adj.
-                final long origId = Binder.clearCallingIdentity();
-                updateOomAdjLocked();
-                Binder.restoreCallingIdentity(origId);
-
-            } else {
-                if (!r.persistent) {
-                    // Okay okay, I heard you already!
-                    return;
-                }
-                r.persistent = false;
-                final long origId = Binder.clearCallingIdentity();
-                decPersistentCountLocked(app);
-                Binder.restoreCallingIdentity(origId);
-
-            }
-        }
-    }
-    
     public boolean clearApplicationUserData(final String packageName,
             final IPackageDataObserver observer) {
         int uid = Binder.getCallingUid();
@@ -11585,11 +11507,6 @@
             adj = FOREGROUND_APP_ADJ;
             schedGroup = Process.THREAD_GROUP_DEFAULT;
             app.adjType = "instrumentation";
-        } else if (app.persistentActivities > 0) {
-            // Special persistent activities...  shouldn't be used these days.
-            adj = FOREGROUND_APP_ADJ;
-            schedGroup = Process.THREAD_GROUP_DEFAULT;
-            app.adjType = "persistent";
         } else if (app.curReceiver != null ||
                 (mPendingBroadcast != null && mPendingBroadcast.curApp == app)) {
             // An app that is currently receiving a broadcast also
@@ -12313,8 +12230,7 @@
                     final ProcessRecord app = mLruProcesses.get(i);
 
                     if (app.persistent || app.services.size() != 0
-                            || app.curReceiver != null
-                            || app.persistentActivities > 0) {
+                            || app.curReceiver != null) {
                         // Don't count processes holding services against our
                         // maximum process count.
                         if (localLOGV) Slog.v(
@@ -12379,8 +12295,7 @@
                     // Quit the application only if we have a state saved for
                     // all of its activities.
                     boolean canQuit = !app.persistent && app.curReceiver == null
-                        && app.services.size() == 0
-                        && app.persistentActivities == 0;
+                        && app.services.size() == 0;
                     int NUMA = app.activities.size();
                     int j;
                     if (Config.LOGV) Slog.v(
@@ -12444,7 +12359,7 @@
                 // We can finish this one if we have its icicle saved and
                 // it is not persistent.
                 if ((r.haveState || !r.stateNotNeeded) && !r.visible
-                        && r.stopped && !r.persistent && !r.finishing) {
+                        && r.stopped && !r.finishing) {
                     final int origSize = mMainStack.mLRUActivities.size();
                     r.stack.destroyActivityLocked(r, true);
 
diff --git a/services/java/com/android/server/am/ActivityRecord.java b/services/java/com/android/server/am/ActivityRecord.java
index 53b08d0..4d773e49 100644
--- a/services/java/com/android/server/am/ActivityRecord.java
+++ b/services/java/com/android/server/am/ActivityRecord.java
@@ -96,7 +96,6 @@
     int configChangeFlags;  // which config values have changed
     boolean keysPaused;     // has key dispatching been paused for it?
     boolean inHistory;      // are we in the history stack?
-    boolean persistent;     // requested to be persistent?
     int launchMode;         // the launch mode activity attribute.
     boolean visible;        // does this activity's window need to be shown?
     boolean waitingVisible; // true if waiting for a new act to become vis
@@ -160,7 +159,6 @@
                 pw.print(" finishing="); pw.println(finishing);
         pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused);
                 pw.print(" inHistory="); pw.print(inHistory);
-                pw.print(" persistent="); pw.print(persistent);
                 pw.print(" launchMode="); pw.println(launchMode);
         pw.print(prefix); pw.print("fullscreen="); pw.print(fullscreen);
                 pw.print(" visible="); pw.print(visible);
@@ -213,7 +211,6 @@
         configDestroy = false;
         keysPaused = false;
         inHistory = false;
-        persistent = false;
         visible = true;
         waitingVisible = false;
         nowVisible = false;
diff --git a/services/java/com/android/server/am/ActivityStack.java b/services/java/com/android/server/am/ActivityStack.java
index 9ed1242..016ddcd 100644
--- a/services/java/com/android/server/am/ActivityStack.java
+++ b/services/java/com/android/server/am/ActivityStack.java
@@ -3151,9 +3151,6 @@
                     mService.mHandler.sendEmptyMessage(
                             ActivityManagerService.CANCEL_HEAVY_NOTIFICATION_MSG);
                 }
-                if (r.persistent) {
-                    mService.decPersistentCountLocked(r.app);
-                }
                 if (r.app.activities.size() == 0) {
                     // No longer have activities, so update location in
                     // LRU list.
@@ -3452,54 +3449,49 @@
             return true;
         }
         
-        // If the activity isn't persistent, there is a chance we will
-        // need to restart it.
-        if (!r.persistent) {
-
-            // Figure out what has changed between the two configurations.
-            int changes = oldConfig.diff(newConfig);
-            if (DEBUG_SWITCH || DEBUG_CONFIGURATION) {
-                Slog.v(TAG, "Checking to restart " + r.info.name + ": changed=0x"
-                        + Integer.toHexString(changes) + ", handles=0x"
-                        + Integer.toHexString(r.info.configChanges)
-                        + ", newConfig=" + newConfig);
+        // Figure out what has changed between the two configurations.
+        int changes = oldConfig.diff(newConfig);
+        if (DEBUG_SWITCH || DEBUG_CONFIGURATION) {
+            Slog.v(TAG, "Checking to restart " + r.info.name + ": changed=0x"
+                    + Integer.toHexString(changes) + ", handles=0x"
+                    + Integer.toHexString(r.info.configChanges)
+                    + ", newConfig=" + newConfig);
+        }
+        if ((changes&(~r.info.configChanges)) != 0) {
+            // Aha, the activity isn't handling the change, so DIE DIE DIE.
+            r.configChangeFlags |= changes;
+            r.startFreezingScreenLocked(r.app, globalChanges);
+            if (r.app == null || r.app.thread == null) {
+                if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
+                        "Switch is destroying non-running " + r);
+                destroyActivityLocked(r, true);
+            } else if (r.state == ActivityState.PAUSING) {
+                // A little annoying: we are waiting for this activity to
+                // finish pausing.  Let's not do anything now, but just
+                // flag that it needs to be restarted when done pausing.
+                if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
+                        "Switch is skipping already pausing " + r);
+                r.configDestroy = true;
+                return true;
+            } else if (r.state == ActivityState.RESUMED) {
+                // Try to optimize this case: the configuration is changing
+                // and we need to restart the top, resumed activity.
+                // Instead of doing the normal handshaking, just say
+                // "restart!".
+                if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
+                        "Switch is restarting resumed " + r);
+                relaunchActivityLocked(r, r.configChangeFlags, true);
+                r.configChangeFlags = 0;
+            } else {
+                if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
+                        "Switch is restarting non-resumed " + r);
+                relaunchActivityLocked(r, r.configChangeFlags, false);
+                r.configChangeFlags = 0;
             }
-            if ((changes&(~r.info.configChanges)) != 0) {
-                // Aha, the activity isn't handling the change, so DIE DIE DIE.
-                r.configChangeFlags |= changes;
-                r.startFreezingScreenLocked(r.app, globalChanges);
-                if (r.app == null || r.app.thread == null) {
-                    if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
-                            "Switch is destroying non-running " + r);
-                    destroyActivityLocked(r, true);
-                } else if (r.state == ActivityState.PAUSING) {
-                    // A little annoying: we are waiting for this activity to
-                    // finish pausing.  Let's not do anything now, but just
-                    // flag that it needs to be restarted when done pausing.
-                    if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
-                            "Switch is skipping already pausing " + r);
-                    r.configDestroy = true;
-                    return true;
-                } else if (r.state == ActivityState.RESUMED) {
-                    // Try to optimize this case: the configuration is changing
-                    // and we need to restart the top, resumed activity.
-                    // Instead of doing the normal handshaking, just say
-                    // "restart!".
-                    if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
-                            "Switch is restarting resumed " + r);
-                    relaunchActivityLocked(r, r.configChangeFlags, true);
-                    r.configChangeFlags = 0;
-                } else {
-                    if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
-                            "Switch is restarting non-resumed " + r);
-                    relaunchActivityLocked(r, r.configChangeFlags, false);
-                    r.configChangeFlags = 0;
-                }
-                
-                // All done...  tell the caller we weren't able to keep this
-                // activity around.
-                return false;
-            }
+            
+            // All done...  tell the caller we weren't able to keep this
+            // activity around.
+            return false;
         }
         
         // Default case: the activity can handle this new configuration, so
diff --git a/services/java/com/android/server/am/ProcessRecord.java b/services/java/com/android/server/am/ProcessRecord.java
index 404c6be..353ff6d 100644
--- a/services/java/com/android/server/am/ProcessRecord.java
+++ b/services/java/com/android/server/am/ProcessRecord.java
@@ -115,7 +115,6 @@
     Dialog anrDialog;           // dialog being displayed due to app not resp.
     boolean removed;            // has app package been removed from device?
     boolean debugging;          // was app launched for debugging?
-    int persistentActivities;   // number of activities that are persistent
     boolean waitedForDebugger;  // has process show wait for debugger dialog?
     Dialog waitDialog;          // current wait for debugger dialog
     
@@ -181,8 +180,7 @@
                 pw.print(" foregroundServices="); pw.print(foregroundServices);
                 pw.print(" forcingToForeground="); pw.println(forcingToForeground);
         pw.print(prefix); pw.print("persistent="); pw.print(persistent);
-                pw.print(" removed="); pw.print(removed);
-                pw.print(" persistentActivities="); pw.println(persistentActivities);
+                pw.print(" removed="); pw.println(removed);
         pw.print(prefix); pw.print("adjSeq="); pw.print(adjSeq);
                 pw.print(" lruSeq="); pw.println(lruSeq);
         if (!keeping) {
@@ -259,7 +257,6 @@
         curAdj = setAdj = -100;
         persistent = false;
         removed = false;
-        persistentActivities = 0;
     }
 
     public void setPid(int _pid) {