Implement timeout locking.

This commit is contained in:
Brian Pellin 2009-03-10 17:44:05 -05:00
parent 24a73d1606
commit 0ce2b8546d
15 changed files with 312 additions and 55 deletions

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Android with Source"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Android Library 1.1"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -13,5 +13,7 @@
<activity android:name=".fileselect.FileSelectActivity"></activity><activity android:name=".PasswordActivity"></activity><activity android:name=".GroupActivity"></activity>
<activity android:name=".EntryActivity"></activity>
<meta-data android:name="com.a0soft.gphone.aTrackDog.webURL" android:value="http://keepassdroid.com" />
</application>
<service android:name=".services.TimeoutService"></service>
<activity android:name=".LockingActivity"></activity>
</application>
</manifest>

View file

@ -30,7 +30,7 @@ import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class EntryActivity extends Activity {
public class EntryActivity extends LockingActivity {
public static final String KEY_ENTRY = "entry";
private static final int MENU_PASS = Menu.FIRST;
@ -80,13 +80,6 @@ public class EntryActivity extends Activity {
tv.setText(text);
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);

View file

@ -25,7 +25,6 @@ import org.phoneid.keepassj2me.PwEntry;
import org.phoneid.keepassj2me.PwGroup;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
@ -34,7 +33,7 @@ import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
public class GroupActivity extends ListActivity {
public class GroupActivity extends LockingListActivity {
public static final String KEY_ENTRY = "entry";

View file

@ -19,12 +19,13 @@
*/
package com.android.keepass;
import com.android.keepass.fileselect.FileSelectActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import com.android.keepass.fileselect.FileSelectActivity;
import com.android.keepass.services.TimeoutService;
public class KeePass extends Activity {
public static final int EXIT_NORMAL = 0;
@ -34,9 +35,30 @@ public class KeePass extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i = new Intent(this, FileSelectActivity.class);
startActivityForResult(i, 0);
startService(new Intent(this, TimeoutService.class));
//Intent i = new Intent(this, FileSelectActivity.class);
//startActivityForResult(i, 0);
}
@Override
protected void onStart() {
super.onStart();
startFileSelect();
}
private void startFileSelect() {
Intent intent = new Intent(this, FileSelectActivity.class);
startActivityForResult(intent, 0);
}
@Override
protected void onDestroy() {
super.onDestroy();
stopService(new Intent(this, TimeoutService.class));
}
@Override

View file

@ -0,0 +1,66 @@
/*
* Copyright 2009 Brian Pellin.
*
* This file is part of KeePassDroid.
*
* KeePassDroid 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.
*
* KeePassDroid 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.
*
* You should have received a copy of the GNU General Public License
* along with KeePassDroid. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.android.keepass;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import com.android.keepass.intents.TimeoutIntents;
public class LockManager {
private BroadcastReceiver mIntentReceiver;
private Activity mAct;
public LockManager(Activity act) {
mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if ( action.equals(TimeoutIntents.LOCK) ) {
Database.clear();
mAct.setResult(KeePass.EXIT_LOCK);
mAct.finish();
}
}
};
IntentFilter filter = new IntentFilter();
filter.addAction(TimeoutIntents.LOCK);
mAct.registerReceiver(mIntentReceiver, filter);
}
public void cleanUp() {
mAct.unregisterReceiver(mIntentReceiver);
}
public void startTimeout() {
mAct.sendBroadcast(new Intent(TimeoutIntents.START));
}
public void stopTimeout() {
mAct.sendBroadcast(new Intent(TimeoutIntents.CANCEL));
}
}

View file

@ -0,0 +1,57 @@
/*
* Copyright 2009 Brian Pellin.
*
* This file is part of KeePassDroid.
*
* KeePassDroid 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.
*
* KeePassDroid 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.
*
* You should have received a copy of the GNU General Public License
* along with KeePassDroid. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.android.keepass;
import android.app.Activity;
import android.os.Bundle;
public class LockingActivity extends Activity {
private LockManager mLM;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mLM = new LockManager(this);
}
@Override
protected void onDestroy() {
mLM.cleanUp();
super.onDestroy();
}
@Override
protected void onPause() {
super.onPause();
mLM.startTimeout();
}
@Override
protected void onResume() {
super.onResume();
mLM.stopTimeout();
}
}

View file

@ -0,0 +1,36 @@
package com.android.keepass;
import android.app.ListActivity;
import android.os.Bundle;
public class LockingListActivity extends ListActivity {
private LockManager mLM;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mLM = new LockManager(this);
}
@Override
protected void onDestroy() {
mLM.cleanUp();
super.onDestroy();
}
@Override
protected void onPause() {
super.onPause();
mLM.startTimeout();
}
@Override
protected void onResume() {
super.onResume();
mLM.stopTimeout();
}
}

View file

@ -36,6 +36,7 @@ import android.widget.TextView;
import android.widget.Toast;
import com.android.keepass.fileselect.FileDbHelper;
import com.android.keepass.intents.TimeoutIntents;
import com.android.keepass.keepasslib.InvalidKeyFileException;
public class PasswordActivity extends Activity {
@ -105,6 +106,8 @@ public class PasswordActivity extends Activity {
// Clear password on Database state
setEditText(R.id.pass_password, "");
sendBroadcast(new Intent(TimeoutIntents.CANCEL));
}
@Override
@ -113,6 +116,13 @@ public class PasswordActivity extends Activity {
}
@Override
protected void onPause() {
super.onPause();
sendBroadcast(new Intent(TimeoutIntents.START));
}
private void errorMessage(CharSequence text)
{
Toast.makeText(this, text, Toast.LENGTH_LONG).show();

View file

@ -27,6 +27,11 @@ import android.text.ClipboardManager;
import android.widget.TextView;
public class Util {
public static String getClipboard(Context context) {
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
return clipboard.getText().toString();
}
public static void copyToClipboard(Context context, String text) {
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(text);

View file

@ -37,6 +37,7 @@ import android.widget.Toast;
import com.android.keepass.PasswordActivity;
import com.android.keepass.R;
import com.android.keepass.Util;
import com.android.keepass.intents.TimeoutIntents;
public class FileSelectActivity extends ListActivity {
@ -102,6 +103,19 @@ public class FileSelectActivity extends ListActivity {
fillData();
}
@Override
protected void onPause() {
super.onPause();
sendBroadcast(new Intent(TimeoutIntents.START));
}
@Override
protected void onResume() {
super.onResume();
sendBroadcast(new Intent(TimeoutIntents.CANCEL));
}
private class ClickHandler implements View.OnClickListener {
Activity mAct;

View file

@ -0,0 +1,7 @@
package com.android.keepass.intents;
public class TimeoutIntents {
public static final String START = "com.android.keepass.timeout.start";
public static final String CANCEL = "com.android.keepass.timeout.cancel";
public static final String LOCK = "com.android.keepass.timeout.lock";
}

View file

@ -23,15 +23,55 @@ import java.util.Timer;
import java.util.TimerTask;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Binder;
import android.os.IBinder;
public class TimeoutService extends Service {
import com.android.keepass.intents.TimeoutIntents;
private boolean timeout = false;
private Timer mTimer = new Timer();
public class TimeoutService extends Service {
private static final long DEFAULT_TIMEOUT = 15 * 1000; // 5 * 60 * 1000; // 5 minutes
private boolean timeout = false;
private Timer mTimer;
private BroadcastReceiver mIntentReceiver;
@Override
public void onCreate() {
super.onCreate();
mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if ( action.equals(TimeoutIntents.START) ) {
startTimeout(DEFAULT_TIMEOUT);
} else if ( action.equals(TimeoutIntents.CANCEL) ) {
cancel();
}
}
};
IntentFilter filter = new IntentFilter();
filter.addAction(TimeoutIntents.START);
filter.addAction(TimeoutIntents.CANCEL);
registerReceiver(mIntentReceiver, filter);
}
@Override
public void onDestroy() {
super.onDestroy();
unregisterReceiver(mIntentReceiver);
}
public class TimeoutBinder extends Binder {
public TimeoutService getService() {
return TimeoutService.this;
@ -51,16 +91,22 @@ public class TimeoutService extends Service {
@Override
public void run() {
timeout = true;
sendBroadcast(new Intent(TimeoutIntents.LOCK));
}
}
public void startTimeout(long seconds) {
mTimer.schedule(new TimeoutTask(), seconds);
public void startTimeout(long milliseconds) {
mTimer = new Timer();
mTimer.schedule(new TimeoutTask(), milliseconds);
}
public void cancel() {
mTimer.cancel();
if ( mTimer != null ) {
mTimer.cancel();
}
timeout = false;
}

View file

@ -1,19 +1,22 @@
/*
* Copyright (C) 2008 The Android Open Source Project
* Copyright 2009 Brian Pellin.
*
* This file is part of KeePassDroid.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* KeePassDroid 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.
*
* http://www.apache.org/licenses/LICENSE-2.0
* KeePassDroid 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.
*
* You should have received a copy of the GNU General Public License
* along with KeePassDroid. If not, see <http://www.gnu.org/licenses/>.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.keepass.tests;
import junit.framework.Test;
@ -21,28 +24,6 @@ import junit.framework.TestSuite;
import android.test.suitebuilder.TestSuiteBuilder;
/**
* A test suite containing all tests for ApiDemos.
*
* To run all suites found in this apk:
* $ adb shell am instrument -w \
* com.example.android.apis.tests/android.test.InstrumentationTestRunner
*
* To run just this suite from the command line:
* $ adb shell am instrument -w \
* -e class com.example.android.apis.AllTests \
* com.example.android.apis.tests/android.test.InstrumentationTestRunner
*
* To run an individual test case, e.g. {@link com.example.android.apis.os.MorseCodeConverterTest}:
* $ adb shell am instrument -w \
* -e class com.example.android.apis.os.MorseCodeConverterTest \
* com.example.android.apis.tests/android.test.InstrumentationTestRunner
*
* To run an individual test, e.g. {@link com.example.android.apis.os.MorseCodeConverterTest#testCharacterS()}:
* $ adb shell am instrument -w \
* -e class com.example.android.apis.os.MorseCodeConverterTest#testCharacterS \
* com.example.android.apis.tests/android.test.InstrumentationTestRunner
*/
public class AllTests extends TestSuite {
public static Test suite() {

View file

@ -1,3 +1,22 @@
/*
* Copyright 2009 Brian Pellin.
*
* This file is part of KeePassDroid.
*
* KeePassDroid 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.
*
* KeePassDroid 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.
*
* You should have received a copy of the GNU General Public License
* along with KeePassDroid. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.android.keepass.tests;
import junit.framework.TestCase;