Merge "Use device model and name for internal storage." into nyc-dev

This commit is contained in:
Steve McKay
2016-03-02 23:03:39 +00:00
committed by Android (Google) Code Review

View File

@@ -41,6 +41,7 @@ import android.provider.DocumentsContract.Document;
import android.provider.DocumentsContract.Root; import android.provider.DocumentsContract.Root;
import android.provider.DocumentsProvider; import android.provider.DocumentsProvider;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.provider.Settings;
import android.support.provider.DocumentArchiveHelper; import android.support.provider.DocumentArchiveHelper;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.ArrayMap; import android.util.ArrayMap;
@@ -62,6 +63,7 @@ import java.util.List;
public class ExternalStorageProvider extends DocumentsProvider { public class ExternalStorageProvider extends DocumentsProvider {
private static final String TAG = "ExternalStorage"; private static final String TAG = "ExternalStorage";
private static final boolean DEBUG = false;
private static final boolean LOG_INOTIFY = false; private static final boolean LOG_INOTIFY = false;
public static final String AUTHORITY = "com.android.externalstorage.documents"; public static final String AUTHORITY = "com.android.externalstorage.documents";
@@ -136,10 +138,25 @@ public class ExternalStorageProvider extends DocumentsProvider {
if (volume.getType() == VolumeInfo.TYPE_EMULATED) { if (volume.getType() == VolumeInfo.TYPE_EMULATED) {
// We currently only support a single emulated volume mounted at // We currently only support a single emulated volume mounted at
// a time, and it's always considered the primary // a time, and it's always considered the primary
if (DEBUG) Log.d(TAG, "Found primary volume: " + volume);
rootId = ROOT_ID_PRIMARY_EMULATED; rootId = ROOT_ID_PRIMARY_EMULATED;
if (VolumeInfo.ID_EMULATED_INTERNAL.equals(volume.getId())) { if (VolumeInfo.ID_EMULATED_INTERNAL.equals(volume.getId())) {
title = getContext().getString(R.string.root_internal_storage); // This is basically the user's primary device storage.
// Use device name for the volume since this is likely same thing
// the user sees when they mount their phone on another device.
String deviceName = Settings.Global.getString(
getContext().getContentResolver(), Settings.Global.DEVICE_NAME);
// Device name should always be set. In case it isn't, though,
// fall back to a localized "Internal Storage" string.
title = !TextUtils.isEmpty(deviceName)
? deviceName
: getContext().getString(R.string.root_internal_storage);
} else { } else {
// This should cover all other storage devices, like an SD card
// or USB OTG drive plugged in. Using getBestVolumeDescription()
// will give us a nice string like "Samsung SD card" or "SanDisk USB drive"
final VolumeInfo privateVol = mStorageManager.findPrivateForEmulated(volume); final VolumeInfo privateVol = mStorageManager.findPrivateForEmulated(volume);
title = mStorageManager.getBestVolumeDescription(privateVol); title = mStorageManager.getBestVolumeDescription(privateVol);
} }
@@ -192,8 +209,9 @@ public class ExternalStorageProvider extends DocumentsProvider {
} }
} }
// Finally, if primary storage is available we add the "Home" directory, // Finally, if primary storage is available we add the "Documents" directory.
// creating it as needed. // If I recall correctly the actual directory is created on demand
// by calling either getPathForUser, or getInternalPathForUser.
if (primaryVolume != null && primaryVolume.isVisible()) { if (primaryVolume != null && primaryVolume.isVisible()) {
final RootInfo root = new RootInfo(); final RootInfo root = new RootInfo();
root.rootId = ROOT_ID_HOME; root.rootId = ROOT_ID_HOME;
@@ -210,8 +228,7 @@ public class ExternalStorageProvider extends DocumentsProvider {
root.flags |= Root.FLAG_SUPPORTS_CREATE; root.flags |= Root.FLAG_SUPPORTS_CREATE;
} }
// Create the "Home" directory on disk, but don't the localized root.title // Create the "Documents" directory on disk (don't use the localized title).
// since the directories shouldn't be localized.
root.visiblePath = new File( root.visiblePath = new File(
primaryVolume.getPathForUser(userId), Environment.DIRECTORY_DOCUMENTS); primaryVolume.getPathForUser(userId), Environment.DIRECTORY_DOCUMENTS);
root.path = new File( root.path = new File(