]> hydra-www.ietfng.org Git - android-vcpass-oisafe/commitdiff
OI Safe: added keypad to AskPassword. Access via menu or preferences.
authorrmceoin <rmceoin@72b678ce-9140-0410-bee8-679b907dd61a>
Sat, 14 Feb 2009 05:12:48 +0000 (05:12 +0000)
committerrmceoin <rmceoin@72b678ce-9140-0410-bee8-679b907dd61a>
Sat, 14 Feb 2009 05:12:48 +0000 (05:12 +0000)
git-svn-id: http://openintents.googlecode.com/svn/trunk/Safe@1940 72b678ce-9140-0410-bee8-679b907dd61a

res/layout/keypad.xml [new file with mode: 0644]
res/raw/click6a.ogg [new file with mode: 0644]
res/raw/dooropening1.ogg [new file with mode: 0644]
res/raw/dtmf2a.ogg [new file with mode: 0644]
res/values/strings.xml
res/xml/preferences.xml
src/org/openintents/safe/AskPassword.java
src/org/openintents/safe/Preferences.java

diff --git a/res/layout/keypad.xml b/res/layout/keypad.xml
new file mode 100644 (file)
index 0000000..50160dc
--- /dev/null
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="utf-8"?>
+ <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:layout_height="wrap_content"
+    android:scrollbars="vertical">
+   
+<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    android:stretchColumns="0,1,2">
+
+    <TableRow>
+               <ImageView android:id="@+id/entry_icon"
+                       android:layout_height="wrap_content"
+                       android:layout_width="wrap_content"
+                       android:src="@drawable/icon_safe"
+                       />
+               <TextView android:id="@+id/entry_header"
+               android:layout_width="fill_parent" 
+               android:layout_height="wrap_content" 
+               android:text="@string/app_name"
+               android:paddingTop="10px"
+                       android:textSize="24px"
+                       android:layout_span="2"
+               />
+    </TableRow>
+    <TableRow>
+        <Button android:id="@+id/keypad1"
+               android:text="1" />
+        <Button android:id="@+id/keypad2"
+               android:text="2" />
+        <Button android:id="@+id/keypad3"
+               android:text="3" />
+    </TableRow>
+    <TableRow>
+        <Button android:id="@+id/keypad4"
+               android:text="4" />
+        <Button android:id="@+id/keypad5"
+               android:text="5" />
+        <Button android:id="@+id/keypad6"
+               android:text="6" />
+    </TableRow>
+    <TableRow>
+        <Button android:id="@+id/keypad7"
+               android:text="7" />
+        <Button android:id="@+id/keypad8"
+               android:text="8" />
+        <Button android:id="@+id/keypad9"
+               android:text="9" />
+    </TableRow>
+    <TableRow>
+        <Button android:id="@+id/keypad_star"
+               android:text="*" />
+        <Button android:id="@+id/keypad0"
+               android:text="0" />
+        <Button android:id="@+id/keypad_pound"
+               android:text="#" />
+    </TableRow>
+    <TableRow>
+        <Button android:id="@+id/keypad_continue"
+               android:layout_span="3"
+               android:text="@string/continue_text" />
+    </TableRow>
+</TableLayout>
+</ScrollView>
diff --git a/res/raw/click6a.ogg b/res/raw/click6a.ogg
new file mode 100644 (file)
index 0000000..f5089f6
Binary files /dev/null and b/res/raw/click6a.ogg differ
diff --git a/res/raw/dooropening1.ogg b/res/raw/dooropening1.ogg
new file mode 100644 (file)
index 0000000..442c426
Binary files /dev/null and b/res/raw/dooropening1.ogg differ
diff --git a/res/raw/dtmf2a.ogg b/res/raw/dtmf2a.ogg
new file mode 100644 (file)
index 0000000..e5a4d59
Binary files /dev/null and b/res/raw/dtmf2a.ogg differ
index c33fb3fbcd5d406eff801a6f11b152c7389becea..d86aae3d0d529374e54b9ee8fd73667a82ea97af 100644 (file)
        <string name="pref_title_lock_timeout">Auto lock timeout</string>\r
        <string name="pref_summary_lock_timeout">Minutes before timeout occurs and safe is locked</string>\r
        <string name="pref_dialog_title_lock_timeout">Auto lock timeout</string>\r
+       <string name="pref_title_keypad">Keypad</string>\r
+       <string name="pref_summary_keypad">Use a keypad to enter Master Password</string>\r
+       <string name="pref_title_keypad_mute">Keypad Mute</string>\r
+       <string name="pref_summary_keypad_mute">Mute keypad sounds</string>\r
        <string name="intent_decrypt">Decrypt (OI Safe)</string>\r
        <string name="intent_encrypt">Encrypt (OI Safe)</string>\r
        <string name="intent_get_password">Get password (OI Safe)</string>\r
        <string name="not_found">not found</string>\r
        <string name="dialog_title_first_time_warning">New master key</string>\r
        <string name="dialog_summary_first_time_warning">A new random master key has been created. Use menu > backup and store this key in a safe place. Without this key you may lose encrypted data.</string>\r
+       <string name="switch_mode">Switch mode</string>\r
 </resources>
index 453eacd006760e732c375a9d621cc365a8fb4de2..3b062fcc770e885e98a41e79e779f18dd4677991 100644 (file)
                 android:dialogTitle="@string/pref_dialog_title_lock_timeout"\r
                android:defaultValue="5" />    
 
+               <CheckBoxPreference
+                       android:title="@string/pref_title_keypad"
+                       android:summary="@string/pref_summary_keypad"
+                       android:key="keypad"
+                       android:defaultValue="false"/>
+               <CheckBoxPreference
+                       android:title="@string/pref_title_keypad_mute"
+                       android:summary="@string/pref_summary_keypad_mute"
+                       android:key="keypad_mute"
+                       android:defaultValue="false"
+                       android:dependency="keypad"/>
+
     </PreferenceCategory>
 </PreferenceScreen>
\ No newline at end of file
index f5a4ca95074abd939df5c213ff17ad6ae578289f..6a436ea1c4c543b52d25cffc25d07c4d43d206d9 100644 (file)
@@ -20,7 +20,6 @@ import java.io.File;
 import java.security.NoSuchAlgorithmException;
 
 import org.openintents.distribution.EulaActivity;
-import org.openintents.safe.dialog.DialogHostingActivity;
 import org.openintents.util.VersionUtils;
 
 import android.app.Activity;
@@ -28,8 +27,13 @@ import android.app.AlertDialog;
 import android.app.Dialog;
 import android.content.DialogInterface;
 import android.content.Intent;
+import android.content.SharedPreferences;
+import android.media.MediaPlayer;
 import android.os.Bundle;
+import android.preference.PreferenceManager;
 import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
 import android.view.View;
 import android.view.animation.Animation;
 import android.view.animation.AnimationUtils;
@@ -55,6 +59,14 @@ public class AskPassword extends Activity {
 
     public static final int REQUEST_RESTORE = 0;
 
+    // Menu Item order
+    public static final int SWITCH_MODE_INDEX = Menu.FIRST;
+    
+    public static final int VIEW_NORMAL = 0;
+    public static final int VIEW_KEYPAD = 1;
+    
+    private int viewMode = VIEW_NORMAL;
+
        private EditText pbeKey;
        private DBHelper dbHelper;
        private TextView introText;
@@ -67,6 +79,14 @@ public class AskPassword extends Activity {
        private CryptoHelper ch;
        private boolean firstTime = false;
 
+       // Keypad variables
+       private String keypadPassword="";
+       
+       private MediaPlayer mpDigitBeep = null;
+       private MediaPlayer mpErrorBeep = null;
+       private MediaPlayer mpSuccessBeep = null;
+       private boolean mute=false;
+       
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle icicle) {
@@ -75,13 +95,8 @@ public class AskPassword extends Activity {
                if (!EulaActivity.checkEula(this, getIntent())) {
             return;
         }
-        
-               Intent thisIntent = getIntent();
-               
-               boolean isLocal = thisIntent.getBooleanExtra (EXTRA_IS_LOCAL, false);
                        
-               if (debug)
-                       Log.d(TAG, "onCreate()");
+               if (debug) Log.d(TAG, "onCreate()");
 
                dbHelper = new DBHelper(this);
                        
@@ -92,7 +107,28 @@ public class AskPassword extends Activity {
                                databaseVersionError();
                        }
                }
+               salt = dbHelper.fetchSalt();
+               masterKey = dbHelper.fetchMasterKey();
 
+               SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
+        boolean prefKeypad = sp.getBoolean(Preferences.PREFERENCE_KEYPAD, false);
+        boolean prefKeypadMute = sp.getBoolean(Preferences.PREFERENCE_KEYPAD_MUTE, false);
+        mute=prefKeypadMute;
+        
+        if (prefKeypad) {
+               viewMode=VIEW_KEYPAD;
+        }
+               if (masterKey.length() == 0) {
+                       firstTime=true;
+               }               
+               if ((viewMode==VIEW_NORMAL) || (firstTime)) {
+                       normalInit();
+               } else {
+                       keypadInit();
+               }
+       }
+       
+       private void normalInit() {
                // Setup layout
                setContentView(R.layout.front_door);
                ImageView icon = (ImageView) findViewById(R.id.entry_icon);
@@ -103,13 +139,14 @@ public class AskPassword extends Activity {
                String head = appName + " " + version + "\n";
                header.setText(head);
 
+               Intent thisIntent = getIntent();
+               boolean isLocal = thisIntent.getBooleanExtra (EXTRA_IS_LOCAL, false);
+
                pbeKey = (EditText) findViewById(R.id.password);
                introText = (TextView) findViewById(R.id.first_time);
                remoteAsk = (TextView) findViewById(R.id.remote);
                confirmPass = (EditText) findViewById(R.id.pass_confirm);
                confirmText = (TextView) findViewById(R.id.confirm_lbl);
-               salt = dbHelper.fetchSalt();
-               masterKey = dbHelper.fetchMasterKey();
                if (masterKey.length() == 0) {
                        firstTime = true;
                        introText.setVisibility(View.VISIBLE);
@@ -191,23 +228,25 @@ public class AskPassword extends Activity {
                                findViewById(R.id.password).startAnimation(shake);
                                        return;
                                }
-
-                               Intent callbackIntent = new Intent();
-                               
-                               // Return the master key to our caller.  We no longer need the
-                               // user-entered PBEKey. The master key is used for everything
-                               // from here on out.
-                               if (debug) Log.d(TAG,"calbackintent: masterKey="+masterKey+" salt="+salt);
-                               callbackIntent.putExtra("masterKey", masterKey);
-                               callbackIntent.putExtra("salt", salt);
-                               setResult(RESULT_OK, callbackIntent);
-                               
-                               finish();
-                               
+                               gotPassword();
                        }
                });
        }
        
+       private void gotPassword() {
+               Intent callbackIntent = new Intent();
+               
+               // Return the master key to our caller.  We no longer need the
+               // user-entered PBEKey. The master key is used for everything
+               // from here on out.
+               if (debug) Log.d(TAG,"calbackintent: masterKey="+masterKey+" salt="+salt);
+               callbackIntent.putExtra("masterKey", masterKey);
+               callbackIntent.putExtra("salt", salt);
+               setResult(RESULT_OK, callbackIntent);
+               
+               finish();
+       }
+       
        private void checkForBackup() {
                String filename=CategoryList.BACKUP_FILENAME;
                File restoreFile=new File(filename);
@@ -234,25 +273,79 @@ public class AskPassword extends Activity {
        protected void onPause() {
                super.onPause();
 
-               if (debug)
-                       Log.d(TAG, "onPause()");
+               if (debug) Log.d(TAG, "onPause()");
 
                dbHelper.close();
                dbHelper = null;
        }
 
+       @Override
+       public void onDestroy() {
+               super.onDestroy();
+               
+               if (debug) Log.d(TAG,"onDestroy()");
+               keypadOnDestroy();
+       }
+
        @Override
        protected void onResume() {
                super.onPause();
 
-               if (debug)
-                       Log.d(TAG, "onResume()");
+               if (debug) Log.d(TAG, "onResume()");
                if (dbHelper == null) {
                        dbHelper = new DBHelper(this);
                }
 
        }
 
+       @Override
+       public boolean onMenuOpened(int featureId, Menu menu) {
+               if (menu != null) {
+                       MenuItem miSwitch = menu.findItem(SWITCH_MODE_INDEX);
+                       if (firstTime) {
+                               miSwitch.setEnabled(false);
+                       } else {
+                               miSwitch.setEnabled(true);
+                       }
+               }
+               return super.onMenuOpened(featureId, menu);
+       }
+
+       @Override
+       public boolean onCreateOptionsMenu(Menu menu) {
+               super.onCreateOptionsMenu(menu);
+       
+               menu.add(0, SWITCH_MODE_INDEX, 0, R.string.switch_mode)
+                       .setIcon(android.R.drawable.ic_menu_directions);
+               
+               return super.onCreateOptionsMenu(menu);
+    }
+       
+    public boolean onOptionsItemSelected(MenuItem item) {
+               switch(item.getItemId()) {
+               case SWITCH_MODE_INDEX:
+                       SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
+                       SharedPreferences.Editor spe=sp.edit();
+                       if (viewMode==VIEW_NORMAL) {
+                               viewMode=VIEW_KEYPAD;
+                               spe.putBoolean(Preferences.PREFERENCE_KEYPAD, true);
+                               keypadInit();
+                       } else {
+                               viewMode=VIEW_NORMAL;
+                               spe.putBoolean(Preferences.PREFERENCE_KEYPAD, false);
+                               normalInit();
+                       }
+                       if (spe.commit()) {
+                               if (debug) Log.d(TAG,"commitment issues");
+                       }
+                       break;
+               default:
+                       Log.e(TAG,"Unknown itemId");
+                       break;
+               }
+               return super.onOptionsItemSelected(item);
+    }
+
        private void databaseVersionError() {
                Dialog about = new AlertDialog.Builder(this)
                .setIcon(R.drawable.passicon)
@@ -306,4 +399,145 @@ public class AskPassword extends Activity {
        }
     }
 
+       /////////////// Keypad Functions /////////////////////
+
+       private void keypadInit() {
+               if (mpDigitBeep==null) {
+                       mpDigitBeep = MediaPlayer.create(this, R.raw.dtmf2a);
+                       mpErrorBeep = MediaPlayer.create(this, R.raw.click6a);
+                       mpSuccessBeep = MediaPlayer.create(this, R.raw.dooropening1);
+               }
+
+               keypadPassword="";
+       
+               setContentView(R.layout.keypad);
+
+               TextView header = (TextView) findViewById(R.id.entry_header);
+               String version = VersionUtils.getVersionNumber(this);
+               String appName = VersionUtils.getApplicationName(this);
+               String head = appName + " " + version;
+               header.setText(head);
+
+               Button keypad1 = (Button) findViewById(R.id.keypad1);
+               keypad1.setOnClickListener(new View.OnClickListener() {
+                       public void onClick(View arg0) {
+                               keypadPassword += "1";
+                               if (!mute) { mpDigitBeep.start(); }
+                       }
+               });
+               Button keypad2 = (Button) findViewById(R.id.keypad2);
+               keypad2.setOnClickListener(new View.OnClickListener() {
+                       public void onClick(View arg0) {
+                               keypadPassword += "2";
+                               if (!mute) { mpDigitBeep.start(); }
+                       }
+               });
+               Button keypad3 = (Button) findViewById(R.id.keypad3);
+               keypad3.setOnClickListener(new View.OnClickListener() {
+                       public void onClick(View arg0) {
+                               keypadPassword += "3";
+                               if (!mute) { mpDigitBeep.start(); }
+                       }
+               });
+               Button keypad4 = (Button) findViewById(R.id.keypad4);
+               keypad4.setOnClickListener(new View.OnClickListener() {
+                       public void onClick(View arg0) {
+                               keypadPassword += "4";
+                               if (!mute) { mpDigitBeep.start(); }
+                       }
+               });
+               Button keypad5 = (Button) findViewById(R.id.keypad5);
+               keypad5.setOnClickListener(new View.OnClickListener() {
+                       public void onClick(View arg0) {
+                               keypadPassword += "5";
+                               if (!mute) { mpDigitBeep.start(); }
+                       }
+               });
+               Button keypad6 = (Button) findViewById(R.id.keypad6);
+               keypad6.setOnClickListener(new View.OnClickListener() {
+                       public void onClick(View arg0) {
+                               keypadPassword += "6";
+                               if (!mute) { mpDigitBeep.start(); }
+                       }
+               });
+               Button keypad7 = (Button) findViewById(R.id.keypad7);
+               keypad7.setOnClickListener(new View.OnClickListener() {
+                       public void onClick(View arg0) {
+                               keypadPassword += "7";
+                               if (!mute) { mpDigitBeep.start(); }
+                       }
+               });
+               Button keypad8 = (Button) findViewById(R.id.keypad8);
+               keypad8.setOnClickListener(new View.OnClickListener() {
+                       public void onClick(View arg0) {
+                               keypadPassword += "8";
+                               if (!mute) { mpDigitBeep.start(); }
+                       }
+               });
+               Button keypad9 = (Button) findViewById(R.id.keypad9);
+               keypad9.setOnClickListener(new View.OnClickListener() {
+                       public void onClick(View arg0) {
+                               keypadPassword += "9";
+                               if (!mute) { mpDigitBeep.start(); }
+                       }
+               });
+               Button keypadStar = (Button) findViewById(R.id.keypad_star);
+               keypadStar.setOnClickListener(new View.OnClickListener() {
+                       public void onClick(View arg0) {
+                               keypadPassword += "*";
+                               if (!mute) { mpDigitBeep.start(); }
+                       }
+               });
+               Button keypad0 = (Button) findViewById(R.id.keypad0);
+               keypad0.setOnClickListener(new View.OnClickListener() {
+                       public void onClick(View arg0) {
+                               keypadPassword += "0";
+                               if (!mute) { mpDigitBeep.start(); }
+                       }
+               });
+               Button keypadPound = (Button) findViewById(R.id.keypad_pound);
+               keypadPound.setOnClickListener(new View.OnClickListener() {
+                       public void onClick(View arg0) {
+                               keypadPassword += "#";
+                               if (!mute) { mpDigitBeep.start(); }
+                       }
+               });
+               Button keypadContinue = (Button) findViewById(R.id.keypad_continue);
+               keypadContinue.setOnClickListener(new View.OnClickListener() {
+                       public void onClick(View arg0) {
+                               keypadTryPassword(keypadPassword);
+                       }
+               });
+       }
+    
+       private void keypadOnDestroy() {
+               if (mpDigitBeep!=null) {
+                       mpDigitBeep.release();
+                       mpErrorBeep.release();
+                       mpSuccessBeep.release();
+                       mpDigitBeep=null;
+                       mpErrorBeep=null;
+                       mpSuccessBeep=null;
+               }
+       }
+       
+       private void keypadTryPassword(String password) {
+               if (checkUserPassword(password)){
+                       if (debug) Log.d(TAG,"match!!");
+                       if (!mute) {
+                               mpSuccessBeep.start();
+                       }
+                       gotPassword();
+               }else{
+                       if (debug) Log.d(TAG,"bad password");
+                       if (!mute) {
+                               mpErrorBeep.start();
+                       }
+                   Animation shake = AnimationUtils
+                       .loadAnimation(AskPassword.this, R.anim.shake);
+               findViewById(R.id.keypad_continue).startAnimation(shake);
+
+               keypadPassword="";
+               }
+       }
 }
index b55165b3203928fff3c81aee95843bc3d0c918a8..22c87396b5504a4efc31069a1cda9a12e0a11ac9 100644 (file)
@@ -9,6 +9,8 @@ public class Preferences extends PreferenceActivity {
        public static final String PREFERENCE_LOCK_TIMEOUT = "lock_timeout";
        public static final String PREFERENCE_LOCK_TIMEOUT_DEFAULT_VALUE = "5";
        public static final String PREFERENCE_FIRST_TIME_WARNING = "first_time_warning";
+       public static final String PREFERENCE_KEYPAD = "keypad";
+       public static final String PREFERENCE_KEYPAD_MUTE = "keypad_mute";
        
     @Override
     protected void onCreate(Bundle savedInstanceState) {