(Context context, String user, String password, long lrevision)
| 243 | } |
| 244 | |
| 245 | private static void sendLocalData(Context context, String user, String password, long lrevision) |
| 246 | throws JSONException, GeneralSecurityException, IOException, InvalidCipherTextException { |
| 247 | DB db = DB.getInstance(context); |
| 248 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); |
| 249 | boolean cloud_send = prefs.getBoolean("cloud_send", true); |
| 250 | |
| 251 | if (!cloud_send) { |
| 252 | EntityLog.log(context, EntityLog.Type.Cloud, "Cloud skip send"); |
| 253 | return; |
| 254 | } |
| 255 | |
| 256 | List<EntityAccount> accounts = db.account().getAccounts(); |
| 257 | EntityLog.log(context, EntityLog.Type.Cloud, |
| 258 | "Cloud accounts=" + (accounts == null ? null : accounts.size())); |
| 259 | if (accounts == null || accounts.size() == 0) |
| 260 | return; |
| 261 | |
| 262 | List<String> uuidAccounts = new ArrayList<>(); |
| 263 | List<String> uuidIdentities = new ArrayList<>(); |
| 264 | |
| 265 | JSONArray jupload = new JSONArray(); |
| 266 | |
| 267 | JSONArray jaccountuuidlist = new JSONArray(); |
| 268 | for (EntityAccount account : accounts) |
| 269 | if (account.synchronize && !TextUtils.isEmpty(account.uuid) && |
| 270 | account.auth_type != ServiceAuthenticator.AUTH_TYPE_GMAIL) { |
| 271 | if (uuidAccounts.contains(account.uuid)) { |
| 272 | Log.w("Duplicate account uuid=" + account.uuid); |
| 273 | account.uuid = UUID.randomUUID().toString(); |
| 274 | db.account().setAccountUuid(account.id, account.uuid); |
| 275 | } else |
| 276 | uuidAccounts.add(account.uuid); |
| 277 | |
| 278 | jaccountuuidlist.put(account.uuid); |
| 279 | |
| 280 | JSONArray jidentitieuuids = new JSONArray(); |
| 281 | List<EntityIdentity> identities = db.identity().getIdentities(account.id); |
| 282 | if (identities != null) |
| 283 | for (EntityIdentity identity : identities) |
| 284 | if (identity.synchronize && !TextUtils.isEmpty(identity.uuid)) { |
| 285 | if (uuidIdentities.contains(identity.uuid)) { |
| 286 | Log.w("Duplicate identity uuid=" + identity.uuid); |
| 287 | identity.uuid = UUID.randomUUID().toString(); |
| 288 | db.identity().setIdentityUuid(identity.id, identity.uuid); |
| 289 | } else |
| 290 | uuidIdentities.add(identity.uuid); |
| 291 | |
| 292 | jidentitieuuids.put(identity.uuid); |
| 293 | |
| 294 | JSONObject jidentity = identity.toJSON(); |
| 295 | jidentity.put("account_uuid", account.uuid); |
| 296 | |
| 297 | JSONObject jidentitykv = new JSONObject(); |
| 298 | jidentitykv.put("key", "identity." + identity.uuid); |
| 299 | jidentitykv.put("val", jidentity.toString()); |
| 300 | jidentitykv.put("rev", lrevision); |
| 301 | jupload.put(jidentitykv); |
| 302 | } |
no test coverage detected