Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into cust_remove_call_…
Browse files Browse the repository at this point in the history
…confirm
  • Loading branch information
simonsso committed Mar 3, 2021
2 parents b1df951 + 2be3068 commit f44af52
Show file tree
Hide file tree
Showing 103 changed files with 2,197 additions and 806 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ protobuf {
}
}

def canonicalVersionCode = 794
def canonicalVersionName = "5.4.8"
def canonicalVersionCode = 798
def canonicalVersionName = "5.4.12"

def postFixSize = 100
def abiPostFix = ['universal' : 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@
public class ApplicationPreferencesActivity extends PassphraseRequiredActivity
implements SharedPreferences.OnSharedPreferenceChangeListener
{
public static final String LAUNCH_TO_BACKUPS_FRAGMENT = "launch.to.backups.fragment";
public static final String LAUNCH_TO_HELP_FRAGMENT = "launch.to.help.fragment";
public static final String LAUNCH_TO_PROXY_FRAGMENT = "launch.to.proxy.fragment";
public static final String LAUNCH_TO_BACKUPS_FRAGMENT = "launch.to.backups.fragment";
public static final String LAUNCH_TO_HELP_FRAGMENT = "launch.to.help.fragment";
public static final String LAUNCH_TO_PROXY_FRAGMENT = "launch.to.proxy.fragment";
public static final String LAUNCH_TO_NOTIFICATIONS_FRAGMENT = "launch.to.notifications.fragment";

@SuppressWarnings("unused")
private static final String TAG = ApplicationPreferencesActivity.class.getSimpleName();
Expand Down Expand Up @@ -112,6 +113,8 @@ protected void onCreate(Bundle icicle, boolean ready) {
initFragment(android.R.id.content, new HelpFragment());
} else if (getIntent() != null && getIntent().getBooleanExtra(LAUNCH_TO_PROXY_FRAGMENT, false)) {
initFragment(android.R.id.content, EditProxyFragment.newInstance());
} else if (getIntent() != null && getIntent().getBooleanExtra(LAUNCH_TO_NOTIFICATIONS_FRAGMENT, false)) {
initFragment(android.R.id.content, new NotificationsPreferenceFragment());
} else if (icicle == null) {
initFragment(android.R.id.content, new ApplicationPreferenceFragment());
} else {
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/org/thoughtcrime/securesms/InviteActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
Expand Down Expand Up @@ -40,6 +42,7 @@
import org.thoughtcrime.securesms.util.WindowUtil;
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture.Listener;
import org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask;
import org.thoughtcrime.securesms.util.text.AfterTextChanged;
import org.whispersystems.libsignal.util.guava.Optional;

import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -105,6 +108,14 @@ private void initializeResources() {
contactsFragment = (ContactSelectionListFragment)getSupportFragmentManager().findFragmentById(R.id.contact_selection_list_fragment);

inviteText.setText(getString(R.string.InviteActivity_lets_switch_to_signal, getString(R.string.install_url)));
inviteText.addTextChangedListener(new AfterTextChanged(editable -> {
boolean isEnabled = editable.length() > 0;
smsButton.setEnabled(isEnabled);
shareButton.setEnabled(isEnabled);
smsButton.animate().alpha(isEnabled ? 1f : 0.5f);
shareButton.animate().alpha(isEnabled ? 1f : 0.5f);
}));

updateSmsButtonText(contactsFragment.getSelectedContacts().size());

smsCancelButton.setOnClickListener(new SmsCancelClickListener());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public class PassphrasePromptActivity extends PassphraseActivity {
private static final int BIOMETRIC_AUTHENTICATORS = Authenticators.BIOMETRIC_STRONG | Authenticators.BIOMETRIC_WEAK;
private static final int ALLOWED_AUTHENTICATORS = BIOMETRIC_AUTHENTICATORS | Authenticators.DEVICE_CREDENTIAL;
private static final short AUTHENTICATE_REQUEST_CODE = 1007;
private static final String BUNDLE_ALREADY_SHOWN = "bundle_already_shown";
public static final String FROM_FOREGROUND = "from_foreground";

private DynamicIntroTheme dynamicTheme = new DynamicIntroTheme();
private DynamicLanguage dynamicLanguage = new DynamicLanguage();
Expand All @@ -94,6 +96,7 @@ public class PassphrasePromptActivity extends PassphraseActivity {

private boolean authenticated;
private boolean hadFailure;
private boolean alreadyShown;

@Override
public void onCreate(Bundle savedInstanceState) {
Expand All @@ -106,6 +109,15 @@ public void onCreate(Bundle savedInstanceState) {

setContentView(R.layout.prompt_passphrase_activity);
initializeResources();

alreadyShown = (savedInstanceState != null && savedInstanceState.getBoolean(BUNDLE_ALREADY_SHOWN)) ||
getIntent().getBooleanExtra(FROM_FOREGROUND, false);
}

@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(BUNDLE_ALREADY_SHOWN, alreadyShown);
}

@Override
Expand All @@ -117,7 +129,8 @@ public void onResume() {
setLockTypeVisibility();

if (TextSecurePreferences.isScreenLockEnabled(this) && !authenticated && !hadFailure) {
resumeScreenLock();
resumeScreenLock(!alreadyShown);
alreadyShown = true;
}

hadFailure = false;
Expand Down Expand Up @@ -248,7 +261,7 @@ private void initializeResources() {
fingerprintPrompt.setImageResource(R.drawable.ic_fingerprint_white_48dp);
fingerprintPrompt.getBackground().setColorFilter(getResources().getColor(R.color.core_ultramarine), PorterDuff.Mode.SRC_IN);

lockScreenButton.setOnClickListener(v -> resumeScreenLock());
lockScreenButton.setOnClickListener(v -> resumeScreenLock(true));
}

private void setLockTypeVisibility() {
Expand All @@ -264,7 +277,7 @@ private void setLockTypeVisibility() {
}
}

private void resumeScreenLock() {
private void resumeScreenLock(boolean force) {
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);

assert keyguardManager != null;
Expand All @@ -275,13 +288,21 @@ private void resumeScreenLock() {
return;
}

if (biometricManager.canAuthenticate(ALLOWED_AUTHENTICATORS) == BiometricManager.BIOMETRIC_SUCCESS) {
Log.i(TAG, "Listening for biometric authentication...");
biometricPrompt.authenticate(biometricPromptInfo);
} else if (Build.VERSION.SDK_INT >= 21){
Log.i(TAG, "firing intent...");
Intent intent = keyguardManager.createConfirmDeviceCredentialIntent(getString(R.string.PassphrasePromptActivity_unlock_signal), "");
startActivityForResult(intent, AUTHENTICATE_REQUEST_CODE);
if (Build.VERSION.SDK_INT != 29 && biometricManager.canAuthenticate(ALLOWED_AUTHENTICATORS) == BiometricManager.BIOMETRIC_SUCCESS) {
if (force) {
Log.i(TAG, "Listening for biometric authentication...");
biometricPrompt.authenticate(biometricPromptInfo);
} else {
Log.i(TAG, "Skipping show system biometric dialog unless forced");
}
} else if (Build.VERSION.SDK_INT >= 21) {
if (force) {
Log.i(TAG, "firing intent...");
Intent intent = keyguardManager.createConfirmDeviceCredentialIntent(getString(R.string.PassphrasePromptActivity_unlock_signal), "");
startActivityForResult(intent, AUTHENTICATE_REQUEST_CODE);
} else {
Log.i(TAG, "Skipping firing intent unless forced");
}
} else {
Log.w(TAG, "Not compatible...");
handleAuthenticated();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ private Intent getCreatePassphraseIntent() {
}

private Intent getPromptPassphraseIntent() {
return getRoutedIntent(PassphrasePromptActivity.class, getIntent());
Intent intent = getRoutedIntent(PassphrasePromptActivity.class, getIntent());
intent.putExtra(PassphrasePromptActivity.FROM_FOREGROUND, ApplicationDependencies.getAppForegroundObserver().isForegrounded());
return intent;
}

private Intent getUiBlockingUpgradeIntent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,13 @@ public void onActivityResult(final int reqCode, int resultCode, Intent data) {
break;
case MEDIA_SENDER:
MediaSendActivityResult result = data.getParcelableExtra(MediaSendActivity.EXTRA_RESULT);

if (!Objects.equals(result.getRecipientId(), recipient.getId())) {
Log.w(TAG, "Result's recipientId did not match ours! Result: " + result.getRecipientId() + ", Activity: " + recipient.getId());
Toast.makeText(this, R.string.ConversationActivity_error_sending_media, Toast.LENGTH_SHORT).show();
return;
}

sendButton.setTransport(result.getTransport());

if (result.isPushPreUpload()) {
Expand Down Expand Up @@ -705,7 +712,8 @@ public void onActivityResult(final int reqCode, int resultCode, Intent data) {

final Context context = ConversationActivity.this.getApplicationContext();

sendMediaMessage(result.getTransport().isSms(),
sendMediaMessage(result.getRecipientId(),
result.getTransport().isSms(),
result.getBody(),
slideDeck,
quote,
Expand Down Expand Up @@ -2425,7 +2433,7 @@ private void sendSharedContact(List<Contact> contacts) {
long expiresIn = recipient.get().getExpireMessages() * 1000L;
boolean initiating = threadId == -1;

sendMediaMessage(isSmsForced(), "", attachmentManager.buildSlideDeck(), null, contacts, Collections.emptyList(), Collections.emptyList(), expiresIn, false, subscriptionId, initiating, false);
sendMediaMessage(recipient.getId(), isSmsForced(), "", attachmentManager.buildSlideDeck(), null, contacts, Collections.emptyList(), Collections.emptyList(), expiresIn, false, subscriptionId, initiating, false);
}

private void selectContactInfo(ContactData contactData) {
Expand Down Expand Up @@ -2751,7 +2759,8 @@ private void sendMediaMessage(final boolean forceSms, final long expiresIn, fina
throws InvalidMessageException
{
Log.i(TAG, "Sending media message...");
sendMediaMessage(forceSms,
sendMediaMessage(recipient.getId(),
forceSms,
getMessage(),
attachmentManager.buildSlideDeck(),
inputPanel.getQuote().orNull(),
Expand All @@ -2765,7 +2774,8 @@ private void sendMediaMessage(final boolean forceSms, final long expiresIn, fina
true);
}

private ListenableFuture<Void> sendMediaMessage(final boolean forceSms,
private ListenableFuture<Void> sendMediaMessage(@NonNull RecipientId recipientId,
final boolean forceSms,
@NonNull String body,
SlideDeck slideDeck,
QuoteModel quote,
Expand Down Expand Up @@ -2794,7 +2804,7 @@ private ListenableFuture<Void> sendMediaMessage(final boolean forceSms,
}
}

OutgoingMediaMessage outgoingMessageCandidate = new OutgoingMediaMessage(recipient.get(), slideDeck, body, System.currentTimeMillis(), subscriptionId, expiresIn, viewOnce, distributionType, quote, contacts, previews, mentions);
OutgoingMediaMessage outgoingMessageCandidate = new OutgoingMediaMessage(Recipient.resolved(recipientId), slideDeck, body, System.currentTimeMillis(), subscriptionId, expiresIn, viewOnce, distributionType, quote, contacts, previews, mentions);

final SettableFuture<Void> future = new SettableFuture<>();
final Context context = getApplicationContext();
Expand Down Expand Up @@ -2985,7 +2995,8 @@ public void onSuccess(final @NonNull Pair<Uri, Long> result) {
SlideDeck slideDeck = new SlideDeck();
slideDeck.addSlide(audioSlide);

ListenableFuture<Void> sendResult = sendMediaMessage(forceSms,
ListenableFuture<Void> sendResult = sendMediaMessage(recipient.getId(),
forceSms,
"",
slideDeck,
inputPanel.getQuote().orNull(),
Expand Down Expand Up @@ -3128,7 +3139,7 @@ private void sendSticker(@NonNull StickerLocator stickerLocator, @NonNull String

slideDeck.addSlide(stickerSlide);

sendMediaMessage(transport.isSms(), "", slideDeck, null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), expiresIn, false, subscriptionId, initiating, clearCompose);
sendMediaMessage(recipient.getId(), transport.isSms(), "", slideDeck, null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), expiresIn, false, subscriptionId, initiating, clearCompose);
}

private void silentlySetComposeText(String text) {
Expand Down Expand Up @@ -3600,7 +3611,8 @@ private void sendKeyboardImage(@NonNull Uri uri, @NonNull String contentType, @N
throw new AssertionError("Only images are supported!");
}

sendMediaMessage(isSmsForced(),
sendMediaMessage(recipient.getId(),
isSmsForced(),
"",
slideDeck,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ private static boolean mapToGroupV1MigrationReminder(@Nullable GroupRecord recor
if (record == null ||
!record.isV1Group() ||
!record.isActive() ||
!FeatureFlags.groupsV1ManualMigration() ||
FeatureFlags.groupsV1ForcedMigration() ||
Recipient.self().getGroupsV1MigrationCapability() != Recipient.Capability.SUPPORTED ||
!Recipient.resolved(record.getRecipientId()).isProfileSharing())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

public class ConversationIntents {
Expand Down Expand Up @@ -162,15 +163,15 @@ public final static class Builder {
private final RecipientId recipientId;
private final long threadId;

private String draftText;
private ArrayList<Media> media;
private StickerLocator stickerLocator;
private boolean isBorderless;
private int distributionType = ThreadDatabase.DistributionTypes.DEFAULT;
private int startingPosition = -1;
private Uri dataUri;
private String dataType;
private boolean firstTimeInSelfCreatedGroup;
private String draftText;
private List<Media> media;
private StickerLocator stickerLocator;
private boolean isBorderless;
private int distributionType = ThreadDatabase.DistributionTypes.DEFAULT;
private int startingPosition = -1;
private Uri dataUri;
private String dataType;
private boolean firstTimeInSelfCreatedGroup;

private Builder(@NonNull Context context,
@NonNull RecipientId recipientId,
Expand Down Expand Up @@ -265,7 +266,7 @@ public Builder firstTimeInSelfCreatedGroup() {
}

if (media != null) {
intent.putParcelableArrayListExtra(EXTRA_MEDIA, media);
intent.putParcelableArrayListExtra(EXTRA_MEDIA, new ArrayList<>(media));
}

if (stickerLocator != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ protected Conversation getItem(int position) {
public long getItemId(int position) {
Conversation item = getItem(position);

if (item == null) {
return 0;
}

switch (item.getType()) {
case THREAD: return item.getThreadRecord().getThreadId();
case PINNED_HEADER: return -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,67 @@

import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.whispersystems.signalservice.api.SignalSessionLock;

import java.util.concurrent.locks.ReentrantLock;

/**
* An implementation of {@link SignalSessionLock} that effectively re-uses our database lock.
*/
public enum DatabaseSessionLock implements SignalSessionLock {

INSTANCE;

public static final long NO_OWNER = -1;

private static final ReentrantLock LEGACY_LOCK = new ReentrantLock();

private volatile long ownerThreadId = NO_OWNER;

@Override
public Lock acquire() {
SQLiteDatabase db = DatabaseFactory.getInstance(ApplicationDependencies.getApplication()).getRawDatabase();
if (FeatureFlags.internalUser()) {
SQLiteDatabase db = DatabaseFactory.getInstance(ApplicationDependencies.getApplication()).getRawDatabase();

if (db.isDbLockedByCurrentThread()) {
return () -> {};
}

if (db.isDbLockedByCurrentThread()) {
return () -> {};
db.beginTransaction();

ownerThreadId = Thread.currentThread().getId();

return () -> {
ownerThreadId = -1;
db.setTransactionSuccessful();
db.endTransaction();
};
} else {
LEGACY_LOCK.lock();
return LEGACY_LOCK::unlock;
}
}

db.beginTransaction();
/**
* Important: Only truly useful for debugging. Do not rely on this for functionality. There's tiny
* windows where this state might not be fully accurate.
*
* @return True if it's likely that some other thread owns this lock, and it's not you.
*/
public boolean isLikelyHeldByOtherThread() {
long ownerThreadId = this.ownerThreadId;
return ownerThreadId != -1 && ownerThreadId == Thread.currentThread().getId();
}

return () -> {
db.setTransactionSuccessful();
db.endTransaction();
};
/**
* Important: Only truly useful for debugging. Do not rely on this for functionality. There's a
* tiny window where a thread may still own the lock, but the state we track around it has been
* cleared.
*
* @return The ID of the thread that likely owns this lock, or {@link #NO_OWNER} if no one owns it.
*/
public long getLikeyOwnerThreadId() {
return ownerThreadId;
}
}
Loading

0 comments on commit f44af52

Please sign in to comment.