Changed: Rename UriUtils getUriFilePath() to getUriFilePathWithFragment()

This commit is contained in:
agnostic-apollo
2022-01-22 18:44:56 +05:00
parent 1f3d3616a4
commit 3898ebdc74
4 changed files with 11 additions and 8 deletions

View File

@@ -73,7 +73,7 @@ public class TermuxOpenReceiver extends BroadcastReceiver {
} }
// Get full path including fragment (anything after last "#") // Get full path including fragment (anything after last "#")
String filePath = UriUtils.getUriFilePath(data); String filePath = UriUtils.getUriFilePathWithFragment(data);
final File fileToShare = new File(filePath); final File fileToShare = new File(filePath);
if (!(fileToShare.isFile() && fileToShare.canRead())) { if (!(fileToShare.isFile() && fileToShare.canRead())) {

View File

@@ -351,11 +351,11 @@ public final class TermuxService extends Service implements AppShell.AppShellCli
Logger.logVerbose(LOG_TAG, "uri: \"" + executionCommand.executableUri + "\", path: \"" + executionCommand.executableUri.getPath() + "\", fragment: \"" + executionCommand.executableUri.getFragment() + "\""); Logger.logVerbose(LOG_TAG, "uri: \"" + executionCommand.executableUri + "\", path: \"" + executionCommand.executableUri.getPath() + "\", fragment: \"" + executionCommand.executableUri.getFragment() + "\"");
// Get full path including fragment (anything after last "#") // Get full path including fragment (anything after last "#")
executionCommand.executable = UriUtils.getUriFilePath(executionCommand.executableUri); executionCommand.executable = UriUtils.getUriFilePathWithFragment(executionCommand.executableUri);
executionCommand.arguments = IntentUtils.getStringArrayExtraIfSet(intent, TERMUX_SERVICE.EXTRA_ARGUMENTS, null); executionCommand.arguments = IntentUtils.getStringArrayExtraIfSet(intent, TERMUX_SERVICE.EXTRA_ARGUMENTS, null);
if (executionCommand.inBackground) if (executionCommand.inBackground)
executionCommand.stdin = IntentUtils.getStringExtraIfSet(intent, TERMUX_SERVICE.EXTRA_STDIN, null); executionCommand.stdin = IntentUtils.getStringExtraIfSet(intent, TERMUX_SERVICE.EXTRA_STDIN, null);
executionCommand.backgroundCustomLogLevel = IntentUtils.getIntegerExtraIfSet(intent, TERMUX_SERVICE.EXTRA_BACKGROUND_CUSTOM_LOG_LEVEL, null); executionCommand.backgroundCustomLogLevel = IntentUtils.getIntegerExtraIfSet(intent, TERMUX_SERVICE.EXTRA_BACKGROUND_CUSTOM_LOG_LEVEL, null);
} }
executionCommand.workingDirectory = IntentUtils.getStringExtraIfSet(intent, TERMUX_SERVICE.EXTRA_WORKDIR, null); executionCommand.workingDirectory = IntentUtils.getStringExtraIfSet(intent, TERMUX_SERVICE.EXTRA_WORKDIR, null);

View File

@@ -99,7 +99,7 @@ public class TermuxFileReceiverActivity extends Activity {
Logger.logVerbose(LOG_TAG, "uri: \"" + dataUri + "\", path: \"" + dataUri.getPath() + "\", fragment: \"" + dataUri.getFragment() + "\""); Logger.logVerbose(LOG_TAG, "uri: \"" + dataUri + "\", path: \"" + dataUri.getPath() + "\", fragment: \"" + dataUri.getFragment() + "\"");
// Get full path including fragment (anything after last "#") // Get full path including fragment (anything after last "#")
String path = UriUtils.getUriFilePath(dataUri); String path = UriUtils.getUriFilePathWithFragment(dataUri);
if (DataUtils.isNullOrEmpty(path)) { if (DataUtils.isNullOrEmpty(path)) {
showErrorDialogAndQuit("File path from data uri is null, empty or invalid."); showErrorDialogAndQuit("File path from data uri is null, empty or invalid.");
return; return;

View File

@@ -3,6 +3,7 @@ package com.termux.shared.net.uri;
import android.net.Uri; import android.net.Uri;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.termux.shared.data.DataUtils; import com.termux.shared.data.DataUtils;
import com.termux.shared.file.FileUtils; import com.termux.shared.file.FileUtils;
@@ -10,7 +11,7 @@ import com.termux.shared.file.FileUtils;
public class UriUtils { public class UriUtils {
/** /**
* Get the full file path from a {@link Uri}. * Get the full file path from a {@link Uri} including the fragment.
* *
* If the {@link Uri} was created from file path with {@link Uri#parse(String)}, like "am" * If the {@link Uri} was created from file path with {@link Uri#parse(String)}, like "am"
* command "-d" option does, and the path contained a "#", then anything after it would become * command "-d" option does, and the path contained a "#", then anything after it would become
@@ -21,10 +22,11 @@ public class UriUtils {
* with {@link Uri.Builder#path(String)}, then "#" will automatically be encoded to "%23" * with {@link Uri.Builder#path(String)}, then "#" will automatically be encoded to "%23"
* and separate fragment will not exist. * and separate fragment will not exist.
* *
* @param uri The {@link Uri} to get basename from. * @param uri The {@link Uri} to get file path from.
* @return Returns the file path if found, otherwise {@code null}. * @return Returns the file path if found, otherwise {@code null}.
*/ */
public static String getUriFilePath(Uri uri) { @Nullable
public static String getUriFilePathWithFragment(Uri uri) {
if (uri == null) return null; if (uri == null) return null;
String path = uri.getPath(); String path = uri.getPath();
if (DataUtils.isNullOrEmpty(path)) return null; if (DataUtils.isNullOrEmpty(path)) return null;
@@ -40,12 +42,13 @@ public class UriUtils {
* @param withFragment If the {@link Uri} fragment should be included in basename. * @param withFragment If the {@link Uri} fragment should be included in basename.
* @return Returns the file basename if found, otherwise {@code null}. * @return Returns the file basename if found, otherwise {@code null}.
*/ */
@Nullable
public static String getUriFileBasename(Uri uri, boolean withFragment) { public static String getUriFileBasename(Uri uri, boolean withFragment) {
if (uri == null) return null; if (uri == null) return null;
String path; String path;
if (withFragment) { if (withFragment) {
path = getUriFilePath(uri); path = getUriFilePathWithFragment(uri);
} else { } else {
path = uri.getPath(); path = uri.getPath();
if (DataUtils.isNullOrEmpty(path)) return null; if (DataUtils.isNullOrEmpty(path)) return null;