Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.OPEN_DOCUMENT" />
<data android:mimeType="*/*" />
<category android:name="android.intent.category.OPENABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.RINGTONE_PICKER" />
<category android:name="android.intent.category.DEFAULT" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public void onCreate(final Bundle savedInstanceState) {

String actionIntent = intent != null ? intent.getAction() : null;

if (Intent.ACTION_GET_CONTENT.equals(actionIntent)
if (isFilePickerIntent(actionIntent)
|| RingtoneManager.ACTION_RINGTONE_PICKER.equals(actionIntent)
|| Intent.ACTION_VIEW.equals(actionIntent)
|| Intent.ACTION_SEND.equals(actionIntent)
Expand Down Expand Up @@ -605,6 +605,11 @@ private boolean ensureStoragePermission() {
return false;
}

private static boolean isFilePickerIntent(@Nullable String actionIntent) {
return Intent.ACTION_GET_CONTENT.equals(actionIntent)
|| Intent.ACTION_OPEN_DOCUMENT.equals(actionIntent);
}

/** Checks for the action to take when Amaze receives an intent from external source */
private void checkForExternalIntent(Intent intent) {
final String actionIntent = intent.getAction();
Expand All @@ -614,7 +619,7 @@ private void checkForExternalIntent(Intent intent) {

final String type = intent.getType();

if (actionIntent.equals(Intent.ACTION_GET_CONTENT)) {
if (isFilePickerIntent(actionIntent)) {
// file picker intent
mReturnIntent = true;
String text =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@

package com.amaze.filemanager.ui.activities

import android.content.Intent
import android.content.pm.PackageManager
import androidx.lifecycle.Lifecycle
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import com.amaze.filemanager.application.AppConfig
import com.amaze.filemanager.ui.icons.MimeTypes
import com.amaze.filemanager.utils.smb.SmbUtil.getSmbDecryptedPath
import com.amaze.filemanager.utils.smb.SmbUtil.getSmbEncryptedPath
import org.awaitility.Awaitility.await
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.robolectric.shadows.ShadowLooper
import java.util.concurrent.TimeUnit
Expand All @@ -37,6 +42,59 @@ import java.util.concurrent.TimeUnit
*/
@Suppress("StringLiteralDuplication")
class MainActivityTest : AbstractMainActivityTestBase() {
/** Test Amaze is advertised as a document picker. */
@Test
fun testOpenDocumentIntentResolvesToMainActivity() {
val context = ApplicationProvider.getApplicationContext<AppConfig>()
val intent =
Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = MimeTypes.ALL_MIME_TYPES
setPackage(context.packageName)
}

val handlers =
context.packageManager.queryIntentActivities(
intent,
PackageManager.MATCH_DEFAULT_ONLY,
)

assertTrue(
"MainActivity must handle ACTION_OPEN_DOCUMENT",
handlers.any { it.activityInfo.name == MainActivity::class.java.name },
)
}

/** Test OPEN_DOCUMENT starts the existing file-picking flow. */
@Test
fun testOpenDocumentIntentEnablesFilePicking() {
val context = ApplicationProvider.getApplicationContext<AppConfig>()
val intent =
Intent(context, MainActivity::class.java).apply {
action = Intent.ACTION_OPEN_DOCUMENT
addCategory(Intent.CATEGORY_OPENABLE)
type = MimeTypes.ALL_MIME_TYPES
}
val scenario = ActivityScenario.launch<MainActivity>(intent)

try {
ShadowLooper.idleMainLooper()
scenario.moveToState(Lifecycle.State.STARTED)
scenario.onActivity { activity ->
assertTrue(
"OPEN_DOCUMENT must enable file-picking mode",
activity.mReturnIntent,
)
assertFalse(
"OPEN_DOCUMENT must not enable ringtone-picking mode",
activity.mRingtonePickerIntent,
)
}
} finally {
scenario.close()
}
}

/**
* Test update SMB connection should never throw [NullPointerException] i.e. the correct
* connection is updated.
Expand Down