Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b3714e46 authored by Erfan Norozi's avatar Erfan Norozi
Browse files

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
parent c3f05294
Loading
Loading
Loading
Loading
+19 −6
Original line number Diff line number Diff line
@@ -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,6 +545,16 @@ public class ActionHandler<T extends FragmentActivity & AbstractActionHandler.Co
            return;
        }

        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 {
@@ -551,6 +563,7 @@ public class ActionHandler<T extends FragmentActivity & AbstractActionHandler.Co
                mDialogs.showNoApplicationFound();
            }
        }
    }

    @Override
    public void showInspector(DocumentInfo doc) {
+13 −0
Original line number Diff line number Diff line
@@ -460,6 +460,7 @@ public class ActionHandlerTest {
    }

    @Test
    @DisableFlags({Flags.FLAG_DESKTOP_FILE_HANDLING})
    public void testShowChooser() throws Exception {
        mActivity.currentRoot = TestProvidersAccess.DOWNLOADS;

@@ -467,6 +468,18 @@ public class ActionHandlerTest {
        mActivity.assertActivityStarted(Intent.ACTION_CHOOSER);
    }

    @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"));