Merge "Support for triggering the lockscreen while the screen is on:"
diff --git a/core/java/com/android/internal/backup/IBackupTransport.aidl b/core/java/com/android/internal/backup/IBackupTransport.aidl
index a830ebd..9da1066 100644
--- a/core/java/com/android/internal/backup/IBackupTransport.aidl
+++ b/core/java/com/android/internal/backup/IBackupTransport.aidl
@@ -102,7 +102,7 @@
     int finishBackup();
 
     /**
-     * Get the set of backups currently available over this transport.
+     * Get the set of all backups currently available over this transport.
      *
      * @return Descriptions of the set of restore images available for this device,
      *   or null if an error occurred (the attempt should be rescheduled).
@@ -110,11 +110,22 @@
     RestoreSet[] getAvailableRestoreSets();
 
     /**
+     * Get the identifying token of the backup set currently being stored from
+     * this device.  This is used in the case of applications wishing to restore
+     * their last-known-good data.
+     *
+     * @return A token that can be passed to {@link #startRestore}, or 0 if there
+     *   is no backup set available corresponding to the current device state.
+     */
+    long getCurrentRestoreSet();
+
+    /**
      * Start restoring application data from backup.  After calling this function,
      * alternate calls to {@link #nextRestorePackage} and {@link #nextRestoreData}
      * to walk through the actual application data.
      *
-     * @param token A backup token as returned by {@link #getAvailableRestoreSets}.
+     * @param token A backup token as returned by {@link #getAvailableRestoreSets}
+     *   or {@link #getCurrentRestoreSet}.
      * @param packages List of applications to restore (if data is available).
      *   Application data will be restored in the order given.
      * @return One of {@link BackupConstants#TRANSPORT_OK} (OK so far, call
diff --git a/core/java/com/android/internal/backup/LocalTransport.java b/core/java/com/android/internal/backup/LocalTransport.java
index 12bc5a8..23ec6470 100644
--- a/core/java/com/android/internal/backup/LocalTransport.java
+++ b/core/java/com/android/internal/backup/LocalTransport.java
@@ -33,6 +33,9 @@
     private static final String TRANSPORT_DIR_NAME
             = "com.android.internal.backup.LocalTransport";
 
+    // The single hardcoded restore set always has the same (nonzero!) token
+    private static final long RESTORE_TOKEN = 1;
+
     private Context mContext;
     private PackageManager mPackageManager;
     private File mDataDir = new File(Environment.getDownloadCacheDirectory(), "backup");
@@ -149,11 +152,16 @@
     // Restore handling
     public RestoreSet[] getAvailableRestoreSets() throws android.os.RemoteException {
         // one hardcoded restore set
-        RestoreSet set = new RestoreSet("Local disk image", "flash", 0);
+        RestoreSet set = new RestoreSet("Local disk image", "flash", RESTORE_TOKEN);
         RestoreSet[] array = { set };
         return array;
     }
 
+    public long getCurrentRestoreSet() {
+        // The hardcoded restore set always has the same token
+        return RESTORE_TOKEN;
+    }
+
     public int startRestore(long token, PackageInfo[] packages) {
         if (DEBUG) Log.v(TAG, "start restore " + token);
         mRestorePackages = packages;
diff --git a/include/media/stagefright/AudioPlayer.h b/include/media/stagefright/AudioPlayer.h
index 71344e6..26fcc95 100644
--- a/include/media/stagefright/AudioPlayer.h
+++ b/include/media/stagefright/AudioPlayer.h
@@ -47,7 +47,7 @@
     // Return time in us.
     virtual int64_t getRealTimeUs();
 
-    void start();
+    status_t start();
 
     void pause();
     void resume();
diff --git a/media/libstagefright/AudioPlayer.cpp b/media/libstagefright/AudioPlayer.cpp
index 14842c0..efe7ebb 100644
--- a/media/libstagefright/AudioPlayer.cpp
+++ b/media/libstagefright/AudioPlayer.cpp
@@ -58,12 +58,15 @@
     mSource = source;
 }
 
-void AudioPlayer::start() {
+status_t AudioPlayer::start() {
     CHECK(!mStarted);
     CHECK(mSource != NULL);
 
     status_t err = mSource->start();
-    CHECK_EQ(err, OK);
+
+    if (err != OK) {
+        return err;
+    }
 
     sp<MetaData> format = mSource->getFormat();
     const char *mime;
@@ -83,7 +86,11 @@
                 mSampleRate, numChannels, AudioSystem::PCM_16_BIT,
                 DEFAULT_AUDIOSINK_BUFFERCOUNT,
                 &AudioPlayer::AudioSinkCallback, this);
-        CHECK_EQ(err, OK);
+        if (err != OK) {
+            mSource->stop();
+
+            return err;
+        }
 
         mLatencyUs = (int64_t)mAudioSink->latency() * 1000;
         mFrameSize = mAudioSink->frameSize();
@@ -97,7 +104,14 @@
                     : AudioSystem::CHANNEL_OUT_MONO,
                 8192, 0, &AudioCallback, this, 0);
 
-        CHECK_EQ(mAudioTrack->initCheck(), OK);
+        if (mAudioTrack->initCheck() != OK) {
+            delete mAudioTrack;
+            mAudioTrack = NULL;
+
+            mSource->stop();
+
+            return mAudioTrack->initCheck();
+        }
 
         mLatencyUs = (int64_t)mAudioTrack->latency() * 1000;
         mFrameSize = mAudioTrack->frameSize();
@@ -106,6 +120,8 @@
     }
 
     mStarted = true;
+
+    return OK;
 }
 
 void AudioPlayer::pause() {
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index 85019aa..4e7738e 100644
--- a/media/libstagefright/AwesomePlayer.cpp
+++ b/media/libstagefright/AwesomePlayer.cpp
@@ -378,7 +378,16 @@
                         &AwesomePlayer::AudioNotify, this);
 
                 mAudioPlayer->setSource(mAudioSource);
-                mAudioPlayer->start();
+                status_t err = mAudioPlayer->start();
+
+                if (err != OK) {
+                    delete mAudioPlayer;
+                    mAudioPlayer = NULL;
+
+                    mFlags &= ~(PLAYING | FIRST_FRAME);
+
+                    return err;
+                }
 
                 delete mTimeSource;
                 mTimeSource = mAudioPlayer;