Move roots constants to a shared location.

Include URIs in debug output.
Don't cancel search after dbg: input.

Change-Id: Id0eeb0f2ee2d847c0e88c18320977ed99d3e49bb
diff --git a/res/layout/document_debug_info.xml b/res/layout/document_debug_info.xml
index 83664af..c24a05b 100644
--- a/res/layout/document_debug_info.xml
+++ b/res/layout/document_debug_info.xml
@@ -21,6 +21,5 @@
     android:layout_height="wrap_content"
     android:layout_margin="@dimen/grid_item_margin"
     android:textAlignment="viewStart"
-    android:typeface="monospace"
     android:textSize="11sp"
     android:textColor="#FF000000" />
diff --git a/src/com/android/documentsui/MenuManager.java b/src/com/android/documentsui/MenuManager.java
index 0d9b188..a3732e3 100644
--- a/src/com/android/documentsui/MenuManager.java
+++ b/src/com/android/documentsui/MenuManager.java
@@ -25,7 +25,6 @@
 import com.android.documentsui.base.DocumentInfo;
 import com.android.documentsui.base.Menus;
 import com.android.documentsui.base.RootInfo;
-import com.android.documentsui.base.Shared;
 import com.android.documentsui.base.State;
 import com.android.documentsui.dirlist.DirectoryFragment;
 import com.android.documentsui.queries.SearchViewManager;
diff --git a/src/com/android/documentsui/Metrics.java b/src/com/android/documentsui/Metrics.java
index 52d348d..15cf902 100644
--- a/src/com/android/documentsui/Metrics.java
+++ b/src/com/android/documentsui/Metrics.java
@@ -31,6 +31,7 @@
 import android.util.Log;
 
 import com.android.documentsui.base.DocumentInfo;
+import com.android.documentsui.base.Providers;
 import com.android.documentsui.base.RootInfo;
 import com.android.documentsui.base.State;
 import com.android.documentsui.base.State.ActionType;
@@ -48,13 +49,6 @@
 public final class Metrics {
     private static final String TAG = "Metrics";
 
-    // These are the native provider authorities that the metrics code is capable of recognizing and
-    // explicitly counting.
-    private static final String AUTHORITY_MEDIA = "com.android.providers.media.documents";
-    private static final String AUTHORITY_STORAGE = "com.android.externalstorage.documents";
-    private static final String AUTHORITY_DOWNLOADS = "com.android.providers.downloads.documents";
-    private static final String AUTHORITY_MTP = "com.android.mtp.documents";
-
     // These strings have to be whitelisted in tron. Do not change them.
     private static final String COUNT_LAUNCH_ACTION = "docsui_launch_action";
     private static final String COUNT_ROOT_VISITED = "docsui_root_visited";
@@ -668,26 +662,26 @@
         }
 
         switch (uri.getAuthority()) {
-            case AUTHORITY_MEDIA:
+            case Providers.AUTHORITY_MEDIA:
                 switch (DocumentsContract.getRootId(uri)) {
-                    case "audio_root":
+                    case Providers.ROOT_ID_AUDIO:
                         return ROOT_AUDIO;
-                    case "images_root":
+                    case Providers.ROOT_ID_IMAGES:
                         return ROOT_IMAGES;
-                    case "videos_root":
+                    case Providers.ROOT_ID_VIDEOS:
                         return ROOT_VIDEOS;
                     default:
                         return ROOT_OTHER;
                 }
-            case AUTHORITY_STORAGE:
-                if ("home".equals(DocumentsContract.getRootId(uri))) {
+            case Providers.AUTHORITY_STORAGE:
+                if (Providers.ROOT_ID_HOME.equals(DocumentsContract.getRootId(uri))) {
                     return ROOT_HOME;
                 } else {
                     return ROOT_DEVICE_STORAGE;
                 }
-            case AUTHORITY_DOWNLOADS:
+            case Providers.AUTHORITY_DOWNLOADS:
                 return ROOT_DOWNLOADS;
-            case AUTHORITY_MTP:
+            case Providers.AUTHORITY_MTP:
                 return ROOT_MTP;
             default:
                 return ROOT_OTHER;
@@ -748,9 +742,9 @@
 
     private static boolean isSystemProvider(String authority) {
         switch (authority) {
-            case AUTHORITY_MEDIA:
-            case AUTHORITY_STORAGE:
-            case AUTHORITY_DOWNLOADS:
+            case Providers.AUTHORITY_MEDIA:
+            case Providers.AUTHORITY_STORAGE:
+            case Providers.AUTHORITY_DOWNLOADS:
                 return true;
             default:
                 return false;
diff --git a/src/com/android/documentsui/OpenExternalDirectoryActivity.java b/src/com/android/documentsui/OpenExternalDirectoryActivity.java
index 77e76f9..44ccc1e 100644
--- a/src/com/android/documentsui/OpenExternalDirectoryActivity.java
+++ b/src/com/android/documentsui/OpenExternalDirectoryActivity.java
@@ -68,6 +68,8 @@
 import android.widget.CompoundButton.OnCheckedChangeListener;
 import android.widget.TextView;
 
+import com.android.documentsui.base.Providers;
+
 import java.io.File;
 import java.io.IOException;
 import java.util.List;
@@ -78,7 +80,6 @@
 public class OpenExternalDirectoryActivity extends Activity {
     private static final String TAG = "OpenExternalDirectory";
     private static final String FM_TAG = "open_external_directory";
-    private static final String EXTERNAL_STORAGE_AUTH = "com.android.externalstorage.documents";
     private static final String EXTRA_FILE = "com.android.documentsui.FILE";
     private static final String EXTRA_APP_LABEL = "com.android.documentsui.APP_LABEL";
     private static final String EXTRA_VOLUME_LABEL = "com.android.documentsui.VOLUME_LABEL";
@@ -315,7 +316,7 @@
         }
         if (DEBUG) Log.d(TAG, "doc id for " + file + ": " + docId);
 
-        final Uri uri = DocumentsContract.buildTreeDocumentUri(EXTERNAL_STORAGE_AUTH, docId);
+        final Uri uri = DocumentsContract.buildTreeDocumentUri(Providers.AUTHORITY_STORAGE, docId);
         if (uri == null) {
             Log.e(TAG, "Could not get URI for doc id " + docId);
             return null;
@@ -502,7 +503,7 @@
     private synchronized ContentProviderClient getExternalStorageClient() {
         if (mExternalStorageClient == null) {
             mExternalStorageClient =
-                    getContentResolver().acquireContentProviderClient(EXTERNAL_STORAGE_AUTH);
+                    getContentResolver().acquireContentProviderClient(Providers.AUTHORITY_STORAGE);
         }
         return mExternalStorageClient;
     }
diff --git a/src/com/android/documentsui/base/DocumentInfo.java b/src/com/android/documentsui/base/DocumentInfo.java
index afdaccc..bf01f2f 100644
--- a/src/com/android/documentsui/base/DocumentInfo.java
+++ b/src/com/android/documentsui/base/DocumentInfo.java
@@ -222,7 +222,8 @@
                 + ", isDeleteSupported=" + isDeleteSupported()
                 + ", isCreateSupported=" + isCreateSupported()
                 + ", isRenameSupported=" + isRenameSupported()
-                + "}";
+                + "} @ "
+                + derivedUri;
     }
 
     public boolean isCreateSupported() {
diff --git a/src/com/android/documentsui/base/Providers.java b/src/com/android/documentsui/base/Providers.java
new file mode 100644
index 0000000..561c442
--- /dev/null
+++ b/src/com/android/documentsui/base/Providers.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.documentsui.base;
+
+/**
+ * Details about various system providers. These all need to be in sync with the
+ * resources in their respective packages.
+ */
+public final class Providers {
+
+    public static final String AUTHORITY_STORAGE = "com.android.externalstorage.documents";
+    public static final String ROOT_ID_DEVICE = "primary";
+    public static final String ROOT_ID_HOME = "home";
+
+    public static final String AUTHORITY_DOWNLOADS = "com.android.providers.downloads.documents";
+    public static final String ROOT_ID_DOWNLOADS = "downloads";
+
+    public static final String AUTHORITY_MEDIA = "com.android.providers.media.documents";
+    public static final String ROOT_ID_IMAGES = "images_root";
+    public static final String ROOT_ID_VIDEOS = "videos_root";
+    public static final String ROOT_ID_AUDIO = "audio_root";
+
+    public static final String AUTHORITY_MTP = "com.android.mtp.documents";
+}
diff --git a/src/com/android/documentsui/base/RootInfo.java b/src/com/android/documentsui/base/RootInfo.java
index 3a19ef7..50b9603 100644
--- a/src/com/android/documentsui/base/RootInfo.java
+++ b/src/com/android/documentsui/base/RootInfo.java
@@ -252,30 +252,30 @@
     }
 
     public boolean isExternalStorage() {
-        return "com.android.externalstorage.documents".equals(authority);
+        return Providers.AUTHORITY_STORAGE.equals(authority);
     }
 
     public boolean isDownloads() {
-        return "com.android.providers.downloads.documents".equals(authority);
+        return Providers.AUTHORITY_DOWNLOADS.equals(authority);
     }
 
     public boolean isImages() {
-        return "com.android.providers.media.documents".equals(authority)
-                && "images_root".equals(rootId);
+        return Providers.AUTHORITY_MEDIA.equals(authority)
+                && Providers.ROOT_ID_IMAGES.equals(rootId);
     }
 
     public boolean isVideos() {
-        return "com.android.providers.media.documents".equals(authority)
-                && "videos_root".equals(rootId);
+        return Providers.AUTHORITY_MEDIA.equals(authority)
+                && Providers.ROOT_ID_VIDEOS.equals(rootId);
     }
 
     public boolean isAudio() {
-        return "com.android.providers.media.documents".equals(authority)
-                && "audio_root".equals(rootId);
+        return Providers.AUTHORITY_MEDIA.equals(authority)
+                && Providers.ROOT_ID_AUDIO.equals(rootId);
     }
 
     public boolean isMtp() {
-        return "com.android.mtp.documents".equals(authority);
+        return Providers.AUTHORITY_MTP.equals(authority);
     }
 
     public boolean isLibrary() {
@@ -412,7 +412,8 @@
                 + ", isUsb=" + isUsb()
                 + ", isSd=" + isSd()
                 + ", isMtp=" + isMtp()
-                + "}";
+                + "} @ "
+                + getUri();
     }
 
     public String getDirectoryString() {
diff --git a/src/com/android/documentsui/base/Shared.java b/src/com/android/documentsui/base/Shared.java
index 8e93587..31a9451 100644
--- a/src/com/android/documentsui/base/Shared.java
+++ b/src/com/android/documentsui/base/Shared.java
@@ -217,7 +217,7 @@
         return shouldShowDocumentsRoot(activity)
                 ? DocumentsContract.buildHomeUri()
                 : DocumentsContract.buildRootUri(
-                        "com.android.providers.downloads.documents", "downloads");
+                        Providers.AUTHORITY_DOWNLOADS, Providers.ROOT_ID_DOWNLOADS);
     }
 
     public static boolean isHardwareKeyboardAvailable(Context context) {
@@ -226,7 +226,8 @@
 
     public static void ensureKeyboardPresent(Context context, AlertDialog dialog) {
         if (!isHardwareKeyboardAvailable(context)) {
-            dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
+            dialog.getWindow().setSoftInputMode(
+                    WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
         }
     }
 
diff --git a/src/com/android/documentsui/queries/SearchViewManager.java b/src/com/android/documentsui/queries/SearchViewManager.java
index 6ade64d..04bc53f 100644
--- a/src/com/android/documentsui/queries/SearchViewManager.java
+++ b/src/com/android/documentsui/queries/SearchViewManager.java
@@ -244,7 +244,7 @@
     public boolean onQueryTextSubmit(String query) {
 
         if (mCommandProcessor.accept(query)) {
-            cancelSearch();
+            mSearchView.setQuery("", false);
         } else {
             mCurrentSearch = query;
             mSearchView.clearFocus();
diff --git a/src/com/android/documentsui/roots/RootsAccess.java b/src/com/android/documentsui/roots/RootsAccess.java
index 8259337..784ccfb 100644
--- a/src/com/android/documentsui/roots/RootsAccess.java
+++ b/src/com/android/documentsui/roots/RootsAccess.java
@@ -25,8 +25,8 @@
 import com.android.documentsui.base.RootInfo;
 import com.android.documentsui.base.State;
 
-import java.util.Arrays;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 
@@ -63,6 +63,8 @@
         final List<RootInfo> matching = new ArrayList<>();
         for (RootInfo root : roots) {
 
+            if (DEBUG) Log.v(tag, "Evaluationg root: " + root);
+
             if (state.action == State.ACTION_CREATE && !root.supportsCreate()) {
                 if (DEBUG) Log.v(tag, "Excluding read-only root because: ACTION_CREATE.");
                 continue;
diff --git a/src/com/android/documentsui/ui/DocumentDebugInfo.java b/src/com/android/documentsui/ui/DocumentDebugInfo.java
index 18d66f2..80dc8c9 100644
--- a/src/com/android/documentsui/ui/DocumentDebugInfo.java
+++ b/src/com/android/documentsui/ui/DocumentDebugInfo.java
@@ -49,7 +49,9 @@
                 .append("** OPERATIONS **\n\n")
                 .append("create: " + doc.isCreateSupported()).append("\n")
                 .append("delete: " + doc.isDeleteSupported()).append("\n")
-                .append("rename: " + doc.isRenameSupported()).append("\n")
+                .append("rename: " + doc.isRenameSupported()).append("\n\n")
+                .append("** URI **\n\n")
+                .append(doc.derivedUri).append("\n")
                 .toString();
 
         setText(dbgInfo);
diff --git a/tests/common/com/android/documentsui/testing/TestRootsAccess.java b/tests/common/com/android/documentsui/testing/TestRootsAccess.java
index 0a2fbd2..7a97ffb 100644
--- a/tests/common/com/android/documentsui/testing/TestRootsAccess.java
+++ b/tests/common/com/android/documentsui/testing/TestRootsAccess.java
@@ -15,6 +15,7 @@
  */
 package com.android.documentsui.testing;
 
+import com.android.documentsui.base.Providers;
 import com.android.documentsui.base.RootInfo;
 import com.android.documentsui.base.State;
 import com.android.documentsui.roots.RootsAccess;
@@ -36,12 +37,12 @@
 
     static {
         DOWNLOADS = new RootInfo();
-        DOWNLOADS.authority = "com.android.providers.downloads.documents";
-        DOWNLOADS.rootId = "downloads";
+        DOWNLOADS.authority = Providers.AUTHORITY_DOWNLOADS;
+        DOWNLOADS.rootId = Providers.ROOT_ID_DOWNLOADS;
 
         HOME = new RootInfo();
-        HOME.authority = "com.android.externalstorage.documents";
-        HOME.rootId = "home";
+        HOME.authority = Providers.AUTHORITY_STORAGE;
+        HOME.rootId = Providers.ROOT_ID_HOME;
 
         HAMMY = new RootInfo();
         HAMMY.authority = "yummies";
diff --git a/tests/unit/com/android/documentsui/roots/RootsCacheTest.java b/tests/unit/com/android/documentsui/roots/RootsCacheTest.java
index ff7277b..e9c9883 100644
--- a/tests/unit/com/android/documentsui/roots/RootsCacheTest.java
+++ b/tests/unit/com/android/documentsui/roots/RootsCacheTest.java
@@ -21,6 +21,7 @@
 import android.test.AndroidTestCase;
 import android.test.suitebuilder.annotation.SmallTest;
 
+import com.android.documentsui.base.Providers;
 import com.android.documentsui.base.RootInfo;
 import com.android.documentsui.base.State;
 
@@ -68,7 +69,7 @@
 
     public void testMatchingRoots_DirectoryCopy() throws Exception {
         RootInfo downloads = buildForMimeTypes("*/*");
-        downloads.authority = "com.android.providers.downloads.documents";
+        downloads.authority = Providers.AUTHORITY_DOWNLOADS;
         mRoots.add(downloads);
 
         mState.acceptMimes = new String[] { "*/*" };