2012-07-31 21:18:14 +00:00
|
|
|
/**
|
2011-12-20 18:20:44 +00:00
|
|
|
* Copyright (C) 2011 Whisper Systems
|
2012-07-31 21:18:14 +00:00
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2012-07-31 21:18:14 +00:00
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
2014-02-26 03:53:12 +00:00
|
|
|
import android.content.Intent;
|
2014-05-14 03:41:16 +00:00
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.os.Build;
|
2011-12-20 18:20:44 +00:00
|
|
|
import android.os.Bundle;
|
2012-08-08 02:06:23 +00:00
|
|
|
import android.text.Editable;
|
2014-05-14 03:41:16 +00:00
|
|
|
import android.text.SpannableString;
|
|
|
|
import android.text.Spanned;
|
|
|
|
import android.text.style.ForegroundColorSpan;
|
|
|
|
import android.text.style.RelativeSizeSpan;
|
|
|
|
import android.text.style.TypefaceSpan;
|
2011-12-20 18:20:44 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
import android.widget.EditText;
|
2014-05-14 03:41:16 +00:00
|
|
|
import android.widget.ImageButton;
|
2011-12-20 18:20:44 +00:00
|
|
|
import android.widget.Toast;
|
|
|
|
|
2014-05-14 03:41:16 +00:00
|
|
|
import com.actionbarsherlock.app.ActionBar;
|
2014-02-26 03:53:12 +00:00
|
|
|
import com.actionbarsherlock.view.Menu;
|
|
|
|
import com.actionbarsherlock.view.MenuInflater;
|
|
|
|
import com.actionbarsherlock.view.MenuItem;
|
|
|
|
|
2012-07-31 21:18:14 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.InvalidPassphraseException;
|
2013-08-18 01:37:18 +00:00
|
|
|
import org.whispersystems.textsecure.crypto.MasterSecret;
|
2012-07-31 21:18:14 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
|
|
|
|
import org.thoughtcrime.securesms.util.MemoryCleaner;
|
2014-05-14 03:41:16 +00:00
|
|
|
import org.whispersystems.textsecure.util.Util;
|
2012-07-31 21:18:14 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
/**
|
2014-05-14 03:41:16 +00:00
|
|
|
* Activity that prompts for a user's passphrase.
|
2012-07-31 21:18:14 +00:00
|
|
|
*
|
|
|
|
* @author Moxie Marlinspike
|
2011-12-20 18:20:44 +00:00
|
|
|
*/
|
|
|
|
public class PassphrasePromptActivity extends PassphraseActivity {
|
|
|
|
|
|
|
|
private EditText passphraseText;
|
2012-07-31 21:18:14 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
setContentView(R.layout.prompt_passphrase_activity);
|
|
|
|
initializeResources();
|
|
|
|
}
|
2012-07-31 21:18:14 +00:00
|
|
|
|
2014-02-26 03:53:12 +00:00
|
|
|
@Override
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
|
|
|
MenuInflater inflater = this.getSupportMenuInflater();
|
|
|
|
menu.clear();
|
|
|
|
|
|
|
|
inflater.inflate(R.menu.log_submit, menu);
|
|
|
|
super.onPrepareOptionsMenu(menu);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
super.onOptionsItemSelected(item);
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.menu_submit_debug_logs: handleLogSubmit(); return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleLogSubmit() {
|
|
|
|
Intent intent = new Intent(this, LogSubmitActivity.class);
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private void initializeResources() {
|
2014-05-14 03:41:16 +00:00
|
|
|
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
|
|
|
|
getSupportActionBar().setCustomView(R.layout.light_centered_app_title);
|
|
|
|
mitigateAndroidTilingBug();
|
|
|
|
|
|
|
|
ImageButton okButton = (ImageButton) findViewById(R.id.ok_button);
|
|
|
|
passphraseText = (EditText) findViewById(R.id.passphrase_edit);
|
|
|
|
SpannableString hint = new SpannableString(getString(R.string.PassphrasePromptActivity_enter_passphrase));
|
|
|
|
hint.setSpan(new RelativeSizeSpan(0.8f), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
|
|
|
hint.setSpan(new TypefaceSpan("sans-serif"), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
|
|
|
hint.setSpan(new ForegroundColorSpan(0x66000000), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
|
|
|
passphraseText.setHint(hint);
|
2011-12-20 18:20:44 +00:00
|
|
|
okButton.setOnClickListener(new OkButtonClickListener());
|
|
|
|
}
|
2012-07-31 21:18:14 +00:00
|
|
|
|
2014-05-14 03:41:16 +00:00
|
|
|
private void mitigateAndroidTilingBug() {
|
|
|
|
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
|
|
|
Drawable actionBarBackground = getResources().getDrawable(R.drawable.background_pattern_repeat);
|
|
|
|
Util.fixBackgroundRepeat(actionBarBackground);
|
|
|
|
getSupportActionBar().setBackgroundDrawable(actionBarBackground);
|
|
|
|
Util.fixBackgroundRepeat(findViewById(R.id.scroll_parent).getBackground());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private class OkButtonClickListener implements OnClickListener {
|
2013-02-17 19:42:30 +00:00
|
|
|
@Override
|
2011-12-20 18:20:44 +00:00
|
|
|
public void onClick(View v) {
|
|
|
|
try {
|
2012-08-08 02:06:23 +00:00
|
|
|
Editable text = passphraseText.getText();
|
|
|
|
String passphrase = (text == null ? "" : text.toString());
|
2011-12-20 18:20:44 +00:00
|
|
|
MasterSecret masterSecret = MasterSecretUtil.getMasterSecret(PassphrasePromptActivity.this, passphrase);
|
2012-07-31 21:18:14 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
MemoryCleaner.clean(passphrase);
|
|
|
|
setMasterSecret(masterSecret);
|
|
|
|
} catch (InvalidPassphraseException ipe) {
|
2013-02-21 22:47:18 +00:00
|
|
|
passphraseText.setText("");
|
2012-09-08 03:03:23 +00:00
|
|
|
Toast.makeText(getApplicationContext(),
|
2012-09-20 02:56:04 +00:00
|
|
|
R.string.PassphrasePromptActivity_invalid_passphrase_exclamation,
|
2012-09-08 03:03:23 +00:00
|
|
|
Toast.LENGTH_SHORT).show();
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-31 21:18:14 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
@Override
|
|
|
|
protected void cleanup() {
|
2013-05-07 02:27:09 +00:00
|
|
|
this.passphraseText.setText("");
|
2011-12-20 18:20:44 +00:00
|
|
|
System.gc();
|
|
|
|
}
|
|
|
|
}
|