From bbd77c5b79076b4bc87fa81a3be6dc75119144fc Mon Sep 17 00:00:00 2001 From: Chirayu Desai Date: Thu, 27 Apr 2017 22:45:46 +0530 Subject: [PATCH] Add a DummyInstaller to handle non apk files * Avoids crashes when trying to treat non apk files, such as privileged extension ota update.zip as apks * Doesn't do anything at all for now. One issue with this is the app is always in the not installed state, so what would be appropriate here would be to change the text of the install button to download, and update that accrodingly. However that is outside of the scope of this change. TODO: Add toast indicating the user that they need to install manually, in case of OTA update.zip --- .../fdroid/installer/DummyInstaller.java | 69 +++++++++++++++++++ .../fdroid/installer/InstallerFactory.java | 8 ++- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/org/fdroid/fdroid/installer/DummyInstaller.java diff --git a/app/src/main/java/org/fdroid/fdroid/installer/DummyInstaller.java b/app/src/main/java/org/fdroid/fdroid/installer/DummyInstaller.java new file mode 100644 index 000000000..ee5658391 --- /dev/null +++ b/app/src/main/java/org/fdroid/fdroid/installer/DummyInstaller.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2017 Chirayu Desai + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 3 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +package org.fdroid.fdroid.installer; + +import android.content.Context; +import android.content.Intent; +import android.net.Uri; + +import org.fdroid.fdroid.data.Apk; + +public class DummyInstaller extends Installer { + + public DummyInstaller(Context context, Apk apk) { + super(context, apk); + } + + @Override + public Intent getPermissionScreen() { + return null; + } + + @Override + public Intent getUninstallScreen() { + return null; + } + + @Override + public void installPackage(Uri localApkUri, Uri downloadUri) { + // Do nothing + } + + @Override + protected void installPackageInternal(Uri localApkUri, Uri downloadUri) { + // Do nothing + } + + @Override + protected void uninstallPackage() { + // Do nothing + } + + @Override + protected boolean isUnattended() { + return false; + } + + @Override + protected boolean supportsContentUri() { + return false; + } + +} \ No newline at end of file diff --git a/app/src/main/java/org/fdroid/fdroid/installer/InstallerFactory.java b/app/src/main/java/org/fdroid/fdroid/installer/InstallerFactory.java index 885d03870..55dfa7a01 100644 --- a/app/src/main/java/org/fdroid/fdroid/installer/InstallerFactory.java +++ b/app/src/main/java/org/fdroid/fdroid/installer/InstallerFactory.java @@ -22,6 +22,7 @@ package org.fdroid.fdroid.installer; import android.content.Context; import android.text.TextUtils; +import android.util.Log; import org.fdroid.fdroid.Utils; import org.fdroid.fdroid.data.Apk; @@ -40,12 +41,17 @@ public class InstallerFactory { * @return instance of an Installer */ public static Installer create(Context context, Apk apk) { + Log.d(TAG, "Apk.apkName " + apk.apkName); if (apk == null || TextUtils.isEmpty(apk.packageName)) { throw new IllegalArgumentException("Apk.packageName must not be empty: " + apk); } + Installer installer; - if (PrivilegedInstaller.isDefault(context)) { + if (!apk.apkName.endsWith(".apk")) { + Utils.debugLog(TAG, "Using DummyInstaller for " + apk.apkName); + installer = new DummyInstaller(context, apk); + } else if (PrivilegedInstaller.isDefault(context)) { Utils.debugLog(TAG, "privileged extension correctly installed -> PrivilegedInstaller"); installer = new PrivilegedInstaller(context, apk); } else if (apk.packageName.equals(PrivilegedInstaller.PRIVILEGED_EXTENSION_PACKAGE_NAME)) {