Improve shutdown process to send broadcast for applications.

This introduces a new class in the base platform for performing a clean
shutdown (which was copied from the classes in the policies).  It
includes new features to send a shutdown broadcast for applications
to do cleanup, and ot have the activity manager pause the current
activity before proceeding with the shutdown.  These facilities are
also use to write at the most recent stat files for sync, battery
and user activity.
diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java
index 53e6f34..541f413 100644
--- a/core/java/android/app/ActivityManagerNative.java
+++ b/core/java/android/app/ActivityManagerNative.java
@@ -990,6 +990,14 @@
             return true;
         }
         
+        case SHUTDOWN_TRANSACTION: {
+            data.enforceInterface(IActivityManager.descriptor);
+            boolean res = shutdown(data.readInt());
+            reply.writeNoException();
+            reply.writeInt(res ? 1 : 0);
+            return true;
+        }
+        
         case PEEK_SERVICE_TRANSACTION: {
             data.enforceInterface(IActivityManager.descriptor);
             Intent service = Intent.CREATOR.createFromParcel(data);
@@ -2160,5 +2168,19 @@
         return res;
     }
     
+    public boolean shutdown(int timeout) throws RemoteException
+    {
+        Parcel data = Parcel.obtain();
+        Parcel reply = Parcel.obtain();
+        data.writeInterfaceToken(IActivityManager.descriptor);
+        data.writeInt(timeout);
+        mRemote.transact(SHUTDOWN_TRANSACTION, data, reply, 0);
+        reply.readException();
+        boolean res = reply.readInt() != 0;
+        reply.recycle();
+        data.recycle();
+        return res;
+    }
+    
     private IBinder mRemote;
 }