use of org.fdroid.fdroid.data.Apk in project fdroidclient by f-droid.
the class InstallManagerService method registerApkDownloaderReceivers.
private void registerApkDownloaderReceivers(String urlString) {
BroadcastReceiver downloadReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (!running) {
localBroadcastManager.unregisterReceiver(this);
return;
}
Uri downloadUri = intent.getData();
String urlString = downloadUri.toString();
long repoId = intent.getLongExtra(Downloader.EXTRA_REPO_ID, 0);
String mirrorUrlString = intent.getStringExtra(Downloader.EXTRA_MIRROR_URL);
switch(intent.getAction()) {
case Downloader.ACTION_STARTED:
// App should currently be in the "PendingDownload" state, so this changes it to "Downloading".
Intent intentObject = new Intent(context, InstallManagerService.class);
intentObject.setAction(ACTION_CANCEL);
intentObject.setData(downloadUri);
PendingIntent action = PendingIntent.getService(context, 0, intentObject, 0);
appUpdateStatusManager.updateApk(urlString, AppUpdateStatusManager.Status.Downloading, action);
break;
case Downloader.ACTION_PROGRESS:
int bytesRead = intent.getIntExtra(Downloader.EXTRA_BYTES_READ, 0);
int totalBytes = intent.getIntExtra(Downloader.EXTRA_TOTAL_BYTES, 0);
appUpdateStatusManager.updateApkProgress(urlString, totalBytes, bytesRead);
break;
case Downloader.ACTION_COMPLETE:
File localFile = new File(intent.getStringExtra(Downloader.EXTRA_DOWNLOAD_PATH));
Uri localApkUri = Uri.fromFile(localFile);
Utils.debugLog(TAG, "download completed of " + mirrorUrlString + " to " + localApkUri);
appUpdateStatusManager.updateApk(urlString, AppUpdateStatusManager.Status.ReadyToInstall, null);
localBroadcastManager.unregisterReceiver(this);
registerInstallerReceivers(downloadUri);
Apk apk = appUpdateStatusManager.getApk(urlString);
if (apk != null) {
InstallerService.install(context, localApkUri, downloadUri, apk);
}
break;
case Downloader.ACTION_INTERRUPTED:
appUpdateStatusManager.markAsNoLongerPendingInstall(urlString);
appUpdateStatusManager.setDownloadError(urlString, intent.getStringExtra(Downloader.EXTRA_ERROR_MESSAGE));
localBroadcastManager.unregisterReceiver(this);
break;
case Downloader.ACTION_CONNECTION_FAILED:
try {
DownloaderService.queue(context, FDroidApp.getMirror(mirrorUrlString, repoId), repoId, urlString);
DownloaderService.setTimeout(FDroidApp.getTimeout());
} catch (IOException e) {
appUpdateStatusManager.markAsNoLongerPendingInstall(urlString);
appUpdateStatusManager.setDownloadError(urlString, intent.getStringExtra(Downloader.EXTRA_ERROR_MESSAGE));
localBroadcastManager.unregisterReceiver(this);
}
break;
default:
throw new RuntimeException("intent action not handled!");
}
}
};
localBroadcastManager.registerReceiver(downloadReceiver, DownloaderService.getIntentFilter(urlString));
}
use of org.fdroid.fdroid.data.Apk in project fdroidclient by f-droid.
the class InstallManagerService method registerInstallerReceivers.
private void registerInstallerReceivers(Uri downloadUri) {
BroadcastReceiver installReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (!running) {
localBroadcastManager.unregisterReceiver(this);
return;
}
String downloadUrl = intent.getDataString();
Apk apk;
switch(intent.getAction()) {
case Installer.ACTION_INSTALL_STARTED:
appUpdateStatusManager.updateApk(downloadUrl, AppUpdateStatusManager.Status.Installing, null);
break;
case Installer.ACTION_INSTALL_COMPLETE:
appUpdateStatusManager.markAsNoLongerPendingInstall(downloadUrl);
appUpdateStatusManager.updateApk(downloadUrl, AppUpdateStatusManager.Status.Installed, null);
Apk apkComplete = appUpdateStatusManager.getApk(downloadUrl);
if (apkComplete != null && apkComplete.isApk()) {
try {
PackageManagerCompat.setInstaller(context, getPackageManager(), apkComplete.packageName);
} catch (SecurityException e) {
// Will happen if we fell back to DefaultInstaller for some reason.
}
}
localBroadcastManager.unregisterReceiver(this);
break;
case Installer.ACTION_INSTALL_INTERRUPTED:
apk = intent.getParcelableExtra(Installer.EXTRA_APK);
String errorMessage = intent.getStringExtra(Installer.EXTRA_ERROR_MESSAGE);
appUpdateStatusManager.markAsNoLongerPendingInstall(downloadUrl);
if (!TextUtils.isEmpty(errorMessage)) {
appUpdateStatusManager.setApkError(apk, errorMessage);
} else {
appUpdateStatusManager.removeApk(downloadUrl);
}
localBroadcastManager.unregisterReceiver(this);
break;
case Installer.ACTION_INSTALL_USER_INTERACTION:
apk = intent.getParcelableExtra(Installer.EXTRA_APK);
PendingIntent installPendingIntent = intent.getParcelableExtra(Installer.EXTRA_USER_INTERACTION_PI);
appUpdateStatusManager.addApk(apk, AppUpdateStatusManager.Status.ReadyToInstall, installPendingIntent);
break;
default:
throw new RuntimeException("intent action not handled!");
}
}
};
localBroadcastManager.registerReceiver(installReceiver, Installer.getInstallIntentFilter(downloadUri));
}
use of org.fdroid.fdroid.data.Apk in project fdroidclient by f-droid.
the class InstallerService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
final Apk apk = intent.getParcelableExtra(Installer.EXTRA_APK);
if (apk == null) {
Utils.debugLog(TAG, "ignoring intent with null EXTRA_APK: " + intent);
return;
}
Installer installer = InstallerFactory.create(this, apk);
if (ACTION_INSTALL.equals(intent.getAction())) {
Uri uri = intent.getData();
Uri downloadUri = intent.getParcelableExtra(Installer.EXTRA_DOWNLOAD_URI);
installer.installPackage(uri, downloadUri);
} else if (ACTION_UNINSTALL.equals(intent.getAction())) {
installer.uninstallPackage();
new Thread() {
@Override
public void run() {
setPriority(MIN_PRIORITY);
File mainObbFile = apk.getMainObbFile();
if (mainObbFile == null) {
return;
}
File obbDir = mainObbFile.getParentFile();
if (obbDir == null) {
return;
}
FileFilter filter = new WildcardFileFilter("*.obb");
File[] obbFiles = obbDir.listFiles(filter);
if (obbFiles == null) {
return;
}
for (File f : obbFiles) {
Utils.debugLog(TAG, "Uninstalling OBB " + f);
FileUtils.deleteQuietly(f);
}
}
}.start();
}
}
use of org.fdroid.fdroid.data.Apk in project fdroidclient by f-droid.
the class ProperMultiRepoUpdaterTest method assertMainRepo.
/**
* + 2048 (com.uberspot.a2048)
* - Version 1.96 (19)
* - Version 1.95 (18)
* + AdAway (org.adaway)
* - Version 3.0.2 (54)
* - Version 3.0.1 (53)
* - Version 3.0 (52)
* + adbWireless (siir.es.adbWireless)
* - Version 1.5.4 (12)
*/
private void assertMainRepo(List<Repo> allRepos) {
Repo repo = findRepo(REPO_MAIN, allRepos);
List<Apk> apks = ApkProvider.Helper.findByRepo(context, repo, Schema.ApkTable.Cols.ALL);
assertEquals("Apks for main repo", apks.size(), 6);
assertApksExist(apks, "com.uberspot.a2048", new int[] { 18, 19 });
assertApksExist(apks, "org.adaway", new int[] { 52, 53, 54 });
assertApksExist(apks, "siir.es.adbWireless", new int[] { 12 });
assert2048Metadata(repo, "Normal");
assertAdAwayMetadata(repo, "Normal");
assertAdbMetadata(repo, "Normal");
}
use of org.fdroid.fdroid.data.Apk in project fdroidclient by f-droid.
the class ProperMultiRepoUpdaterTest method assertConflictingRepo.
/**
* + AdAway (org.adaway)
* - Version 3.0.1 (53) *
* - Version 3.0 (52) *
* - Version 2.9.2 (51) *
* - Version 2.2.1 (50) *
* + Add to calendar (org.dgtale.icsimport)
* - Version 1.2 (3)
* - Version 1.1 (2)
*/
private void assertConflictingRepo(List<Repo> allRepos) {
Repo repo = findRepo(REPO_CONFLICTING, allRepos);
List<Apk> apks = ApkProvider.Helper.findByRepo(context, repo, Schema.ApkTable.Cols.ALL);
assertEquals("Apks for conflicting repo", 6, apks.size());
assertApksExist(apks, "org.adaway", new int[] { 50, 51, 52, 53 });
assertApksExist(apks, "org.dgtale.icsimport", new int[] { 2, 3 });
assertAdAwayMetadata(repo, "Conflicting");
assertCalendarMetadata(repo, "Conflicting");
}
Aggregations