More MasterSecret cleanup

This commit is contained in:
Moxie Marlinspike 2018-02-01 19:22:48 -08:00
parent 59092e2ec0
commit 3633d805c8
52 changed files with 228 additions and 725 deletions

View File

@ -26,7 +26,6 @@ import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
@ -35,15 +34,14 @@ import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.preference.Preference;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.preferences.AdvancedPreferenceFragment;
import org.thoughtcrime.securesms.preferences.AppProtectionPreferenceFragment;
import org.thoughtcrime.securesms.preferences.AppearancePreferenceFragment;
import org.thoughtcrime.securesms.preferences.ChatsPreferenceFragment;
import org.thoughtcrime.securesms.preferences.CorrectedPreferenceFragment;
import org.thoughtcrime.securesms.preferences.NotificationsPreferenceFragment;
import org.thoughtcrime.securesms.preferences.widgets.ProfilePreference;
import org.thoughtcrime.securesms.preferences.SmsMmsPreferenceFragment;
import org.thoughtcrime.securesms.preferences.ChatsPreferenceFragment;
import org.thoughtcrime.securesms.preferences.widgets.ProfilePreference;
import org.thoughtcrime.securesms.service.KeyCachingService;
import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.DynamicTheme;
@ -81,12 +79,12 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
}
@Override
protected void onCreate(Bundle icicle, @NonNull MasterSecret masterSecret) {
protected void onCreate(Bundle icicle, boolean ready) {
//noinspection ConstantConditions
this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (icicle == null) {
initFragment(android.R.id.content, new ApplicationPreferenceFragment(), masterSecret);
initFragment(android.R.id.content, new ApplicationPreferenceFragment());
}
}
@ -138,23 +136,22 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
MasterSecret masterSecret = getArguments().getParcelable("master_secret");
this.findPreference(PREFERENCE_CATEGORY_PROFILE)
.setOnPreferenceClickListener(new ProfileClickListener());
this.findPreference(PREFERENCE_CATEGORY_SMS_MMS)
.setOnPreferenceClickListener(new CategoryClickListener(masterSecret, PREFERENCE_CATEGORY_SMS_MMS));
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_SMS_MMS));
this.findPreference(PREFERENCE_CATEGORY_NOTIFICATIONS)
.setOnPreferenceClickListener(new CategoryClickListener(masterSecret, PREFERENCE_CATEGORY_NOTIFICATIONS));
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_NOTIFICATIONS));
this.findPreference(PREFERENCE_CATEGORY_APP_PROTECTION)
.setOnPreferenceClickListener(new CategoryClickListener(masterSecret, PREFERENCE_CATEGORY_APP_PROTECTION));
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_APP_PROTECTION));
this.findPreference(PREFERENCE_CATEGORY_APPEARANCE)
.setOnPreferenceClickListener(new CategoryClickListener(masterSecret, PREFERENCE_CATEGORY_APPEARANCE));
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_APPEARANCE));
this.findPreference(PREFERENCE_CATEGORY_CHATS)
.setOnPreferenceClickListener(new CategoryClickListener(masterSecret, PREFERENCE_CATEGORY_CHATS));
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_CHATS));
this.findPreference(PREFERENCE_CATEGORY_DEVICES)
.setOnPreferenceClickListener(new CategoryClickListener(masterSecret, PREFERENCE_CATEGORY_DEVICES));
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_DEVICES));
this.findPreference(PREFERENCE_CATEGORY_ADVANCED)
.setOnPreferenceClickListener(new CategoryClickListener(masterSecret, PREFERENCE_CATEGORY_ADVANCED));
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_ADVANCED));
if (VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
tintIcons(getActivity());
@ -230,11 +227,9 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
}
private class CategoryClickListener implements Preference.OnPreferenceClickListener {
private MasterSecret masterSecret;
private String category;
CategoryClickListener(MasterSecret masterSecret, String category) {
this.masterSecret = masterSecret;
CategoryClickListener(String category) {
this.category = category;
}
@ -271,7 +266,6 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
if (fragment != null) {
Bundle args = new Bundle();
args.putParcelable("master_secret", masterSecret);
fragment.setArguments(args);
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();

View File

@ -17,7 +17,6 @@ import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.loaders.BlockedContactsLoader;
import org.thoughtcrime.securesms.mms.GlideApp;
@ -40,10 +39,10 @@ public class BlockedContactsActivity extends PassphraseRequiredActionBarActivity
@Override
public void onCreate(Bundle bundle, @NonNull MasterSecret masterSecret) {
public void onCreate(Bundle bundle, boolean ready) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(R.string.BlockedContactsActivity_blocked_contacts);
initFragment(android.R.id.content, new BlockedContactsFragment(), masterSecret);
initFragment(android.R.id.content, new BlockedContactsFragment());
}
@Override

View File

@ -19,12 +19,10 @@ package org.thoughtcrime.securesms;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import org.thoughtcrime.securesms.components.ContactFilterToolbar;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.util.DirectoryHelper;
import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
@ -61,7 +59,7 @@ public abstract class ContactSelectionActivity extends PassphraseRequiredActionB
}
@Override
protected void onCreate(Bundle icicle, @NonNull MasterSecret masterSecret) {
protected void onCreate(Bundle icicle, boolean ready) {
if (!getIntent().hasExtra(ContactSelectionListFragment.DISPLAY_MODE)) {
getIntent().putExtra(ContactSelectionListFragment.DISPLAY_MODE,
TextSecurePreferences.isSmsEnabled(this)

View File

@ -97,7 +97,6 @@ import org.thoughtcrime.securesms.components.reminder.UnauthorizedReminder;
import org.thoughtcrime.securesms.contacts.ContactAccessor;
import org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData;
import org.thoughtcrime.securesms.crypto.IdentityKeyParcelable;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.crypto.SecurityEvent;
import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.DatabaseFactory;
@ -259,7 +258,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
}
@Override
protected void onCreate(Bundle state, @NonNull MasterSecret masterSecret) {
protected void onCreate(Bundle state, boolean ready) {
Log.w(TAG, "onCreate()");
supportRequestWindowFeature(WindowCompat.FEATURE_ACTION_BAR_OVERLAY);
@ -271,8 +270,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
getWindow().getDecorView().setBackgroundColor(color);
fragment = initFragment(R.id.fragment_content, new ConversationFragment(),
masterSecret, dynamicLanguage.getCurrentLocale());
fragment = initFragment(R.id.fragment_content, new ConversationFragment(), dynamicLanguage.getCurrentLocale());
initializeReceivers();
initializeActionBar();

View File

@ -17,9 +17,9 @@
package org.thoughtcrime.securesms;
import android.Manifest;
import android.annotation.SuppressLint;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.TypedArray;
import android.graphics.Color;
@ -53,7 +53,6 @@ import org.thoughtcrime.securesms.components.DeliveryStatusView;
import org.thoughtcrime.securesms.components.DocumentView;
import org.thoughtcrime.securesms.components.ExpirationTimerView;
import org.thoughtcrime.securesms.components.ThumbnailView;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.AttachmentDatabase;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.MmsDatabase;
@ -105,7 +104,6 @@ public class ConversationItem extends LinearLayout
private final static String TAG = ConversationItem.class.getSimpleName();
private MessageRecord messageRecord;
private MasterSecret masterSecret;
private Locale locale;
private boolean groupThread;
private Recipient recipient;
@ -190,7 +188,6 @@ public class ConversationItem extends LinearLayout
@NonNull Set<MessageRecord> batchSelected,
@NonNull Recipient conversationRecipient)
{
this.masterSecret = masterSecret;
this.messageRecord = messageRecord;
this.locale = locale;
this.glideRequests = glideRequests;
@ -472,6 +469,7 @@ public class ConversationItem extends LinearLayout
}
}
@SuppressLint("StaticFieldLeak")
private void setExpiration(final MessageRecord messageRecord) {
if (messageRecord.getExpiresIn() > 0) {
this.expirationTimer.setVisibility(View.VISIBLE);
@ -536,6 +534,7 @@ public class ConversationItem extends LinearLayout
messageRecord.isBundleKeyExchange());
}
@SuppressLint("SetTextI18n")
private void setGroupMessageStatus(MessageRecord messageRecord, Recipient recipient) {
if (groupThread && !messageRecord.isOutgoing()) {
this.groupSender.setText(recipient.toShortString());
@ -650,7 +649,7 @@ public class ConversationItem extends LinearLayout
private class ClickListener implements View.OnClickListener {
private OnClickListener parent;
public ClickListener(@Nullable OnClickListener parent) {
ClickListener(@Nullable OnClickListener parent) {
this.parent = parent;
}
@ -687,9 +686,7 @@ public class ConversationItem extends LinearLayout
if (message > -1) builder.setMessage(message);
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
builder.setPositiveButton(R.string.yes, (dialogInterface, i) -> {
if (messageRecord.isMms()) {
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
database.markAsInsecure(messageRecord.getId());
@ -710,18 +707,14 @@ public class ConversationItem extends LinearLayout
.add(new SmsSendJob(context, messageRecord.getId(),
messageRecord.getIndividualRecipient().getAddress().serialize()));
}
}
});
builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
builder.setNegativeButton(R.string.no, (dialogInterface, i) -> {
if (messageRecord.isMms()) {
DatabaseFactory.getMmsDatabase(context).markAsSentFailed(messageRecord.getId());
} else {
DatabaseFactory.getSmsDatabase(context).markAsSentFailed(messageRecord.getId());
}
}
});
builder.show();
}

View File

@ -24,7 +24,6 @@ import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuInflater;
@ -34,7 +33,6 @@ import android.widget.Toast;
import org.thoughtcrime.securesms.components.RatingManager;
import org.thoughtcrime.securesms.components.SearchToolbar;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo;
import org.thoughtcrime.securesms.notifications.MarkReadReceiver;
@ -69,7 +67,7 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
}
@Override
protected void onCreate(Bundle icicle, @NonNull MasterSecret masterSecret) {
protected void onCreate(Bundle icicle, boolean ready) {
setContentView(R.layout.conversation_list_activity);
Toolbar toolbar = findViewById(R.id.toolbar);
@ -77,7 +75,7 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
searchToolbar = findViewById(R.id.search_toolbar);
searchAction = findViewById(R.id.search_action);
fragment = initFragment(R.id.fragment_container, new ConversationListFragment(), masterSecret, dynamicLanguage.getCurrentLocale());
fragment = initFragment(R.id.fragment_container, new ConversationListFragment(), dynamicLanguage.getCurrentLocale());
initializeSearchListener();

View File

@ -2,10 +2,8 @@ package org.thoughtcrime.securesms;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.MenuItem;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.DynamicTheme;
@ -24,15 +22,14 @@ public class ConversationListArchiveActivity extends PassphraseRequiredActionBar
}
@Override
protected void onCreate(Bundle icicle, @NonNull MasterSecret masterSecret) {
protected void onCreate(Bundle icicle, boolean ready) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(R.string.AndroidManifest_archived_conversations);
Bundle bundle = new Bundle();
bundle.putBoolean(ConversationListFragment.ARCHIVE, true);
initFragment(android.R.id.content, new ConversationListFragment(),
masterSecret, dynamicLanguage.getCurrentLocale(), bundle);
initFragment(android.R.id.content, new ConversationListFragment(), dynamicLanguage.getCurrentLocale(), bundle);
}
@Override

View File

@ -97,7 +97,6 @@ public class ConversationListFragment extends Fragment
@SuppressWarnings("unused")
private static final String TAG = ConversationListFragment.class.getSimpleName();
private MasterSecret masterSecret;
private ActionMode actionMode;
private RecyclerView list;
private ReminderView reminderView;
@ -111,7 +110,6 @@ public class ConversationListFragment extends Fragment
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
masterSecret = getArguments().getParcelable("master_secret");
locale = (Locale) getArguments().getSerializable(PassphraseRequiredActionBarActivity.LOCALE_EXTRA);
archive = getArguments().getBoolean(ARCHIVE, false);
}
@ -197,9 +195,9 @@ public class ConversationListFragment extends Fragment
} else if (DefaultSmsReminder.isEligible(context)) {
return Optional.of(new DefaultSmsReminder(context));
} else if (Util.isDefaultSmsProvider(context) && SystemSmsImportReminder.isEligible(context)) {
return Optional.of((new SystemSmsImportReminder(context, masterSecret)));
return Optional.of((new SystemSmsImportReminder(context)));
} else if (PushRegistrationReminder.isEligible(context)) {
return Optional.of((new PushRegistrationReminder(context, masterSecret)));
return Optional.of((new PushRegistrationReminder(context)));
} else if (ShareReminder.isEligible(context)) {
return Optional.of(new ShareReminder(context));
} else if (DozeReminder.isEligible(context)) {

View File

@ -4,7 +4,6 @@ import android.content.Intent;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityOptionsCompat;
import android.util.Log;
import android.view.Display;
@ -15,7 +14,6 @@ import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
import java.util.concurrent.ExecutionException;
@ -31,7 +29,7 @@ public class ConversationPopupActivity extends ConversationActivity {
}
@Override
protected void onCreate(Bundle bundle, @NonNull MasterSecret masterSecret) {
protected void onCreate(Bundle bundle, boolean ready) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
WindowManager.LayoutParams.FLAG_DIM_BEHIND);
@ -48,7 +46,7 @@ public class ConversationPopupActivity extends ConversationActivity {
if (height > width) getWindow().setLayout((int) (width * .85), (int) (height * .5));
else getWindow().setLayout((int) (width * .7), (int) (height * .75));
super.onCreate(bundle, masterSecret);
super.onCreate(bundle, ready);
titleView.setOnClickListener(null);
}

View File

@ -11,14 +11,12 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.SmsMigrator.ProgressDescription;
import org.thoughtcrime.securesms.service.ApplicationMigrationService;
import org.thoughtcrime.securesms.service.ApplicationMigrationService.ImportState;
@ -40,7 +38,7 @@ public class DatabaseMigrationActivity extends PassphraseRequiredActionBarActivi
private boolean isVisible = false;
@Override
protected void onCreate(Bundle bundle, @NonNull MasterSecret masterSecret) {
protected void onCreate(Bundle bundle, boolean ready) {
setContentView(R.layout.database_migration_activity);
initializeResources();

View File

@ -46,6 +46,7 @@ import org.thoughtcrime.securesms.jobs.DirectoryRefreshJob;
import org.thoughtcrime.securesms.jobs.PushDecryptJob;
import org.thoughtcrime.securesms.jobs.RefreshAttributesJob;
import org.thoughtcrime.securesms.notifications.MessageNotifier;
import org.thoughtcrime.securesms.service.KeyCachingService;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.VersionTracker;
@ -102,7 +103,7 @@ public class DatabaseUpgradeActivity extends BaseActivity {
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
this.masterSecret = getIntent().getParcelableExtra("master_secret");
this.masterSecret = KeyCachingService.getMasterSecret(this);
if (needsUpgradeTask()) {
Log.w("DatabaseUpgradeActivity", "Upgrading...");

View File

@ -18,7 +18,6 @@ import android.widget.Button;
import android.widget.Toast;
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.crypto.ProfileKeyUtil;
import org.thoughtcrime.securesms.permissions.Permissions;
import org.thoughtcrime.securesms.push.AccountManagerFactory;
@ -60,7 +59,7 @@ public class DeviceActivity extends PassphraseRequiredActionBarActivity
}
@Override
public void onCreate(Bundle bundle, @NonNull MasterSecret masterSecret) {
public void onCreate(Bundle bundle, boolean ready) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(R.string.AndroidManifest__linked_devices);
this.deviceAddFragment = new DeviceAddFragment();
@ -71,9 +70,9 @@ public class DeviceActivity extends PassphraseRequiredActionBarActivity
this.deviceAddFragment.setScanListener(this);
if (getIntent().getBooleanExtra("add", false)) {
initFragment(android.R.id.content, deviceAddFragment, masterSecret, dynamicLanguage.getCurrentLocale());
initFragment(android.R.id.content, deviceAddFragment, dynamicLanguage.getCurrentLocale());
} else {
initFragment(android.R.id.content, deviceListFragment, masterSecret, dynamicLanguage.getCurrentLocale());
initFragment(android.R.id.content, deviceListFragment, dynamicLanguage.getCurrentLocale());
}
}

View File

@ -1,16 +1,13 @@
package org.thoughtcrime.securesms;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.view.Window;
import org.thoughtcrime.securesms.crypto.MasterSecret;
public class DeviceProvisioningActivity extends PassphraseRequiredActionBarActivity {
@SuppressWarnings("unused")
private static final String TAG = DeviceProvisioningActivity.class.getSimpleName();
@Override
@ -19,34 +16,24 @@ public class DeviceProvisioningActivity extends PassphraseRequiredActionBarActiv
}
@Override
protected void onCreate(Bundle bundle, @NonNull MasterSecret masterSecret) {
protected void onCreate(Bundle bundle, boolean ready) {
assert getSupportActionBar() != null;
getSupportActionBar().hide();
AlertDialog dialog = new AlertDialog.Builder(this)
.setTitle(getString(R.string.DeviceProvisioningActivity_link_a_signal_device))
.setMessage(getString(R.string.DeviceProvisioningActivity_it_looks_like_youre_trying_to_link_a_signal_device_using_a_3rd_party_scanner))
.setPositiveButton(R.string.DeviceProvisioningActivity_continue, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
.setPositiveButton(R.string.DeviceProvisioningActivity_continue, (dialog1, which) -> {
Intent intent = new Intent(DeviceProvisioningActivity.this, DeviceActivity.class);
intent.putExtra("add", true);
startActivity(intent);
finish();
}
})
.setNegativeButton(R.string.DeviceProvisioningActivity_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
.setNegativeButton(R.string.DeviceProvisioningActivity_cancel, (dialog12, which) -> {
dialog12.dismiss();
finish();
}
})
.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
finish();
}
})
.setOnDismissListener(dialog13 -> finish())
.create();
dialog.setIcon(getResources().getDrawable(R.drawable.icon_dialog));

View File

@ -47,7 +47,6 @@ import org.thoughtcrime.securesms.components.PushRecipientsPanel.RecipientsPanel
import org.thoughtcrime.securesms.contacts.RecipientsEditor;
import org.thoughtcrime.securesms.contacts.avatars.ContactColors;
import org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.GroupDatabase;
@ -112,7 +111,7 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
}
@Override
protected void onCreate(Bundle state, @NonNull MasterSecret masterSecret) {
protected void onCreate(Bundle state, boolean ready) {
setContentView(R.layout.group_create_activity);
//noinspection ConstantConditions
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

View File

@ -1,10 +1,8 @@
package org.thoughtcrime.securesms;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.MenuItem;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.DynamicTheme;
@ -20,10 +18,10 @@ public class ImportExportActivity extends PassphraseRequiredActionBarActivity {
}
@Override
protected void onCreate(Bundle savedInstanceState, @NonNull MasterSecret masterSecret) {
protected void onCreate(Bundle savedInstanceState, boolean ready) {
assert getSupportActionBar() != null;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
initFragment(android.R.id.content, new ImportExportFragment(),
masterSecret, dynamicLanguage.getCurrentLocale());
initFragment(android.R.id.content, new ImportExportFragment(), dynamicLanguage.getCurrentLocale());
}
@Override

View File

@ -1,16 +1,15 @@
package org.thoughtcrime.securesms;
import android.animation.Animator;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.support.annotation.AnimRes;
import android.support.annotation.NonNull;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.support.v7.app.AlertDialog;
import android.view.View;
@ -27,45 +26,35 @@ import android.widget.Toast;
import org.thoughtcrime.securesms.components.ContactFilterToolbar;
import org.thoughtcrime.securesms.components.ContactFilterToolbar.OnFilterChangedListener;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.RecipientDatabase.RecipientSettings;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.sms.MessageSender;
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
import org.thoughtcrime.securesms.util.ViewUtil;
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture.Listener;
import org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.concurrent.ExecutionException;
public class InviteActivity extends PassphraseRequiredActionBarActivity implements ContactSelectionListFragment.OnContactSelectedListener {
private MasterSecret masterSecret;
private ContactSelectionListFragment contactsFragment;
private EditText inviteText;
private View shareButton;
private View smsButton;
private ViewGroup smsSendFrame;
private Button smsSendButton;
private Button smsCancelButton;
private Animation slideInAnimation;
private Animation slideOutAnimation;
private ContactFilterToolbar contactFilter;
private ImageView heart;
@Override
protected void onCreate(Bundle savedInstanceState, @NonNull MasterSecret masterSecret) {
this.masterSecret = masterSecret;
protected void onCreate(Bundle savedInstanceState, boolean ready) {
getIntent().putExtra(ContactSelectionListFragment.DISPLAY_MODE, ContactSelectionListFragment.DISPLAY_MODE_SMS_ONLY);
getIntent().putExtra(ContactSelectionListFragment.MULTI_SELECT, true);
getIntent().putExtra(ContactSelectionListFragment.REFRESHABLE, false);
super.onCreate(savedInstanceState, masterSecret);
setContentView(R.layout.invite_activity);
assert getSupportActionBar() != null;
getSupportActionBar().setTitle(R.string.AndroidManifest__invite_friends);
initializeResources();
@ -74,13 +63,15 @@ public class InviteActivity extends PassphraseRequiredActionBarActivity implemen
private void initializeResources() {
slideInAnimation = loadAnimation(R.anim.slide_from_bottom);
slideOutAnimation = loadAnimation(R.anim.slide_to_bottom);
shareButton = ViewUtil.findById(this, R.id.share_button);
smsButton = ViewUtil.findById(this, R.id.sms_button);
View shareButton = ViewUtil.findById(this, R.id.share_button);
View smsButton = ViewUtil.findById(this, R.id.sms_button);
Button smsCancelButton = ViewUtil.findById(this, R.id.cancel_sms_button);
ContactFilterToolbar contactFilter = ViewUtil.findById(this, R.id.contact_filter);
inviteText = ViewUtil.findById(this, R.id.invite_text);
smsSendFrame = ViewUtil.findById(this, R.id.sms_send_frame);
smsSendButton = ViewUtil.findById(this, R.id.send_sms_button);
smsCancelButton = ViewUtil.findById(this, R.id.cancel_sms_button);
contactFilter = ViewUtil.findById(this, R.id.contact_filter);
heart = ViewUtil.findById(this, R.id.heart);
contactsFragment = (ContactSelectionListFragment)getSupportFragmentManager().findFragmentById(R.id.contact_selection_list_fragment);
@ -180,16 +171,8 @@ public class InviteActivity extends PassphraseRequiredActionBarActivity implemen
contactsFragment.getSelectedContacts().size(),
contactsFragment.getSelectedContacts().size()))
.setMessage(inviteText.getText().toString())
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override public void onClick(DialogInterface dialog, int which) {
sendSmsInvites();
}
})
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
@Override public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.setPositiveButton(R.string.yes, (dialog, which) -> sendSmsInvites())
.setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss())
.show();
}
}
@ -218,10 +201,11 @@ public class InviteActivity extends PassphraseRequiredActionBarActivity implemen
}
}
@SuppressLint("StaticFieldLeak")
private class SendSmsInvitesAsyncTask extends ProgressDialogAsyncTask<String,Void,Void> {
private final String message;
public SendSmsInvitesAsyncTask(Context context, String message) {
SendSmsInvitesAsyncTask(Context context, String message) {
super(context, R.string.InviteActivity_sending, R.string.InviteActivity_sending);
this.message = message;
}

View File

@ -39,7 +39,6 @@ import android.widget.TextView;
import com.codewaves.stickyheadergrid.StickyHeaderGridLayoutManager;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.CursorRecyclerViewAdapter;
import org.thoughtcrime.securesms.database.loaders.BucketedThreadMediaLoader;
@ -71,7 +70,6 @@ public class MediaOverviewActivity extends PassphraseRequiredActionBarActivity
private Toolbar toolbar;
private TabLayout tabLayout;
private ViewPager viewPager;
private MasterSecret masterSecret;
private Recipient recipient;
@Override
@ -81,9 +79,8 @@ public class MediaOverviewActivity extends PassphraseRequiredActionBarActivity
}
@Override
protected void onCreate(Bundle bundle, @NonNull MasterSecret masterSecret) {
protected void onCreate(Bundle bundle, boolean ready) {
setContentView(R.layout.media_overview_activity);
this.masterSecret = masterSecret;
initializeResources();
initializeToolbar();
@ -142,7 +139,6 @@ public class MediaOverviewActivity extends PassphraseRequiredActionBarActivity
Bundle args = new Bundle();
args.putString(MediaOverviewGalleryFragment.ADDRESS_EXTRA, recipient.getAddress().serialize());
args.putParcelable(MediaOverviewGalleryFragment.MASTER_SECRET_EXTRA, masterSecret);
args.putSerializable(MediaOverviewGalleryFragment.LOCALE_EXTRA, dynamicLanguage.getCurrentLocale());
fragment.setArguments(args);
@ -166,12 +162,10 @@ public class MediaOverviewActivity extends PassphraseRequiredActionBarActivity
public static abstract class MediaOverviewFragment<T> extends Fragment implements LoaderManager.LoaderCallbacks<T> {
public static final String ADDRESS_EXTRA = "address";
public static final String MASTER_SECRET_EXTRA = "master_secret";
public static final String LOCALE_EXTRA = "locale_extra";
protected TextView noMedia;
protected Recipient recipient;
protected MasterSecret masterSecret;
protected RecyclerView recyclerView;
protected Locale locale;
@ -180,15 +174,12 @@ public class MediaOverviewActivity extends PassphraseRequiredActionBarActivity
super.onCreate(bundle);
String address = getArguments().getString(ADDRESS_EXTRA);
MasterSecret masterSecret = getArguments().getParcelable(MASTER_SECRET_EXTRA);
Locale locale = (Locale)getArguments().getSerializable(LOCALE_EXTRA);
if (address == null) throw new AssertionError();
if (masterSecret == null) throw new AssertionError();
if (locale == null) throw new AssertionError();
this.recipient = Recipient.from(getContext(), Address.fromSerialized(address), true);
this.masterSecret = masterSecret;
this.locale = locale;
getLoaderManager().initLoader(0, null, this);
@ -263,7 +254,7 @@ public class MediaOverviewActivity extends PassphraseRequiredActionBarActivity
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
return new ThreadMediaLoader(getContext(), masterSecret, recipient.getAddress(), false);
return new ThreadMediaLoader(getContext(), recipient.getAddress(), false);
}
@Override

View File

@ -48,7 +48,6 @@ import android.widget.Toast;
import org.thoughtcrime.securesms.components.MediaView;
import org.thoughtcrime.securesms.components.viewpager.ExtendedOnPageChangedListener;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.MediaDatabase.MediaRecord;
import org.thoughtcrime.securesms.database.loaders.PagingMediaLoader;
@ -92,7 +91,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
@SuppressWarnings("ConstantConditions")
@Override
protected void onCreate(Bundle bundle, @NonNull MasterSecret masterSecret) {
protected void onCreate(Bundle bundle, boolean ready) {
this.setTheme(R.style.TextSecure_DarkTheme);
dynamicLanguage.onCreate(this);

View File

@ -16,6 +16,7 @@
*/
package org.thoughtcrime.securesms;
import android.annotation.SuppressLint;
import android.content.Context;
import android.database.Cursor;
import android.graphics.drawable.ColorDrawable;
@ -36,8 +37,6 @@ import android.widget.TextView;
import org.thoughtcrime.securesms.MessageDetailsRecipientAdapter.RecipientDeliveryStatus;
import org.thoughtcrime.securesms.color.MaterialColor;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.GroupReceiptDatabase;
import org.thoughtcrime.securesms.database.GroupReceiptDatabase.GroupReceiptInfo;
@ -106,7 +105,7 @@ public class MessageDetailsActivity extends PassphraseRequiredActionBarActivity
}
@Override
public void onCreate(Bundle bundle, @NonNull MasterSecret masterSecret) {
public void onCreate(Bundle bundle, boolean ready) {
setContentView(R.layout.message_details_activity);
running = true;
@ -120,6 +119,8 @@ public class MessageDetailsActivity extends PassphraseRequiredActionBarActivity
super.onResume();
dynamicTheme.onResume(this);
dynamicLanguage.onResume(this);
assert getSupportActionBar() != null;
getSupportActionBar().setTitle(R.string.AndroidManifest__message_details);
MessageNotifier.setVisibleThread(threadId);
@ -138,15 +139,17 @@ public class MessageDetailsActivity extends PassphraseRequiredActionBarActivity
}
private void initializeActionBar() {
assert getSupportActionBar() != null;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Recipient recipient = Recipient.from(this, (Address)getIntent().getParcelableExtra(ADDRESS_EXTRA), true);
Recipient recipient = Recipient.from(this, getIntent().getParcelableExtra(ADDRESS_EXTRA), true);
recipient.addListener(this);
setActionBarColor(recipient.getColor());
}
private void setActionBarColor(MaterialColor color) {
assert getSupportActionBar() != null;
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color.toActionBarColor(this)));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
@ -315,6 +318,7 @@ public class MessageDetailsActivity extends PassphraseRequiredActionBarActivity
return false;
}
@SuppressLint("StaticFieldLeak")
private class MessageRecipientAsyncTask extends AsyncTask<Void,Void,List<RecipientDeliveryStatus>> {
private final WeakReference<Context> weakContext;

View File

@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2015 Open Whisper Systems
*
* This program is free software: you can redistribute it and/or modify
@ -18,13 +18,11 @@ package org.thoughtcrime.securesms;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.ThreadDatabase;
@ -38,12 +36,12 @@ import org.thoughtcrime.securesms.recipients.Recipient;
*/
public class NewConversationActivity extends ContactSelectionActivity {
@SuppressWarnings("unused")
private static final String TAG = NewConversationActivity.class.getSimpleName();
@Override
public void onCreate(Bundle bundle, @NonNull MasterSecret masterSecret) {
super.onCreate(bundle, masterSecret);
public void onCreate(Bundle bundle, boolean ready) {
assert getSupportActionBar() != null;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

View File

@ -11,7 +11,6 @@ import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
import org.thoughtcrime.securesms.jobs.PushNotificationReceiveJob;
import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess;
@ -42,17 +41,20 @@ public abstract class PassphraseRequiredActionBarActivity extends BaseActionBarA
Log.w(TAG, "onCreate(" + savedInstanceState + ")");
this.networkAccess = new SignalServiceNetworkAccess(this);
onPreCreate();
final MasterSecret masterSecret = KeyCachingService.getMasterSecret(this);
routeApplicationState(masterSecret);
final boolean locked = KeyCachingService.isLocked(this);
routeApplicationState(locked);
super.onCreate(savedInstanceState);
if (!isFinishing()) {
initializeClearKeyReceiver();
onCreate(savedInstanceState, masterSecret);
onCreate(savedInstanceState, true);
}
}
protected void onPreCreate() {}
protected void onCreate(Bundle savedInstanceState, @NonNull MasterSecret masterSecret) {}
protected void onCreate(Bundle savedInstanceState, boolean ready) {}
@Override
protected void onResume() {
@ -87,33 +89,29 @@ public abstract class PassphraseRequiredActionBarActivity extends BaseActionBarA
@Override
public void onMasterSecretCleared() {
Log.w(TAG, "onMasterSecretCleared()");
if (isVisible) routeApplicationState(null);
if (isVisible) routeApplicationState(false);
else finish();
}
protected <T extends Fragment> T initFragment(@IdRes int target,
@NonNull T fragment,
@NonNull MasterSecret masterSecret)
@NonNull T fragment)
{
return initFragment(target, fragment, masterSecret, null);
return initFragment(target, fragment, null);
}
protected <T extends Fragment> T initFragment(@IdRes int target,
@NonNull T fragment,
@NonNull MasterSecret masterSecret,
@Nullable Locale locale)
{
return initFragment(target, fragment, masterSecret, locale, null);
return initFragment(target, fragment, locale, null);
}
protected <T extends Fragment> T initFragment(@IdRes int target,
@NonNull T fragment,
@NonNull MasterSecret masterSecret,
@Nullable Locale locale,
@Nullable Bundle extras)
{
Bundle args = new Bundle();
args.putParcelable("master_secret", masterSecret);
args.putSerializable(LOCALE_EXTRA, locale);
if (extras != null) {
@ -127,31 +125,31 @@ public abstract class PassphraseRequiredActionBarActivity extends BaseActionBarA
return fragment;
}
private void routeApplicationState(MasterSecret masterSecret) {
Intent intent = getIntentForState(masterSecret, getApplicationState(masterSecret));
private void routeApplicationState(boolean locked) {
Intent intent = getIntentForState(getApplicationState(locked));
if (intent != null) {
startActivity(intent);
finish();
}
}
private Intent getIntentForState(MasterSecret masterSecret, int state) {
private Intent getIntentForState(int state) {
Log.w(TAG, "routeApplicationState(), state: " + state);
switch (state) {
case STATE_CREATE_PASSPHRASE: return getCreatePassphraseIntent();
case STATE_PROMPT_PASSPHRASE: return getPromptPassphraseIntent();
case STATE_UPGRADE_DATABASE: return getUpgradeDatabaseIntent(masterSecret);
case STATE_PROMPT_PUSH_REGISTRATION: return getPushRegistrationIntent(masterSecret);
case STATE_UPGRADE_DATABASE: return getUpgradeDatabaseIntent();
case STATE_PROMPT_PUSH_REGISTRATION: return getPushRegistrationIntent();
case STATE_EXPERIENCE_UPGRADE: return getExperienceUpgradeIntent();
default: return null;
}
}
private int getApplicationState(MasterSecret masterSecret) {
private int getApplicationState(boolean locked) {
if (!MasterSecretUtil.isPassphraseInitialized(this)) {
return STATE_CREATE_PASSPHRASE;
} else if (masterSecret == null) {
} else if (locked) {
return STATE_PROMPT_PASSPHRASE;
} else if (DatabaseUpgradeActivity.isUpdate(this)) {
return STATE_UPGRADE_DATABASE;
@ -165,37 +163,35 @@ public abstract class PassphraseRequiredActionBarActivity extends BaseActionBarA
}
private Intent getCreatePassphraseIntent() {
return getRoutedIntent(PassphraseCreateActivity.class, getIntent(), null);
return getRoutedIntent(PassphraseCreateActivity.class, getIntent());
}
private Intent getPromptPassphraseIntent() {
return getRoutedIntent(PassphrasePromptActivity.class, getIntent(), null);
return getRoutedIntent(PassphrasePromptActivity.class, getIntent());
}
private Intent getUpgradeDatabaseIntent(MasterSecret masterSecret) {
private Intent getUpgradeDatabaseIntent() {
return getRoutedIntent(DatabaseUpgradeActivity.class,
TextSecurePreferences.hasPromptedPushRegistration(this)
? getConversationListIntent()
: getPushRegistrationIntent(masterSecret),
masterSecret);
: getPushRegistrationIntent());
}
private Intent getExperienceUpgradeIntent() {
return getRoutedIntent(ExperienceUpgradeActivity.class, getIntent(), null);
return getRoutedIntent(ExperienceUpgradeActivity.class, getIntent());
}
private Intent getPushRegistrationIntent(MasterSecret masterSecret) {
return getRoutedIntent(RegistrationActivity.class, getCreateProfileIntent(masterSecret), masterSecret);
private Intent getPushRegistrationIntent() {
return getRoutedIntent(RegistrationActivity.class, getCreateProfileIntent());
}
private Intent getCreateProfileIntent(MasterSecret masterSecret) {
return getRoutedIntent(CreateProfileActivity.class, getConversationListIntent(), masterSecret);
private Intent getCreateProfileIntent() {
return getRoutedIntent(CreateProfileActivity.class, getConversationListIntent());
}
private Intent getRoutedIntent(Class<?> destination, @Nullable Intent nextIntent, @Nullable MasterSecret masterSecret) {
private Intent getRoutedIntent(Class<?> destination, @Nullable Intent nextIntent) {
final Intent intent = new Intent(this, destination);
if (nextIntent != null) intent.putExtra("next_intent", nextIntent);
if (masterSecret != null) intent.putExtra("master_secret", masterSecret);
return intent;
}

View File

@ -2,44 +2,30 @@ package org.thoughtcrime.securesms;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.Button;
import org.thoughtcrime.securesms.preferences.MmsPreferencesActivity;
import org.thoughtcrime.securesms.crypto.MasterSecret;
public class PromptMmsActivity extends PassphraseRequiredActionBarActivity {
private Button okButton;
private Button cancelButton;
@Override
protected void onCreate(Bundle bundle, @NonNull MasterSecret masterSecret) {
protected void onCreate(Bundle bundle, boolean ready) {
setContentView(R.layout.prompt_apn_activity);
initializeResources();
}
private void initializeResources() {
this.okButton = (Button)findViewById(R.id.ok_button);
this.cancelButton = (Button)findViewById(R.id.cancel_button);
Button okButton = findViewById(R.id.ok_button);
Button cancelButton = findViewById(R.id.cancel_button);
this.okButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
okButton.setOnClickListener(v -> {
Intent intent = new Intent(PromptMmsActivity.this, MmsPreferencesActivity.class);
intent.putExtras(PromptMmsActivity.this.getIntent().getExtras());
startActivity(intent);
finish();
}
});
this.cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
cancelButton.setOnClickListener(v -> finish());
}
}

View File

@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2011 Whisper Systems
*
* This program is free software: you can redistribute it and/or modify
@ -18,10 +18,6 @@ package org.thoughtcrime.securesms;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import java.util.ArrayList;
import java.util.List;
@ -34,17 +30,16 @@ import java.util.List;
*/
public class PushContactSelectionActivity extends ContactSelectionActivity {
@SuppressWarnings("unused")
private final static String TAG = PushContactSelectionActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle icicle, @NonNull MasterSecret masterSecret) {
protected void onCreate(Bundle icicle, boolean ready) {
getIntent().putExtra(ContactSelectionListFragment.MULTI_SELECT, true);
super.onCreate(icicle, masterSecret);
super.onCreate(icicle, ready);
getToolbar().setNavigationIcon(R.drawable.ic_check_white_24dp);
getToolbar().setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getToolbar().setNavigationOnClickListener(v -> {
Intent resultIntent = getIntent();
List<String> selectedContacts = contactsFragment.getSelectedContacts();
@ -54,7 +49,6 @@ public class PushContactSelectionActivity extends ContactSelectionActivity {
setResult(RESULT_OK, resultIntent);
finish();
}
});
}
}

View File

@ -39,7 +39,6 @@ import org.thoughtcrime.securesms.color.MaterialColor;
import org.thoughtcrime.securesms.color.MaterialColors;
import org.thoughtcrime.securesms.components.ThreadPhotoRailView;
import org.thoughtcrime.securesms.crypto.IdentityKeyParcelable;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.IdentityDatabase;
@ -86,7 +85,6 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
private ImageView avatar;
private MasterSecret masterSecret;
private GlideRequests glideRequests;
private Address address;
private TextView threadPhotoRailLabel;
@ -100,9 +98,8 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
}
@Override
public void onCreate(Bundle instanceState, @NonNull MasterSecret masterSecret) {
public void onCreate(Bundle instanceState, boolean ready) {
setContentView(R.layout.recipient_preference_activity);
this.masterSecret = masterSecret;
this.glideRequests = GlideApp.with(this);
this.address = getIntent().getParcelableExtra(ADDRESS_EXTRA);
@ -205,7 +202,7 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
return new ThreadMediaLoader(this, masterSecret, address, true);
return new ThreadMediaLoader(this, address, true);
}
@Override
@ -218,16 +215,16 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
this.threadPhotoRailView.setVisibility(View.GONE);
}
this.threadPhotoRailView.setCursor(masterSecret, glideRequests, data);
this.threadPhotoRailView.setCursor(glideRequests, data);
Bundle bundle = new Bundle();
bundle.putParcelable(ADDRESS_EXTRA, address);
initFragment(R.id.preference_fragment, new RecipientPreferenceFragment(), masterSecret, null, bundle);
initFragment(R.id.preference_fragment, new RecipientPreferenceFragment(), null, bundle);
}
@Override
public void onLoaderReset(Loader<Cursor> loader) {
this.threadPhotoRailView.setCursor(masterSecret, glideRequests, null);
this.threadPhotoRailView.setCursor(glideRequests, null);
}
public static class RecipientPreferenceFragment

View File

@ -38,7 +38,6 @@ import android.view.View;
import android.widget.ImageView;
import org.thoughtcrime.securesms.components.SearchToolbar;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.ThreadDatabase;
@ -74,7 +73,6 @@ public class ShareActivity extends PassphraseRequiredActionBarActivity
private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme();
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
private MasterSecret masterSecret;
private ContactSelectionListFragment contactsFragment;
private SearchToolbar searchToolbar;
private ImageView searchAction;
@ -90,9 +88,7 @@ public class ShareActivity extends PassphraseRequiredActionBarActivity
}
@Override
protected void onCreate(Bundle icicle, @NonNull MasterSecret masterSecret) {
this.masterSecret = masterSecret;
protected void onCreate(Bundle icicle, boolean ready) {
if (!getIntent().hasExtra(ContactSelectionListFragment.DISPLAY_MODE)) {
getIntent().putExtra(ContactSelectionListFragment.DISPLAY_MODE,
TextSecurePreferences.isSmsEnabled(this)

View File

@ -16,7 +16,6 @@
*/
package org.thoughtcrime.securesms;
import android.*;
import android.Manifest;
import android.animation.TypeEvaluator;
import android.animation.ValueAnimator;
@ -66,8 +65,6 @@ import org.thoughtcrime.securesms.color.MaterialColor;
import org.thoughtcrime.securesms.components.camera.CameraView;
import org.thoughtcrime.securesms.crypto.IdentityKeyParcelable;
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.crypto.MasterSecretUnion;
import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.IdentityDatabase.VerifiedStatus;
@ -122,7 +119,7 @@ public class VerifyIdentityActivity extends PassphraseRequiredActionBarActivity
}
@Override
protected void onCreate(Bundle state, @NonNull MasterSecret masterSecret) {
protected void onCreate(Bundle state, boolean ready) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(R.string.AndroidManifest__verify_safety_number);
@ -142,7 +139,7 @@ public class VerifyIdentityActivity extends PassphraseRequiredActionBarActivity
scanFragment.setScanListener(this);
displayFragment.setClickListener(this);
initFragment(android.R.id.content, displayFragment, masterSecret, dynamicLanguage.getCurrentLocale(), extras);
initFragment(android.R.id.content, displayFragment, dynamicLanguage.getCurrentLocale(), extras);
}
@Override
@ -210,7 +207,6 @@ public class VerifyIdentityActivity extends PassphraseRequiredActionBarActivity
public static final String LOCAL_NUMBER = "local_number";
public static final String VERIFIED_STATE = "verified_state";
private MasterSecret masterSecret;
private Recipient recipient;
private String localNumber;
private String remoteNumber;
@ -276,7 +272,6 @@ public class VerifyIdentityActivity extends PassphraseRequiredActionBarActivity
if (localIdentityParcelable == null) throw new AssertionError("local identity required");
if (remoteIdentityParcelable == null) throw new AssertionError("remote identity required");
this.masterSecret = getArguments().getParcelable("master_secret");
this.localNumber = getArguments().getString(LOCAL_NUMBER);
this.localIdentity = localIdentityParcelable.get();
this.remoteNumber = getArguments().getString(REMOTE_NUMBER);

View File

@ -15,7 +15,6 @@ import android.view.ViewGroup;
import android.widget.FrameLayout;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.CursorRecyclerViewAdapter;
import org.thoughtcrime.securesms.database.MediaDatabase;
import org.thoughtcrime.securesms.mms.GlideRequests;
@ -55,27 +54,25 @@ public class ThreadPhotoRailView extends FrameLayout {
}
}
public void setCursor(@NonNull MasterSecret masterSecret, @NonNull GlideRequests glideRequests, @Nullable Cursor cursor) {
this.recyclerView.setAdapter(new ThreadPhotoRailAdapter(getContext(), masterSecret, glideRequests, cursor, this.listener));
public void setCursor(@NonNull GlideRequests glideRequests, @Nullable Cursor cursor) {
this.recyclerView.setAdapter(new ThreadPhotoRailAdapter(getContext(), glideRequests, cursor, this.listener));
}
private static class ThreadPhotoRailAdapter extends CursorRecyclerViewAdapter<ThreadPhotoRailAdapter.ThreadPhotoViewHolder> {
@SuppressWarnings("unused")
private static final String TAG = ThreadPhotoRailAdapter.class.getName();
@NonNull private final MasterSecret masterSecret;
@NonNull private final GlideRequests glideRequests;
@Nullable private OnItemClickedListener clickedListener;
private ThreadPhotoRailAdapter(@NonNull Context context,
@NonNull MasterSecret masterSecret,
@NonNull GlideRequests glideRequests,
@Nullable Cursor cursor,
@Nullable OnItemClickedListener listener)
{
super(context, cursor);
this.masterSecret = masterSecret;
this.glideRequests = glideRequests;
this.clickedListener = listener;
}
@ -120,6 +117,6 @@ public class ThreadPhotoRailView extends FrameLayout {
}
public interface OnItemClickedListener {
public void onItemClicked(MediaDatabase.MediaRecord mediaRecord);
void onItemClicked(MediaDatabase.MediaRecord mediaRecord);
}
}

View File

@ -2,28 +2,22 @@ package org.thoughtcrime.securesms.components.reminder;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.RegistrationActivity;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.crypto.MasterSecret;
public class PushRegistrationReminder extends Reminder {
public PushRegistrationReminder(final Context context, final MasterSecret masterSecret) {
public PushRegistrationReminder(final Context context) {
super(context.getString(R.string.reminder_header_push_title),
context.getString(R.string.reminder_header_push_text));
final OnClickListener okListener = new OnClickListener() {
@Override
public void onClick(View v) {
final OnClickListener okListener = v -> {
Intent intent = new Intent(context, RegistrationActivity.class);
intent.putExtra("master_secret", masterSecret);
intent.putExtra("cancel_button", true);
context.startActivity(intent);
}
};
setOkListener(okListener);

View File

@ -9,29 +9,22 @@ import org.thoughtcrime.securesms.ConversationListActivity;
import org.thoughtcrime.securesms.DatabaseMigrationActivity;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.service.ApplicationMigrationService;
import org.thoughtcrime.securesms.crypto.MasterSecret;
public class SystemSmsImportReminder extends Reminder {
public SystemSmsImportReminder(final Context context, final MasterSecret masterSecret) {
public SystemSmsImportReminder(final Context context) {
super(context.getString(R.string.reminder_header_sms_import_title),
context.getString(R.string.reminder_header_sms_import_text));
final OnClickListener okListener = new OnClickListener() {
@Override
public void onClick(View v) {
final OnClickListener okListener = v -> {
Intent intent = new Intent(context, ApplicationMigrationService.class);
intent.setAction(ApplicationMigrationService.MIGRATE_DATABASE);
context.startService(intent);
Intent nextIntent = new Intent(context, ConversationListActivity.class);
intent.putExtra("master_secret", masterSecret);
Intent activityIntent = new Intent(context, DatabaseMigrationActivity.class);
activityIntent.putExtra("master_secret", masterSecret);
activityIntent.putExtra("next_intent", nextIntent);
context.startActivity(activityIntent);
}
};
final OnClickListener cancelListener = new OnClickListener() {
@Override

View File

@ -1,29 +0,0 @@
package org.thoughtcrime.securesms.crypto;
import android.support.annotation.NonNull;
import org.whispersystems.libsignal.util.guava.Optional;
public class MasterSecretUnion {
private final Optional<MasterSecret> masterSecret;
private final Optional<AsymmetricMasterSecret> asymmetricMasterSecret;
public MasterSecretUnion(@NonNull MasterSecret masterSecret) {
this.masterSecret = Optional.of(masterSecret);
this.asymmetricMasterSecret = Optional.absent();
}
public MasterSecretUnion(@NonNull AsymmetricMasterSecret asymmetricMasterSecret) {
this.masterSecret = Optional.absent();
this.asymmetricMasterSecret = Optional.of(asymmetricMasterSecret);
}
public Optional<MasterSecret> getMasterSecret() {
return masterSecret;
}
public Optional<AsymmetricMasterSecret> getAsymmetricMasterSecret() {
return asymmetricMasterSecret;
}
}

View File

@ -5,9 +5,7 @@ import android.content.Context;
import android.database.Cursor;
import android.support.annotation.NonNull;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.Database;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.AbstractCursorLoader;
@ -15,12 +13,10 @@ import org.thoughtcrime.securesms.util.AbstractCursorLoader;
public class ThreadMediaLoader extends AbstractCursorLoader {
private final Address address;
private final MasterSecret masterSecret;
private final boolean gallery;
public ThreadMediaLoader(@NonNull Context context, @NonNull MasterSecret masterSecret, @NonNull Address address, boolean gallery) {
public ThreadMediaLoader(@NonNull Context context, @NonNull Address address, boolean gallery) {
super(context);
this.masterSecret = masterSecret;
this.address = address;
this.gallery = gallery;
}
@ -37,7 +33,4 @@ public class ThreadMediaLoader extends AbstractCursorLoader {
return address;
}
public MasterSecret getMasterSecret() {
return masterSecret;
}
}

View File

@ -17,6 +17,7 @@
package org.thoughtcrime.securesms.database.model;
import android.content.Context;
import android.support.annotation.NonNull;
import android.text.SpannableString;
import org.thoughtcrime.securesms.database.MmsSmsColumns;
@ -61,8 +62,8 @@ public abstract class DisplayRecord {
this.deliveryStatus = deliveryStatus;
}
public String getBody() {
return body;
public @NonNull String getBody() {
return body == null ? "" : body;
}
public boolean isFailed() {

View File

@ -19,7 +19,6 @@ import android.widget.Toast;
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
import org.thoughtcrime.securesms.util.DynamicTheme;
@ -53,7 +52,7 @@ public class GiphyActivity extends PassphraseRequiredActionBarActivity
}
@Override
public void onCreate(Bundle bundle, @NonNull MasterSecret masterSecret) {
public void onCreate(Bundle bundle, boolean ready) {
setContentView(R.layout.giphy_activity);
initializeToolbar();

View File

@ -9,7 +9,6 @@ import com.annimon.stream.Stream;
import org.thoughtcrime.securesms.ApplicationContext;
import org.thoughtcrime.securesms.attachments.Attachment;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.GroupReceiptDatabase.GroupReceiptInfo;
@ -77,7 +76,7 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType {
}
@Override
public void onPushSend(MasterSecret masterSecret)
public void onPushSend()
throws MmsException, IOException, NoSuchMessageException
{
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);

View File

@ -5,7 +5,6 @@ import android.util.Log;
import org.thoughtcrime.securesms.ApplicationContext;
import org.thoughtcrime.securesms.attachments.Attachment;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.MmsDatabase;
@ -53,7 +52,7 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType {
}
@Override
public void onPushSend(MasterSecret masterSecret)
public void onPushSend()
throws RetryLaterException, MmsException, NoSuchMessageException,
UndeliverableMessageException
{

View File

@ -2,7 +2,6 @@ package org.thoughtcrime.securesms.jobs;
import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.Log;
import org.greenrobot.eventbus.EventBus;
@ -13,15 +12,12 @@ import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.crypto.ProfileKeyUtil;
import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.RecipientDatabase.RecipientSettings;
import org.thoughtcrime.securesms.events.PartProgressEvent;
import org.thoughtcrime.securesms.jobs.requirements.MasterSecretRequirement;
import org.thoughtcrime.securesms.mms.PartAuthority;
import org.thoughtcrime.securesms.notifications.MessageNotifier;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.Base64;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.Util;
import org.whispersystems.jobqueue.JobParameters;
import org.whispersystems.jobqueue.requirements.NetworkRequirement;
import org.whispersystems.libsignal.util.guava.Optional;
@ -63,7 +59,7 @@ public abstract class PushSendJob extends SendJob {
throw new TextSecureExpiredException("Too many signed prekey rotation failures");
}
onPushSend(masterSecret);
onPushSend();
}
protected Optional<byte[]> getProfileKey(@NonNull Recipient recipient) {
@ -117,5 +113,5 @@ public abstract class PushSendJob extends SendJob {
}
}
protected abstract void onPushSend(MasterSecret masterSecret) throws Exception;
protected abstract void onPushSend() throws Exception;
}

View File

@ -4,7 +4,6 @@ import android.content.Context;
import android.util.Log;
import org.thoughtcrime.securesms.ApplicationContext;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.NoSuchMessageException;
@ -46,7 +45,7 @@ public class PushTextSendJob extends PushSendJob implements InjectableType {
public void onAdded() {}
@Override
public void onPushSend(MasterSecret masterSecret) throws NoSuchMessageException, RetryLaterException {
public void onPushSend() throws NoSuchMessageException, RetryLaterException {
ExpiringMessageManager expirationManager = ApplicationContext.getInstance(context).getExpiringMessageManager();
SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
SmsMessageRecord record = database.getMessage(messageId);

View File

@ -18,13 +18,12 @@
package org.thoughtcrime.securesms.notifications;
import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationManagerCompat;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo;
import org.whispersystems.libsignal.logging.Log;
@ -35,7 +34,7 @@ import java.util.List;
/**
* Marks an Android Auto as read after the driver have listened to it
*/
public class AndroidAutoHeardReceiver extends MasterSecretBroadcastReceiver {
public class AndroidAutoHeardReceiver extends BroadcastReceiver {
public static final String TAG = AndroidAutoHeardReceiver.class.getSimpleName();
public static final String HEARD_ACTION = "org.thoughtcrime.securesms.notifications.ANDROID_AUTO_HEARD";
@ -44,8 +43,7 @@ public class AndroidAutoHeardReceiver extends MasterSecretBroadcastReceiver {
@SuppressLint("StaticFieldLeak")
@Override
protected void onReceive(final Context context, Intent intent,
@Nullable final MasterSecret masterSecret)
public void onReceive(final Context context, Intent intent)
{
if (!HEARD_ACTION.equals(intent.getAction()))
return;

View File

@ -18,14 +18,13 @@
package org.thoughtcrime.securesms.notifications;
import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.RemoteInput;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo;
@ -41,7 +40,7 @@ import java.util.List;
/**
* Get the response text from the Android Auto and sends an message as a reply
*/
public class AndroidAutoReplyReceiver extends MasterSecretBroadcastReceiver {
public class AndroidAutoReplyReceiver extends BroadcastReceiver {
public static final String TAG = AndroidAutoReplyReceiver.class.getSimpleName();
public static final String REPLY_ACTION = "org.thoughtcrime.securesms.notifications.ANDROID_AUTO_REPLY";
@ -51,8 +50,7 @@ public class AndroidAutoReplyReceiver extends MasterSecretBroadcastReceiver {
@SuppressLint("StaticFieldLeak")
@Override
protected void onReceive(final Context context, Intent intent,
final @Nullable MasterSecret masterSecret)
public void onReceive(final Context context, Intent intent)
{
if (!REPLY_ACTION.equals(intent.getAction())) return;

View File

@ -1,11 +1,11 @@
package org.thoughtcrime.securesms.notifications;
import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationManagerCompat;
import android.util.Log;
@ -13,7 +13,6 @@ import com.annimon.stream.Collectors;
import com.annimon.stream.Stream;
import org.thoughtcrime.securesms.ApplicationContext;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.MessagingDatabase.ExpirationInfo;
@ -27,7 +26,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class MarkReadReceiver extends MasterSecretBroadcastReceiver {
public class MarkReadReceiver extends BroadcastReceiver {
private static final String TAG = MarkReadReceiver.class.getSimpleName();
public static final String CLEAR_ACTION = "org.thoughtcrime.securesms.notifications.CLEAR";
@ -36,8 +35,7 @@ public class MarkReadReceiver extends MasterSecretBroadcastReceiver {
@SuppressLint("StaticFieldLeak")
@Override
protected void onReceive(final Context context, Intent intent, @Nullable final MasterSecret masterSecret)
{
public void onReceive(final Context context, Intent intent) {
if (!CLEAR_ACTION.equals(intent.getAction()))
return;

View File

@ -1,19 +0,0 @@
package org.thoughtcrime.securesms.notifications;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.Nullable;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.service.KeyCachingService;
public abstract class MasterSecretBroadcastReceiver extends BroadcastReceiver {
@Override
public final void onReceive(Context context, Intent intent) {
onReceive(context, intent, KeyCachingService.getMasterSecret(context));
}
protected abstract void onReceive(Context context, Intent intent, @Nullable MasterSecret masterSecret);
}

View File

@ -18,14 +18,13 @@
package org.thoughtcrime.securesms.notifications;
import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.RemoteInput;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo;
@ -40,7 +39,7 @@ import java.util.List;
/**
* Get the response text from the Wearable Device and sends an message as a reply
*/
public class RemoteReplyReceiver extends MasterSecretBroadcastReceiver {
public class RemoteReplyReceiver extends BroadcastReceiver {
public static final String TAG = RemoteReplyReceiver.class.getSimpleName();
public static final String REPLY_ACTION = "org.thoughtcrime.securesms.notifications.WEAR_REPLY";
@ -48,9 +47,7 @@ public class RemoteReplyReceiver extends MasterSecretBroadcastReceiver {
@SuppressLint("StaticFieldLeak")
@Override
protected void onReceive(final Context context, Intent intent,
final @Nullable MasterSecret masterSecret)
{
public void onReceive(final Context context, Intent intent) {
if (!REPLY_ACTION.equals(intent.getAction())) return;
Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
@ -60,7 +57,7 @@ public class RemoteReplyReceiver extends MasterSecretBroadcastReceiver {
final Address address = intent.getParcelableExtra(ADDRESS_EXTRA);
final CharSequence responseText = remoteInput.getCharSequence(MessageNotifier.EXTRA_REMOTE_REPLY);
if (masterSecret != null && responseText != null) {
if (responseText != null) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {

View File

@ -25,7 +25,6 @@ import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.RegistrationActivity;
import org.thoughtcrime.securesms.contacts.ContactAccessor;
import org.thoughtcrime.securesms.contacts.ContactIdentityManager;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.push.AccountManagerFactory;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask;
@ -43,12 +42,9 @@ public class AdvancedPreferenceFragment extends CorrectedPreferenceFragment {
private static final int PICK_IDENTITY_CONTACT = 1;
private MasterSecret masterSecret;
@Override
public void onCreate(Bundle paramBundle) {
super.onCreate(paramBundle);
masterSecret = getArguments().getParcelable("master_secret");
initializeIdentitySelection();
@ -229,7 +225,6 @@ public class AdvancedPreferenceFragment extends CorrectedPreferenceFragment {
Intent intent = new Intent(getActivity(), RegistrationActivity.class);
intent.putExtra("cancel_button", true);
intent.putExtra("next_intent", nextIntent);
intent.putExtra("master_secret", masterSecret);
startActivity(intent);
}

View File

@ -1,16 +1,13 @@
package org.thoughtcrime.securesms.preferences;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.TypedArray;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.preference.CheckBoxPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.widget.Toast;
import com.doomonafireball.betterpickers.hmspicker.HmsPickerBuilder;
@ -21,7 +18,6 @@ import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
import org.thoughtcrime.securesms.BlockedContactsActivity;
import org.thoughtcrime.securesms.PassphraseChangeActivity;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
import org.thoughtcrime.securesms.jobs.MultiDeviceReadReceiptUpdateJob;
import org.thoughtcrime.securesms.service.KeyCachingService;
@ -33,14 +29,12 @@ public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment
private static final String PREFERENCE_CATEGORY_BLOCKED = "preference_category_blocked";
private MasterSecret masterSecret;
private CheckBoxPreference disablePassphrase;
@Override
public void onCreate(Bundle paramBundle) {
super.onCreate(paramBundle);
masterSecret = getArguments().getParcelable("master_secret");
disablePassphrase = (CheckBoxPreference) this.findPreference("pref_enable_passphrase_temporary");
this.findPreference(TextSecurePreferences.CHANGE_PASSPHRASE_PREF)
@ -65,22 +59,11 @@ public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment
super.onResume();
((ApplicationPreferencesActivity) getActivity()).getSupportActionBar().setTitle(R.string.preferences__privacy);
initializePlatformSpecificOptions();
initializeTimeoutSummary();
disablePassphrase.setChecked(!TextSecurePreferences.isPasswordDisabled(getActivity()));
}
private void initializePlatformSpecificOptions() {
PreferenceScreen preferenceScreen = getPreferenceScreen();
Preference screenSecurityPreference = findPreference(TextSecurePreferences.SCREEN_SECURITY_PREF);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH &&
screenSecurityPreference != null) {
preferenceScreen.removePreference(screenSecurityPreference);
}
}
private void initializeTimeoutSummary() {
int timeoutMinutes = TextSecurePreferences.getPassphraseTimeoutInterval(getActivity());
this.findPreference(TextSecurePreferences.PASSPHRASE_TIMEOUT_INTERVAL_PREF)
@ -148,11 +131,9 @@ public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment
builder.setTitle(R.string.ApplicationPreferencesActivity_disable_passphrase);
builder.setMessage(R.string.ApplicationPreferencesActivity_this_will_permanently_unlock_signal_and_message_notifications);
builder.setIconAttribute(R.attr.dialog_alert_icon);
builder.setPositiveButton(R.string.ApplicationPreferencesActivity_disable, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
builder.setPositiveButton(R.string.ApplicationPreferencesActivity_disable, (dialog, which) -> {
MasterSecretUtil.changeMasterSecretPassphrase(getActivity(),
masterSecret,
KeyCachingService.getMasterSecret(getContext()),
MasterSecretUtil.UNENCRYPTED_PASSPHRASE);
TextSecurePreferences.setPasswordDisabled(getActivity(), true);
@ -161,7 +142,6 @@ public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment
Intent intent = new Intent(getActivity(), KeyCachingService.class);
intent.setAction(KeyCachingService.DISABLE_ACTION);
getActivity().startService(intent);
}
});
builder.setNegativeButton(android.R.string.cancel, null);
builder.show();

View File

@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2011 Whisper Systems
*
* This program is free software: you can redistribute it and/or modify
@ -17,14 +17,12 @@
package org.thoughtcrime.securesms.preferences;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.MenuItem;
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.DynamicTheme;
@ -40,7 +38,8 @@ public class MmsPreferencesActivity extends PassphraseRequiredActionBarActivity
}
@Override
protected void onCreate(Bundle icicle, @NonNull MasterSecret masterSecret) {
protected void onCreate(Bundle icicle, boolean ready) {
assert getSupportActionBar() != null;
this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Fragment fragment = new MmsPreferencesFragment();

View File

@ -16,7 +16,6 @@ import android.text.TextUtils;
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.notifications.MessageNotifier;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
@ -27,12 +26,9 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
@SuppressWarnings("unused")
private static final String TAG = NotificationsPreferenceFragment.class.getSimpleName();
private MasterSecret masterSecret;
@Override
public void onCreate(Bundle paramBundle) {
super.onCreate(paramBundle);
masterSecret = getArguments().getParcelable("master_secret");
this.findPreference(TextSecurePreferences.LED_COLOR_PREF)
.setOnPreferenceChangeListener(new ListSummaryListener());

View File

@ -31,7 +31,6 @@ import android.util.Log;
import org.thoughtcrime.securesms.attachments.AttachmentId;
import org.thoughtcrime.securesms.attachments.DatabaseAttachment;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.mms.PartUriParser;
import org.thoughtcrime.securesms.service.KeyCachingService;
@ -71,10 +70,9 @@ public class PartProvider extends ContentProvider {
@Override
public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode) throws FileNotFoundException {
final MasterSecret masterSecret = KeyCachingService.getMasterSecret(getContext());
Log.w(TAG, "openFile() called!");
if (masterSecret == null) {
if (KeyCachingService.isLocked(getContext())) {
Log.w(TAG, "masterSecret was null, abandoning.");
return null;
}

View File

@ -53,7 +53,7 @@ public class ScribbleActivity extends PassphraseRequiredActionBarActivity implem
private GlideRequests glideRequests;
@Override
protected void onCreate(Bundle savedInstanceState, @NonNull MasterSecret masterSecret) {
protected void onCreate(Bundle savedInstanceState, boolean ready) {
setContentView(R.layout.scribble_activity);
this.glideRequests = GlideApp.with(this);

View File

@ -1,21 +0,0 @@
package org.thoughtcrime.securesms.service;
import android.app.IntentService;
import android.content.Intent;
import android.support.annotation.Nullable;
import org.thoughtcrime.securesms.crypto.MasterSecret;
public abstract class MasterSecretIntentService extends IntentService {
public MasterSecretIntentService(String name) {
super(name);
}
@Override
protected final void onHandleIntent(Intent intent) {
onHandleIntent(intent, KeyCachingService.getMasterSecret(this));
}
protected abstract void onHandleIntent(Intent intent, @Nullable MasterSecret masterSecret);
}

View File

@ -1,27 +1,23 @@
package org.thoughtcrime.securesms.service;
import android.app.IntentService;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.RecipientDatabase.RecipientSettings;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.sms.MessageSender;
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
import org.thoughtcrime.securesms.util.Rfc5724Uri;
import org.whispersystems.libsignal.util.guava.Optional;
import java.net.URISyntaxException;
import java.net.URLDecoder;
public class QuickResponseService extends MasterSecretIntentService {
public class QuickResponseService extends IntentService {
private static final String TAG = QuickResponseService.class.getSimpleName();
@ -30,13 +26,13 @@ public class QuickResponseService extends MasterSecretIntentService {
}
@Override
protected void onHandleIntent(Intent intent, @Nullable MasterSecret masterSecret) {
protected void onHandleIntent(Intent intent) {
if (!TelephonyManager.ACTION_RESPOND_VIA_MESSAGE.equals(intent.getAction())) {
Log.w(TAG, "Received unknown intent: " + intent.getAction());
return;
}
if (masterSecret == null) {
if (KeyCachingService.isLocked(this)) {
Log.w(TAG, "Got quick response request when locked...");
Toast.makeText(this, R.string.QuickResponseService_quick_response_unavailable_when_Signal_is_locked, Toast.LENGTH_LONG).show();
return;

View File

@ -1,242 +0,0 @@
package org.thoughtcrime.securesms.util;
import android.content.Context;
import android.net.Uri;
import android.view.View;
import org.thoughtcrime.securesms.TextSecureTestCase;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.NoExternalStorageException;
import org.whispersystems.libsignal.util.Pair;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
public class SaveAttachmentTaskTest extends TextSecureTestCase
{
private static final long TEST_TIMESTAMP = 585001320000L;
private TestSaveAttachmentTask saveAttachmentTask;
@Override
public void setUp() {
super.setUp();
saveAttachmentTask = createTestSaveAttachmentTask();
}
private TestSaveAttachmentTask createTestSaveAttachmentTask() {
return new TestSaveAttachmentTask(getInstrumentation().getTargetContext(), null, null);
}
public void testDoInBackground_emptyImageAttachmentWithFileNameIsCorrectlySaved()
throws IOException, NoExternalStorageException
{
final String name = "testImageThatShouldNotAlreadyExist";
final String extension = "png";
final String outputFileName = name + "." + extension;
final String contentType = "image/png";
final File outputDir = StorageUtil.getImageDir();
final File expectedOutputFile = generateOutputFileForKnownFilename(name, extension, outputDir);
verifyAttachmentSavedCorrectly(outputFileName, contentType, outputDir, expectedOutputFile);
assertTrue(expectedOutputFile.delete());
}
public void testDoInBackground_emptyImageAttachmentWithFileNameIsCorrectlySavedWithIndex()
throws IOException, NoExternalStorageException
{
final String name = "testImageThatShouldNotAlreadyExist";
final String extension = "png";
final String outputFileName = name + "." + extension;
final String contentType = "image/png";
final File outputDir = StorageUtil.getImageDir();
final ArrayList<File> testFiles = populateWithTestFiles(name, extension, outputDir);
final File expectedOutputFile = generateOutputFileForKnownFilename(name, extension, outputDir);
testFiles.add(expectedOutputFile);
verifyAttachmentSavedCorrectly(outputFileName, contentType, outputDir, expectedOutputFile);
for (File tmpFile : testFiles) {
assertTrue(tmpFile.delete());
}
}
public void testDoInBackground_emptyImageAttachmentWithoutFileNameIsCorrectlySaved()
throws IOException, NoExternalStorageException
{
final String extension = "png";
final String contentType = "image/png";
final File outputDir = StorageUtil.getImageDir();
final File expectedOutputFile = generateOutputFileForUnknownFilename(extension, TEST_TIMESTAMP, outputDir);
verifyAttachmentSavedCorrectly(null, contentType, outputDir, expectedOutputFile);
assertTrue(expectedOutputFile.delete());
}
public void testDoInBackground_emptyImageAttachmentWithoutFileNameNorExtensionIsCorrectlySaved()
throws IOException, NoExternalStorageException
{
final String extension = "attach";
final String contentType = "image/";
final File outputDir = StorageUtil.getImageDir();
final File expectedOutputFile = generateOutputFileForUnknownFilename(extension, TEST_TIMESTAMP, outputDir);
verifyAttachmentSavedCorrectly(null, contentType, outputDir, expectedOutputFile);
assertTrue(expectedOutputFile.delete());
}
public void testDoInBackground_emptyAudioAttachmentWithFileNameIsCorrectlySaved()
throws IOException, NoExternalStorageException
{
final String name = "testAudioThatShouldNotAlreadyExist";
final String extension = "mp3";
final String outputFileName = name + "." + extension;
final String contentType = "audio/";
final File outputDir = StorageUtil.getAudioDir();
final File expectedOutputFile = generateOutputFileForKnownFilename(name, extension, outputDir);
verifyAttachmentSavedCorrectly(outputFileName, contentType, outputDir, expectedOutputFile);
assertTrue(expectedOutputFile.delete());
}
public void testDoInBackground_emptyVideoAttachmentWithFileNameIsCorrectlySaved()
throws IOException, NoExternalStorageException
{
final String name = "testVideoThatShouldNotAlreadyExist";
final String extension = "mp4";
final String outputFileName = name + "." + extension;
final String contentType = "video/";
final File outputDir = StorageUtil.getVideoDir();
final File expectedOutputFile = generateOutputFileForKnownFilename(name, extension, outputDir);
verifyAttachmentSavedCorrectly(outputFileName, contentType, outputDir, expectedOutputFile);
assertTrue(expectedOutputFile.delete());
}
public void testDoInBackground_emptyUnknownAttachmentWithFileNameIsCorrectlySaved()
throws IOException, NoExternalStorageException
{
final String name = "testFileThatShouldNotAlreadyExist";
final String extension = "rand";
final String outputFileName = name + "." + extension;
final String contentType = "somethingweird/";
final File outputDir = StorageUtil.getDownloadDir();
final File expectedOutputFile = generateOutputFileForKnownFilename(name, extension, outputDir);
verifyAttachmentSavedCorrectly(outputFileName, contentType, outputDir, expectedOutputFile);
assertTrue(expectedOutputFile.delete());
}
private ArrayList<File> populateWithTestFiles(String name, String extension, final File outputDir)
throws IOException
{
ArrayList<File> testFiles = new ArrayList<>();
for (int i = 0; i < 4; i++) {
File tmpFile = generateOutputFileForKnownFilename(name, extension, outputDir);
if (tmpFile.createNewFile()) {
testFiles.add(tmpFile);
}
}
return testFiles;
}
private File generateOutputFileForKnownFilename(String name,
String extension,
final File outputDir)
{
final String outputFileName = guessOutputFileNameIndex(name, extension, outputDir);
final File outputFile = new File(outputDir, outputFileName);
assertFalse(outputFile.exists());
return outputFile;
}
private String guessOutputFileNameIndex(String name, String extension, final File outputDir) {
final File outputFile = new File(outputDir, name + "." + extension);
if (outputFile.exists()) {
String newName;
if (name.charAt(name.length() - 2) == '-') {
int newIndex = Integer.parseInt("" + name.charAt(name.length() - 1)) + 1;
newName = name.substring(0, name.length() - 1) + newIndex;
} else {
newName = name + "-1";
}
return guessOutputFileNameIndex(newName, extension, outputDir);
} else {
return name + "." + extension;
}
}
private void verifyAttachmentSavedCorrectly(String outputFileName,
String contentType,
final File outputDir,
final File expectedOutputFile)
throws IOException
{
final File testFile = createEmptyTempFile("testFile", "ext");
final SaveAttachmentTask.Attachment attachment
= new SaveAttachmentTask.Attachment(Uri.fromFile(testFile),
contentType,
TEST_TIMESTAMP,
outputFileName);
Pair<Integer, File> result = saveAttachmentTask.doInBackground(attachment);
assertTrue(result.first() == SaveAttachmentTask.SUCCESS);
assertEquals(result.second().getAbsolutePath(), outputDir.getAbsolutePath());
assertTrue(expectedOutputFile.exists());
}
private File createEmptyTempFile(String fileName, String extension) throws IOException
{
String fullName = fileName + "." + extension;
File file = new File(getInstrumentation().getTargetContext().getCacheDir(), fullName);
if (file.exists()) {
file = createEmptyTempFile(fileName + "-" + System.currentTimeMillis(), extension);
} else {
file.createNewFile();
}
return file;
}
private File generateOutputFileForUnknownFilename(String extension,
long date,
final File outputDir)
{
if (extension == null) extension = "attach";
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd-HHmmss");
String base = "signal-" + dateFormatter.format(date);
final String outputFileName = guessOutputFileNameIndex(base, extension, outputDir);
final File outputFile = new File(outputDir, outputFileName);
assertFalse(outputFile.exists());
return outputFile;
}
private class TestSaveAttachmentTask extends SaveAttachmentTask {
private TestSaveAttachmentTask(Context context, MasterSecret masterSecret, View view)
{
super(context, masterSecret, view);
}
@Override
protected void onPreExecute() {}
}
}

View File

@ -15,9 +15,6 @@ import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import javax.crypto.spec.SecretKeySpec;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
@ -32,15 +29,12 @@ import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PrepareForTest({ Log.class, Handler.class, Looper.class, TextUtils.class, PreferenceManager.class })
public abstract class BaseUnitTest {
protected MasterSecret masterSecret;
protected Context context = mock(Context.class);
protected SharedPreferences sharedPreferences = mock(SharedPreferences.class);
@Before
public void setUp() throws Exception {
masterSecret = new MasterSecret(new SecretKeySpec(new byte[16], "AES"),
new SecretKeySpec(new byte[16], "HmacSHA1"));
mockStatic(Looper.class);
mockStatic(Log.class);
mockStatic(Handler.class);