receive Downloader error messages in swap

This commit is contained in:
Hans-Christoph Steiner 2019-05-15 22:41:52 +02:00
parent f0158063fb
commit bc14e62e46
2 changed files with 22 additions and 0 deletions

View File

@ -35,6 +35,7 @@ import org.fdroid.fdroid.localrepo.peers.PeerFinder;
import org.fdroid.fdroid.localrepo.type.BluetoothSwap; import org.fdroid.fdroid.localrepo.type.BluetoothSwap;
import org.fdroid.fdroid.localrepo.type.SwapType; import org.fdroid.fdroid.localrepo.type.SwapType;
import org.fdroid.fdroid.localrepo.type.WifiSwap; import org.fdroid.fdroid.localrepo.type.WifiSwap;
import org.fdroid.fdroid.net.Downloader;
import org.fdroid.fdroid.net.WifiStateChangeService; import org.fdroid.fdroid.net.WifiStateChangeService;
import org.fdroid.fdroid.views.swap.SwapWorkflowActivity; import org.fdroid.fdroid.views.swap.SwapWorkflowActivity;
import rx.Observable; import rx.Observable;
@ -190,6 +191,10 @@ public class SwapService extends Service {
"POSTing to \"/request-swap\" with repo \"" + swapBackUri + "\"): " + responseCode); "POSTing to \"/request-swap\" with repo \"" + swapBackUri + "\"): " + responseCode);
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Error while asking server to swap with us", e); Log.e(TAG, "Error while asking server to swap with us", e);
Intent intent = new Intent(Downloader.ACTION_INTERRUPTED);
intent.setData(Uri.parse(repo.address));
intent.putExtra(Downloader.EXTRA_ERROR_MESSAGE, e.getLocalizedMessage());
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent);
} finally { } finally {
conn.disconnect(); conn.disconnect();
} }

View File

@ -57,6 +57,8 @@ import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.data.Apk; import org.fdroid.fdroid.data.Apk;
import org.fdroid.fdroid.data.App; import org.fdroid.fdroid.data.App;
import org.fdroid.fdroid.data.NewRepoConfig; import org.fdroid.fdroid.data.NewRepoConfig;
import org.fdroid.fdroid.data.Repo;
import org.fdroid.fdroid.data.RepoProvider;
import org.fdroid.fdroid.installer.InstallManagerService; import org.fdroid.fdroid.installer.InstallManagerService;
import org.fdroid.fdroid.installer.Installer; import org.fdroid.fdroid.installer.Installer;
import org.fdroid.fdroid.localrepo.LocalRepoService; import org.fdroid.fdroid.localrepo.LocalRepoService;
@ -64,6 +66,7 @@ import org.fdroid.fdroid.localrepo.SwapService;
import org.fdroid.fdroid.localrepo.SwapView; import org.fdroid.fdroid.localrepo.SwapView;
import org.fdroid.fdroid.localrepo.peers.Peer; import org.fdroid.fdroid.localrepo.peers.Peer;
import org.fdroid.fdroid.net.BluetoothDownloader; import org.fdroid.fdroid.net.BluetoothDownloader;
import org.fdroid.fdroid.net.Downloader;
import org.fdroid.fdroid.net.HttpDownloader; import org.fdroid.fdroid.net.HttpDownloader;
import org.fdroid.fdroid.net.WifiStateChangeService; import org.fdroid.fdroid.net.WifiStateChangeService;
import org.fdroid.fdroid.views.main.MainActivity; import org.fdroid.fdroid.views.main.MainActivity;
@ -225,6 +228,9 @@ public class SwapWorkflowActivity extends AppCompatActivity {
container = (ViewGroup) findViewById(R.id.container); container = (ViewGroup) findViewById(R.id.container);
localBroadcastManager = LocalBroadcastManager.getInstance(this); localBroadcastManager = LocalBroadcastManager.getInstance(this);
localBroadcastManager.registerReceiver(downloaderInterruptedReceiver,
new IntentFilter(Downloader.ACTION_INTERRUPTED));
wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
new SwapDebug().logStatus(); new SwapDebug().logStatus();
@ -232,6 +238,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
@Override @Override
protected void onDestroy() { protected void onDestroy() {
localBroadcastManager.unregisterReceiver(downloaderInterruptedReceiver);
unbindService(serviceConnection); unbindService(serviceConnection);
super.onDestroy(); super.onDestroy();
} }
@ -1172,6 +1179,16 @@ public class SwapWorkflowActivity extends AppCompatActivity {
} }
}; };
private final BroadcastReceiver downloaderInterruptedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Repo repo = RepoProvider.Helper.findByUrl(context, intent.getData(), null);
if (repo != null && repo.isSwap) {
setUpConnectingProgressText(intent.getStringExtra(Downloader.EXTRA_ERROR_MESSAGE));
}
}
};
private void setUpConnectingView() { private void setUpConnectingView() {
TextView heading = container.findViewById(R.id.progress_text); TextView heading = container.findViewById(R.id.progress_text);
heading.setText(R.string.swap_connecting); heading.setText(R.string.swap_connecting);