Skip to content

Explicit MIME type declaration on querying available packages for opening files #3020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: release/4.0
Choose a base branch
from
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
11 changes: 9 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />

<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:mimeType="*/*" />
</intent>
</queries>

<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
Expand All @@ -67,8 +74,7 @@
android:name=".ui.activities.MainActivity"
android:theme="@style/appCompatBlack"
android:configChanges="uiMode"
android:windowSoftInputMode="adjustPan"
>
android:windowSoftInputMode="adjustPan">

<intent-filter android:label="@string/appbar_name">
<action android:name="android.intent.action.MAIN" />
Expand Down Expand Up @@ -180,6 +186,7 @@
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="db/*" />
<data android:mimeType="application/vnd.sqlite3" />
</intent-filter>

</activity>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public class FileUtils {

private static final String[] COMPRESSED_FILE_EXTENSIONS =
new String[] {
"zip", "rar", "cab", "bz2", "ace", "bz", "gz", "7z", "jar", "apk", "xz", "lzma", "Z"
"zip", "cab", "bz2", "ace", "bz", "gz", "7z", "jar", "apk", "xz", "lzma", "Z", "rar"
};

public static final String FILE_PROVIDER_PREFIX = "storage_root";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -884,10 +884,8 @@ public synchronized ArrayList<StorageDirectoryParcelable> getStorageDirectoriesL
File usb = getUsbDrive();
if (usb != null && !rv.contains(usb.getPath())) rv.add(usb.getPath());

if (SDK_INT >= KITKAT) {
if (SingletonUsbOtg.getInstance().isDeviceConnected()) {
rv.add(OTGUtil.PREFIX_OTG + "/");
}
if (SDK_INT >= KITKAT && SingletonUsbOtg.INSTANCE.isDeviceConnected()) {
rv.add(OTGUtil.PREFIX_OTG + "/");
}

// Assign a label and icon to each directory
Expand Down Expand Up @@ -1383,28 +1381,27 @@ private void updateUsbInformation() {
List<UsbOtgRepresentation> connectedDevices = OTGUtil.getMassStorageDevicesConnected(this);

if (!connectedDevices.isEmpty()) {
if (SingletonUsbOtg.getInstance().getUsbOtgRoot() != null
&& OTGUtil.isUsbUriAccessible(this)) {
if (SingletonUsbOtg.INSTANCE.getUsbOtgRoot() != null && OTGUtil.isUsbUriAccessible(this)) {
for (UsbOtgRepresentation device : connectedDevices) {
if (SingletonUsbOtg.getInstance().checkIfRootIsFromDevice(device)) {
if (SingletonUsbOtg.INSTANCE.checkIfRootIsFromDevice(device)) {
isInformationUpdated = true;
break;
}
}

if (!isInformationUpdated) {
SingletonUsbOtg.getInstance().resetUsbOtgRoot();
SingletonUsbOtg.INSTANCE.resetUsbOtgRoot();
}
}

if (!isInformationUpdated) {
SingletonUsbOtg.getInstance().setConnectedDevice(connectedDevices.get(0));
SingletonUsbOtg.INSTANCE.setConnectedDevice(connectedDevices.get(0));
isInformationUpdated = true;
}
}

if (!isInformationUpdated) {
SingletonUsbOtg.getInstance().resetUsbOtgRoot();
SingletonUsbOtg.INSTANCE.resetUsbOtgRoot();
drawer.refreshDrawer();
}

Expand All @@ -1424,12 +1421,12 @@ public void onReceive(Context context, Intent intent) {
List<UsbOtgRepresentation> connectedDevices =
OTGUtil.getMassStorageDevicesConnected(MainActivity.this);
if (!connectedDevices.isEmpty()) {
SingletonUsbOtg.getInstance().resetUsbOtgRoot();
SingletonUsbOtg.getInstance().setConnectedDevice(connectedDevices.get(0));
SingletonUsbOtg.INSTANCE.resetUsbOtgRoot();
SingletonUsbOtg.INSTANCE.setConnectedDevice(connectedDevices.get(0));
drawer.refreshDrawer();
}
} else if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_DETACHED)) {
SingletonUsbOtg.getInstance().resetUsbOtgRoot();
SingletonUsbOtg.INSTANCE.resetUsbOtgRoot();
drawer.refreshDrawer();
goToMain(null);
}
Expand Down Expand Up @@ -1695,7 +1692,7 @@ protected void onActivityResult(int requestCode, int responseCode, Intent intent
if (responseCode == Activity.RESULT_OK && intent.getData() != null) {
// otg access
Uri usbOtgRoot = intent.getData();
SingletonUsbOtg.getInstance().setUsbOtgRoot(usbOtgRoot);
SingletonUsbOtg.INSTANCE.setUsbOtgRoot(usbOtgRoot);
mainFragment.loadlist(OTGUtil.PREFIX_OTG, false, OpenMode.OTG, true);
drawer.closeIfNotLocked();
if (drawer.isLocked()) drawer.onDrawerClosed();
Expand Down Expand Up @@ -2048,7 +2045,7 @@ public void onNewIntent(Intent i) {

if (SDK_INT >= KITKAT) {
if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_DETACHED)) {
SingletonUsbOtg.getInstance().resetUsbOtgRoot();
SingletonUsbOtg.INSTANCE.resetUsbOtgRoot();
drawer.refreshDrawer();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ public final class MimeTypes {
MIME_TYPES.put("ksh", "text/plain");
MIME_TYPES.put("sh", "application/x-sh");

MIME_TYPES.put("db", "application/octet-stream");
MIME_TYPES.put("db3", "application/octet-stream");
MIME_TYPES.put("db", "application/vnd.sqlite3");
MIME_TYPES.put("db3", "application/vnd.sqlite3");
MIME_TYPES.put("sqlite", "application/vnd.sqlite3");
MIME_TYPES.put("sqlite3", "application/vnd.sqlite3");

MIME_TYPES.put("otf", "application/x-font-otf");
MIME_TYPES.put("ttf", "application/x-font-ttf");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
&& (meta.path.contains(OTGUtil.PREFIX_OTG)
|| meta.path.startsWith(OTGUtil.PREFIX_MEDIA_REMOVABLE))
&& SingletonUsbOtg.getInstance().getUsbOtgRoot() == null) {
&& SingletonUsbOtg.INSTANCE.getUsbOtgRoot() == null) {
MaterialDialog dialog = GeneralDialogCreation.showOtgSafExplanationDialog(mainActivity);
dialog
.getActionButton(DialogAction.POSITIVE)
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/amaze/filemanager/utils/OTGUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ object OTGUtil {
fileFound: OnFileFound,
) {
val rootUriString =
SingletonUsbOtg.getInstance().usbOtgRoot
SingletonUsbOtg.getUsbOtgRoot()
?: throw NullPointerException("USB OTG root not set!")
return getDocumentFiles(rootUriString, path, context, OpenMode.OTG, fileFound)
}
Expand Down Expand Up @@ -163,7 +163,7 @@ object OTGUtil {
createRecursive: Boolean,
): DocumentFile? {
val rootUriString =
SingletonUsbOtg.getInstance().usbOtgRoot
SingletonUsbOtg.getUsbOtgRoot()
?: throw NullPointerException("USB OTG root not set!")

return getDocumentFile(path, rootUriString, context, OpenMode.OTG, createRecursive)
Expand Down Expand Up @@ -208,7 +208,7 @@ object OTGUtil {
@RequiresApi(api = KITKAT)
@JvmStatic
fun isUsbUriAccessible(context: Context?): Boolean {
val rootUriString = SingletonUsbOtg.getInstance().usbOtgRoot
val rootUriString = SingletonUsbOtg.getUsbOtgRoot()
return DocumentsContract.isDocumentUri(context, rootUriString)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public void usbConnectionTest() {

Uri rootBefore = Uri.parse("ssh://testuser:[email protected]:22222");

SingletonUsbOtg.getInstance().setUsbOtgRoot(rootBefore);
SingletonUsbOtg.INSTANCE.setUsbOtgRoot(rootBefore);

controller.pause().resume().get();

Uri rootAfter = SingletonUsbOtg.getInstance().getUsbOtgRoot();
Uri rootAfter = SingletonUsbOtg.INSTANCE.getUsbOtgRoot();

assertEquals(
"Uris are different: (before:) " + rootBefore + " (after:) " + rootAfter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
*
* See the end of the source file for distribution license (Modified BSD licence)
*/
@SuppressWarnings("PMD")
public abstract class CloudStreamServer {
private static final Logger LOG = LoggerFactory.getLogger(CloudStreamServer.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
*
* See the end of the source file for distribution license (Modified BSD licence)
*/
@SuppressWarnings("PMD")
public abstract class StreamServer {

private static final Logger LOG = LoggerFactory.getLogger(StreamServer.class);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (C) 2014-2024 Arpit Khurana <[email protected]>, Vishal Nehra <[email protected]>,
* Emmanuel Messulam<[email protected]>, Raymond Lai <airwave209gt at gmail.com> and Contributors.
*
* This file is part of Amaze File Manager.
*
* Amaze File Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.amaze.filemanager.fileoperations.filesystem.usb

import android.net.Uri

/**
* USB OTG device representation.
*/
object SingletonUsbOtg {
var connectedDevice: UsbOtgRepresentation? = null
var _usbOtgRoot: Uri? = null

val isDeviceConnected: Boolean
get() = connectedDevice != null

/**
* Get the root of the connected USB OTG device.
*
* @return the root URI of the connected USB OTG device, or null if no device is connected.
*/
fun getUsbOtgRoot(): Uri? {
return _usbOtgRoot
}

/**
* Set the root of the connected USB OTG device. Will throw exception if no device is connected.
*
* @param root the root URI of the connected USB OTG device.
*/
fun setUsbOtgRoot(root: Uri?) {
checkNotNull(connectedDevice) { "No device connected!" }
_usbOtgRoot = root
}

/**
* Clear the reference to connected device and root.
*/
fun resetUsbOtgRoot() {
connectedDevice = null
_usbOtgRoot = null
}

/**
* Check if the root is from the given device.
*
* Used by [MainActivity.updateUsbInformation].
*/
fun checkIfRootIsFromDevice(device: UsbOtgRepresentation): Boolean {
return _usbOtgRoot != null && connectedDevice.hashCode() == device.hashCode()
}
}
Loading
Loading