MCPcopy Create free account
hub / github.com/M66B/FairEmail / execute

Method execute

app/src/main/java/eu/faircode/email/CloudSync.java:76–185  ·  view source on GitHub ↗
(Context context, String command, boolean manual)

Source from the content-addressed store, hash-verified

74 // Upper level
75
76 static void execute(Context context, String command, boolean manual)
77 throws JSONException, GeneralSecurityException, IOException, InvalidCipherTextException {
78 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
79 String user = prefs.getString("cloud_user", null);
80 String password = prefs.getString("cloud_password", null);
81
82 if (TextUtils.isEmpty(user) || TextUtils.isEmpty(password))
83 return;
84 if (!ActivityBilling.isPro(context))
85 return;
86
87 JSONObject jrequest = new JSONObject();
88 if ("login".equals(command)) {
89 String iab_json = prefs.getString("iab_json", null);
90 String iab_signature = prefs.getString("iab_signature", null);
91 if (!TextUtils.isEmpty(iab_json) & !TextUtils.isEmpty(iab_signature)) {
92 Log.i("Cloud IAB " + iab_json);
93 jrequest.put("iab_json", iab_json);
94 jrequest.put("iab_signature", iab_signature);
95 }
96 }
97
98 EntityLog.log(context, EntityLog.Type.Cloud, "Cloud request=" + command);
99 if ("sync".equals(command)) {
100 long lrevision = prefs.getLong("cloud_lrevision", 0);
101 EntityLog.log(context, EntityLog.Type.Cloud,
102 "Cloud local revision=" + lrevision + " (" + new Date(lrevision) + ")");
103
104 Long lastUpdate = updateSyncdata(context);
105 EntityLog.log(context, EntityLog.Type.Cloud,
106 "Cloud last update=" + (lastUpdate == null ? null : new Date(lastUpdate)));
107 if (lastUpdate != null && lrevision > lastUpdate) {
108 String msg = "Cloud invalid local revision" +
109 " lrevision=" + lrevision + " last=" + lastUpdate;
110 Log.w(msg);
111 EntityLog.log(context, EntityLog.Type.Cloud, msg);
112 lrevision = lastUpdate;
113 prefs.edit().putLong("cloud_lrevision", lrevision).apply();
114 }
115
116 JSONObject jsyncstatus = new JSONObject();
117 jsyncstatus.put("key", "sync.status");
118 jsyncstatus.put("rev", lrevision);
119
120 JSONArray jitems = new JSONArray();
121 jitems.put(jsyncstatus);
122
123 jrequest.put("items", jitems);
124
125 JSONObject jresponse = call(context, user, password, "read", jrequest);
126 jitems = jresponse.getJSONArray("items");
127
128 if (jitems.length() == 0) {
129 EntityLog.log(context, EntityLog.Type.Cloud, "Cloud server is empty");
130 sendLocalData(context, user, password, lrevision == 0
131 ? (lastUpdate == null ? new Date().getTime() : lastUpdate)
132 : lrevision);
133 } else if (jitems.length() == 1) {

Callers 2

doWorkMethod · 0.95
onExecuteMethod · 0.95

Calls 15

isProMethod · 0.95
iMethod · 0.95
logMethod · 0.95
updateSyncdataMethod · 0.95
wMethod · 0.95
callMethod · 0.95
sendLocalDataMethod · 0.95
receiveRemoteDataMethod · 0.95
getLongMethod · 0.80
getStringMethod · 0.45
isEmptyMethod · 0.45
equalsMethod · 0.45

Tested by

no test coverage detected