Created
March 8, 2013 15:12
-
-
Save huttneab/5117085 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onClick(View v) { | |
String password1 = mPass1View.getText().toString(); | |
if (mIsFirstTime) { | |
String password2 = mPass2View.getText().toString(); | |
if (password1.equals(password2)) { | |
checkIfGoodPassphrase(password1.trim()); | |
} else { | |
// prompt the user | |
toast(getString(R.string.pass_err_match)); | |
clearPassword(); | |
mPass1View.requestFocus(); | |
} | |
} else { | |
// initialize KeyCachingService, this will call the normalLogin method once it is bound | |
Intent bindIntent = new Intent(this, KeyCachingService.class); | |
bindService(bindIntent, serviceConnection, Context.BIND_AUTO_CREATE); | |
} | |
if (mCurrentPassAttempts >= MAX_PASS_ATTEMPTS) { | |
toast(getString(R.string.pass_err_lock)); | |
try { | |
toast("too many attempts, try again in " + PASS_RETRY_WAIT_TIMEOUT / 1000 + " seconds"); | |
Thread.sleep(PASS_RETRY_WAIT_TIMEOUT); | |
} catch (Exception e) { | |
} | |
mCurrentPassAttempts = 0; | |
} | |
} | |
... | |
private void normalLogin(String password) { | |
try { | |
// try opening the VFS before the sql db since the latter relies on | |
// the former | |
java.io.File vfsDb = new java.io.File(this.getApplicationContext().getDir("vfs", Context.MODE_PRIVATE).getAbsoluteFile(), | |
KeyguardScreenLoginFragment.SECURE_APP_PARTS_DB + ".db"); | |
VirtualFileSystem vfs = new VirtualFileSystem(vfsDb.getAbsolutePath()); | |
vfs.mount(password); | |
// try opening the sql db | |
String path = KeyguardScreen.this.getDatabasePath(SecureComMmsSmsDatabaseHelper.DATABASE_NAME).getPath(); | |
File dbFile = new File(path); | |
if (dbFile.exists()) { | |
SecureComMmsSmsDatabaseHelper.getInstance(this).getReadableDatabase(); | |
} else { | |
throw new UnsupportedOperationException("database does not exist but should"); | |
} | |
PasswordUtils.getInstance(this).setScreenLock(false); | |
if (!MmsApp.sResourcesInitialized) { | |
MmsApp.getApplication().initApplicationResources(); | |
} | |
// startActivity(myIntent); | |
startActivity(nextIntent); | |
KeyguardScreen.this.finish(); | |
} catch (Exception e) { | |
mCurrentPassAttempts++; | |
toast(getString(R.string.err_pass)); | |
clearPassword(); | |
return; | |
} | |
} | |
public ServiceConnection serviceConnection = new ServiceConnection() { | |
public void onServiceConnected(ComponentName className, IBinder service) { | |
String password = mPass1View.getText().toString(); | |
keyCachingService = ((KeyCachingService.KeyCachingBinder) service).getService(); | |
keyCachingService.setPassword(password); | |
KeyguardScreen.this.unbindService(KeyguardScreen.this.serviceConnection); | |
// manually set the password for the sql open helpers so they don't have to wait for a broadcast | |
SecureComMmsSmsDatabaseHelper.getInstance(KeyguardScreen.this).initializeWithPassword(password); | |
PrivateKeyDatabaseHelper.getInstance(KeyguardScreen.this).initializeWithPassword(password); | |
Intent intent = new Intent(KeyguardScreen.this, KeyCachingService.class); | |
intent.setAction(KeyCachingService.ACTIVITY_START_EVENT); | |
startService(intent); | |
normalLogin(password); | |
} | |
public void onServiceDisconnected(ComponentName name) { | |
keyCachingService = null; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment