Search in sources :

Example 6 with DirectoryRefreshJob

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();
}
Also used : DirectoryRefreshJob(org.thoughtcrime.securesms.jobs.DirectoryRefreshJob) Intent(android.content.Intent)

Example 7 with DirectoryRefreshJob

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);
    }
}
Also used : Context(android.content.Context) SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) Context(android.content.Context) SyncResult(android.content.SyncResult) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) Bundle(android.os.Bundle) DirectoryRefreshJob(org.thoughtcrime.securesms.jobs.DirectoryRefreshJob) Stream(com.annimon.stream.Stream) DirectoryHelper(org.thoughtcrime.securesms.contacts.sync.DirectoryHelper) Account(android.accounts.Account) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) AbstractThreadedSyncAdapter(android.content.AbstractThreadedSyncAdapter) Set(java.util.Set) IOException(java.io.IOException) SetUtil(org.thoughtcrime.securesms.util.SetUtil) Log(org.signal.core.util.logging.Log) List(java.util.List) ContentProviderClient(android.content.ContentProviderClient) Recipient(org.thoughtcrime.securesms.recipients.Recipient) DirectoryRefreshJob(org.thoughtcrime.securesms.jobs.DirectoryRefreshJob) List(java.util.List) IOException(java.io.IOException)

Example 8 with DirectoryRefreshJob

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());
}
Also used : DirectoryRefreshJob(org.thoughtcrime.securesms.jobs.DirectoryRefreshJob) JobData(org.thoughtcrime.securesms.jobmanager.JobMigration.JobData) Application(android.app.Application) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with DirectoryRefreshJob

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;
}
Also used : DirectoryRefreshJob(org.thoughtcrime.securesms.jobs.DirectoryRefreshJob)

Example 10 with DirectoryRefreshJob

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());
    }
}
Also used : StorageSyncJob(org.thoughtcrime.securesms.jobs.StorageSyncJob) DirectoryRefreshJob(org.thoughtcrime.securesms.jobs.DirectoryRefreshJob)

Aggregations

DirectoryRefreshJob (org.thoughtcrime.securesms.jobs.DirectoryRefreshJob)13 Application (android.app.Application)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 JobData (org.thoughtcrime.securesms.jobmanager.JobMigration.JobData)4 Account (android.accounts.Account)2 AbstractThreadedSyncAdapter (android.content.AbstractThreadedSyncAdapter)2 ContentProviderClient (android.content.ContentProviderClient)2 Context (android.content.Context)2 SyncResult (android.content.SyncResult)2 Bundle (android.os.Bundle)2 Stream (com.annimon.stream.Stream)2 File (java.io.File)2 IOException (java.io.IOException)2 List (java.util.List)2 Set (java.util.Set)2 Log (org.signal.core.util.logging.Log)2 DirectoryHelper (org.thoughtcrime.securesms.contacts.sync.DirectoryHelper)2 MasterSecret (org.thoughtcrime.securesms.crypto.MasterSecret)2 SignalDatabase (org.thoughtcrime.securesms.database.SignalDatabase)2