use of org.thoughtcrime.securesms.jobs.DirectoryRefreshJob in project Signal-Android by signalapp.
the class RegistrationActivity method handleSuccessfulRegistration.
private void handleSuccessfulRegistration() {
ApplicationContext.getInstance(RegistrationActivity.this).getJobManager().add(new DirectoryRefreshJob(RegistrationActivity.this, false));
DirectoryRefreshListener.schedule(RegistrationActivity.this);
RotateSignedPreKeyListener.schedule(RegistrationActivity.this);
Intent nextIntent = getIntent().getParcelableExtra("next_intent");
if (nextIntent == null) {
nextIntent = new Intent(RegistrationActivity.this, ConversationListActivity.class);
}
startActivity(nextIntent);
finish();
}
use of org.thoughtcrime.securesms.jobs.DirectoryRefreshJob in project Signal-Android by WhisperSystems.
the class ContactsSyncAdapter method onPerformSync.
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
Log.i(TAG, "onPerformSync(" + authority + ")");
Context context = getContext();
if (SignalStore.account().getE164() == null) {
Log.i(TAG, "No local number set, skipping all sync operations.");
return;
}
if (!SignalStore.account().isRegistered()) {
Log.i(TAG, "Not push registered. Just syncing contact info.");
DirectoryHelper.syncRecipientInfoWithSystemContacts(context);
return;
}
Set<String> allSystemNumbers = ContactAccessor.getInstance().getAllContactsWithNumbers(context);
Set<String> knownSystemNumbers = SignalDatabase.recipients().getAllPhoneNumbers();
Set<String> unknownSystemNumbers = SetUtil.difference(allSystemNumbers, knownSystemNumbers);
if (unknownSystemNumbers.size() > FULL_SYNC_THRESHOLD) {
Log.i(TAG, "There are " + unknownSystemNumbers.size() + " unknown contacts. Doing a full sync.");
try {
DirectoryHelper.refreshDirectory(context, true);
} catch (IOException e) {
Log.w(TAG, e);
}
} else if (unknownSystemNumbers.size() > 0) {
Log.i(TAG, "There are " + unknownSystemNumbers.size() + " unknown contacts. Doing an individual sync.");
List<Recipient> recipients = Stream.of(unknownSystemNumbers).filter(s -> s.startsWith("+")).map(s -> Recipient.external(getContext(), s)).toList();
try {
DirectoryHelper.refreshDirectoryFor(context, recipients, true);
} catch (IOException e) {
Log.w(TAG, "Failed to refresh! Scheduling for later.", e);
ApplicationDependencies.getJobManager().add(new DirectoryRefreshJob(true));
}
} else {
Log.i(TAG, "No new contacts. Just syncing system contact data.");
DirectoryHelper.syncRecipientInfoWithSystemContacts(context);
}
}
use of org.thoughtcrime.securesms.jobs.DirectoryRefreshJob in project Signal-Android by WhisperSystems.
the class RecipientIdJobMigrationTest method migrate_directoryRefreshJob_null.
@Test
public void migrate_directoryRefreshJob_null() throws Exception {
JobData testData = new JobData("DirectoryRefreshJob", "DirectoryRefreshJob", new Data.Builder().putString("address", null).putBoolean("notify_of_new_users", true).build());
RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
JobData converted = subject.migrate(testData);
assertEquals("DirectoryRefreshJob", converted.getFactoryKey());
assertEquals("DirectoryRefreshJob", converted.getQueueKey());
assertNull(converted.getData().getString("recipient"));
assertTrue(converted.getData().getBoolean("notify_of_new_users"));
assertFalse(converted.getData().hasString("address"));
new DirectoryRefreshJob.Factory().create(mock(Job.Parameters.class), converted.getData());
}
use of org.thoughtcrime.securesms.jobs.DirectoryRefreshJob in project Signal-Android by WhisperSystems.
the class DirectoryRefreshListener method onAlarm.
@Override
protected long onAlarm(Context context, long scheduledTime) {
if (scheduledTime != 0 && SignalStore.account().isRegistered()) {
ApplicationDependencies.getJobManager().add(new DirectoryRefreshJob(true));
}
long interval = TimeUnit.SECONDS.toMillis(FeatureFlags.cdsRefreshIntervalSeconds());
long newTime = System.currentTimeMillis() + interval;
TextSecurePreferences.setDirectoryRefreshTime(context, newTime);
return newTime;
}
use of org.thoughtcrime.securesms.jobs.DirectoryRefreshJob in project Signal-Android by signalapp.
the class RegistrationUtil method maybeMarkRegistrationComplete.
/**
* There's several events where a registration may or may not be considered complete based on what
* path a user has taken. This will only truly mark registration as complete if all of the
* requirements are met.
*/
public static void maybeMarkRegistrationComplete(@NonNull Context context) {
if (!SignalStore.registrationValues().isRegistrationComplete() && SignalStore.account().isRegistered() && !Recipient.self().getProfileName().isEmpty() && (SignalStore.kbsValues().hasPin() || SignalStore.kbsValues().hasOptedOut())) {
Log.i(TAG, "Marking registration completed.", new Throwable());
SignalStore.registrationValues().setRegistrationComplete();
ApplicationDependencies.getJobManager().startChain(new StorageSyncJob()).then(new DirectoryRefreshJob(false)).enqueue();
} else if (!SignalStore.registrationValues().isRegistrationComplete()) {
Log.i(TAG, "Registration is not yet complete.", new Throwable());
}
}
Aggregations