Skip to content
Snippets Groups Projects
Commit 020e4df8 authored by akwizgran's avatar akwizgran
Browse files

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.
parent d136964b
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment