(Context context)
| 185 | } |
| 186 | |
| 187 | private static Long updateSyncdata(Context context) throws IOException, JSONException { |
| 188 | DB db = DB.getInstance(context); |
| 189 | File dir = Helper.ensureExists(context, "syncdata"); |
| 190 | |
| 191 | Long last = null; |
| 192 | |
| 193 | List<EntityAccount> accounts = db.account().getAccounts(); |
| 194 | if (accounts != null) |
| 195 | for (EntityAccount account : accounts) |
| 196 | if (account.synchronize && !TextUtils.isEmpty(account.uuid) && |
| 197 | account.auth_type != ServiceAuthenticator.AUTH_TYPE_GMAIL) { |
| 198 | EntityAccount aexisting = null; |
| 199 | File afile = new File(dir, "account." + account.uuid + ".json"); |
| 200 | if (afile.exists()) |
| 201 | try (InputStream is = new FileInputStream(afile)) { |
| 202 | aexisting = EntityAccount.fromJSON(new JSONObject(Helper.readStream(is))); |
| 203 | } |
| 204 | |
| 205 | boolean apassword = (account.auth_type == ServiceAuthenticator.AUTH_TYPE_PASSWORD); |
| 206 | if (aexisting == null || |
| 207 | !EntityAccount.areEqual(account, aexisting, apassword, false)) { |
| 208 | Helper.writeText(afile, account.toJSON().toString()); |
| 209 | if (account.last_modified != null) |
| 210 | afile.setLastModified(account.last_modified); |
| 211 | } |
| 212 | |
| 213 | long atime = afile.lastModified(); |
| 214 | if (last == null || atime > last) |
| 215 | last = atime; |
| 216 | |
| 217 | List<EntityIdentity> identities = db.identity().getIdentities(account.id); |
| 218 | if (identities != null) |
| 219 | for (EntityIdentity identity : identities) |
| 220 | if (identity.synchronize && !TextUtils.isEmpty(identity.uuid)) { |
| 221 | EntityIdentity iexisting = null; |
| 222 | File ifile = new File(dir, "identity." + identity.uuid + ".json"); |
| 223 | if (ifile.exists()) |
| 224 | try (InputStream is = new FileInputStream(ifile)) { |
| 225 | iexisting = EntityIdentity.fromJSON(new JSONObject(Helper.readStream(is))); |
| 226 | } |
| 227 | |
| 228 | boolean ipassword = (account.auth_type == ServiceAuthenticator.AUTH_TYPE_PASSWORD); |
| 229 | if (iexisting == null || |
| 230 | !EntityIdentity.areEqual(identity, iexisting, ipassword, false)) { |
| 231 | Helper.writeText(ifile, identity.toJSON().toString()); |
| 232 | if (identity.last_modified != null) |
| 233 | ifile.setLastModified(identity.last_modified); |
| 234 | } |
| 235 | |
| 236 | long itime = ifile.lastModified(); |
| 237 | if (itime > last) |
| 238 | last = itime; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | return last; |
| 243 | } |
| 244 |
no test coverage detected