Cloud sync: added data wipe

pull/212/head
M66B 2 years ago
parent b8791cdffd
commit 77ae4c42e4

@ -84,7 +84,7 @@ public class CloudSync {
JSONObject jrequest = new JSONObject();
EntityLog.log(context, EntityLog.Type.Cloud, "Cloud command=" + command);
EntityLog.log(context, EntityLog.Type.Cloud, "Cloud request=" + command);
if ("sync".equals(command)) {
long lrevision = prefs.getLong("cloud_lrevision", 0);
EntityLog.log(context, EntityLog.Type.Cloud,
@ -155,13 +155,22 @@ public class CloudSync {
receiveRemoteData(context, user, password, lrevision - 1, rrevision, jstatus);
} else
throw new IllegalArgumentException("Expected one status item");
prefs.edit().putLong("cloud_last_sync", new Date().getTime()).apply();
} else if ("wipe".equals(command)) {
jrequest.put("items", new JSONArray());
JSONObject jresponse = call(context, user, password, "keys", jrequest);
JSONArray jitems = jresponse.getJSONArray("items");
for (int i = 0; i < jitems.length(); i++)
jitems.getJSONObject(i).put("val", null);
jrequest.put("items", jitems);
call(context, user, password, "write", jrequest); // wipe data
call(context, user, password, "wipe", jrequest); // wipe account
} else {
JSONArray jitems = new JSONArray();
jrequest.put("items", jitems);
call(context, user, password, command, jrequest);
}
prefs.edit().putLong("cloud_last_sync", new Date().getTime()).apply();
}
private static Long updateSyncdata(Context context) throws IOException, JSONException {
@ -599,7 +608,7 @@ public class CloudSync {
JSONArray jitems = jrequest.getJSONArray("items");
for (int i = 0; i < jitems.length(); i++) {
JSONObject jitem = jitems.getJSONObject(i);
long revision = jitem.getLong("rev");
long revision = jitem.optLong("rev", 0);
String k = jitem.getString("key");
String v = null;
@ -668,7 +677,7 @@ public class CloudSync {
JSONArray jitems = jresponse.getJSONArray("items");
for (int i = 0; i < jitems.length(); i++) {
JSONObject jitem = jitems.getJSONObject(i);
long revision = jitem.getLong("rev");
long revision = jitem.optLong("rev", 0);
String k = jitem.getString("key");
String v = null;
@ -757,6 +766,7 @@ public class CloudSync {
}
private static List<JSONArray> partition(JSONArray jarray) throws JSONException {
Log.i("Cloud batch size=" + jarray.length() + "/" + BATCH_SIZE);
if (jarray.length() <= BATCH_SIZE)
return Arrays.asList(jarray);
@ -771,6 +781,8 @@ public class CloudSync {
jpartitions.add(jpartition);
}
Log.i("Cloud partitions=" + jpartitions.size());
if (count != jarray.length())
throw new IllegalArgumentException("Partition error size=" + count + "/" + jarray.length());

@ -242,7 +242,7 @@ public class FragmentOptionsBackup extends FragmentBase implements SharedPrefere
Helper.linkPro(tvExportPro);
cardCloud.setVisibility(
BuildConfig.DEBUG &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
!TextUtils.isEmpty(BuildConfig.CLOUD_URI)
? View.VISIBLE : View.GONE);
Helper.linkPro(tvCloudPro);
@ -1511,8 +1511,6 @@ public class FragmentOptionsBackup extends FragmentBase implements SharedPrefere
}
private void cloud(Bundle args) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
new SimpleTask<Void>() {
@Override
protected void onPreExecute(Bundle args) {
@ -1536,7 +1534,7 @@ public class FragmentOptionsBackup extends FragmentBase implements SharedPrefere
command = "logout";
throw ex;
} finally {
if ("logout".equals(command)) {
if ("logout".equals(command) || "wipe".equals(command)) {
prefs.edit()
.remove("cloud_revision")
.remove("cloud_user")
@ -1555,7 +1553,6 @@ public class FragmentOptionsBackup extends FragmentBase implements SharedPrefere
return null;
}
@Override
protected void onExecuted(Bundle args, Void data) {
view.post(new Runnable() {

Loading…
Cancel
Save