Add periodic sync support to requestsync.

Test: manual test
Change-Id: Ie53249de5e9c5e53bdf87cb9f78745c994bc34e6
This commit is contained in:
Makoto Onuki
2017-06-08 17:12:05 -07:00
parent a94b152df1
commit 4a7554afc6

View File

@@ -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" +
"With no options, a sync will be requested for all account and all sync\n" +
"authorities with no extras. Options can be:\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" +
" --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" +
" --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" +
" -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"
"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.\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" +
" 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" +
" --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" +
" --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" +
"\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"
);
}
}