send Installer.ACTION_INSTALL_STARTED consistently

ACTION_INSTALL_STARTED was being sent twice per transaction with the
default installer. Also, it should be sent as the first step of the install
process.
This commit is contained in:
Hans-Christoph Steiner 2016-09-20 11:47:49 +02:00
parent a08a32020a
commit d2291b2134
5 changed files with 16 additions and 21 deletions

View File

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2016 Dominik Schürmann <dominik@dominikschuermann.de> * Copyright (C) 2016 Dominik Schürmann <dominik@dominikschuermann.de>
* Copyright (C) 2016 Blue Jay Wireless
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -25,11 +26,8 @@ import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.data.Apk; import org.fdroid.fdroid.data.Apk;
import java.io.File;
/** /**
* The default installer of F-Droid. It uses the normal Intents APIs of Android * The default installer of F-Droid. It uses the normal Intents APIs of Android
* to install apks. Its main inner workings are encapsulated in DefaultInstallerActivity. * to install apks. Its main inner workings are encapsulated in DefaultInstallerActivity.
@ -39,7 +37,7 @@ import java.io.File;
*/ */
public class DefaultInstaller extends Installer { public class DefaultInstaller extends Installer {
private static final String TAG = "DefaultInstaller"; public static final String TAG = "DefaultInstaller";
DefaultInstaller(Context context, Apk apk) { DefaultInstaller(Context context, Apk apk) {
super(context, apk); super(context, apk);
@ -47,9 +45,6 @@ public class DefaultInstaller extends Installer {
@Override @Override
protected void installPackageInternal(Uri localApkUri, Uri downloadUri, Apk apk) { protected void installPackageInternal(Uri localApkUri, Uri downloadUri, Apk apk) {
sendBroadcastInstall(downloadUri, Installer.ACTION_INSTALL_STARTED);
Utils.debugLog(TAG, "DefaultInstaller uri: " + localApkUri + " file: " + new File(localApkUri.getPath()));
Intent installIntent = new Intent(context, DefaultInstallerActivity.class); Intent installIntent = new Intent(context, DefaultInstallerActivity.class);
installIntent.setAction(DefaultInstallerActivity.ACTION_INSTALL_PACKAGE); installIntent.setAction(DefaultInstallerActivity.ACTION_INSTALL_PACKAGE);

View File

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2014-2016 Dominik Schürmann <dominik@dominikschuermann.de> * Copyright (C) 2014-2016 Dominik Schürmann <dominik@dominikschuermann.de>
* Copyright (C) 2016 Blue Jay Wireless
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -37,7 +38,7 @@ import org.fdroid.fdroid.data.Apk;
* A transparent activity as a wrapper around Android's PackageInstaller Intents * A transparent activity as a wrapper around Android's PackageInstaller Intents
*/ */
public class DefaultInstallerActivity extends FragmentActivity { public class DefaultInstallerActivity extends FragmentActivity {
private static final String TAG = "AndroidInstallerAct"; private static final String TAG = "DefaultInstallerActivit";
static final String ACTION_INSTALL_PACKAGE = "org.fdroid.fdroid.installer.DefaultInstaller.action.INSTALL_PACKAGE"; static final String ACTION_INSTALL_PACKAGE = "org.fdroid.fdroid.installer.DefaultInstaller.action.INSTALL_PACKAGE";
static final String ACTION_UNINSTALL_PACKAGE = "org.fdroid.fdroid.installer.DefaultInstaller.action.UNINSTALL_PACKAGE"; static final String ACTION_UNINSTALL_PACKAGE = "org.fdroid.fdroid.installer.DefaultInstaller.action.UNINSTALL_PACKAGE";
@ -121,7 +122,6 @@ public class DefaultInstallerActivity extends FragmentActivity {
"This Android rom does not support ACTION_INSTALL_PACKAGE!"); "This Android rom does not support ACTION_INSTALL_PACKAGE!");
finish(); finish();
} }
installer.sendBroadcastInstall(downloadUri, Installer.ACTION_INSTALL_STARTED);
} }
private void uninstallPackage(String packageName) { private void uninstallPackage(String packageName) {

View File

@ -462,10 +462,13 @@ public class InstallManagerService extends Service {
*/ */
public static void queue(Context context, App app, Apk apk) { public static void queue(Context context, App app, Apk apk) {
String urlString = apk.getUrl(); String urlString = apk.getUrl();
Uri downloadUri = Uri.parse(urlString);
Installer.sendBroadcastInstall(context, downloadUri, Installer.ACTION_INSTALL_STARTED, apk,
null, null);
Utils.debugLog(TAG, "queue " + app.packageName + " " + apk.versionCode + " from " + urlString); Utils.debugLog(TAG, "queue " + app.packageName + " " + apk.versionCode + " from " + urlString);
Intent intent = new Intent(context, InstallManagerService.class); Intent intent = new Intent(context, InstallManagerService.class);
intent.setAction(ACTION_INSTALL); intent.setAction(ACTION_INSTALL);
intent.setData(Uri.parse(urlString)); intent.setData(downloadUri);
intent.putExtra(EXTRA_APP, app); intent.putExtra(EXTRA_APP, app);
intent.putExtra(EXTRA_APK, apk); intent.putExtra(EXTRA_APK, apk);
context.startService(intent); context.startService(intent);

View File

@ -47,7 +47,6 @@ public abstract class Installer {
final Context context; final Context context;
final Apk apk; final Apk apk;
private final LocalBroadcastManager localBroadcastManager;
public static final String ACTION_INSTALL_STARTED = "org.fdroid.fdroid.installer.Installer.action.INSTALL_STARTED"; public static final String ACTION_INSTALL_STARTED = "org.fdroid.fdroid.installer.Installer.action.INSTALL_STARTED";
public static final String ACTION_INSTALL_COMPLETE = "org.fdroid.fdroid.installer.Installer.action.INSTALL_COMPLETE"; public static final String ACTION_INSTALL_COMPLETE = "org.fdroid.fdroid.installer.Installer.action.INSTALL_COMPLETE";
@ -79,7 +78,6 @@ public abstract class Installer {
Installer(Context context, Apk apk) { Installer(Context context, Apk apk) {
this.context = context; this.context = context;
this.apk = apk; this.apk = apk;
localBroadcastManager = LocalBroadcastManager.getInstance(context);
} }
/** /**
@ -148,18 +146,19 @@ public abstract class Installer {
} }
void sendBroadcastInstall(Uri downloadUri, String action, PendingIntent pendingIntent) { void sendBroadcastInstall(Uri downloadUri, String action, PendingIntent pendingIntent) {
sendBroadcastInstall(downloadUri, action, pendingIntent, null); sendBroadcastInstall(context, downloadUri, action, apk, pendingIntent, null);
} }
void sendBroadcastInstall(Uri downloadUri, String action) { void sendBroadcastInstall(Uri downloadUri, String action) {
sendBroadcastInstall(downloadUri, action, null, null); sendBroadcastInstall(context, downloadUri, action, apk, null, null);
} }
void sendBroadcastInstall(Uri downloadUri, String action, String errorMessage) { void sendBroadcastInstall(Uri downloadUri, String action, String errorMessage) {
sendBroadcastInstall(downloadUri, action, null, errorMessage); sendBroadcastInstall(context, downloadUri, action, apk, null, errorMessage);
} }
void sendBroadcastInstall(Uri downloadUri, String action, static void sendBroadcastInstall(Context context,
Uri downloadUri, String action, Apk apk,
PendingIntent pendingIntent, String errorMessage) { PendingIntent pendingIntent, String errorMessage) {
Intent intent = new Intent(action); Intent intent = new Intent(action);
intent.setData(downloadUri); intent.setData(downloadUri);
@ -168,7 +167,7 @@ public abstract class Installer {
if (!TextUtils.isEmpty(errorMessage)) { if (!TextUtils.isEmpty(errorMessage)) {
intent.putExtra(Installer.EXTRA_ERROR_MESSAGE, errorMessage); intent.putExtra(Installer.EXTRA_ERROR_MESSAGE, errorMessage);
} }
localBroadcastManager.sendBroadcast(intent); LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
} }
void sendBroadcastUninstall(String action, String errorMessage) { void sendBroadcastUninstall(String action, String errorMessage) {
@ -193,7 +192,7 @@ public abstract class Installer {
if (!TextUtils.isEmpty(errorMessage)) { if (!TextUtils.isEmpty(errorMessage)) {
intent.putExtra(Installer.EXTRA_ERROR_MESSAGE, errorMessage); intent.putExtra(Installer.EXTRA_ERROR_MESSAGE, errorMessage);
} }
localBroadcastManager.sendBroadcast(intent); LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
} }
/** /**

View File

@ -308,8 +308,6 @@ public class PrivilegedInstaller extends Installer {
@Override @Override
protected void installPackageInternal(final Uri localApkUri, final Uri downloadUri, Apk apk) { protected void installPackageInternal(final Uri localApkUri, final Uri downloadUri, Apk apk) {
sendBroadcastInstall(downloadUri, Installer.ACTION_INSTALL_STARTED);
ServiceConnection mServiceConnection = new ServiceConnection() { ServiceConnection mServiceConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName name, IBinder service) { public void onServiceConnected(ComponentName name, IBinder service) {
IPrivilegedService privService = IPrivilegedService.Stub.asInterface(service); IPrivilegedService privService = IPrivilegedService.Stub.asInterface(service);