Make downloaded apk files in Recent as managed document

ACTION_MANAGE_DOCUMENT only support apk files in Downloads root
but not support downloaded apk files in Recent root. Because recent
root is primary and first root after launch DocsUI. We should make
this also support in Recent roots.
Use docs's authority to check files is from download provider or not.

Fix: 129017335
Test: manual
Test: atest DocumentsUIGoogleTests
Merged-In: I16c4d96c75c535504665768e57a210331bc2d565
Change-Id: I16c4d96c75c535504665768e57a210331bc2d565
(cherry picked from commit 74d3a2de7f6ef6cb5ac1d1326d1b67a16fecca6d)
diff --git a/src/com/android/documentsui/files/ActionHandler.java b/src/com/android/documentsui/files/ActionHandler.java
index 4d4f082..06d3671 100644
--- a/src/com/android/documentsui/files/ActionHandler.java
+++ b/src/com/android/documentsui/files/ActionHandler.java
@@ -701,19 +701,18 @@
         // treatment, thusly the "isDownloads" check.
 
         // Launch MANAGE_DOCUMENTS only for the root level files, so it's not called for
-        // files in archives. Also, if the activity is already browsing a ZIP from downloads,
-        // then skip MANAGE_DOCUMENTS.
+        // files in archives or in child folders. Also, if the activity is already browsing
+        // a ZIP from downloads, then skip MANAGE_DOCUMENTS.
         if (Intent.ACTION_VIEW.equals(mActivity.getIntent().getAction())
                 && mState.stack.size() > 1) {
             // viewing the contents of an archive.
             return false;
         }
 
-        // management is only supported in downloads.
-        if (mActivity.getCurrentRoot().isDownloads()) {
-            // and only and only on APKs or partial files.
-            return MimeTypes.isApkType(doc.mimeType)
-                    || doc.isPartial();
+        // management is only supported in Downloads root or downloaded files show in Recent root.
+        if (Providers.AUTHORITY_DOWNLOADS.equals(doc.authority)) {
+            // only on APKs or partial files.
+            return MimeTypes.isApkType(doc.mimeType) || doc.isPartial();
         }
 
         return false;
diff --git a/tests/unit/com/android/documentsui/files/ActionHandlerTest.java b/tests/unit/com/android/documentsui/files/ActionHandlerTest.java
index de4f7fa..e4a6e31 100644
--- a/tests/unit/com/android/documentsui/files/ActionHandlerTest.java
+++ b/tests/unit/com/android/documentsui/files/ActionHandlerTest.java
@@ -331,6 +331,27 @@
     @Test
     public void testDocumentPicked_Downloads_ManagesApks() throws Exception {
         mActivity.currentRoot = TestProvidersAccess.DOWNLOADS;
+        TestEnv.FILE_APK.authority = TestProvidersAccess.DOWNLOADS.authority;
+
+        mHandler.openDocument(TestEnv.FILE_APK, ActionHandler.VIEW_TYPE_PREVIEW,
+                ActionHandler.VIEW_TYPE_REGULAR);
+        mActivity.assertActivityStarted(DocumentsContract.ACTION_MANAGE_DOCUMENT);
+    }
+
+    @Test
+    public void testDocumentPicked_Downloads_ManagesPartialFiles() throws Exception {
+        mActivity.currentRoot = TestProvidersAccess.DOWNLOADS;
+        TestEnv.FILE_PARTIAL.authority = TestProvidersAccess.DOWNLOADS.authority;
+
+        mHandler.openDocument(TestEnv.FILE_PARTIAL, ActionHandler.VIEW_TYPE_PREVIEW,
+                ActionHandler.VIEW_TYPE_REGULAR);
+        mActivity.assertActivityStarted(DocumentsContract.ACTION_MANAGE_DOCUMENT);
+    }
+
+    @Test
+    public void testDocumentPicked_Recent_ManagesApks() throws Exception {
+        mActivity.currentRoot = TestProvidersAccess.RECENTS;
+        TestEnv.FILE_APK.authority = TestProvidersAccess.DOWNLOADS.authority;
 
         mHandler.openDocument(TestEnv.FILE_APK, ActionHandler.VIEW_TYPE_PREVIEW,
                 ActionHandler.VIEW_TYPE_REGULAR);
@@ -347,15 +368,6 @@
     }
 
     @Test
-    public void testDocumentPicked_Downloads_ManagesPartialFiles() throws Exception {
-        mActivity.currentRoot = TestProvidersAccess.DOWNLOADS;
-
-        mHandler.openDocument(TestEnv.FILE_PARTIAL, ActionHandler.VIEW_TYPE_PREVIEW,
-                ActionHandler.VIEW_TYPE_REGULAR);
-        mActivity.assertActivityStarted(DocumentsContract.ACTION_MANAGE_DOCUMENT);
-    }
-
-    @Test
     public void testDocumentPicked_OpensArchives() throws Exception {
         mActivity.currentRoot = TestProvidersAccess.HOME;
         mEnv.docs.nextDocument = TestEnv.FILE_ARCHIVE;