switch out swap Repo instance all at once
Before, it would change fields in a final Repo instance, which means that things could be out of sync when accessed. Now it swaps out the old one with a new Repo instance in one step. The local repo variables are now declared volatile so that they are more predictable when accessed from various threads (WifiStateChangeService, SwapService, etc.) askServerToSwapWithUs(NewRepoConfig) was unused, so I removed it.
This commit is contained in:
parent
26d173acdc
commit
426e03a649
@ -81,12 +81,12 @@ public class FDroidApp extends Application {
|
||||
private static Locale locale;
|
||||
|
||||
// for the local repo on this device, all static since there is only one
|
||||
public static int port;
|
||||
public static String ipAddressString;
|
||||
public static SubnetUtils.SubnetInfo subnetInfo;
|
||||
public static String ssid;
|
||||
public static String bssid;
|
||||
public static final Repo REPO = new Repo();
|
||||
public static volatile int port;
|
||||
public static volatile String ipAddressString;
|
||||
public static volatile SubnetUtils.SubnetInfo subnetInfo;
|
||||
public static volatile String ssid;
|
||||
public static volatile String bssid;
|
||||
public static volatile Repo repo = new Repo();
|
||||
|
||||
// Leaving the fully qualified class name here to help clarify the difference between spongy/bouncy castle.
|
||||
private static final org.spongycastle.jce.provider.BouncyCastleProvider SPONGYCASTLE_PROVIDER;
|
||||
@ -147,6 +147,7 @@ public class FDroidApp extends Application {
|
||||
subnetInfo = new SubnetUtils("0.0.0.0/32").getInfo();
|
||||
ssid = "";
|
||||
bssid = "";
|
||||
repo = new Repo();
|
||||
}
|
||||
|
||||
public void updateLanguage() {
|
||||
|
@ -31,7 +31,6 @@ import org.fdroid.fdroid.Preferences;
|
||||
import org.fdroid.fdroid.R;
|
||||
import org.fdroid.fdroid.UpdateService;
|
||||
import org.fdroid.fdroid.Utils;
|
||||
import org.fdroid.fdroid.data.NewRepoConfig;
|
||||
import org.fdroid.fdroid.data.Repo;
|
||||
import org.fdroid.fdroid.data.RepoProvider;
|
||||
import org.fdroid.fdroid.localrepo.peers.Peer;
|
||||
@ -208,16 +207,12 @@ public class SwapService extends Service {
|
||||
askServerToSwapWithUs(repo.address);
|
||||
}
|
||||
|
||||
public void askServerToSwapWithUs(final NewRepoConfig config) {
|
||||
askServerToSwapWithUs(config.getRepoUriString());
|
||||
}
|
||||
|
||||
private void askServerToSwapWithUs(final String address) {
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... args) {
|
||||
Uri repoUri = Uri.parse(address);
|
||||
String swapBackUri = Utils.getLocalRepoUri(FDroidApp.REPO).toString();
|
||||
String swapBackUri = Utils.getLocalRepoUri(FDroidApp.repo).toString();
|
||||
|
||||
AndroidHttpClient client = AndroidHttpClient.newInstance("F-Droid", SwapService.this);
|
||||
HttpPost request = new HttpPost("/request-swap");
|
||||
|
@ -130,7 +130,7 @@ class BonjourFinder extends PeerFinder implements ServiceListener {
|
||||
final String type = serviceInfo.getPropertyString("type");
|
||||
final String fingerprint = serviceInfo.getPropertyString("fingerprint");
|
||||
final boolean isFDroid = type != null && type.startsWith("fdroidrepo");
|
||||
final boolean isSelf = FDroidApp.REPO != null && fingerprint != null && fingerprint.equalsIgnoreCase(FDroidApp.REPO.fingerprint);
|
||||
final boolean isSelf = FDroidApp.repo != null && fingerprint != null && fingerprint.equalsIgnoreCase(FDroidApp.repo.fingerprint);
|
||||
if (isFDroid && !isSelf) {
|
||||
Utils.debugLog(TAG, "Found F-Droid swap Bonjour service:\n" + serviceInfo);
|
||||
subscriber.onNext(new BonjourPeer(serviceInfo));
|
||||
|
@ -55,7 +55,7 @@ public class BonjourBroadcast extends SwapType {
|
||||
HashMap<String, String> values = new HashMap<>();
|
||||
values.put("path", "/fdroid/repo");
|
||||
values.put("name", repoName);
|
||||
values.put("fingerprint", FDroidApp.REPO.fingerprint);
|
||||
values.put("fingerprint", FDroidApp.repo.fingerprint);
|
||||
String type;
|
||||
if (Preferences.get().isLocalRepoHttpsEnabled()) {
|
||||
values.put("type", "fdroidrepos");
|
||||
|
@ -17,6 +17,7 @@ import org.apache.commons.net.util.SubnetUtils;
|
||||
import org.fdroid.fdroid.FDroidApp;
|
||||
import org.fdroid.fdroid.Preferences;
|
||||
import org.fdroid.fdroid.Utils;
|
||||
import org.fdroid.fdroid.data.Repo;
|
||||
import org.fdroid.fdroid.localrepo.LocalRepoKeyStore;
|
||||
import org.fdroid.fdroid.localrepo.LocalRepoManager;
|
||||
|
||||
@ -135,8 +136,9 @@ public class WifiStateChangeService extends IntentService {
|
||||
} else {
|
||||
scheme = "http";
|
||||
}
|
||||
FDroidApp.REPO.name = Preferences.get().getLocalRepoName();
|
||||
FDroidApp.REPO.address = String.format(Locale.ENGLISH, "%s://%s:%d/fdroid/repo",
|
||||
Repo repo = new Repo();
|
||||
repo.name = Preferences.get().getLocalRepoName();
|
||||
repo.address = String.format(Locale.ENGLISH, "%s://%s:%d/fdroid/repo",
|
||||
scheme, FDroidApp.ipAddressString, FDroidApp.port);
|
||||
|
||||
if (isInterrupted()) { // can be canceled by a change via WifiStateChangeReceiver
|
||||
@ -145,7 +147,7 @@ public class WifiStateChangeService extends IntentService {
|
||||
|
||||
Context context = WifiStateChangeService.this.getApplicationContext();
|
||||
LocalRepoManager lrm = LocalRepoManager.get(context);
|
||||
lrm.writeIndexPage(Utils.getSharingUri(FDroidApp.REPO).toString());
|
||||
lrm.writeIndexPage(Utils.getSharingUri(FDroidApp.repo).toString());
|
||||
|
||||
if (isInterrupted()) { // can be canceled by a change via WifiStateChangeReceiver
|
||||
return;
|
||||
@ -154,7 +156,9 @@ public class WifiStateChangeService extends IntentService {
|
||||
// the fingerprint for the local repo's signing key
|
||||
LocalRepoKeyStore localRepoKeyStore = LocalRepoKeyStore.get(context);
|
||||
Certificate localCert = localRepoKeyStore.getCertificate();
|
||||
FDroidApp.REPO.fingerprint = Utils.calcFingerprint(localCert);
|
||||
repo.fingerprint = Utils.calcFingerprint(localCert);
|
||||
|
||||
FDroidApp.repo = repo;
|
||||
|
||||
/*
|
||||
* Once the IP address is known we need to generate a self
|
||||
|
@ -504,7 +504,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
||||
// Even if they opted to skip the message which says "Touch devices to swap",
|
||||
// we still want to actually enable the feature, so that they could touch
|
||||
// during the wifi qr code being shown too.
|
||||
boolean nfcMessageReady = NfcHelper.setPushMessage(this, Utils.getSharingUri(FDroidApp.REPO));
|
||||
boolean nfcMessageReady = NfcHelper.setPushMessage(this, Utils.getSharingUri(FDroidApp.repo));
|
||||
|
||||
if (Preferences.get().showNfcDuringSwap() && nfcMessageReady) {
|
||||
inflateInnerView(R.layout.swap_nfc);
|
||||
@ -669,7 +669,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
||||
PrepareSwapRepo(@NonNull Set<String> apps) {
|
||||
context = SwapWorkflowActivity.this;
|
||||
selectedApps = apps;
|
||||
sharingUri = Utils.getSharingUri(FDroidApp.REPO);
|
||||
sharingUri = Utils.getSharingUri(FDroidApp.repo);
|
||||
}
|
||||
|
||||
private void broadcast(int type) {
|
||||
|
@ -121,7 +121,7 @@ public class WifiQrView extends ScrollView implements SwapWorkflowActivity.Inner
|
||||
|
||||
private void setUIFromWifi() {
|
||||
|
||||
if (TextUtils.isEmpty(FDroidApp.REPO.address)) {
|
||||
if (TextUtils.isEmpty(FDroidApp.repo.address)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -139,7 +139,7 @@ public class WifiQrView extends ScrollView implements SwapWorkflowActivity.Inner
|
||||
* wifi AP to join. Lots of QR Scanners are buggy and do not respect
|
||||
* custom URI schemes, so we have to use http:// or https:// :-(
|
||||
*/
|
||||
Uri sharingUri = Utils.getSharingUri(FDroidApp.REPO);
|
||||
Uri sharingUri = Utils.getSharingUri(FDroidApp.repo);
|
||||
String qrUriString = (scheme + sharingUri.getHost()).toUpperCase(Locale.ENGLISH);
|
||||
if (sharingUri.getPort() != 80) {
|
||||
qrUriString += ":" + sharingUri.getPort();
|
||||
|
Loading…
x
Reference in New Issue
Block a user