Merge "Allow StubVolume to be browseable in Settings" am: 8f516adef7 am: e613923d66
am: 1670c69b7c

Change-Id: Id567d995f6f25a46225a2080609048051cca2337
diff --git a/src/com/android/settings/deviceinfo/StorageSettings.java b/src/com/android/settings/deviceinfo/StorageSettings.java
index 49d5455..b32da9d 100644
--- a/src/com/android/settings/deviceinfo/StorageSettings.java
+++ b/src/com/android/settings/deviceinfo/StorageSettings.java
@@ -146,6 +146,7 @@
         switch (vol.getType()) {
             case VolumeInfo.TYPE_PRIVATE:
             case VolumeInfo.TYPE_PUBLIC:
+            case VolumeInfo.TYPE_STUB:
                 return true;
             default:
                 return false;
@@ -178,7 +179,8 @@
                 final int color = COLOR_PRIVATE[privateCount++ % COLOR_PRIVATE.length];
                 mInternalCategory.addPreference(
                         new StorageVolumePreference(context, vol, color, volumeTotalBytes));
-            } else if (vol.getType() == VolumeInfo.TYPE_PUBLIC) {
+            } else if (vol.getType() == VolumeInfo.TYPE_PUBLIC
+                    || vol.getType() == VolumeInfo.TYPE_STUB) {
                 mExternalCategory.addPreference(
                         new StorageVolumePreference(context, vol, COLOR_PUBLIC, 0));
             }
@@ -306,6 +308,8 @@
 
             } else if (vol.getType() == VolumeInfo.TYPE_PUBLIC) {
                 return handlePublicVolumeClick(getContext(), vol);
+            } else if (vol.getType() == VolumeInfo.TYPE_STUB) {
+                return handleStubVolumeClick(getContext(), vol);
             }
 
         } else if (key.startsWith("disk:")) {
@@ -330,6 +334,16 @@
     }
 
     @VisibleForTesting
+    static boolean handleStubVolumeClick(Context context, VolumeInfo vol) {
+        final Intent intent = vol.buildBrowseIntent();
+        if (vol.isMountedReadable() && intent != null) {
+            context.startActivity(intent);
+            return true;
+        }
+        return false;
+    }
+
+    @VisibleForTesting
     static boolean handlePublicVolumeClick(Context context, VolumeInfo vol) {
         final Intent intent = vol.buildBrowseIntent();
         if (vol.isMountedReadable() && intent != null) {
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/StorageSettingsTest.java b/tests/robotests/src/com/android/settings/deviceinfo/StorageSettingsTest.java
index cb02c76..2598105 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/StorageSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/StorageSettingsTest.java
@@ -66,4 +66,16 @@
         verify(mActivity, never()).startActivity(null);
         verify(mActivity).startActivity(any(Intent.class));
     }
+
+    @Test
+    public void handleStubVolumeClick_startsANonNullActivityWhenVolumeHasNoBrowse() {
+        VolumeInfo volumeInfo = mock(VolumeInfo.class, RETURNS_DEEP_STUBS);
+        when(volumeInfo.isMountedReadable()).thenReturn(true);
+
+        StorageSettings.handleStubVolumeClick(mActivity, volumeInfo);
+
+        verify(mActivity, never()).startActivity(null);
+        verify(mActivity).startActivity(any(Intent.class));
+    }
+
 }