mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-12 01:33:39 +00:00
Partially disable settings for slave devices
This commit is contained in:
parent
d0e5ddfe3f
commit
bf958fffe1
@ -156,8 +156,13 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
this.findPreference(PREFERENCE_CATEGORY_PROFILE)
|
||||
.setOnPreferenceClickListener(new ProfileClickListener());
|
||||
String masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(getContext());
|
||||
boolean isMasterDevice = (masterHexEncodedPublicKey != null);
|
||||
|
||||
Preference profilePreference = this.findPreference(PREFERENCE_CATEGORY_PROFILE);
|
||||
// Hide if this is a slave device
|
||||
profilePreference.setVisible(isMasterDevice);
|
||||
profilePreference.setOnPreferenceClickListener(new ProfileClickListener());
|
||||
/*
|
||||
this.findPreference(PREFERENCE_CATEGORY_SMS_MMS)
|
||||
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_SMS_MMS));
|
||||
@ -184,10 +189,12 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
|
||||
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_QR_CODE));
|
||||
Preference linkDevicePreference = this.findPreference(PREFERENCE_CATEGORY_LINK_DEVICE);
|
||||
// Hide if this is a slave device
|
||||
linkDevicePreference.setVisible(!TextSecurePreferences.isSecondaryDevice(getContext()));
|
||||
linkDevicePreference.setVisible(isMasterDevice);
|
||||
linkDevicePreference.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_LINK_DEVICE));
|
||||
this.findPreference(PREFERENCE_CATEGORY_SEED)
|
||||
.setOnPreferenceClickListener(new CategoryClickListener((PREFERENCE_CATEGORY_SEED)));
|
||||
Preference seedPreference = this.findPreference(PREFERENCE_CATEGORY_SEED);
|
||||
// Hide if this is a slave device
|
||||
seedPreference.setVisible(isMasterDevice);
|
||||
seedPreference.setOnPreferenceClickListener(new CategoryClickListener((PREFERENCE_CATEGORY_SEED)));
|
||||
|
||||
if (VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||
tintIcons(getActivity());
|
||||
@ -322,7 +329,10 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
|
||||
*/
|
||||
case PREFERENCE_CATEGORY_PUBLIC_KEY:
|
||||
Analytics.Companion.getShared().track("Public Key Shared");
|
||||
String hexEncodedPublicKey = TextSecurePreferences.getLocalNumber(getContext());
|
||||
String hexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(getContext());
|
||||
if (hexEncodedPublicKey == null) {
|
||||
hexEncodedPublicKey = TextSecurePreferences.getLocalNumber(getContext());
|
||||
}
|
||||
Intent shareIntent = new Intent();
|
||||
shareIntent.setAction(Intent.ACTION_SEND);
|
||||
shareIntent.putExtra(Intent.EXTRA_TEXT, hexEncodedPublicKey);
|
||||
|
@ -9,7 +9,7 @@ import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.ThreadDatabase;
|
||||
import org.thoughtcrime.securesms.jobs.TypingSendJob;
|
||||
import org.thoughtcrime.securesms.loki.MultiDeviceUtilKt;
|
||||
import org.thoughtcrime.securesms.loki.MultiDeviceUtilitiesKt;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.signalservice.loki.api.LokiStorageAPI;
|
||||
@ -91,7 +91,7 @@ public class TypingStatusSender {
|
||||
return;
|
||||
}
|
||||
|
||||
MultiDeviceUtilKt.getAllDevicePublicKeys(context, originalRecipient.getAddress().serialize(), storageAPI, (devicePublicKey, isFriend, friendCount) -> {
|
||||
MultiDeviceUtilitiesKt.getAllDevicePublicKeys(context, originalRecipient.getAddress().serialize(), storageAPI, (devicePublicKey, isFriend, friendCount) -> {
|
||||
Recipient device = Recipient.from(context, Address.fromSerialized(devicePublicKey), false);
|
||||
long deviceThreadID = threadDatabase.getThreadIdIfExistsFor(device);
|
||||
if (deviceThreadID > -1) {
|
||||
|
@ -71,7 +71,7 @@ import org.thoughtcrime.securesms.loki.LokiMessageDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiPreKeyBundleDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiPreKeyRecordDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiThreadDatabase;
|
||||
import org.thoughtcrime.securesms.loki.MultiDeviceUtilKt;
|
||||
import org.thoughtcrime.securesms.loki.MultiDeviceUtilitiesKt;
|
||||
import org.thoughtcrime.securesms.mms.IncomingMediaMessage;
|
||||
import org.thoughtcrime.securesms.mms.MmsException;
|
||||
import org.thoughtcrime.securesms.mms.OutgoingExpirationUpdateMessage;
|
||||
@ -1154,7 +1154,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
private void updateFriendRequestStatusIfNeeded(@NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceContent content, @NonNull SignalServiceDataMessage message) {
|
||||
if (!envelope.isFriendRequest()) { return; }
|
||||
// This handles the case where another user sends us a regular message without authorisation
|
||||
MultiDeviceUtilKt.shouldAutomaticallyBecomeFriendsWithDevice(content.getSender(), context).success( becomeFriends -> {
|
||||
MultiDeviceUtilitiesKt.shouldAutomaticallyBecomeFriendsWithDevice(content.getSender(), context).success(becomeFriends -> {
|
||||
if (becomeFriends) {
|
||||
// Become friends AND update the message they sent
|
||||
becomeFriendsWithContact(content.getSender());
|
||||
|
@ -65,8 +65,8 @@ class DeviceLinkingDialog private constructor(private val context: Context, priv
|
||||
return true
|
||||
}
|
||||
|
||||
override fun handleDeviceLinkAuthorized() {
|
||||
delegate?.handleDeviceLinkAuthorized()
|
||||
override fun handleDeviceLinkAuthorized(pairing: PairingAuthorisation) {
|
||||
delegate?.handleDeviceLinkAuthorized(pairing)
|
||||
}
|
||||
|
||||
override fun handleDeviceLinkingDialogDismissed() {
|
||||
|
@ -1,6 +1,9 @@
|
||||
package org.thoughtcrime.securesms.loki
|
||||
|
||||
import org.whispersystems.signalservice.loki.api.PairingAuthorisation
|
||||
|
||||
interface DeviceLinkingDialogDelegate {
|
||||
fun handleDeviceLinkAuthorized() { }
|
||||
|
||||
fun handleDeviceLinkAuthorized(pairing: PairingAuthorisation) { }
|
||||
fun handleDeviceLinkingDialogDismissed() { }
|
||||
}
|
@ -116,7 +116,7 @@ class DeviceLinkingView private constructor(context: Context, attrs: AttributeSe
|
||||
buttonContainer.visibility = View.GONE
|
||||
cancelButton.visibility = View.GONE
|
||||
Handler().postDelayed({
|
||||
delegate.handleDeviceLinkAuthorized()
|
||||
delegate.handleDeviceLinkAuthorized(authorisation)
|
||||
dismiss?.invoke()
|
||||
}, 4000)
|
||||
}
|
||||
@ -126,7 +126,7 @@ class DeviceLinkingView private constructor(context: Context, attrs: AttributeSe
|
||||
private fun authorizePairing() {
|
||||
if (pairingAuthorisation == null || mode != Mode.Master ) { return; }
|
||||
if (delegate.sendPairingAuthorizedMessage(pairingAuthorisation!!)) {
|
||||
delegate.handleDeviceLinkAuthorized()
|
||||
delegate.handleDeviceLinkAuthorized(pairingAuthorisation!!)
|
||||
dismiss?.invoke()
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,8 @@ package org.thoughtcrime.securesms.loki
|
||||
import org.whispersystems.signalservice.loki.api.PairingAuthorisation
|
||||
|
||||
interface DeviceLinkingViewDelegate {
|
||||
fun handleDeviceLinkAuthorized() { }
|
||||
|
||||
fun handleDeviceLinkAuthorized(pairing: PairingAuthorisation) { }
|
||||
fun handleDeviceLinkingDialogDismissed() { }
|
||||
fun sendPairingAuthorizedMessage(pairing: PairingAuthorisation): Boolean { return false }
|
||||
}
|
@ -28,7 +28,7 @@ class QRCodeView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : Li
|
||||
|
||||
init {
|
||||
inflate(context, R.layout.view_qr_code, this)
|
||||
val hexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context)
|
||||
val hexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(getContext()) ?: TextSecurePreferences.getLocalNumber(context)
|
||||
val displayMetrics = DisplayMetrics()
|
||||
ServiceUtil.getWindowManager(context).defaultDisplay.getMetrics(displayMetrics)
|
||||
val size = displayMetrics.widthPixels - 2 * toPx(96, resources)
|
||||
|
@ -217,8 +217,11 @@ class SeedActivity : BaseActionBarActivity(), DeviceLinkingDialogDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
override fun handleDeviceLinkAuthorized() {
|
||||
override fun handleDeviceLinkAuthorized(pairing: PairingAuthorisation) {
|
||||
Analytics.shared.track("Device Linked Successfully")
|
||||
if (pairing.secondaryDevicePublicKey == TextSecurePreferences.getLocalNumber(this)) {
|
||||
TextSecurePreferences.setMasterHexEncodedPublicKey(this, pairing.primaryDevicePublicKey)
|
||||
}
|
||||
startActivity(Intent(this, ConversationListActivity::class.java))
|
||||
finish()
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import org.thoughtcrime.securesms.database.MessagingDatabase.SyncMessageId;
|
||||
import org.thoughtcrime.securesms.jobs.MultiDeviceReadUpdateJob;
|
||||
import org.thoughtcrime.securesms.jobs.SendReadReceiptJob;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.loki.MultiDeviceUtilKt;
|
||||
import org.thoughtcrime.securesms.loki.MultiDeviceUtilitiesKt;
|
||||
import org.thoughtcrime.securesms.service.ExpiringMessageManager;
|
||||
import org.whispersystems.signalservice.loki.api.LokiStorageAPI;
|
||||
|
||||
@ -92,7 +92,7 @@ public class MarkReadReceiver extends BroadcastReceiver {
|
||||
|
||||
List<Long> timestamps = Stream.of(addressMap.get(address)).map(SyncMessageId::getTimetamp).toList();
|
||||
|
||||
MultiDeviceUtilKt.getAllDevicePublicKeys(context, address.serialize(), storageAPI, (devicePublicKey, isFriend, friendCount) -> {
|
||||
MultiDeviceUtilitiesKt.getAllDevicePublicKeys(context, address.serialize(), storageAPI, (devicePublicKey, isFriend, friendCount) -> {
|
||||
// Loki - This also prevents read receipts from being sent in group chats as they don't maintain a friend request status
|
||||
if (isFriend) {
|
||||
ApplicationContext.getInstance(context).getJobManager().add(new SendReadReceiptJob(Address.fromSerialized(devicePublicKey), timestamps));
|
||||
|
@ -43,7 +43,7 @@ import org.thoughtcrime.securesms.linkpreview.LinkPreviewRepository;
|
||||
import org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.loki.GeneralUtilitiesKt;
|
||||
import org.thoughtcrime.securesms.loki.MultiDeviceUtilKt;
|
||||
import org.thoughtcrime.securesms.loki.MultiDeviceUtilitiesKt;
|
||||
import org.thoughtcrime.securesms.mms.MmsException;
|
||||
import org.thoughtcrime.securesms.mms.OutgoingMediaMessage;
|
||||
import org.thoughtcrime.securesms.push.AccountManagerFactory;
|
||||
@ -218,7 +218,7 @@ public class MessageSender {
|
||||
return;
|
||||
}
|
||||
|
||||
MultiDeviceUtilKt.getAllDevicePublicKeys(context, recipientPublicKey, storageAPI, (devicePublicKey, isFriend, friendCount) -> {
|
||||
MultiDeviceUtilitiesKt.getAllDevicePublicKeys(context, recipientPublicKey, storageAPI, (devicePublicKey, isFriend, friendCount) -> {
|
||||
Address address = Address.fromSerialized(devicePublicKey);
|
||||
long messageIDToUse = recipientPublicKey.equals(devicePublicKey) ? messageId : -1L;
|
||||
|
||||
@ -248,7 +248,7 @@ public class MessageSender {
|
||||
return;
|
||||
}
|
||||
|
||||
MultiDeviceUtilKt.getAllDevicePublicKeys(context, recipientPublicKey, storageAPI, (devicePublicKey, isFriend, friendCount) -> {
|
||||
MultiDeviceUtilitiesKt.getAllDevicePublicKeys(context, recipientPublicKey, storageAPI, (devicePublicKey, isFriend, friendCount) -> {
|
||||
Address address = Address.fromSerialized(devicePublicKey);
|
||||
long messageIDToUse = recipientPublicKey.equals(devicePublicKey) ? messageId : -1L;
|
||||
|
||||
|
@ -1178,12 +1178,12 @@ public class TextSecurePreferences {
|
||||
setBooleanPreference(context, "is_chat_set_up" + "?chat=" + id, true);
|
||||
}
|
||||
|
||||
public static boolean isSecondaryDevice(Context context) {
|
||||
return getBooleanPreference(context, "is_secondary_device", false);
|
||||
public static String getMasterHexEncodedPublicKey(Context context) {
|
||||
return getStringPreference(context, "master_hex_encoded_public_key", null);
|
||||
}
|
||||
|
||||
public static void setIsSecondaryDevice(Context context, boolean isSecondaryDevice) {
|
||||
setBooleanPreference(context, "is_secondary_device", isSecondaryDevice);
|
||||
public static void setMasterHexEncodedPublicKey(Context context, String masterHexEncodedPublicKey) {
|
||||
setStringPreference(context, "master_hex_encoded_publicKey", masterHexEncodedPublicKey);
|
||||
}
|
||||
// endregion
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user