Merge change I715333b8 into eclair

* changes:
  Add support for dumping RS objects to aid in debugging of white blocks bug.
diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java
index 70af91f..809e230 100644
--- a/core/java/android/server/BluetoothService.java
+++ b/core/java/android/server/BluetoothService.java
@@ -172,6 +172,10 @@
 
     public boolean isEnabled() {
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+        return isEnabledInternal();
+    }
+
+    private boolean isEnabledInternal() {
         return mBluetoothState == BluetoothAdapter.STATE_ON;
     }
 
@@ -328,7 +332,7 @@
         public void handleMessage(Message msg) {
             switch (msg.what) {
             case MESSAGE_REGISTER_SDP_RECORDS:
-                if (!isEnabled()) {
+                if (!isEnabledInternal()) {
                     return;
                 }
                 // SystemService.start() forks sdptool to register service
@@ -375,7 +379,7 @@
                 break;
             case MESSAGE_DISCOVERABLE_TIMEOUT:
                 int mode = msg.arg1;
-                if (isEnabled()) {
+                if (isEnabledInternal()) {
                     // TODO: Switch back to the previous scan mode
                     // This is ok for now, because we only use
                     // CONNECTABLE and CONNECTABLE_DISCOVERABLE
@@ -675,7 +679,9 @@
     }
 
     /*package*/synchronized void getAllProperties() {
+
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+        if (!isEnabledInternal()) return;
         mAdapterProperties.clear();
 
         String properties[] = (String [])getAdapterPropertiesNative();
@@ -734,16 +740,19 @@
     // The following looks dirty.
     private boolean setPropertyString(String key, String value) {
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+        if (!isEnabledInternal()) return false;
         return setAdapterPropertyStringNative(key, value);
     }
 
     private boolean setPropertyInteger(String key, int value) {
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+        if (!isEnabledInternal()) return false;
         return setAdapterPropertyIntegerNative(key, value);
     }
 
     private boolean setPropertyBoolean(String key, boolean value) {
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+        if (!isEnabledInternal()) return false;
         return setAdapterPropertyBooleanNative(key, value ? 1 : 0);
     }
 
@@ -852,7 +861,7 @@
 
     public synchronized int getScanMode() {
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
-        if (!isEnabled())
+        if (!isEnabledInternal())
             return BluetoothAdapter.SCAN_MODE_NONE;
 
         boolean pairable = getProperty("Pairable").equals("true");
@@ -863,15 +872,16 @@
     public synchronized boolean startDiscovery() {
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
                                                 "Need BLUETOOTH_ADMIN permission");
-        if (!isEnabled()) {
-            return false;
-        }
+        if (!isEnabledInternal()) return false;
+
         return startDiscoveryNative();
     }
 
     public synchronized boolean cancelDiscovery() {
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
                                                 "Need BLUETOOTH_ADMIN permission");
+        if (!isEnabledInternal()) return false;
+
         return stopDiscoveryNative();
     }
 
@@ -887,6 +897,8 @@
     public synchronized boolean createBond(String address) {
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
                                                 "Need BLUETOOTH_ADMIN permission");
+        if (!isEnabledInternal()) return false;
+
         if (!BluetoothAdapter.checkBluetoothAddress(address)) {
             return false;
         }
@@ -919,6 +931,8 @@
     public synchronized boolean cancelBondProcess(String address) {
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
                                                 "Need BLUETOOTH_ADMIN permission");
+        if (!isEnabledInternal()) return false;
+
         if (!BluetoothAdapter.checkBluetoothAddress(address)) {
             return false;
         }
@@ -936,6 +950,8 @@
     public synchronized boolean removeBond(String address) {
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
                                                 "Need BLUETOOTH_ADMIN permission");
+        if (!isEnabledInternal()) return false;
+
         if (!BluetoothAdapter.checkBluetoothAddress(address)) {
             return false;
         }
@@ -960,6 +976,8 @@
     }
 
     /*package*/ String[] getRemoteDeviceProperties(String address) {
+        if (!isEnabledInternal()) return null;
+
         String objectPath = getObjectPathFromAddress(address);
         return (String [])getDevicePropertiesNative(objectPath);
     }
@@ -1055,6 +1073,8 @@
             return false;
         }
 
+        if (!isEnabledInternal()) return false;
+
         return setDevicePropertyBooleanNative(getObjectPathFromAddress(address), "Trusted",
                 value ? 1 : 0);
     }
@@ -1144,6 +1164,8 @@
     public synchronized boolean fetchRemoteUuids(String address, ParcelUuid uuid,
             IBluetoothCallback callback) {
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+        if (!isEnabledInternal()) return false;
+
         if (!BluetoothAdapter.checkBluetoothAddress(address)) {
             return false;
         }
@@ -1198,6 +1220,8 @@
      */
     public int getRemoteServiceChannel(String address, ParcelUuid uuid) {
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+        if (!isEnabledInternal()) return -1;
+
         if (!BluetoothAdapter.checkBluetoothAddress(address)) {
             return BluetoothDevice.ERROR;
         }
@@ -1216,6 +1240,8 @@
     public synchronized boolean setPin(String address, byte[] pin) {
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
                                                 "Need BLUETOOTH_ADMIN permission");
+        if (!isEnabledInternal()) return false;
+
         if (pin == null || pin.length <= 0 || pin.length > 16 ||
             !BluetoothAdapter.checkBluetoothAddress(address)) {
             return false;
@@ -1242,6 +1268,8 @@
     public synchronized boolean setPasskey(String address, int passkey) {
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
                                                 "Need BLUETOOTH_ADMIN permission");
+        if (!isEnabledInternal()) return false;
+
         if (passkey < 0 || passkey > 999999 || !BluetoothAdapter.checkBluetoothAddress(address)) {
             return false;
         }
@@ -1259,6 +1287,8 @@
     public synchronized boolean setPairingConfirmation(String address, boolean confirm) {
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
                                                 "Need BLUETOOTH_ADMIN permission");
+        if (!isEnabledInternal()) return false;
+
         address = address.toUpperCase();
         Integer data = mEventLoop.getPasskeyAgentRequestData().remove(address);
         if (data == null) {
@@ -1273,6 +1303,8 @@
     public synchronized boolean cancelPairingUserInput(String address) {
         mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
                                                 "Need BLUETOOTH_ADMIN permission");
+        if (!isEnabledInternal()) return false;
+
         if (!BluetoothAdapter.checkBluetoothAddress(address)) {
             return false;
         }
@@ -1289,7 +1321,7 @@
         return cancelPairingUserInputNative(address, data.intValue());
     }
 
-    public void updateDeviceServiceChannelCache(String address) {
+    /*package*/ void updateDeviceServiceChannelCache(String address) {
         ParcelUuid[] deviceUuids = getRemoteUuids(address);
         // We are storing the rfcomm channel numbers only for the uuids
         // we are interested in.
@@ -1364,8 +1396,9 @@
      */
     public synchronized int addRfcommServiceRecord(String serviceName, ParcelUuid uuid,
             int channel, IBinder b) {
-        mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM,
-                                                "Need BLUETOOTH permission");
+        mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+        if (!isEnabledInternal()) return -1;
+
         if (serviceName == null || uuid == null || channel < 1 ||
                 channel > BluetoothSocket.MAX_RFCOMM_CHANNEL) {
             return -1;
diff --git a/core/java/com/android/internal/widget/ContactHeaderWidget.java b/core/java/com/android/internal/widget/ContactHeaderWidget.java
index d441155..19debec 100644
--- a/core/java/com/android/internal/widget/ContactHeaderWidget.java
+++ b/core/java/com/android/internal/widget/ContactHeaderWidget.java
@@ -119,6 +119,14 @@
         int CONTACT_STATUS_RES_PACKAGE = 8;
         int CONTACT_STATUS_LABEL = 9;
     }
+    
+    private interface PhotoQuery {
+        String[] COLUMNS = new String[] {
+            Photo.PHOTO
+        };
+        
+        int PHOTO = 0;
+    }
 
     //Projection used for looking up contact id from phone number
     protected static final String[] PHONE_LOOKUP_PROJECTION = new String[] {
@@ -144,6 +152,7 @@
     private static final int TOKEN_CONTACT_INFO = 0;
     private static final int TOKEN_PHONE_LOOKUP = 1;
     private static final int TOKEN_EMAIL_LOOKUP = 2;
+    private static final int TOKEN_PHOTO_QUERY = 3;
 
     public ContactHeaderWidget(Context context) {
         this(context, null);
@@ -229,11 +238,36 @@
         protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
             try{
                 switch (token) {
-                    case TOKEN_CONTACT_INFO: {
-                        bindContactInfo(cursor);
+                    case TOKEN_PHOTO_QUERY: {
+                        //Set the photo
+                        Bitmap photoBitmap = null;
+                        if (cursor != null && cursor.moveToFirst() 
+                                && !cursor.isNull(PhotoQuery.PHOTO)) {
+                            byte[] photoData = cursor.getBlob(PhotoQuery.PHOTO);
+                            photoBitmap = BitmapFactory.decodeByteArray(photoData, 0,
+                                    photoData.length, null);
+                        }
+                            
+                        if (photoBitmap == null) {
+                            photoBitmap = loadPlaceholderPhoto(null);
+                        }
+                        mPhotoView.setImageBitmap(photoBitmap);
+                        if (cookie != null && cookie instanceof Uri) {
+                            mPhotoView.assignContactUri((Uri) cookie);
+                        }
                         invalidate();
                         break;
                     }
+                    case TOKEN_CONTACT_INFO: {
+                        if (cursor != null && cursor.moveToFirst()) {
+                            bindContactInfo(cursor);
+                            Uri lookupUri = Contacts.getLookupUri(cursor.getLong(ContactQuery._ID), 
+                                    cursor.getString(ContactQuery.LOOKUP_KEY));
+                            startPhotoQuery(cursor.getLong(ContactQuery.PHOTO_ID), lookupUri);
+                            invalidate();
+                        }
+                        break;
+                    }
                     case TOKEN_PHONE_LOOKUP: {
                         if (cursor != null && cursor.moveToFirst()) {
                             long contactId = cursor.getLong(PHONE_LOOKUP_CONTACT_ID_COLUMN_INDEX);
@@ -375,8 +409,6 @@
      */
     public void bindFromContactUri(Uri contactUri) {
         mContactUri = contactUri;
-        long contactId = ContentUris.parseId(contactUri);
-
         startContactQuery(contactUri);
     }
 
@@ -424,30 +456,24 @@
                 null, null, null);
     }
 
+    protected void startPhotoQuery(long photoId, Uri lookupKey) {
+        mQueryHandler.startQuery(TOKEN_PHOTO_QUERY, lookupKey, 
+                ContentUris.withAppendedId(Data.CONTENT_URI, photoId), PhotoQuery.COLUMNS,
+                null, null, null);
+    }
+    
     /**
      * Bind the contact details provided by the given {@link Cursor}.
      */
     protected void bindContactInfo(Cursor c) {
-        if (c == null || !c.moveToFirst()) return;
-
         // TODO: Bring back phonetic name
         final String displayName = c.getString(ContactQuery.DISPLAY_NAME);
-        final long contactId = c.getLong(ContactQuery._ID);
-        final String lookupKey = c.getString(ContactQuery.LOOKUP_KEY);
         final String phoneticName = null;
         this.setDisplayName(displayName, null);
 
         final boolean starred = c.getInt(ContactQuery.STARRED) != 0;
         mStarredView.setChecked(starred);
 
-        //Set the photo
-        Bitmap photoBitmap = loadContactPhoto(c.getLong(ContactQuery.PHOTO_ID), null);
-        if (photoBitmap == null) {
-            photoBitmap = loadPlaceholderPhoto(null);
-        }
-        mPhotoView.setImageBitmap(photoBitmap);
-        mPhotoView.assignContactUri(Contacts.getLookupUri(contactId, lookupKey));
-
         //Set the presence status
         if (!c.isNull(ContactQuery.CONTACT_PRESENCE_STATUS)) {
             int presence = c.getInt(ContactQuery.CONTACT_PRESENCE_STATUS);
@@ -554,30 +580,6 @@
         }
     }
 
-    private Bitmap loadContactPhoto(long photoId, BitmapFactory.Options options) {
-        Cursor photoCursor = null;
-        Bitmap photoBm = null;
-
-        try {
-            photoCursor = mContentResolver.query(
-                    ContentUris.withAppendedId(Data.CONTENT_URI, photoId),
-                    new String[] { Photo.PHOTO },
-                    null, null, null);
-
-            if (photoCursor != null && photoCursor.moveToFirst() && !photoCursor.isNull(0)) {
-                byte[] photoData = photoCursor.getBlob(0);
-                photoBm = BitmapFactory.decodeByteArray(photoData, 0,
-                        photoData.length, options);
-            }
-        } finally {
-            if (photoCursor != null) {
-                photoCursor.close();
-            }
-        }
-
-        return photoBm;
-    }
-
     private Bitmap loadPlaceholderPhoto(BitmapFactory.Options options) {
         if (mNoPhotoResource == 0) {
             return null;
diff --git a/media/java/android/media/MediaScanner.java b/media/java/android/media/MediaScanner.java
index afdc8f7..da25f97 100644
--- a/media/java/android/media/MediaScanner.java
+++ b/media/java/android/media/MediaScanner.java
@@ -640,10 +640,13 @@
                 map.put(Video.Media.ARTIST, (mArtist != null && mArtist.length() > 0 ? mArtist : MediaFile.UNKNOWN_STRING));
                 map.put(Video.Media.ALBUM, (mAlbum != null && mAlbum.length() > 0 ? mAlbum : MediaFile.UNKNOWN_STRING));
                 map.put(Video.Media.DURATION, mDuration);
+                map.put(Video.Media.DATE_TAKEN, mLastModified);
                 // FIXME - add RESOLUTION
             } else if (MediaFile.isImageFileType(mFileType)) {
                 // FIXME - add DESCRIPTION
-                // map.put(field, value);
+                // DATE_TAKEN will be overridden later if this is a JPEG image whose EXIF data
+                // contains date time information.
+                map.put(Images.Media.DATE_TAKEN, mLastModified);
             } else if (MediaFile.isAudioFileType(mFileType)) {
                 map.put(Audio.Media.ARTIST, (mArtist != null && mArtist.length() > 0 ? mArtist : MediaFile.UNKNOWN_STRING));
                 map.put(Audio.Media.ALBUM, (mAlbum != null && mAlbum.length() > 0 ? mAlbum : MediaFile.UNKNOWN_STRING));
diff --git a/services/java/com/android/server/status/StatusBarService.java b/services/java/com/android/server/status/StatusBarService.java
index 8d73904..1db20df 100644
--- a/services/java/com/android/server/status/StatusBarService.java
+++ b/services/java/com/android/server/status/StatusBarService.java
@@ -85,10 +85,8 @@
 public class StatusBarService extends IStatusBar.Stub
 {
     static final String TAG = "StatusBar";
-    static final boolean DEBUG = false;
     static final boolean SPEW = false;
-    static final boolean DBG = false;
-        
+
     static final int EXPANDED_LEAVE_ALONE = -10000;
     static final int EXPANDED_FULL_OPEN = -10001;
 
@@ -656,7 +654,7 @@
 
     /* private */ void performAddUpdateIcon(IBinder key, IconData data, NotificationData n)
                         throws StatusBarException {
-        if (DBG) {
+        if (SPEW) {
             Log.d(TAG, "performAddUpdateIcon icon=" + data + " notification=" + n + " key=" + key);
         }
         // notification
@@ -748,7 +746,7 @@
 
     /* private */ void performSetIconVisibility(IBinder key, boolean visible) {
         synchronized (mIconMap) {
-            if (DBG) {
+            if (SPEW) {
                 Log.d(TAG, "performSetIconVisibility key=" + key + " visible=" + visible);
             }
             StatusBarIcon icon = mIconMap.get(key);
@@ -758,7 +756,7 @@
     
     /* private */ void performRemoveIcon(IBinder key) {
         synchronized (this) {
-            if (DBG) {
+            if (SPEW) {
                 Log.d(TAG, "performRemoveIcon key=" + key);
             }
             StatusBarIcon icon = mIconMap.remove(key);
@@ -997,7 +995,7 @@
     }
     
     void performExpand() {
-        if (SPEW) Log.d(TAG, "Perform expand: expanded=" + mExpanded);
+        if (SPEW) Log.d(TAG, "performExpand: mExpanded=" + mExpanded);
         if ((mDisabled & StatusBarManager.DISABLE_EXPAND) != 0) {
             return ;
         }
@@ -1022,8 +1020,8 @@
     }
 
     void performCollapse() {
-        if (SPEW) Log.d(TAG, "Perform collapse: expanded=" + mExpanded
-                + " expanded visible=" + mExpandedVisible);
+        if (SPEW) Log.d(TAG, "performCollapse: mExpanded=" + mExpanded
+                + " mExpandedVisible=" + mExpandedVisible);
         
         if (!mExpandedVisible) {
             return;
@@ -1668,7 +1666,7 @@
         // act accordingly
         if ((diff & StatusBarManager.DISABLE_EXPAND) != 0) {
             if ((net & StatusBarManager.DISABLE_EXPAND) != 0) {
-                performCollapse();
+                animateCollapse();
             }
         }
         if ((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) {