Make field that's used on background thread volatile.

This commit is contained in:
akwizgran
2018-05-11 09:21:45 +01:00
parent f3b69a26f8
commit 1987dcb936

View File

@@ -26,7 +26,7 @@ public class SetupControllerImpl extends PasswordControllerImpl
Logger.getLogger(SetupControllerImpl.class.getName());
@Nullable
private SetupActivity setupActivity; // TODO: Should be volatile
private volatile SetupActivity setupActivity;
@Inject
SetupControllerImpl(SharedPreferences briarPrefs,
@@ -44,6 +44,7 @@ public class SetupControllerImpl extends PasswordControllerImpl
@Override
public boolean needToShowDozeFragment() {
SetupActivity setupActivity = this.setupActivity;
if (setupActivity == null) throw new IllegalStateException();
return DozeView.needsToBeShown(setupActivity) ||
HuaweiView.needsToBeShown(setupActivity);
@@ -51,31 +52,35 @@ public class SetupControllerImpl extends PasswordControllerImpl
@Override
public void setAuthorName(String authorName) {
SetupActivity setupActivity = this.setupActivity;
if (setupActivity == null) throw new IllegalStateException();
setupActivity.setAuthorName(authorName);
}
@Override
public void setPassword(String password) {
SetupActivity setupActivity = this.setupActivity;
if (setupActivity == null) throw new IllegalStateException();
setupActivity.setPassword(password);
}
@Override
public void showPasswordFragment() {
SetupActivity setupActivity = this.setupActivity;
if (setupActivity == null) throw new IllegalStateException();
setupActivity.showPasswordFragment();
}
@Override
public void showDozeFragment() {
SetupActivity setupActivity = this.setupActivity;
if (setupActivity == null) throw new IllegalStateException();
setupActivity.showDozeFragment();
}
@Override
public void createAccount() {
if (setupActivity == null) throw new IllegalStateException();
SetupActivity setupActivity = this.setupActivity;
UiResultHandler<Void> resultHandler =
new UiResultHandler<Void>(setupActivity) {
@Override
@@ -90,6 +95,7 @@ public class SetupControllerImpl extends PasswordControllerImpl
// Package access for testing
void createAccount(ResultHandler<Void> resultHandler) {
SetupActivity setupActivity = this.setupActivity;
if (setupActivity == null) throw new IllegalStateException();
String authorName = setupActivity.getAuthorName();
if (authorName == null) throw new IllegalStateException();