Merge "Revive drop shadow of SuggestionWindow."
diff --git a/core/java/com/android/internal/app/LocaleHelper.java b/core/java/com/android/internal/app/LocaleHelper.java
index 71c2c21..c7459d7 100644
--- a/core/java/com/android/internal/app/LocaleHelper.java
+++ b/core/java/com/android/internal/app/LocaleHelper.java
@@ -17,6 +17,7 @@
package com.android.internal.app;
import android.icu.util.ULocale;
+import android.icu.text.ListFormatter;
import android.util.LocaleList;
import java.text.Collator;
@@ -145,20 +146,16 @@
* @return the locale aware list of locale names
*/
public static String getDisplayLocaleList(LocaleList locales, Locale displayLocale) {
- final StringBuilder result = new StringBuilder();
-
final Locale dispLocale = displayLocale == null ? Locale.getDefault() : displayLocale;
+
int localeCount = locales.size();
+ final String[] localeNames = new String[localeCount];
for (int i = 0; i < localeCount; i++) {
- Locale locale = locales.get(i);
- result.append(LocaleHelper.getDisplayName(locale, dispLocale, false));
- // TODO: language aware list formatter. ICU has one.
- if (i < localeCount - 1) {
- result.append(", ");
- }
+ localeNames[i] = LocaleHelper.getDisplayName(locales.get(i), dispLocale, false);
}
- return result.toString();
+ ListFormatter lfn = ListFormatter.getInstance(dispLocale);
+ return lfn.format(localeNames);
}
/**
diff --git a/media/java/android/media/browse/MediaBrowser.java b/media/java/android/media/browse/MediaBrowser.java
index 869512d..93e6dac 100644
--- a/media/java/android/media/browse/MediaBrowser.java
+++ b/media/java/android/media/browse/MediaBrowser.java
@@ -473,8 +473,9 @@
// the service will be told when we connect.
if (mState == CONNECT_STATE_CONNECTED) {
try {
- // NOTE: In order not to break the behavior of the support library, call
- // addSubscription instead of addSubscriptionWithOptions when the options are null.
+ // NOTE: Do not call addSubscriptionWithOptions when options are null. Otherwise,
+ // it will break the action of support library which expects addSubscription will
+ // be called when options are null.
if (options == null) {
mServiceBinder.addSubscription(parentId, mServiceCallbacks);
} else {
@@ -500,9 +501,9 @@
// Tell the service if necessary.
if (sub != null && sub.remove(options) && mState == CONNECT_STATE_CONNECTED) {
try {
- // NOTE: In order not to break the behavior of the support library, call
- // removeSubscription instead of removeSubscriptionWithOptions when the options
- // are null.
+ // NOTE: Do not call removeSubscriptionWithOptions when options are null. Otherwise,
+ // it will break the action of support library which expects removeSubscription will
+ // be called when options are null.
if (options == null) {
mServiceBinder.removeSubscription(parentId, mServiceCallbacks);
} else {
@@ -572,9 +573,9 @@
Subscription sub = subscriptionEntry.getValue();
for (Bundle options : sub.getOptionsList()) {
try {
- // NOTE: In order not to break the behavior of the support library,
- // call addSubscription instead of addSubscriptionWithOptions when
- // the options are null.
+ // NOTE: Do not call addSubscriptionWithOptions when options are null.
+ // Otherwise, it will break the action of support library which expects
+ // addSubscription will be called when options are null.
if (options == null) {
mServiceBinder.addSubscription(id, mServiceCallbacks);
} else {
@@ -1034,7 +1035,7 @@
* are the initial data as requested.
*/
@Override
- public void onConnect(final String root, final MediaSession.Token session,
+ public void onConnect(String root, MediaSession.Token session,
final Bundle extras) {
MediaBrowser mediaBrowser = mMediaBrowser.get();
if (mediaBrowser != null) {
@@ -1054,7 +1055,12 @@
}
@Override
- public void onLoadChildren(final String parentId, final ParceledListSlice list,
+ public void onLoadChildren(String parentId, ParceledListSlice list) {
+ onLoadChildrenWithOptions(parentId, list, null);
+ }
+
+ @Override
+ public void onLoadChildrenWithOptions(String parentId, ParceledListSlice list,
final Bundle options) {
MediaBrowser mediaBrowser = mMediaBrowser.get();
if (mediaBrowser != null) {
diff --git a/media/java/android/service/media/IMediaBrowserService.aidl b/media/java/android/service/media/IMediaBrowserService.aidl
index fe7ebfa..6ca5ac5 100644
--- a/media/java/android/service/media/IMediaBrowserService.aidl
+++ b/media/java/android/service/media/IMediaBrowserService.aidl
@@ -16,7 +16,7 @@
oneway interface IMediaBrowserService {
// Warning: DO NOT CHANGE the methods signature and order of methods.
- // The change of the order or the method signatures could break the support library.
+ // A change of the order or the method signatures could break the support library.
void connect(String pkg, in Bundle rootHints, IMediaBrowserServiceCallbacks callbacks);
void disconnect(IMediaBrowserServiceCallbacks callbacks);
diff --git a/media/java/android/service/media/IMediaBrowserServiceCallbacks.aidl b/media/java/android/service/media/IMediaBrowserServiceCallbacks.aidl
index dadb025..e6b0e8c 100644
--- a/media/java/android/service/media/IMediaBrowserServiceCallbacks.aidl
+++ b/media/java/android/service/media/IMediaBrowserServiceCallbacks.aidl
@@ -13,6 +13,10 @@
* @hide
*/
oneway interface IMediaBrowserServiceCallbacks {
+
+ // Warning: DO NOT CHANGE the methods signature and order of methods.
+ // A change of the order or the method signatures could break the support library.
+
/**
* Invoked when the connected has been established.
* @param root The root media id for browsing.
@@ -22,5 +26,6 @@
*/
void onConnect(String root, in MediaSession.Token session, in Bundle extras);
void onConnectFailed();
- void onLoadChildren(String mediaId, in ParceledListSlice list, in Bundle options);
+ void onLoadChildren(String mediaId, in ParceledListSlice list);
+ void onLoadChildrenWithOptions(String mediaId, in ParceledListSlice list, in Bundle options);
}
diff --git a/media/java/android/service/media/MediaBrowserService.java b/media/java/android/service/media/MediaBrowserService.java
index 6cf90d5..299b770 100644
--- a/media/java/android/service/media/MediaBrowserService.java
+++ b/media/java/android/service/media/MediaBrowserService.java
@@ -589,7 +589,14 @@
final ParceledListSlice<MediaBrowser.MediaItem> pls =
filteredList == null ? null : new ParceledListSlice<>(filteredList);
try {
- connection.callbacks.onLoadChildren(parentId, pls, options);
+ // NOTE: Do not call onLoadChildrenWithOptions when options are null. Otherwise,
+ // it will break the action of support library which expects onLoadChildren will
+ // be called when options are null.
+ if (options == null) {
+ connection.callbacks.onLoadChildren(parentId, pls);
+ } else {
+ connection.callbacks.onLoadChildrenWithOptions(parentId, pls, options);
+ }
} catch (RemoteException ex) {
// The other side is in the process of crashing.
Log.w(TAG, "Calling onLoadChildren() failed for id=" + parentId
diff --git a/packages/MtpDocumentsProvider/src/com/android/mtp/MtpDatabase.java b/packages/MtpDocumentsProvider/src/com/android/mtp/MtpDatabase.java
index 112914e..959fac6 100644
--- a/packages/MtpDocumentsProvider/src/com/android/mtp/MtpDatabase.java
+++ b/packages/MtpDocumentsProvider/src/com/android/mtp/MtpDatabase.java
@@ -165,22 +165,27 @@
cursor.close();
}
- long capacityBytes = 0;
- long availableBytes = 0;
- int capacityIndex = cursor.getColumnIndex(Root.COLUMN_CAPACITY_BYTES);
- int availableIndex = cursor.getColumnIndex(Root.COLUMN_AVAILABLE_BYTES);
- while (storageCursor.moveToNext()) {
- // If requested columnNames does not include COLUMN_XXX_BYTES, we don't
- // calculate corresponding values.
- if (capacityIndex != -1) {
- capacityBytes += cursor.getLong(capacityIndex);
+ if (storageCursor.getCount() != 0) {
+ long capacityBytes = 0;
+ long availableBytes = 0;
+ int capacityIndex = cursor.getColumnIndex(Root.COLUMN_CAPACITY_BYTES);
+ int availableIndex = cursor.getColumnIndex(Root.COLUMN_AVAILABLE_BYTES);
+ while (storageCursor.moveToNext()) {
+ // If requested columnNames does not include COLUMN_XXX_BYTES, we
+ // don't calculate corresponding values.
+ if (capacityIndex != -1) {
+ capacityBytes += cursor.getLong(capacityIndex);
+ }
+ if (availableIndex != -1) {
+ availableBytes += cursor.getLong(availableIndex);
+ }
}
- if (availableIndex != -1) {
- availableBytes += cursor.getLong(availableIndex);
- }
+ values.put(Root.COLUMN_CAPACITY_BYTES, capacityBytes);
+ values.put(Root.COLUMN_AVAILABLE_BYTES, availableBytes);
+ } else {
+ values.putNull(Root.COLUMN_CAPACITY_BYTES);
+ values.putNull(Root.COLUMN_AVAILABLE_BYTES);
}
- values.put(Root.COLUMN_CAPACITY_BYTES, capacityBytes);
- values.put(Root.COLUMN_AVAILABLE_BYTES, availableBytes);
}
} finally {
storageCursor.close();
diff --git a/packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpDatabaseTest.java b/packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpDatabaseTest.java
index 97ea717..8075999 100644
--- a/packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpDatabaseTest.java
+++ b/packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpDatabaseTest.java
@@ -899,4 +899,24 @@
mDatabase.getMapper().stopAddingDocuments(null);
assertEquals("1", mDatabase.getDocumentIdForDevice(100));
}
+
+ public void testGetClosedDevice() {
+ mDatabase.getMapper().startAddingDocuments(null);
+ mDatabase.getMapper().putDeviceDocument(new MtpDeviceRecord(
+ 0, "Device", /* opened is */ false , new MtpRoot[0], null, null));
+ mDatabase.getMapper().stopAddingDocuments(null);
+
+ final String[] columns = new String [] {
+ DocumentsContract.Root.COLUMN_ROOT_ID,
+ DocumentsContract.Root.COLUMN_TITLE,
+ DocumentsContract.Root.COLUMN_AVAILABLE_BYTES
+ };
+ try (final Cursor cursor = mDatabase.queryRoots(columns)) {
+ assertEquals(1, cursor.getCount());
+ assertTrue(cursor.moveToNext());
+ assertEquals(1, cursor.getLong(0));
+ assertEquals("Device", cursor.getString(1));
+ assertTrue(cursor.isNull(2));
+ }
+ }
}