mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Added boilerplate bundle encryption code to HelloWorldActivity.
It would be nice to be able to put this code in a superclass, since in the case of an activity like this it only deals with superclass state.
This commit is contained in:
@@ -8,9 +8,13 @@ import static java.util.logging.Level.INFO;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import net.sf.briar.R;
|
||||
import net.sf.briar.android.BriarService;
|
||||
import net.sf.briar.android.invitation.AddContactActivity;
|
||||
import net.sf.briar.api.android.BundleEncrypter;
|
||||
import roboguice.activity.RoboActivity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
@@ -27,8 +31,14 @@ implements OnClickListener {
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(HelloWorldActivity.class.getName());
|
||||
|
||||
@Inject private static Provider<BundleEncrypter> bundleEncrypterProvider;
|
||||
|
||||
private final BundleEncrypter bundleEncrypter =
|
||||
bundleEncrypterProvider.get();
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
if(state != null && !bundleEncrypter.decrypt(state)) state = null;
|
||||
super.onCreate(state);
|
||||
if(LOG.isLoggable(INFO)) LOG.info("Created");
|
||||
LinearLayout layout = new LinearLayout(this);
|
||||
@@ -60,6 +70,18 @@ implements OnClickListener {
|
||||
startService(new Intent(BriarService.class.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRestoreInstanceState(Bundle state) {
|
||||
if(bundleEncrypter.decrypt(state))
|
||||
super.onRestoreInstanceState(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle state) {
|
||||
super.onSaveInstanceState(state);
|
||||
bundleEncrypter.encrypt(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
@@ -53,13 +53,13 @@ implements InvitationListener {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
if(state == null || !bundleEncrypter.decrypt(state)) {
|
||||
// This is a new activity or the process has restarted
|
||||
super.onCreate(null);
|
||||
if(state != null && !bundleEncrypter.decrypt(state)) state = null;
|
||||
super.onCreate(state);
|
||||
if(state == null) {
|
||||
// This is a new activity or the app has restarted
|
||||
setView(new NetworkSetupView(this));
|
||||
} else {
|
||||
// Restore the activity's state
|
||||
super.onCreate(state);
|
||||
networkName = state.getString("net.sf.briar.NETWORK_NAME");
|
||||
useBluetooth = state.getBoolean("net.sf.briar.USE_BLUETOOTH");
|
||||
taskHandle = state.getLong("net.sf.briar.TASK_HANDLE", -1);
|
||||
|
||||
Reference in New Issue
Block a user