wip: when a download is completed, app is woken up and app details screen displayed
This commit is contained in:
parent
5f989739bb
commit
f9fee5beb0
@ -450,6 +450,14 @@
|
|||||||
<action android:name="android.net.wifi.STATE_CHANGE" />
|
<action android:name="android.net.wifi.STATE_CHANGE" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
<receiver android:name=".receiver.DownloadManagerReceiver" >
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
|
||||||
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.DOWNLOAD_NOTIFICATION_CLICKED" />
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
|
||||||
<service android:name=".UpdateService" />
|
<service android:name=".UpdateService" />
|
||||||
<service android:name=".net.WifiStateChangeService" />
|
<service android:name=".net.WifiStateChangeService" />
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
package org.fdroid.fdroid;
|
package org.fdroid.fdroid;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.DownloadManager;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
@ -34,6 +35,7 @@ import android.content.pm.PackageInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.Signature;
|
import android.content.pm.Signature;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
|
import android.database.Cursor;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -91,6 +93,7 @@ import org.fdroid.fdroid.installer.Installer;
|
|||||||
import org.fdroid.fdroid.installer.Installer.AndroidNotCompatibleException;
|
import org.fdroid.fdroid.installer.Installer.AndroidNotCompatibleException;
|
||||||
import org.fdroid.fdroid.installer.Installer.InstallerCallback;
|
import org.fdroid.fdroid.installer.Installer.InstallerCallback;
|
||||||
import org.fdroid.fdroid.net.ApkDownloader;
|
import org.fdroid.fdroid.net.ApkDownloader;
|
||||||
|
import org.fdroid.fdroid.net.AsyncDownloader;
|
||||||
import org.fdroid.fdroid.net.Downloader;
|
import org.fdroid.fdroid.net.Downloader;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -361,9 +364,16 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
|
|||||||
private String getAppIdFromIntent() {
|
private String getAppIdFromIntent() {
|
||||||
Intent i = getIntent();
|
Intent i = getIntent();
|
||||||
if (!i.hasExtra(EXTRA_APPID)) {
|
if (!i.hasExtra(EXTRA_APPID)) {
|
||||||
|
if (i.hasExtra(DownloadManager.EXTRA_DOWNLOAD_ID)) {
|
||||||
|
// we have been passed a DownloadManager download id, so get the app id for it
|
||||||
|
long downloadId = i.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
|
||||||
|
return AsyncDownloader.getAppId(this, downloadId);
|
||||||
|
}
|
||||||
|
|
||||||
Log.e(TAG, "No application ID found in the intent!");
|
Log.e(TAG, "No application ID found in the intent!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return i.getStringExtra(EXTRA_APPID);
|
return i.getStringExtra(EXTRA_APPID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -451,6 +461,7 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
|
|||||||
refreshApkList();
|
refreshApkList();
|
||||||
refreshHeader();
|
refreshHeader();
|
||||||
supportInvalidateOptionsMenu();
|
supportInvalidateOptionsMenu();
|
||||||
|
|
||||||
if (downloadHandler != null) {
|
if (downloadHandler != null) {
|
||||||
if (downloadHandler.isComplete()) {
|
if (downloadHandler.isComplete()) {
|
||||||
downloadCompleteInstallApk();
|
downloadCompleteInstallApk();
|
||||||
|
@ -197,7 +197,7 @@ public class ApkDownloader implements AsyncDownloadWrapper.Listener {
|
|||||||
if (canUseDownloadManager(new URL(remoteAddress))) {
|
if (canUseDownloadManager(new URL(remoteAddress))) {
|
||||||
// If we can use Android's DownloadManager, let's use it, because
|
// If we can use Android's DownloadManager, let's use it, because
|
||||||
// of better OS integration, reliability, and async ability
|
// of better OS integration, reliability, and async ability
|
||||||
dlWrapper = new AsyncDownloader(context, this, curApk.apkName, remoteAddress, localFile);
|
dlWrapper = new AsyncDownloader(context, this, curApk.apkName, curApk.id, remoteAddress, localFile);
|
||||||
} else {
|
} else {
|
||||||
Downloader downloader = DownloaderFactory.create(context, remoteAddress, localFile);
|
Downloader downloader = DownloaderFactory.create(context, remoteAddress, localFile);
|
||||||
dlWrapper = new AsyncDownloadWrapper(downloader, this);
|
dlWrapper = new AsyncDownloadWrapper(downloader, this);
|
||||||
|
@ -6,10 +6,12 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
|
|
||||||
|
import org.fdroid.fdroid.AppDetails;
|
||||||
import org.fdroid.fdroid.data.SanitizedFile;
|
import org.fdroid.fdroid.data.SanitizedFile;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
@ -30,6 +32,7 @@ public class AsyncDownloader extends AsyncDownloadWrapper {
|
|||||||
private SanitizedFile localFile;
|
private SanitizedFile localFile;
|
||||||
private String remoteAddress;
|
private String remoteAddress;
|
||||||
private String appName;
|
private String appName;
|
||||||
|
private String appId;
|
||||||
private Listener listener;
|
private Listener listener;
|
||||||
|
|
||||||
private long downloadId = -1;
|
private long downloadId = -1;
|
||||||
@ -43,10 +46,11 @@ public class AsyncDownloader extends AsyncDownloadWrapper {
|
|||||||
*
|
*
|
||||||
* @param listener
|
* @param listener
|
||||||
*/
|
*/
|
||||||
public AsyncDownloader(Context context, Listener listener, String appName, String remoteAddress, SanitizedFile localFile) {
|
public AsyncDownloader(Context context, Listener listener, String appName, String appId, String remoteAddress, SanitizedFile localFile) {
|
||||||
super(null, listener);
|
super(null, listener);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.appName = appName;
|
this.appName = appName;
|
||||||
|
this.appId = appId;
|
||||||
this.remoteAddress = remoteAddress;
|
this.remoteAddress = remoteAddress;
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
this.localFile = localFile;
|
this.localFile = localFile;
|
||||||
@ -63,6 +67,7 @@ public class AsyncDownloader extends AsyncDownloadWrapper {
|
|||||||
// set up download request
|
// set up download request
|
||||||
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(remoteAddress));
|
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(remoteAddress));
|
||||||
request.setTitle(appName);
|
request.setTitle(appName);
|
||||||
|
request.setDescription(appId); // we will retrieve this later from the description field
|
||||||
|
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
IntentFilter intentFilter = new IntentFilter();
|
IntentFilter intentFilter = new IntentFilter();
|
||||||
@ -97,7 +102,10 @@ public class AsyncDownloader extends AsyncDownloadWrapper {
|
|||||||
private BroadcastReceiver downloadReceiver = new BroadcastReceiver() {
|
private BroadcastReceiver downloadReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (listener == null) return; // no point if no-one is listening
|
if (listener == null) {
|
||||||
|
// without a listener, install UI won't come up, so ignore this
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(intent.getAction())) {
|
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(intent.getAction())) {
|
||||||
long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
|
long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
|
||||||
@ -135,4 +143,18 @@ public class AsyncDownloader extends AsyncDownloadWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public static String getAppId(Context context, long downloadId) {
|
||||||
|
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
|
||||||
|
DownloadManager.Query query = new DownloadManager.Query();
|
||||||
|
query.setFilterById(downloadId);
|
||||||
|
Cursor c = dm.query(query);
|
||||||
|
if (c.moveToFirst()) {
|
||||||
|
// we use the description column to store the app id
|
||||||
|
int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_DESCRIPTION);
|
||||||
|
return c.getString(columnIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
package org.fdroid.fdroid.receiver;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
|
||||||
|
import org.fdroid.fdroid.AppDetails;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Receive notifications from the Android DownloadManager
|
||||||
|
*/
|
||||||
|
public class DownloadManagerReceiver extends BroadcastReceiver {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
// pass the download manager broadcast onto the AppDetails screen and let it handle it
|
||||||
|
Intent appDetails = new Intent(context, AppDetails.class);
|
||||||
|
appDetails.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
appDetails.setAction(intent.getAction());
|
||||||
|
appDetails.putExtras(intent.getExtras());
|
||||||
|
context.startActivity(appDetails);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user