Merge branch 'master' into 'master'

swap fixes for 0.100

Here are a couple of swap fixes for the upcoming 0.100 release.

See merge request !285
This commit is contained in:
Daniel Martí 2016-05-12 19:17:12 +00:00
commit 00608c1bc3
4 changed files with 32 additions and 38 deletions

View File

@ -47,6 +47,7 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="org.fdroid.fdroid.privileged.USE_SERVICE" />

View File

@ -209,8 +209,7 @@ public class InstallManagerService extends Service {
public void onReceive(Context context, Intent intent) {
String urlString = intent.getDataString();
// TODO these need to be removed based on whether they are fed to InstallerService or not
Apk apk = ACTIVE_APKS.remove(urlString);
ACTIVE_APPS.remove(apk.packageName);
Apk apk = removeFromActive(urlString);
if (AppDetails.isAppVisible(apk.packageName)) {
cancelNotification(urlString);
} else {
@ -223,8 +222,7 @@ public class InstallManagerService extends Service {
@Override
public void onReceive(Context context, Intent intent) {
String urlString = intent.getDataString();
Apk apk = ACTIVE_APKS.remove(urlString);
ACTIVE_APPS.remove(apk.packageName);
Apk apk = removeFromActive(urlString);
unregisterDownloaderReceivers(urlString);
cancelNotification(urlString);
}
@ -319,6 +317,18 @@ public class InstallManagerService extends Service {
notificationManager.cancel(urlString.hashCode());
}
private static void addToActive(String urlString, App app, Apk apk) {
ACTIVE_APKS.put(urlString, apk);
ACTIVE_APPS.put(app.packageName, app);
TEMP_HACK_APP_NAMES.put(urlString, app.name); // TODO delete me once InstallerService exists
}
private static Apk removeFromActive(String urlString) {
Apk apk = ACTIVE_APKS.remove(urlString);
ACTIVE_APPS.remove(apk.packageName);
return apk;
}
/**
* Install an APK, checking the cache and downloading if necessary before starting the process.
* All notifications are sent as an {@link Intent} via local broadcasts to be received by
@ -328,9 +338,7 @@ public class InstallManagerService extends Service {
public static void queue(Context context, App app, Apk apk) {
String urlString = apk.getUrl();
Utils.debugLog(TAG, "queue " + app.packageName + " " + apk.versionCode + " from " + urlString);
ACTIVE_APKS.put(urlString, apk);
ACTIVE_APPS.put(app.packageName, app);
TEMP_HACK_APP_NAMES.put(urlString, app.name); // TODO delete me once InstallerService exists
addToActive(urlString, app, apk);
Intent intent = new Intent(context, InstallManagerService.class);
intent.setAction(ACTION_INSTALL);
intent.setData(Uri.parse(urlString));

View File

@ -436,7 +436,7 @@ public class StartSwapView extends ScrollView implements SwapWorkflowActivity.In
viewWifiId.setVisibility(TextUtils.isEmpty(FDroidApp.ipAddressString) ? View.GONE : View.VISIBLE);
WifiApControl wifiAp = WifiApControl.getInstance(getActivity());
if (wifiAp.isWifiApEnabled()) {
if (wifiAp != null && wifiAp.isWifiApEnabled()) {
WifiConfiguration config = wifiAp.getConfiguration();
viewWifiNetwork.setText(getContext().getString(R.string.swap_active_hotspot, config.SSID));
} else if (TextUtils.isEmpty(FDroidApp.ssid)) {

View File

@ -234,9 +234,6 @@ public class SwapAppsView extends ListView implements
private final LocalBroadcastManager localBroadcastManager;
private App app;
@Nullable
private Apk apkToInstall;
ProgressBar progressView;
TextView nameView;
ImageView iconView;
@ -289,33 +286,32 @@ public class SwapAppsView extends ListView implements
Activity activity = getActivity();
if (activity != null) {
app = AppProvider.Helper.findByPackageName(getActivity().getContentResolver(), app.packageName);
apkToInstall = null; // Force lazy loading to fetch correct apk next time.
resetView();
}
}
};
ViewHolder() {
// TODO: Unregister receivers correctly...
Apk apk = getApkToInstall();
String url = apk.getUrl();
localBroadcastManager = LocalBroadcastManager.getInstance(getActivity());
localBroadcastManager.registerReceiver(appListViewResetReceiver,
DownloaderService.getIntentFilter(url, Downloader.ACTION_STARTED));
localBroadcastManager.registerReceiver(downloadProgressReceiver,
DownloaderService.getIntentFilter(url, Downloader.ACTION_PROGRESS));
localBroadcastManager.registerReceiver(appListViewResetReceiver,
DownloaderService.getIntentFilter(url, Downloader.ACTION_COMPLETE));
localBroadcastManager.registerReceiver(interruptedReceiver,
DownloaderService.getIntentFilter(url, Downloader.ACTION_INTERRUPTED));
localBroadcastManager = LocalBroadcastManager.getInstance(getContext());
}
public void setApp(@NonNull App app) {
if (this.app == null || !this.app.packageName.equals(app.packageName)) {
this.app = app;
apkToInstall = null; // Force lazy loading to fetch the correct apk next time.
Context context = getContext();
Apk apk = ApkProvider.Helper.find(context, app.packageName, app.suggestedVersionCode);
String urlString = apk.getUrl();
// TODO unregister receivers? or will they just die with this instance
localBroadcastManager.registerReceiver(appListViewResetReceiver,
DownloaderService.getIntentFilter(urlString, Downloader.ACTION_STARTED));
localBroadcastManager.registerReceiver(downloadProgressReceiver,
DownloaderService.getIntentFilter(urlString, Downloader.ACTION_PROGRESS));
localBroadcastManager.registerReceiver(appListViewResetReceiver,
DownloaderService.getIntentFilter(urlString, Downloader.ACTION_COMPLETE));
localBroadcastManager.registerReceiver(interruptedReceiver,
DownloaderService.getIntentFilter(urlString, Downloader.ACTION_INTERRUPTED));
// NOTE: Instead of continually unregistering and re-registering the observer
// (with a different URI), this could equally be done by only having one
@ -329,17 +325,6 @@ public class SwapAppsView extends ListView implements
resetView();
}
/**
* Lazily load the apk from the database the first time it is requested. Means it wont
* be loaded unless we receive a download event from the {@link ApkDownloader}.
*/
private Apk getApkToInstall() {
if (apkToInstall == null) {
apkToInstall = ApkProvider.Helper.find(getActivity(), app.packageName, app.suggestedVersionCode);
}
return apkToInstall;
}
private void resetView() {
if (app == null) {