Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support additional sync behavior for linked devices.
- Loading branch information
1 parent
995569d
commit c702ff6
Showing
16 changed files
with
401 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/org/thoughtcrime/securesms/jobs/MultiDeviceProfileContentUpdateJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.thoughtcrime.securesms.jobs; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil; | ||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies; | ||
import org.thoughtcrime.securesms.jobmanager.Data; | ||
import org.thoughtcrime.securesms.jobmanager.Job; | ||
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint; | ||
import org.thoughtcrime.securesms.logging.Log; | ||
import org.thoughtcrime.securesms.util.TextSecurePreferences; | ||
import org.whispersystems.signalservice.api.SignalServiceMessageSender; | ||
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage; | ||
import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException; | ||
|
||
public class MultiDeviceProfileContentUpdateJob extends BaseJob { | ||
|
||
public static final String KEY = "MultiDeviceProfileContentUpdateJob"; | ||
|
||
private static final String TAG = Log.tag(MultiDeviceProfileContentUpdateJob.class); | ||
|
||
public MultiDeviceProfileContentUpdateJob() { | ||
this(new Parameters.Builder() | ||
.setQueue("MultiDeviceProfileUpdateJob") | ||
.addConstraint(NetworkConstraint.KEY) | ||
.setMaxAttempts(10) | ||
.build()); | ||
} | ||
|
||
private MultiDeviceProfileContentUpdateJob(@NonNull Parameters parameters) { | ||
super(parameters); | ||
} | ||
|
||
@Override | ||
public @NonNull Data serialize() { | ||
return Data.EMPTY; | ||
} | ||
|
||
@Override | ||
public @NonNull String getFactoryKey() { | ||
return KEY; | ||
} | ||
|
||
@Override | ||
protected void onRun() throws Exception { | ||
if (!TextSecurePreferences.isMultiDevice(context)) { | ||
Log.i(TAG, "Not multi device, aborting..."); | ||
return; | ||
} | ||
|
||
SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender(); | ||
|
||
messageSender.sendMessage(SignalServiceSyncMessage.forFetchLatest(SignalServiceSyncMessage.FetchType.LOCAL_PROFILE), | ||
UnidentifiedAccessUtil.getAccessForSync(context)); | ||
} | ||
|
||
@Override | ||
protected boolean onShouldRetry(@NonNull Exception e) { | ||
return e instanceof PushNetworkException; | ||
} | ||
|
||
|
||
@Override | ||
public void onCanceled() { | ||
Log.w(TAG, "Did not succeed!"); | ||
} | ||
|
||
public static final class Factory implements Job.Factory<MultiDeviceProfileContentUpdateJob> { | ||
@Override | ||
public @NonNull MultiDeviceProfileContentUpdateJob create(@NonNull Parameters parameters, @NonNull Data data) { | ||
return new MultiDeviceProfileContentUpdateJob(parameters); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
src/org/thoughtcrime/securesms/jobs/RefreshOwnProfileJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package org.thoughtcrime.securesms.jobs; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import org.thoughtcrime.securesms.crypto.ProfileKeyUtil; | ||
import org.thoughtcrime.securesms.database.DatabaseFactory; | ||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies; | ||
import org.thoughtcrime.securesms.jobmanager.Data; | ||
import org.thoughtcrime.securesms.jobmanager.Job; | ||
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint; | ||
import org.thoughtcrime.securesms.logging.Log; | ||
import org.thoughtcrime.securesms.recipients.Recipient; | ||
import org.thoughtcrime.securesms.util.ProfileUtil; | ||
import org.thoughtcrime.securesms.util.TextSecurePreferences; | ||
import org.whispersystems.signalservice.api.crypto.InvalidCiphertextException; | ||
import org.whispersystems.signalservice.api.profiles.SignalServiceProfile; | ||
import org.whispersystems.signalservice.api.push.exceptions.PushNetworkException; | ||
|
||
import java.io.IOException; | ||
|
||
|
||
/** | ||
* Refreshes the profile of the local user. Different from {@link RetrieveProfileJob} in that we | ||
* have to sometimes look at/set different data stores, and we will *always* do the fetch regardless | ||
* of caching. | ||
*/ | ||
public class RefreshOwnProfileJob extends BaseJob { | ||
|
||
public static final String KEY = "RefreshOwnProfileJob"; | ||
|
||
private static final String TAG = Log.tag(RefreshOwnProfileJob.class); | ||
|
||
public RefreshOwnProfileJob() { | ||
this(new Parameters.Builder() | ||
.addConstraint(NetworkConstraint.KEY) | ||
.setQueue("RefreshOwnProfileJob") | ||
.setMaxInstances(1) | ||
.setMaxAttempts(10) | ||
.build()); | ||
} | ||
|
||
|
||
private RefreshOwnProfileJob(@NonNull Parameters parameters) { | ||
super(parameters); | ||
} | ||
|
||
@Override | ||
public @NonNull Data serialize() { | ||
return Data.EMPTY; | ||
} | ||
|
||
@Override | ||
public @NonNull String getFactoryKey() { | ||
return KEY; | ||
} | ||
|
||
@Override | ||
protected void onRun() throws Exception { | ||
SignalServiceProfile profile = ProfileUtil.retrieveProfile(context, Recipient.self()); | ||
|
||
setProfileName(profile.getName()); | ||
setProfileAvatar(profile.getAvatar()); | ||
setProfileCapabilities(profile.getCapabilities()); | ||
} | ||
|
||
@Override | ||
protected boolean onShouldRetry(@NonNull Exception e) { | ||
return e instanceof PushNetworkException; | ||
} | ||
|
||
@Override | ||
public void onCanceled() { } | ||
|
||
private void setProfileName(@Nullable String encryptedName) { | ||
try { | ||
byte[] profileKey = ProfileKeyUtil.getProfileKey(context); | ||
String plaintextName = ProfileUtil.decryptName(profileKey, encryptedName); | ||
|
||
DatabaseFactory.getRecipientDatabase(context).setProfileName(Recipient.self().getId(), plaintextName); | ||
TextSecurePreferences.setProfileName(context, plaintextName); | ||
} catch (InvalidCiphertextException | IOException e) { | ||
Log.w(TAG, e); | ||
} | ||
} | ||
|
||
private void setProfileAvatar(@Nullable String avatar) { | ||
ApplicationDependencies.getJobManager().add(new RetrieveProfileAvatarJob(Recipient.self(), avatar)); | ||
} | ||
|
||
private void setProfileCapabilities(@Nullable SignalServiceProfile.Capabilities capabilities) { | ||
if (capabilities == null) { | ||
return; | ||
} | ||
|
||
DatabaseFactory.getRecipientDatabase(context).setUuidSupported(Recipient.self().getId(), capabilities.isUuid()); | ||
} | ||
|
||
public static final class Factory implements Job.Factory<RefreshOwnProfileJob> { | ||
|
||
@Override | ||
public @NonNull RefreshOwnProfileJob create(@NonNull Parameters parameters, @NonNull Data data) { | ||
return new RefreshOwnProfileJob(parameters); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.