diff options
author | 2024-12-20 11:42:11 +1100 | |
---|---|---|
committer | 2025-01-16 09:14:52 +1100 | |
commit | b3714e467f5df8c061218f5b6bc4e8b128c5129c (patch) | |
tree | e97d3f76220b59c6d6d45f84caf1de2e60cdab35 | |
parent | c3f05294c2e4c6ab4d2593fa6422e6cdeef633c0 (diff) |
Change "Open with" on desktop to open ResolverActivity
ResolverActivity allows users to change the default unlike the current
ChooserActivity.
Bug: 384608361
Flag: com.android.documentsui.flags.desktop_file_handling
Test: Unit tests and manual testing
Change-Id: I918ec6d6fce599bf2b1194d3db3b6d23cde254f5
-rw-r--r-- | src/com/android/documentsui/files/ActionHandler.java | 25 | ||||
-rw-r--r-- | tests/unit/com/android/documentsui/files/ActionHandlerTest.java | 13 |
2 files changed, 32 insertions, 6 deletions
diff --git a/src/com/android/documentsui/files/ActionHandler.java b/src/com/android/documentsui/files/ActionHandler.java index 20b831856..1fa771178 100644 --- a/src/com/android/documentsui/files/ActionHandler.java +++ b/src/com/android/documentsui/files/ActionHandler.java @@ -19,10 +19,12 @@ package com.android.documentsui.files; import static android.content.ContentResolver.wrap; import static com.android.documentsui.base.SharedMinimal.DEBUG; +import static com.android.documentsui.flags.Flags.desktopFileHandling; import android.app.DownloadManager; import android.content.ActivityNotFoundException; import android.content.ClipData; +import android.content.ComponentName; import android.content.ContentProviderClient; import android.content.ContentResolver; import android.content.Intent; @@ -543,12 +545,23 @@ public class ActionHandler<T extends FragmentActivity & AbstractActionHandler.Co return; } - Intent intent = Intent.createChooser(buildViewIntent(doc), null); - intent.putExtra(Intent.EXTRA_AUTO_LAUNCH_SINGLE_CHOICE, false); - try { - doc.userId.startActivityAsUser(mActivity, intent); - } catch (ActivityNotFoundException e) { - mDialogs.showNoApplicationFound(); + if (desktopFileHandling()) { + Intent intent = buildViewIntent(doc); + intent.setComponent( + new ComponentName("android", "com.android.internal.app.ResolverActivity")); + try { + doc.userId.startActivityAsUser(mActivity, intent); + } catch (ActivityNotFoundException e) { + mDialogs.showNoApplicationFound(); + } + } else { + Intent intent = Intent.createChooser(buildViewIntent(doc), null); + intent.putExtra(Intent.EXTRA_AUTO_LAUNCH_SINGLE_CHOICE, false); + try { + doc.userId.startActivityAsUser(mActivity, intent); + } catch (ActivityNotFoundException e) { + mDialogs.showNoApplicationFound(); + } } } diff --git a/tests/unit/com/android/documentsui/files/ActionHandlerTest.java b/tests/unit/com/android/documentsui/files/ActionHandlerTest.java index 6aaa3e5d2..3de1a8ca7 100644 --- a/tests/unit/com/android/documentsui/files/ActionHandlerTest.java +++ b/tests/unit/com/android/documentsui/files/ActionHandlerTest.java @@ -460,6 +460,7 @@ public class ActionHandlerTest { } @Test + @DisableFlags({Flags.FLAG_DESKTOP_FILE_HANDLING}) public void testShowChooser() throws Exception { mActivity.currentRoot = TestProvidersAccess.DOWNLOADS; @@ -468,6 +469,18 @@ public class ActionHandlerTest { } @Test + @EnableFlags({Flags.FLAG_DESKTOP_FILE_HANDLING}) + public void testShowChooserDesktop() throws Exception { + mActivity.currentRoot = TestProvidersAccess.DOWNLOADS; + + mHandler.showChooserForDoc(TestEnv.FILE_PDF); + Intent actual = mActivity.startActivity.getLastValue(); + assertEquals(Intent.ACTION_VIEW, actual.getAction()); + assertEquals("ComponentInfo{android/com.android.internal.app.ResolverActivity}", + actual.getComponent().toString()); + } + + @Test public void testInitLocation_LaunchToStackLocation() { DocumentStack path = new DocumentStack(Roots.create("123"), mEnv.model.getDocument("1")); |