Merge "Remove long_press when WebView lost window focus. Reset touch mode too." into froyo
diff --git a/api/current.xml b/api/current.xml
index 1ac6812..f9470d9 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -27412,17 +27412,6 @@
 <parameter name="context" type="android.content.Context">
 </parameter>
 </constructor>
-<method name="beginRestoreSession"
- return="android.app.backup.RestoreSession"
- abstract="false"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-</method>
 <method name="dataChanged"
  return="void"
  abstract="false"
@@ -27447,6 +27436,19 @@
 <parameter name="packageName" type="java.lang.String">
 </parameter>
 </method>
+<method name="requestRestore"
+ return="int"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="observer" type="android.app.backup.RestoreObserver">
+</parameter>
+</method>
 </class>
 <class name="FileBackupHelper"
  extends="android.app.backup.FileBackupHelperBase"
@@ -27540,41 +27542,6 @@
 >
 </constructor>
 </class>
-<class name="RestoreSession"
- extends="java.lang.Object"
- abstract="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<method name="endRestoreSession"
- return="void"
- abstract="false"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-</method>
-<method name="restorePackage"
- return="int"
- abstract="false"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<parameter name="packageName" type="java.lang.String">
-</parameter>
-<parameter name="observer" type="android.app.backup.RestoreObserver">
-</parameter>
-</method>
-</class>
 <class name="SharedPreferencesBackupHelper"
  extends="android.app.backup.FileBackupHelperBase"
  abstract="false"
diff --git a/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java b/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java
index d040b44..fa8a7c8 100644
--- a/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java
+++ b/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java
@@ -278,8 +278,8 @@
             System.out.println("restoreStarting: " + numPackages + " packages");
         }
 
-        public void onUpdate(int nowBeingRestored) {
-            System.out.println("onUpdate: " + nowBeingRestored);
+        public void onUpdate(int nowBeingRestored, String currentPackage) {
+            System.out.println("onUpdate: " + nowBeingRestored + " = " + currentPackage);
         }
 
         public void restoreFinished(int error) {
diff --git a/core/java/android/app/backup/BackupManager.java b/core/java/android/app/backup/BackupManager.java
index 2da8b56..dff0695 100644
--- a/core/java/android/app/backup/BackupManager.java
+++ b/core/java/android/app/backup/BackupManager.java
@@ -115,8 +115,45 @@
     }
 
     /**
+     * Restore the calling application from backup.  The data will be restored from the
+     * current backup dataset if the application has stored data there, or from
+     * the dataset used during the last full device setup operation if the current
+     * backup dataset has no matching data.  If no backup data exists for this application
+     * in either source, a nonzero value will be returned.
+     *
+     * <p>If this method returns zero (meaning success), the OS will attempt to retrieve
+     * a backed-up dataset from the remote transport, instantiate the application's
+     * backup agent, and pass the dataset to the agent's
+     * {@link android.app.backup.BackupAgent#onRestore(BackupDataInput, int, android.os.ParcelFileDescriptor) onRestore()}
+     * method.
+     *
+     * @return Zero on success; nonzero on error.
+     */
+    public int requestRestore(RestoreObserver observer) {
+        int result = -1;
+        checkServiceBinder();
+        if (sService != null) {
+            RestoreSession session = null;
+            try {
+                String transport = sService.getCurrentTransport();
+                IRestoreSession binder = sService.beginRestoreSession(transport);
+                session = new RestoreSession(mContext, binder);
+                result = session.restorePackage(mContext.getPackageName(), observer);
+            } catch (RemoteException e) {
+                Log.w(TAG, "restoreSelf() unable to contact service");
+            } finally {
+                if (session != null) {
+                    session.endRestoreSession();
+                }
+            }
+        }
+        return result;
+    }
+
+    /**
      * Begin the process of restoring data from backup.  See the
      * {@link android.app.backup.RestoreSession} class for documentation on that process.
+     * @hide
      */
     public RestoreSession beginRestoreSession() {
         RestoreSession session = null;
diff --git a/core/java/android/app/backup/IRestoreObserver.aidl b/core/java/android/app/backup/IRestoreObserver.aidl
index 75d0d17..ec85683 100644
--- a/core/java/android/app/backup/IRestoreObserver.aidl
+++ b/core/java/android/app/backup/IRestoreObserver.aidl
@@ -37,8 +37,9 @@
      *
      * @param nowBeingRestored The index, between 1 and the numPackages parameter
      *   to the restoreStarting() callback, of the package now being restored.
+     * @param currentPackage The name of the package now being restored.
      */
-    void onUpdate(int nowBeingRestored);
+    void onUpdate(int nowBeingRestored, String curentPackage);
 
     /**
      * The restore operation has completed.
diff --git a/core/java/android/app/backup/RestoreObserver.java b/core/java/android/app/backup/RestoreObserver.java
index 7a5e10b..0a4ea17 100644
--- a/core/java/android/app/backup/RestoreObserver.java
+++ b/core/java/android/app/backup/RestoreObserver.java
@@ -16,6 +16,8 @@
 
 package android.app.backup;
 
+import java.lang.String;
+
 /**
  * Callback class for receiving progress reports during a restore operation.  These
  * methods will all be called on your application's main thread.
@@ -32,17 +34,23 @@
 
     /**
      * An indication of which package is being restored currently, out of the
-     * total number provided in the restoreStarting() callback.  This method
-     * is not guaranteed to be called.
+     * total number provided in the {@link #restoreStarting(int)} callback.  This method
+     * is not guaranteed to be called: if the transport is unable to obtain
+     * data for one or more of the requested packages, no onUpdate() call will
+     * occur for those packages.
      *
      * @param nowBeingRestored The index, between 1 and the numPackages parameter
-     *   to the restoreStarting() callback, of the package now being restored.
+     *   to the {@link #restoreStarting(int)} callback, of the package now being
+     *   restored.  This may be non-monotonic; it is intended purely as a rough
+     *   indication of the backup manager's progress through the overall restore process.
+     * @param currentPackage The name of the package now being restored.
      */
-    void onUpdate(int nowBeingRestored) {
+    void onUpdate(int nowBeingRestored, String currentPackage) {
     }
 
     /**
-     * The restore operation has completed.
+     * The restore process has completed.  This method will always be called,
+     * even if no individual package restore operations were attempted.
      *
      * @param error Zero on success; a nonzero error code if the restore operation
      *   as a whole failed.
diff --git a/core/java/android/app/backup/RestoreSession.java b/core/java/android/app/backup/RestoreSession.java
index 730a21f..da2778b 100644
--- a/core/java/android/app/backup/RestoreSession.java
+++ b/core/java/android/app/backup/RestoreSession.java
@@ -27,7 +27,8 @@
 import android.util.Log;
 
 /**
- * Interface for applications to use when managing a restore session.
+ * Interface for managing a restore session.
+ * @hide
  */
 public class RestoreSession {
     static final String TAG = "RestoreSession";
@@ -44,8 +45,6 @@
      *   and a String array under the key "names" whose entries are the user-meaningful
      *   text corresponding to the backup sets at each index in the tokens array.
      *   On error, returns null.
-     *
-     * {@hide}
      */
     public RestoreSet[] getAvailableRestoreSets() {
         try {
@@ -68,8 +67,6 @@
      *   the restore set that should be used.
      * @param observer If non-null, this binder points to an object that will receive
      *   progress callbacks during the restore operation.
-     *
-     * {@hide}
      */
     public int restoreAll(long token, RestoreObserver observer) {
         int err = -1;
@@ -164,7 +161,7 @@
                         mAppObserver.restoreStarting(msg.arg1);
                         break;
                     case MSG_UPDATE:
-                        mAppObserver.onUpdate(msg.arg1);
+                        mAppObserver.onUpdate(msg.arg1, (String)msg.obj);
                         break;
                     case MSG_RESTORE_FINISHED:
                         mAppObserver.restoreFinished(msg.arg1);
@@ -181,9 +178,9 @@
                     mHandler.obtainMessage(MSG_RESTORE_STARTING, numPackages, 0));
         }
 
-        public void onUpdate(int nowBeingRestored) {
+        public void onUpdate(int nowBeingRestored, String currentPackage) {
             mHandler.sendMessage(
-                    mHandler.obtainMessage(MSG_UPDATE, nowBeingRestored, 0));
+                    mHandler.obtainMessage(MSG_UPDATE, nowBeingRestored, 0, currentPackage));
         }
 
         public void restoreFinished(int error) {
diff --git a/core/tests/coretests/AndroidManifest.xml b/core/tests/coretests/AndroidManifest.xml
index 6a7c6ec..eb005ce 100644
--- a/core/tests/coretests/AndroidManifest.xml
+++ b/core/tests/coretests/AndroidManifest.xml
@@ -74,6 +74,16 @@
     <!-- package manager test permissions -->
     <uses-permission android:name="android.permission.INSTALL_PACKAGES" />
     <uses-permission android:name="android.permission.DELETE_PACKAGES" />
+    <uses-permission android:name="android.permission.MOVE_PACKAGE" />
+
+    <!--os storage test permissions -->
+    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
+    <uses-permission android:name="android.permission.ASEC_ACCESS" />
+    <uses-permission android:name="android.permission.ASEC_CREATE" />
+    <uses-permission android:name="android.permission.ASEC_DESTROY" />
+    <uses-permission android:name="android.permission.ASEC_MOUNT_UNMOUNT" />
+    <uses-permission android:name="android.permission.ASEC_RENAME" />
+    <uses-permission android:name="android.permission.SHUTDOWN" />
 
     <application android:theme="@style/Theme">
         <uses-library android:name="android.test.runner" />
diff --git a/tests/AndroidTests/res/raw/install b/core/tests/coretests/res/raw/install
similarity index 100%
rename from tests/AndroidTests/res/raw/install
rename to core/tests/coretests/res/raw/install
Binary files differ
diff --git a/tests/AndroidTests/res/raw/install_decl_perm b/core/tests/coretests/res/raw/install_decl_perm
similarity index 100%
rename from tests/AndroidTests/res/raw/install_decl_perm
rename to core/tests/coretests/res/raw/install_decl_perm
Binary files differ
diff --git a/tests/AndroidTests/res/raw/install_loc_auto b/core/tests/coretests/res/raw/install_loc_auto
similarity index 100%
rename from tests/AndroidTests/res/raw/install_loc_auto
rename to core/tests/coretests/res/raw/install_loc_auto
Binary files differ
diff --git a/tests/AndroidTests/res/raw/install_loc_internal b/core/tests/coretests/res/raw/install_loc_internal
similarity index 100%
rename from tests/AndroidTests/res/raw/install_loc_internal
rename to core/tests/coretests/res/raw/install_loc_internal
Binary files differ
diff --git a/tests/AndroidTests/res/raw/install_loc_sdcard b/core/tests/coretests/res/raw/install_loc_sdcard
similarity index 100%
rename from tests/AndroidTests/res/raw/install_loc_sdcard
rename to core/tests/coretests/res/raw/install_loc_sdcard
Binary files differ
diff --git a/tests/AndroidTests/res/raw/install_loc_unspecified b/core/tests/coretests/res/raw/install_loc_unspecified
similarity index 100%
rename from tests/AndroidTests/res/raw/install_loc_unspecified
rename to core/tests/coretests/res/raw/install_loc_unspecified
Binary files differ
diff --git a/tests/AndroidTests/res/raw/install_use_perm_good b/core/tests/coretests/res/raw/install_use_perm_good
similarity index 100%
rename from tests/AndroidTests/res/raw/install_use_perm_good
rename to core/tests/coretests/res/raw/install_use_perm_good
Binary files differ
diff --git a/tests/AndroidTests/src/com/android/unit_tests/PackageManagerTests.java b/core/tests/coretests/src/android/content/pm/PackageManagerTests.java
similarity index 97%
rename from tests/AndroidTests/src/com/android/unit_tests/PackageManagerTests.java
rename to core/tests/coretests/src/android/content/pm/PackageManagerTests.java
index 449661c..7b9e95a 100755
--- a/tests/AndroidTests/src/com/android/unit_tests/PackageManagerTests.java
+++ b/core/tests/coretests/src/android/content/pm/PackageManagerTests.java
@@ -14,61 +14,37 @@
  * limitations under the License.
  */
 
-package com.android.unit_tests;
+package android.content.pm;
 
+import com.android.frameworks.coretests.R;
 import com.android.internal.content.PackageHelper;
 
-import android.os.storage.IMountService.Stub;
-
-import android.net.Uri;
-import android.os.FileUtils;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import android.app.PendingIntent;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.IPackageDataObserver;
-import android.content.pm.IPackageInstallObserver;
-import android.content.pm.IPackageDeleteObserver;
-import android.content.pm.IPackageMoveObserver;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageParser;
-import android.content.pm.PackageStats;
-import android.content.pm.IPackageManager;
-import android.content.pm.PermissionInfo;
 import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.res.Resources;
 import android.content.res.Resources.NotFoundException;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.LargeTest;
-import android.test.suitebuilder.annotation.MediumTest;
-import android.test.suitebuilder.annotation.SmallTest;
-import android.test.suitebuilder.annotation.Suppress;
-import android.util.DisplayMetrics;
-import android.util.Log;
+import android.net.Uri;
 import android.os.Environment;
-import android.os.Handler;
+import android.os.FileUtils;
 import android.os.IBinder;
-import android.os.storage.IMountService;
-import android.os.storage.IMountServiceListener;
-import android.os.storage.StorageEventListener;
-import android.os.storage.StorageManager;
-import android.os.storage.StorageResultCode;
 import android.os.RemoteException;
 import android.os.ServiceManager;
 import android.os.StatFs;
+import android.os.storage.IMountService;
+import android.os.storage.StorageListener;
+import android.os.storage.StorageManager;
+import android.os.storage.StorageResultCode;
 import android.provider.Settings;
 import android.provider.Settings.SettingNotFoundException;
+import android.test.AndroidTestCase;
+import android.util.DisplayMetrics;
+import android.util.Log;
+
+import java.io.File;
+import java.io.InputStream;
 
 public class PackageManagerTests extends AndroidTestCase {
     private static final boolean localLOGV = true;
@@ -573,17 +549,14 @@
         return ip;
     }
 
-    @MediumTest
     public void testInstallNormalInternal() {
         sampleInstallFromRawResource(0, true);
     }
 
-    @MediumTest
     public void testInstallFwdLockedInternal() {
         sampleInstallFromRawResource(PackageManager.INSTALL_FORWARD_LOCK, true);
     }
 
-    @MediumTest
     public void testInstallSdcard() {
         sampleInstallFromRawResource(PackageManager.INSTALL_EXTERNAL, true);
     }
@@ -674,33 +647,27 @@
         }
     }
 
-    @MediumTest
     public void testReplaceFailNormalInternal() {
         replaceFromRawResource(0);
     }
 
-    @MediumTest
     public void testReplaceFailFwdLockedInternal() {
         replaceFromRawResource(PackageManager.INSTALL_FORWARD_LOCK);
     }
 
-    @MediumTest
     public void testReplaceFailSdcard() {
         replaceFromRawResource(PackageManager.INSTALL_EXTERNAL);
     }
 
-    @MediumTest
     public void testReplaceNormalInternal() {
         replaceFromRawResource(PackageManager.INSTALL_REPLACE_EXISTING);
     }
 
-    @MediumTest
     public void testReplaceFwdLockedInternal() {
         replaceFromRawResource(PackageManager.INSTALL_REPLACE_EXISTING |
                 PackageManager.INSTALL_FORWARD_LOCK);
     }
 
-    @MediumTest
     public void testReplaceSdcard() {
         replaceFromRawResource(PackageManager.INSTALL_REPLACE_EXISTING |
                 PackageManager.INSTALL_EXTERNAL);
@@ -815,32 +782,26 @@
         }
     }
 
-    @MediumTest
     public void testDeleteNormalInternal() {
         deleteFromRawResource(0, 0);
     }
 
-    @MediumTest
     public void testDeleteFwdLockedInternal() {
         deleteFromRawResource(PackageManager.INSTALL_FORWARD_LOCK, 0);
     }
 
-    @MediumTest
     public void testDeleteSdcard() {
         deleteFromRawResource(PackageManager.INSTALL_EXTERNAL, 0);
     }
 
-    @MediumTest
     public void testDeleteNormalInternalRetainData() {
         deleteFromRawResource(0, PackageManager.DONT_DELETE_DATA);
     }
 
-    @MediumTest
     public void testDeleteFwdLockedInternalRetainData() {
         deleteFromRawResource(PackageManager.INSTALL_FORWARD_LOCK, PackageManager.DONT_DELETE_DATA);
     }
 
-    @MediumTest
     public void testDeleteSdcardRetainData() {
         deleteFromRawResource(PackageManager.INSTALL_EXTERNAL, PackageManager.DONT_DELETE_DATA);
     }
@@ -947,27 +908,7 @@
         }
     }
 
-    class StorageListener extends StorageEventListener {
-        String oldState;
-        String newState;
-        String path;
-        private boolean doneFlag = false;
-        @Override
-        public void onStorageStateChanged(String path, String oldState, String newState) {
-            if (localLOGV) Log.i(TAG, "Storage state changed from " + oldState + " to " + newState);
-            synchronized (this) {
-                this.oldState = oldState;
-                this.newState = newState;
-                this.path = path;
-                doneFlag = true;
-                notifyAll();
-            }
-        }
 
-        public boolean isDone() {
-            return doneFlag;
-        }
-    }
 
     private boolean unmountMedia() {
         if (!getMediaState()) {
diff --git a/tests/AndroidTests/src/com/android/unit_tests/AsecTests.java b/core/tests/coretests/src/android/os/storage/AsecTests.java
similarity index 95%
rename from tests/AndroidTests/src/com/android/unit_tests/AsecTests.java
rename to core/tests/coretests/src/android/os/storage/AsecTests.java
index 9a75047..dda3010 100755
--- a/tests/AndroidTests/src/com/android/unit_tests/AsecTests.java
+++ b/core/tests/coretests/src/android/os/storage/AsecTests.java
@@ -14,43 +14,19 @@
  * limitations under the License.
  */
 
-package com.android.unit_tests;
+package android.os.storage;
 
-import com.android.unit_tests.PackageManagerTests.StorageListener;
-
-import android.os.storage.IMountService.Stub;
-
-import android.net.Uri;
-import android.os.FileUtils;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
 import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.Suppress;
-import android.util.DisplayMetrics;
-import android.util.Log;
 import android.os.Environment;
-import android.os.Handler;
 import android.os.IBinder;
-import android.os.storage.IMountService;
-import android.os.storage.IMountShutdownObserver;
-import android.os.storage.StorageEventListener;
-import android.os.storage.StorageManager;
-import android.os.storage.StorageResultCode;
 import android.os.RemoteException;
 import android.os.ServiceManager;
-import android.os.StatFs;
-import android.provider.Settings;
+import android.test.AndroidTestCase;
+import android.util.Log;
+
+import java.io.File;
+import java.io.FileOutputStream;
+
 import junit.framework.Assert;
 
 public class AsecTests extends AndroidTestCase {
diff --git a/core/tests/coretests/src/android/os/storage/StorageListener.java b/core/tests/coretests/src/android/os/storage/StorageListener.java
new file mode 100644
index 0000000..d6dae22
--- /dev/null
+++ b/core/tests/coretests/src/android/os/storage/StorageListener.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.os.storage;
+
+import android.util.Log;
+
+public class StorageListener extends StorageEventListener {
+    private static final boolean localLOGV = true;
+
+    public static final String TAG="StorageListener";
+
+    String oldState;
+    String newState;
+    String path;
+    private boolean doneFlag = false;
+    @Override
+    public void onStorageStateChanged(String path, String oldState, String newState) {
+        if (localLOGV) Log.i(TAG, "Storage state changed from " + oldState + " to " + newState);
+        synchronized (this) {
+            this.oldState = oldState;
+            this.newState = newState;
+            this.path = path;
+            doneFlag = true;
+            notifyAll();
+        }
+    }
+
+    public boolean isDone() {
+        return doneFlag;
+    }
+}
diff --git a/services/java/com/android/server/BackupManagerService.java b/services/java/com/android/server/BackupManagerService.java
index dae7f9c..7607c74 100644
--- a/services/java/com/android/server/BackupManagerService.java
+++ b/services/java/com/android/server/BackupManagerService.java
@@ -1618,7 +1618,7 @@
 
                     if (mObserver != null) {
                         try {
-                            mObserver.onUpdate(count);
+                            mObserver.onUpdate(count, packageName);
                         } catch (RemoteException e) {
                             Slog.d(TAG, "Restore observer died in onUpdate");
                             mObserver = null;