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;
|
2011-12-20 18:20:44 +00:00
|
|
|
import android.os.Bundle;
|
2014-06-29 03:40:57 +00:00
|
|
|
import android.support.v7.app.ActionBar;
|
2012-08-08 02:06:23 +00:00
|
|
|
import android.text.Editable;
|
2015-07-23 15:16:45 +00:00
|
|
|
import android.text.InputType;
|
2014-05-14 03:41:16 +00:00
|
|
|
import android.text.SpannableString;
|
|
|
|
import android.text.Spanned;
|
|
|
|
import android.text.style.RelativeSizeSpan;
|
|
|
|
import android.text.style.TypefaceSpan;
|
2014-05-30 09:40:23 +00:00
|
|
|
import android.view.KeyEvent;
|
2014-06-29 03:40:57 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
2011-12-20 18:20:44 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.View.OnClickListener;
|
2014-05-30 09:40:23 +00:00
|
|
|
import android.view.inputmethod.EditorInfo;
|
2011-12-20 18:20:44 +00:00
|
|
|
import android.widget.EditText;
|
2014-05-14 03:41:16 +00:00
|
|
|
import android.widget.ImageButton;
|
2014-05-30 09:40:23 +00:00
|
|
|
import android.widget.TextView;
|
2011-12-20 18:20:44 +00:00
|
|
|
import android.widget.Toast;
|
|
|
|
|
2015-07-23 15:16:45 +00:00
|
|
|
import org.thoughtcrime.securesms.components.AnimatingToggle;
|
2012-07-31 21:18:14 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.InvalidPassphraseException;
|
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
|
2015-03-08 23:32:57 +00:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicIntroTheme;
|
2014-12-11 23:04:32 +00:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
2014-11-03 23:16:04 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
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 {
|
|
|
|
|
2015-03-08 23:32:57 +00:00
|
|
|
private DynamicIntroTheme dynamicTheme = new DynamicIntroTheme();
|
|
|
|
private DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
2014-12-11 23:04:32 +00:00
|
|
|
|
2015-07-23 15:16:45 +00:00
|
|
|
private EditText passphraseText;
|
|
|
|
private ImageButton showButton;
|
|
|
|
private ImageButton hideButton;
|
|
|
|
private AnimatingToggle visibilityToggle;
|
2012-07-31 21:18:14 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
2015-03-08 23:32:57 +00:00
|
|
|
dynamicTheme.onCreate(this);
|
2014-12-11 23:04:32 +00:00
|
|
|
dynamicLanguage.onCreate(this);
|
2011-12-20 18:20:44 +00:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
setContentView(R.layout.prompt_passphrase_activity);
|
|
|
|
initializeResources();
|
|
|
|
}
|
2012-07-31 21:18:14 +00:00
|
|
|
|
2014-12-11 23:04:32 +00:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
2015-03-08 23:32:57 +00:00
|
|
|
dynamicTheme.onResume(this);
|
2014-12-11 23:04:32 +00:00
|
|
|
dynamicLanguage.onResume(this);
|
|
|
|
}
|
|
|
|
|
2014-12-15 20:25:55 +00:00
|
|
|
@Override
|
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
|
super.onNewIntent(intent);
|
|
|
|
setIntent(intent);
|
|
|
|
}
|
|
|
|
|
2014-02-26 03:53:12 +00:00
|
|
|
@Override
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
2014-06-29 03:40:57 +00:00
|
|
|
MenuInflater inflater = this.getMenuInflater();
|
2014-02-26 03:53:12 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-05-30 09:40:23 +00:00
|
|
|
private void handlePassphrase() {
|
|
|
|
try {
|
|
|
|
Editable text = passphraseText.getText();
|
|
|
|
String passphrase = (text == null ? "" : text.toString());
|
2014-12-15 20:25:55 +00:00
|
|
|
MasterSecret masterSecret = MasterSecretUtil.getMasterSecret(this, passphrase);
|
2014-05-30 09:40:23 +00:00
|
|
|
|
|
|
|
setMasterSecret(masterSecret);
|
|
|
|
} catch (InvalidPassphraseException ipe) {
|
|
|
|
passphraseText.setText("");
|
|
|
|
Toast.makeText(this, R.string.PassphrasePromptActivity_invalid_passphrase_exclamation,
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-23 15:16:45 +00:00
|
|
|
private void setPassphraseVisibility(boolean visibility) {
|
|
|
|
int cursorPosition = passphraseText.getSelectionStart();
|
|
|
|
if (visibility) {
|
|
|
|
passphraseText.setInputType(InputType.TYPE_CLASS_TEXT |
|
|
|
|
InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
|
|
|
|
} else {
|
|
|
|
passphraseText.setInputType(InputType.TYPE_CLASS_TEXT |
|
|
|
|
InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
|
|
|
}
|
|
|
|
passphraseText.setSelection(cursorPosition);
|
|
|
|
}
|
|
|
|
|
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);
|
2015-03-08 23:32:57 +00:00
|
|
|
getSupportActionBar().setCustomView(R.layout.centered_app_title);
|
2014-05-14 03:41:16 +00:00
|
|
|
|
|
|
|
ImageButton okButton = (ImageButton) findViewById(R.id.ok_button);
|
2015-07-23 15:16:45 +00:00
|
|
|
|
|
|
|
showButton = (ImageButton) findViewById(R.id.passphrase_visibility);
|
|
|
|
hideButton = (ImageButton) findViewById(R.id.passphrase_visibility_off);
|
|
|
|
visibilityToggle = (AnimatingToggle) findViewById(R.id.button_toggle);
|
|
|
|
passphraseText = (EditText) findViewById(R.id.passphrase_edit);
|
2015-01-21 07:26:58 +00:00
|
|
|
SpannableString hint = new SpannableString(" " + getString(R.string.PassphrasePromptActivity_enter_passphrase));
|
|
|
|
hint.setSpan(new RelativeSizeSpan(0.9f), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
2014-05-14 03:41:16 +00:00
|
|
|
hint.setSpan(new TypefaceSpan("sans-serif"), 0, hint.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
2015-01-21 07:26:58 +00:00
|
|
|
|
2014-05-14 03:41:16 +00:00
|
|
|
passphraseText.setHint(hint);
|
2011-12-20 18:20:44 +00:00
|
|
|
okButton.setOnClickListener(new OkButtonClickListener());
|
2015-07-23 15:16:45 +00:00
|
|
|
showButton.setOnClickListener(new ShowButtonOnClickListener());
|
|
|
|
hideButton.setOnClickListener(new HideButtonOnClickListener());
|
2014-05-30 09:40:23 +00:00
|
|
|
passphraseText.setOnEditorActionListener(new PassphraseActionListener());
|
|
|
|
passphraseText.setImeActionLabel(getString(R.string.prompt_passphrase_activity__unlock),
|
|
|
|
EditorInfo.IME_ACTION_DONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
private class PassphraseActionListener implements TextView.OnEditorActionListener {
|
|
|
|
@Override
|
|
|
|
public boolean onEditorAction(TextView exampleView, int actionId, KeyEvent keyEvent) {
|
|
|
|
if ((keyEvent == null && actionId == EditorInfo.IME_ACTION_DONE) ||
|
|
|
|
(keyEvent != null && keyEvent.getAction() == KeyEvent.ACTION_DOWN &&
|
|
|
|
(actionId == EditorInfo.IME_NULL)))
|
|
|
|
{
|
|
|
|
handlePassphrase();
|
|
|
|
return true;
|
|
|
|
} else if (keyEvent != null && keyEvent.getAction() == KeyEvent.ACTION_UP &&
|
|
|
|
actionId == EditorInfo.IME_NULL)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-07-31 21:18:14 +00:00
|
|
|
|
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) {
|
2014-05-30 09:40:23 +00:00
|
|
|
handlePassphrase();
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-31 21:18:14 +00:00
|
|
|
|
2015-07-23 15:16:45 +00:00
|
|
|
private class ShowButtonOnClickListener implements OnClickListener {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
visibilityToggle.display(hideButton);
|
|
|
|
setPassphraseVisibility(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class HideButtonOnClickListener implements OnClickListener {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
visibilityToggle.display(showButton);
|
|
|
|
setPassphraseVisibility(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|