(Context context, String command, boolean manual)
| 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) { |
no test coverage detected