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

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

Merge "Add periodic sync support to requestsync."

parents 90de5f2e 4a7554af
Loading
Loading
Loading
Loading
+91 −29
Original line number Diff line number Diff line
@@ -29,10 +29,41 @@ public class RequestSync {
    private int mNextArg;
    private String mCurArgData;

    enum Operation {
        REQUEST_SYNC {
            @Override
            void invoke(RequestSync caller) {
                ContentResolver.requestSync(caller.mAccount, caller.mAuthority, caller.mExtras);
            }
        },
        ADD_PERIODIC_SYNC {
            @Override
            void invoke(RequestSync caller) {
                ContentResolver.addPeriodicSync(caller.mAccount, caller.mAuthority, caller.mExtras,
                        caller.mPeriodicIntervalSeconds);
            }
        },
        REMOVE_PERIODIC_SYNC {
            @Override
            void invoke(RequestSync caller) {
                ContentResolver.removePeriodicSync(
                        caller.mAccount, caller.mAuthority, caller.mExtras);
            }
        };

        abstract void invoke(RequestSync caller);
    }

    private Operation mOperation;

    // account & authority
    private String mAccountName = null;
    private String mAccountType = null;
    private String mAuthority = null;
    private String mAccountName;
    private String mAccountType;
    private String mAuthority;

    private Account mAccount;

    private int mPeriodicIntervalSeconds;

    // extras
    private Bundle mExtras = new Bundle();
@@ -80,11 +111,28 @@ public class RequestSync {
                }
            }

            ContentResolver.requestSync(account, mAuthority, mExtras);
            mAccount = account;

            mOperation.invoke(this);
        }
    }

    private boolean parseArgs() throws URISyntaxException {
        mOperation = Operation.REQUEST_SYNC;
        if (mArgs.length > 0) {
            switch (mArgs[0]) {
                case "add-periodic":
                    mNextArg++;
                    mOperation = Operation.ADD_PERIODIC_SYNC;
                    mPeriodicIntervalSeconds = Integer.parseInt(nextArgRequired());
                    break;
                case "remove-periodic":
                    mNextArg++;
                    mOperation = Operation.REMOVE_PERIODIC_SYNC;
                    break;
            }
        }

        String opt;
        while ((opt=nextOption()) != null) {
            if (opt.equals("-h") || opt.equals("--help")) {
@@ -114,6 +162,8 @@ public class RequestSync {
                mExtras.putBoolean(ContentResolver.SYNC_EXTRAS_OVERRIDE_TOO_MANY_DELETIONS, true);
            } else if (opt.equals("-u") || opt.equals("--upload-only")) {
                mExtras.putBoolean(ContentResolver.SYNC_EXTRAS_UPLOAD, true);
            } else if (opt.equals("--rc") || opt.equals("--require-charging")) {
                mExtras.putBoolean(ContentResolver.SYNC_EXTRAS_REQUIRE_CHARGING, true);
            } else if (opt.equals("-e") || opt.equals("--es") || opt.equals("--extra-string")) {
                final String key = nextArgRequired();
                final String value = nextArgRequired();
@@ -207,31 +257,43 @@ public class RequestSync {

    private static void showUsage() {
        System.err.println(
                "usage: requestsync [options]\n" +
                "Usage:\n" +
                "\n" +
                "  requestsync [options]\n" +
                "    With no options, a sync will be requested for all account and all sync\n" +
                "authorities with no extras. Options can be:\n" +
                "    authorities with no extras.\n" +
                "    Basic options:\n" +
                "       -h|--help: Display this message\n" +
                "       -n|--account-name <ACCOUNT-NAME>\n" +
                "       -t|--account-type <ACCOUNT-TYPE>\n" +
                "       -a|--authority <AUTHORITY>\n" +
                "  Add ContentResolver extras:\n" +
                "    ContentResolver extra options:\n" +
                "      --is|--ignore-settings: Add SYNC_EXTRAS_IGNORE_SETTINGS\n" +
                "      --ib|--ignore-backoff: Add SYNC_EXTRAS_IGNORE_BACKOFF\n" +
                "      --dd|--discard-deletions: Add SYNC_EXTRAS_DISCARD_LOCAL_DELETIONS\n" +
                "      --nr|--no-retry: Add SYNC_EXTRAS_DO_NOT_RETRY\n" +
                "      --ex|--expedited: Add SYNC_EXTRAS_EXPEDITED\n" +
                "    --i|--initialize: Add SYNC_EXTRAS_INITIALIZE\n" +
                "      -i|--initialize: Add SYNC_EXTRAS_INITIALIZE\n" +
                "      --m|--manual: Add SYNC_EXTRAS_MANUAL\n" +
                "      --od|--override-deletions: Add SYNC_EXTRAS_OVERRIDE_TOO_MANY_DELETIONS\n" +
                "    --u|--upload-only: Add SYNC_EXTRAS_UPLOAD\n" +
                "  Add custom extras:\n" +
                "      -u|--upload-only: Add SYNC_EXTRAS_UPLOAD\n" +
                "      --rc|--require-charging: Add SYNC_EXTRAS_REQUIRE_CHARGING\n" +
                "    Custom extra options:\n" +
                "      -e|--es|--extra-string <KEY> <VALUE>\n" +
                "      --esn|--extra-string-null <KEY>\n" +
                "      --ei|--extra-int <KEY> <VALUE>\n" +
                "      --el|--extra-long <KEY> <VALUE>\n" +
                "      --ef|--extra-float <KEY> <VALUE>\n" +
                "      --ed|--extra-double <KEY> <VALUE>\n" +
                "    --ez|--extra-bool <KEY> <VALUE>\n"
                "      --ez|--extra-bool <KEY> <VALUE>\n" +
                "\n" +
                "  requestsync add-periodic INTERVAL-SECOND [options]\n" +
                        "  requestsync remove-periodic [options]\n" +
                "    Mandatory options:\n" +
                "      -n|--account-name <ACCOUNT-NAME>\n" +
                "      -t|--account-type <ACCOUNT-TYPE>\n" +
                "      -a|--authority <AUTHORITY>\n" +
                "    Also takes the above extra options.\n"
                );
    }
}