Merge "MediaScanner: Clear file path before deleting records to avoid accidental file deletions"
diff --git a/core/jni/android_text_format_Time.cpp b/core/jni/android_text_format_Time.cpp
index 69c6021..776733c 100644
--- a/core/jni/android_text_format_Time.cpp
+++ b/core/jni/android_text_format_Time.cpp
@@ -69,7 +69,7 @@
     t->t.tm_yday = env->GetIntField(o, g_ydayField);
     t->t.tm_isdst = env->GetIntField(o, g_isdstField);
     t->t.tm_gmtoff = env->GetLongField(o, g_gmtoffField);
-    bool allDay = env->GetIntField(o, g_allDayField);
+    bool allDay = env->GetBooleanField(o, g_allDayField);
     if (allDay &&
 	((t->t.tm_sec !=0) || (t->t.tm_min != 0) || (t->t.tm_hour != 0))) {
         char msg[100];
@@ -162,7 +162,7 @@
 {
     Time t;
     if (!java2time(env, &t, This)) return env->NewStringUTF("");
-    bool allDay = env->GetIntField(This, g_allDayField);
+    bool allDay = env->GetBooleanField(This, g_allDayField);
     
     if (!allDay) {
         ACQUIRE_TIMEZONE(This, t)
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java
index 8ebb07c..62a263e 100644
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -2580,6 +2580,7 @@
         public IBinder mSourceRef = null;
         public String mClientId;
         public int mFocusChangeType;
+        public AudioFocusDeathHandler mHandler;
         public String mPackageName;
         public int mCallingUid;
 
@@ -2587,15 +2588,23 @@
         }
 
         public FocusStackEntry(int streamType, int duration,
-                IAudioFocusDispatcher afl, IBinder source, String id, String pn, int uid) {
+                IAudioFocusDispatcher afl, IBinder source, String id, AudioFocusDeathHandler hdlr,
+                String pn, int uid) {
             mStreamType = streamType;
             mFocusDispatcher = afl;
             mSourceRef = source;
             mClientId = id;
             mFocusChangeType = duration;
+            mHandler = hdlr;
             mPackageName = pn;
             mCallingUid = uid;
         }
+
+        public void unlinkToDeath() {
+            if (mSourceRef != null && mHandler != null) {
+                mSourceRef.unlinkToDeath(mHandler, 0);
+            }
+        }
     }
 
     private Stack<FocusStackEntry> mFocusStack = new Stack<FocusStackEntry>();
@@ -2630,7 +2639,8 @@
         if (!mFocusStack.empty() && mFocusStack.peek().mClientId.equals(clientToRemove))
         {
             //Log.i(TAG, "   removeFocusStackEntry() removing top of stack");
-            mFocusStack.pop();
+            FocusStackEntry fse = mFocusStack.pop();
+            fse.unlinkToDeath();
             if (signal) {
                 // notify the new top of the stack it gained focus
                 notifyTopOfAudioFocusStack();
@@ -2649,6 +2659,7 @@
                     Log.i(TAG, " AudioFocus  abandonAudioFocus(): removing entry for "
                             + fse.mClientId);
                     stackIterator.remove();
+                    fse.unlinkToDeath();
                 }
             }
         }
@@ -2764,9 +2775,20 @@
             // focus requester might already be somewhere below in the stack, remove it
             removeFocusStackEntry(clientId, false);
 
+            // handle the potential premature death of the new holder of the focus
+            // (premature death == death before abandoning focus)
+            // Register for client death notification
+            AudioFocusDeathHandler afdh = new AudioFocusDeathHandler(cb);
+            try {
+                cb.linkToDeath(afdh, 0);
+            } catch (RemoteException e) {
+                // client has already died!
+                Log.w(TAG, "AudioFocus  requestAudioFocus() could not link to "+cb+" binder death");
+            }
+
             // push focus requester at the top of the audio focus stack
             mFocusStack.push(new FocusStackEntry(mainStreamType, focusChangeHint, fd, cb,
-                    clientId, callingPackageName, Binder.getCallingUid()));
+                    clientId, afdh, callingPackageName, Binder.getCallingUid()));
 
             // there's a new top of the stack, let the remote control know
             synchronized(mRCStack) {
@@ -2774,17 +2796,6 @@
             }
         }//synchronized(mAudioFocusLock)
 
-        // handle the potential premature death of the new holder of the focus
-        // (premature death == death before abandoning focus)
-        // Register for client death notification
-        AudioFocusDeathHandler afdh = new AudioFocusDeathHandler(cb);
-        try {
-            cb.linkToDeath(afdh, 0);
-        } catch (RemoteException e) {
-            // client has already died!
-            Log.w(TAG, "AudioFocus  requestAudioFocus() could not link to "+cb+" binder death");
-        }
-
         return AudioManager.AUDIOFOCUS_REQUEST_GRANTED;
     }