mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Removed static injection hack, moved boilerplate into a superclass.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package net.sf.briar.android;
|
||||
|
||||
import net.sf.briar.android.invitation.AddContactActivity;
|
||||
import net.sf.briar.api.android.AndroidExecutor;
|
||||
import net.sf.briar.api.android.BundleEncrypter;
|
||||
import net.sf.briar.api.android.ReferenceManager;
|
||||
@@ -17,6 +16,5 @@ public class AndroidModule extends AbstractModule {
|
||||
Singleton.class);
|
||||
bind(ReferenceManager.class).to(ReferenceManagerImpl.class).in(
|
||||
Singleton.class);
|
||||
requestStaticInjection(AddContactActivity.class);
|
||||
}
|
||||
}
|
||||
|
||||
28
briar-android/src/net/sf/briar/android/BriarActivity.java
Normal file
28
briar-android/src/net/sf/briar/android/BriarActivity.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package net.sf.briar.android;
|
||||
|
||||
import roboguice.activity.RoboActivity;
|
||||
import android.os.Bundle;
|
||||
|
||||
/**
|
||||
* An abstract superclass for activities that overrides the default behaviour
|
||||
* to prevent sensitive state from being saved unless the subclass explicitly
|
||||
* saves it.
|
||||
*/
|
||||
public abstract class BriarActivity extends RoboActivity {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
// Don't pass state through to the superclass
|
||||
super.onCreate(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRestoreInstanceState(Bundle state) {
|
||||
// Don't pass state through to the superclass
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle state) {
|
||||
// Don't allow the superclass to save state
|
||||
}
|
||||
}
|
||||
@@ -8,14 +8,11 @@ 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.BriarActivity;
|
||||
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;
|
||||
import android.view.View;
|
||||
@@ -25,21 +22,19 @@ import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout.LayoutParams;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class HelloWorldActivity extends RoboActivity
|
||||
import com.google.inject.Inject;
|
||||
|
||||
public class HelloWorldActivity extends BriarActivity
|
||||
implements OnClickListener {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(HelloWorldActivity.class.getName());
|
||||
|
||||
@Inject private static Provider<BundleEncrypter> bundleEncrypterProvider;
|
||||
|
||||
private final BundleEncrypter bundleEncrypter =
|
||||
bundleEncrypterProvider.get();
|
||||
@Inject private BundleEncrypter bundleEncrypter;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
if(state != null && !bundleEncrypter.decrypt(state)) state = null;
|
||||
super.onCreate(state);
|
||||
super.onCreate(null);
|
||||
if(LOG.isLoggable(INFO)) LOG.info("Created");
|
||||
LinearLayout layout = new LinearLayout(this);
|
||||
layout.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT));
|
||||
@@ -70,18 +65,6 @@ 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();
|
||||
|
||||
@@ -5,6 +5,7 @@ import static java.util.logging.Level.WARNING;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.sf.briar.android.BriarActivity;
|
||||
import net.sf.briar.api.android.BundleEncrypter;
|
||||
import net.sf.briar.api.android.ReferenceManager;
|
||||
import net.sf.briar.api.crypto.CryptoComponent;
|
||||
@@ -15,24 +16,17 @@ import net.sf.briar.api.invitation.InvitationListener;
|
||||
import net.sf.briar.api.invitation.InvitationState;
|
||||
import net.sf.briar.api.invitation.InvitationTask;
|
||||
import net.sf.briar.api.invitation.InvitationTaskFactory;
|
||||
import roboguice.activity.RoboActivity;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
public class AddContactActivity extends RoboActivity
|
||||
public class AddContactActivity extends BriarActivity
|
||||
implements InvitationListener {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(AddContactActivity.class.getName());
|
||||
|
||||
// This allows us to access bundleEncrypter before calling super.onCreate()
|
||||
@Inject private static Provider<BundleEncrypter> bundleEncrypterProvider;
|
||||
|
||||
private final BundleEncrypter bundleEncrypter =
|
||||
bundleEncrypterProvider.get();
|
||||
|
||||
@Inject private BundleEncrypter bundleEncrypter;
|
||||
@Inject private CryptoComponent crypto;
|
||||
@Inject private DatabaseComponent db;
|
||||
@Inject @DatabaseExecutor private Executor dbExecutor;
|
||||
@@ -53,9 +47,8 @@ implements InvitationListener {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
if(state != null && !bundleEncrypter.decrypt(state)) state = null;
|
||||
super.onCreate(state);
|
||||
if(state == null) {
|
||||
super.onCreate(null);
|
||||
if(state == null || !bundleEncrypter.decrypt(state)) {
|
||||
// This is a new activity or the app has restarted
|
||||
setView(new NetworkSetupView(this));
|
||||
} else {
|
||||
@@ -120,12 +113,6 @@ implements InvitationListener {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRestoreInstanceState(Bundle state) {
|
||||
if(bundleEncrypter.decrypt(state))
|
||||
super.onRestoreInstanceState(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
@@ -134,7 +121,6 @@ implements InvitationListener {
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle state) {
|
||||
super.onSaveInstanceState(state);
|
||||
state.putString("net.sf.briar.NETWORK_NAME", networkName);
|
||||
state.putBoolean("net.sf.briar.USE_BLUETOOTH", useBluetooth);
|
||||
state.putInt("net.sf.briar.LOCAL_CODE", localInvitationCode);
|
||||
|
||||
Reference in New Issue
Block a user