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;
|
|
|
|
|
|
|
|
import android.content.ComponentName;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.ServiceConnection;
|
|
|
|
import android.os.IBinder;
|
|
|
|
|
2014-11-03 23:16:04 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
2012-07-31 21:18:14 +00:00
|
|
|
import org.thoughtcrime.securesms.service.KeyCachingService;
|
|
|
|
|
2013-02-17 19:42:30 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
/**
|
|
|
|
* Base Activity for changing/prompting local encryption passphrase.
|
2012-07-31 21:18:14 +00:00
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* @author Moxie Marlinspike
|
|
|
|
*/
|
2015-02-08 21:53:12 +00:00
|
|
|
public abstract class PassphraseActivity extends BaseActionBarActivity {
|
2011-12-20 18:20:44 +00:00
|
|
|
|
|
|
|
private KeyCachingService keyCachingService;
|
|
|
|
private MasterSecret masterSecret;
|
2012-07-31 21:18:14 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
protected void setMasterSecret(MasterSecret masterSecret) {
|
|
|
|
this.masterSecret = masterSecret;
|
|
|
|
Intent bindIntent = new Intent(this, KeyCachingService.class);
|
2014-12-15 20:25:55 +00:00
|
|
|
startService(bindIntent);
|
2011-12-20 18:20:44 +00:00
|
|
|
bindService(bindIntent, serviceConnection, Context.BIND_AUTO_CREATE);
|
|
|
|
}
|
2012-07-31 21:18:14 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
protected abstract void cleanup();
|
2012-07-31 21:18:14 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private ServiceConnection serviceConnection = new ServiceConnection() {
|
2013-02-17 19:42:30 +00:00
|
|
|
@Override
|
2011-12-20 18:20:44 +00:00
|
|
|
public void onServiceConnected(ComponentName className, IBinder service) {
|
2014-11-03 23:16:04 +00:00
|
|
|
keyCachingService = ((KeyCachingService.KeySetBinder)service).getService();
|
2011-12-20 18:20:44 +00:00
|
|
|
keyCachingService.setMasterSecret(masterSecret);
|
2012-07-31 21:18:14 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
PassphraseActivity.this.unbindService(PassphraseActivity.this.serviceConnection);
|
|
|
|
|
2014-12-15 20:25:55 +00:00
|
|
|
masterSecret = null;
|
2011-12-20 18:20:44 +00:00
|
|
|
cleanup();
|
2013-02-17 19:42:30 +00:00
|
|
|
|
2014-12-15 20:25:55 +00:00
|
|
|
Intent nextIntent = getIntent().getParcelableExtra("next_intent");
|
|
|
|
if (nextIntent != null) startActivity(nextIntent);
|
|
|
|
finish();
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 19:42:30 +00:00
|
|
|
@Override
|
2011-12-20 18:20:44 +00:00
|
|
|
public void onServiceDisconnected(ComponentName name) {
|
|
|
|
keyCachingService = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|