Installer methods no longer need to accept Apk as an argument
Since e69a6d5a8f24e7745516001f58bee49e05f2ea9e, the Apk instance is provided in the constructor and is available as a final instance variable. No need to pass it around. Thanks to @pserwylo for spotting this.
This commit is contained in:
parent
79df0a1f9b
commit
372b28a71a
@ -942,7 +942,7 @@ public class AppDetails extends AppCompatActivity {
|
||||
|
||||
private void initiateInstall(Apk apk) {
|
||||
Installer installer = InstallerFactory.create(this, apk);
|
||||
Intent intent = installer.getPermissionScreen(apk);
|
||||
Intent intent = installer.getPermissionScreen();
|
||||
if (intent != null) {
|
||||
// permission screen required
|
||||
Utils.debugLog(TAG, "permission screen required");
|
||||
@ -965,7 +965,7 @@ public class AppDetails extends AppCompatActivity {
|
||||
private void uninstallApk() {
|
||||
Apk apk = app.installedApk;
|
||||
Installer installer = InstallerFactory.create(this, apk);
|
||||
Intent intent = installer.getUninstallScreen(apk);
|
||||
Intent intent = installer.getUninstallScreen();
|
||||
if (intent != null) {
|
||||
// uninstall screen required
|
||||
Utils.debugLog(TAG, "screen screen required");
|
||||
|
@ -44,7 +44,7 @@ public class DefaultInstaller extends Installer {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void installPackageInternal(Uri localApkUri, Uri downloadUri, Apk apk) {
|
||||
protected void installPackageInternal(Uri localApkUri, Uri downloadUri) {
|
||||
|
||||
Intent installIntent = new Intent(context, DefaultInstallerActivity.class);
|
||||
installIntent.setAction(DefaultInstallerActivity.ACTION_INSTALL_PACKAGE);
|
||||
|
@ -45,7 +45,7 @@ public class ExtensionInstaller extends Installer {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void installPackageInternal(Uri localApkUri, Uri downloadUri, Apk apk) {
|
||||
protected void installPackageInternal(Uri localApkUri, Uri downloadUri) {
|
||||
// extension must be signed with the same public key as main F-Droid
|
||||
// NOTE: Disabled for debug builds to be able to test official extension from repo
|
||||
ApkSignatureVerifier signatureVerifier = new ApkSignatureVerifier(context);
|
||||
|
@ -83,17 +83,16 @@ public abstract class Installer {
|
||||
/**
|
||||
* Returns permission screen for given apk.
|
||||
*
|
||||
* @param apk instance of Apk
|
||||
* @return Intent with Activity to show required permissions.
|
||||
* Returns null if Installer handles that on itself, e.g., with DefaultInstaller,
|
||||
* or if no new permissions have been introduced during an update
|
||||
*/
|
||||
public Intent getPermissionScreen(Apk apk) {
|
||||
public Intent getPermissionScreen() {
|
||||
if (!isUnattended()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int count = newPermissionCount(apk);
|
||||
int count = newPermissionCount();
|
||||
if (count == 0) {
|
||||
// no permission screen needed!
|
||||
return null;
|
||||
@ -105,7 +104,7 @@ public abstract class Installer {
|
||||
return intent;
|
||||
}
|
||||
|
||||
private int newPermissionCount(Apk apk) {
|
||||
private int newPermissionCount() {
|
||||
boolean supportsRuntimePermissions = apk.targetSdkVersion >= 23;
|
||||
if (supportsRuntimePermissions) {
|
||||
return 0;
|
||||
@ -129,12 +128,11 @@ public abstract class Installer {
|
||||
* Returns an Intent to start a dialog wrapped in an activity
|
||||
* for uninstall confirmation.
|
||||
*
|
||||
* @param apk {@link Apk} instance of app to uninstall
|
||||
* @return Intent with activity for uninstall confirmation
|
||||
* Returns null if Installer handles that on itself, e.g.,
|
||||
* with DefaultInstaller.
|
||||
*/
|
||||
public Intent getUninstallScreen(Apk apk) {
|
||||
public Intent getUninstallScreen() {
|
||||
if (!isUnattended()) {
|
||||
return null;
|
||||
}
|
||||
@ -228,9 +226,8 @@ public abstract class Installer {
|
||||
* @param localApkUri points to the local copy of the APK to be installed
|
||||
* @param downloadUri serves as the unique ID for all actions related to the
|
||||
* installation of that specific APK
|
||||
* @param apk apk object of the app that should be installed
|
||||
*/
|
||||
public void installPackage(Uri localApkUri, Uri downloadUri, Apk apk) {
|
||||
public void installPackage(Uri localApkUri, Uri downloadUri) {
|
||||
try {
|
||||
// verify that permissions of the apk file match the ones from the apk object
|
||||
ApkVerifier apkVerifier = new ApkVerifier(context, localApkUri, apk);
|
||||
@ -248,7 +245,7 @@ public abstract class Installer {
|
||||
Log.e(TAG, e.getMessage(), e);
|
||||
Log.e(TAG, "Falling back to AOSP DefaultInstaller!");
|
||||
DefaultInstaller defaultInstaller = new DefaultInstaller(context, apk);
|
||||
defaultInstaller.installPackageInternal(localApkUri, downloadUri, apk);
|
||||
defaultInstaller.installPackageInternal(localApkUri, downloadUri);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -265,10 +262,10 @@ public abstract class Installer {
|
||||
return;
|
||||
}
|
||||
|
||||
installPackageInternal(sanitizedUri, downloadUri, apk);
|
||||
installPackageInternal(sanitizedUri, downloadUri);
|
||||
}
|
||||
|
||||
protected abstract void installPackageInternal(Uri localApkUri, Uri downloadUri, Apk apk);
|
||||
protected abstract void installPackageInternal(Uri localApkUri, Uri downloadUri);
|
||||
|
||||
/**
|
||||
* Uninstall app as defined by {@link Installer#apk} in
|
||||
|
@ -64,7 +64,7 @@ public class InstallerService extends IntentService {
|
||||
if (ACTION_INSTALL.equals(intent.getAction())) {
|
||||
Uri uri = intent.getData();
|
||||
Uri downloadUri = intent.getParcelableExtra(Installer.EXTRA_DOWNLOAD_URI);
|
||||
installer.installPackage(uri, downloadUri, apk);
|
||||
installer.installPackage(uri, downloadUri);
|
||||
} else if (ACTION_UNINSTALL.equals(intent.getAction())) {
|
||||
installer.uninstallPackage();
|
||||
}
|
||||
|
@ -307,7 +307,7 @@ public class PrivilegedInstaller extends Installer {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void installPackageInternal(final Uri localApkUri, final Uri downloadUri, Apk apk) {
|
||||
protected void installPackageInternal(final Uri localApkUri, final Uri downloadUri) {
|
||||
ServiceConnection mServiceConnection = new ServiceConnection() {
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
IPrivilegedService privService = IPrivilegedService.Stub.asInterface(service);
|
||||
|
Loading…
x
Reference in New Issue
Block a user