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

Commit b490f534 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add "adb shell content gettype" support"

parents 1b5e4c9b ce34881b
Loading
Loading
Loading
Loading
+93 −53
Original line number Diff line number Diff line
@@ -124,6 +124,11 @@ public class Content {
                    + "  # cat default ringtone to a file, then pull to host\n"
                    + "  adb shell 'content read --uri content://settings/system/ringtone >"
                    + " /mnt/sdcard/tmp.ogg' && adb pull /mnt/sdcard/tmp.ogg\n"
                    + "\n"
                    + "usage: adb shell content gettype --uri <URI> [--user <USER_ID>]\n"
                    + "  Example:\n"
                    + "  # Show the mime-type of the URI\n"
                    + "  adb shell content gettype --uri content://media/internal/audio/media/\n"
                    + "\n";

    private static class Parser {
@@ -133,6 +138,7 @@ public class Content {
        private static final String ARGUMENT_QUERY = "query";
        private static final String ARGUMENT_CALL = "call";
        private static final String ARGUMENT_READ = "read";
        private static final String ARGUMENT_GET_TYPE = "gettype";
        private static final String ARGUMENT_WHERE = "--where";
        private static final String ARGUMENT_BIND = "--bind";
        private static final String ARGUMENT_URI = "--uri";
@@ -172,6 +178,8 @@ public class Content {
                    return parseCallCommand();
                } else if (ARGUMENT_READ.equals(operation)) {
                    return parseReadCommand();
                } else if (ARGUMENT_GET_TYPE.equals(operation)) {
                    return parseGetTypeCommand();
                } else {
                    throw new IllegalArgumentException("Unsupported operation: " + operation);
                }
@@ -291,6 +299,26 @@ public class Content {
            return new CallCommand(uri, userId, method, arg, values);
        }

        private GetTypeCommand parseGetTypeCommand() {
            Uri uri = null;
            int userId = UserHandle.USER_SYSTEM;

            for (String argument; (argument = mTokenizer.nextArg()) != null;) {
                if (ARGUMENT_URI.equals(argument)) {
                    uri = Uri.parse(argumentValueRequired(argument));
                } else if (ARGUMENT_USER.equals(argument)) {
                    userId = Integer.parseInt(argumentValueRequired(argument));
                } else {
                    throw new IllegalArgumentException("Unsupported argument: " + argument);
                }
            }
            if (uri == null) {
                throw new IllegalArgumentException("Content provider URI not specified."
                        + " Did you specify --uri argument?");
            }
            return new GetTypeCommand(uri, userId);
        }

        private ReadCommand parseReadCommand() {
            Uri uri = null;
            int userId = UserHandle.USER_SYSTEM;
@@ -511,6 +539,18 @@ public class Content {
        }
    }

    private static class GetTypeCommand extends Command {
        public GetTypeCommand(Uri uri, int userId) {
            super(uri, userId);
        }

        @Override
        public void onExecute(IContentProvider provider) throws Exception {
            String type = provider.getType(mUri);
            System.out.println("Result: " + type);
        }
    }

    private static class ReadCommand extends Command {
        public ReadCommand(Uri uri, int userId) {
            super(uri, userId);