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
This commit is contained in:
parent
66612e906c
commit
bbd77c5b79
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Chirayu Desai <chirayudesai1@gmail.com>
|
||||||
|
*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -22,6 +22,7 @@ package org.fdroid.fdroid.installer;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import org.fdroid.fdroid.Utils;
|
import org.fdroid.fdroid.Utils;
|
||||||
import org.fdroid.fdroid.data.Apk;
|
import org.fdroid.fdroid.data.Apk;
|
||||||
@ -40,12 +41,17 @@ public class InstallerFactory {
|
|||||||
* @return instance of an Installer
|
* @return instance of an Installer
|
||||||
*/
|
*/
|
||||||
public static Installer create(Context context, Apk apk) {
|
public static Installer create(Context context, Apk apk) {
|
||||||
|
Log.d(TAG, "Apk.apkName " + apk.apkName);
|
||||||
if (apk == null || TextUtils.isEmpty(apk.packageName)) {
|
if (apk == null || TextUtils.isEmpty(apk.packageName)) {
|
||||||
throw new IllegalArgumentException("Apk.packageName must not be empty: " + apk);
|
throw new IllegalArgumentException("Apk.packageName must not be empty: " + apk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Installer installer;
|
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");
|
Utils.debugLog(TAG, "privileged extension correctly installed -> PrivilegedInstaller");
|
||||||
installer = new PrivilegedInstaller(context, apk);
|
installer = new PrivilegedInstaller(context, apk);
|
||||||
} else if (apk.packageName.equals(PrivilegedInstaller.PRIVILEGED_EXTENSION_PACKAGE_NAME)) {
|
} else if (apk.packageName.equals(PrivilegedInstaller.PRIVILEGED_EXTENSION_PACKAGE_NAME)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user