convert Installer's Exception into generic InstallFailedException
AndroidNotCompatibleException is not used for anything specific right now, and in the process of adding verification to the start of the install process, there will be other kinds of failures. So convert that Exception into a general usage InstallFailedException.
This commit is contained in:
parent
0b8796e56f
commit
d07c8b5d74
@ -87,7 +87,7 @@ import org.fdroid.fdroid.data.InstalledAppProvider;
|
|||||||
import org.fdroid.fdroid.data.Repo;
|
import org.fdroid.fdroid.data.Repo;
|
||||||
import org.fdroid.fdroid.data.RepoProvider;
|
import org.fdroid.fdroid.data.RepoProvider;
|
||||||
import org.fdroid.fdroid.installer.Installer;
|
import org.fdroid.fdroid.installer.Installer;
|
||||||
import org.fdroid.fdroid.installer.Installer.AndroidNotCompatibleException;
|
import org.fdroid.fdroid.installer.Installer.InstallFailedException;
|
||||||
import org.fdroid.fdroid.installer.Installer.InstallerCallback;
|
import org.fdroid.fdroid.installer.Installer.InstallerCallback;
|
||||||
import org.fdroid.fdroid.net.ApkDownloader;
|
import org.fdroid.fdroid.net.ApkDownloader;
|
||||||
import org.fdroid.fdroid.net.Downloader;
|
import org.fdroid.fdroid.net.Downloader;
|
||||||
@ -501,11 +501,18 @@ public class AppDetails extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the install process one the download is complete.
|
||||||
|
*/
|
||||||
private final BroadcastReceiver completeReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver completeReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
File localFile = new File(intent.getStringExtra(Downloader.EXTRA_DOWNLOAD_PATH));
|
File localFile = new File(intent.getStringExtra(Downloader.EXTRA_DOWNLOAD_PATH));
|
||||||
installApk(localFile);
|
try {
|
||||||
|
installer.installPackage(localFile, app.packageName);
|
||||||
|
} catch (InstallFailedException e) {
|
||||||
|
Log.e(TAG, "Android not compatible with this Installer!", e);
|
||||||
|
}
|
||||||
cleanUpFinishedDownload();
|
cleanUpFinishedDownload();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -852,18 +859,10 @@ public class AppDetails extends AppCompatActivity {
|
|||||||
headerFragment.startProgress();
|
headerFragment.startProgress();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void installApk(File file) {
|
|
||||||
try {
|
|
||||||
installer.installPackage(file, app.packageName);
|
|
||||||
} catch (AndroidNotCompatibleException e) {
|
|
||||||
Log.e(TAG, "Android not compatible with this Installer!", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeApk(String packageName) {
|
public void removeApk(String packageName) {
|
||||||
try {
|
try {
|
||||||
installer.deletePackage(packageName);
|
installer.deletePackage(packageName);
|
||||||
} catch (AndroidNotCompatibleException e) {
|
} catch (InstallFailedException e) {
|
||||||
Log.e(TAG, "Android not compatible with this Installer!", e);
|
Log.e(TAG, "Android not compatible with this Installer!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ public class DefaultInstaller extends Installer {
|
|||||||
private final Activity mActivity;
|
private final Activity mActivity;
|
||||||
|
|
||||||
public DefaultInstaller(Activity activity, PackageManager pm, InstallerCallback callback)
|
public DefaultInstaller(Activity activity, PackageManager pm, InstallerCallback callback)
|
||||||
throws AndroidNotCompatibleException {
|
throws InstallFailedException {
|
||||||
super(activity, pm, callback);
|
super(activity, pm, callback);
|
||||||
this.mActivity = activity;
|
this.mActivity = activity;
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ public class DefaultInstaller extends Installer {
|
|||||||
private static final int REQUEST_CODE_DELETE = 1;
|
private static final int REQUEST_CODE_DELETE = 1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void installPackageInternal(File apkFile) throws AndroidNotCompatibleException {
|
protected void installPackageInternal(File apkFile) throws InstallFailedException {
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.setAction(Intent.ACTION_VIEW);
|
intent.setAction(Intent.ACTION_VIEW);
|
||||||
intent.setDataAndType(Uri.fromFile(apkFile),
|
intent.setDataAndType(Uri.fromFile(apkFile),
|
||||||
@ -56,12 +56,12 @@ public class DefaultInstaller extends Installer {
|
|||||||
try {
|
try {
|
||||||
mActivity.startActivityForResult(intent, REQUEST_CODE_INSTALL);
|
mActivity.startActivityForResult(intent, REQUEST_CODE_INSTALL);
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
throw new AndroidNotCompatibleException(e);
|
throw new InstallFailedException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void deletePackageInternal(String packageName) throws AndroidNotCompatibleException {
|
protected void deletePackageInternal(String packageName) throws InstallFailedException {
|
||||||
try {
|
try {
|
||||||
PackageInfo pkgInfo = mPm.getPackageInfo(packageName, 0);
|
PackageInfo pkgInfo = mPm.getPackageInfo(packageName, 0);
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ public class DefaultInstaller extends Installer {
|
|||||||
try {
|
try {
|
||||||
mActivity.startActivityForResult(intent, REQUEST_CODE_DELETE);
|
mActivity.startActivityForResult(intent, REQUEST_CODE_DELETE);
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
throw new AndroidNotCompatibleException(e);
|
throw new InstallFailedException(e);
|
||||||
}
|
}
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
// already checked in super class
|
// already checked in super class
|
||||||
|
@ -42,7 +42,7 @@ public class DefaultSdk14Installer extends Installer {
|
|||||||
private final Activity mActivity;
|
private final Activity mActivity;
|
||||||
|
|
||||||
public DefaultSdk14Installer(Activity activity, PackageManager pm, InstallerCallback callback)
|
public DefaultSdk14Installer(Activity activity, PackageManager pm, InstallerCallback callback)
|
||||||
throws AndroidNotCompatibleException {
|
throws InstallFailedException {
|
||||||
super(activity, pm, callback);
|
super(activity, pm, callback);
|
||||||
this.mActivity = activity;
|
this.mActivity = activity;
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ public class DefaultSdk14Installer extends Installer {
|
|||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
protected void installPackageInternal(File apkFile) throws AndroidNotCompatibleException {
|
protected void installPackageInternal(File apkFile) throws InstallFailedException {
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.setAction(Intent.ACTION_INSTALL_PACKAGE);
|
intent.setAction(Intent.ACTION_INSTALL_PACKAGE);
|
||||||
intent.setData(Uri.fromFile(apkFile));
|
intent.setData(Uri.fromFile(apkFile));
|
||||||
@ -68,12 +68,12 @@ public class DefaultSdk14Installer extends Installer {
|
|||||||
try {
|
try {
|
||||||
mActivity.startActivityForResult(intent, REQUEST_CODE_INSTALL);
|
mActivity.startActivityForResult(intent, REQUEST_CODE_INSTALL);
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
throw new AndroidNotCompatibleException(e);
|
throw new InstallFailedException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void deletePackageInternal(String packageName) throws AndroidNotCompatibleException {
|
protected void deletePackageInternal(String packageName) throws InstallFailedException {
|
||||||
try {
|
try {
|
||||||
PackageInfo pkgInfo = mPm.getPackageInfo(packageName, 0);
|
PackageInfo pkgInfo = mPm.getPackageInfo(packageName, 0);
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ public class DefaultSdk14Installer extends Installer {
|
|||||||
try {
|
try {
|
||||||
mActivity.startActivityForResult(intent, REQUEST_CODE_DELETE);
|
mActivity.startActivityForResult(intent, REQUEST_CODE_DELETE);
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
throw new AndroidNotCompatibleException(e);
|
throw new InstallFailedException(e);
|
||||||
}
|
}
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
// already checked in super class
|
// already checked in super class
|
||||||
|
@ -49,11 +49,15 @@ public abstract class Installer {
|
|||||||
* RootInstaller or due to an incompatible Android version in case of
|
* RootInstaller or due to an incompatible Android version in case of
|
||||||
* SystemPermissionInstaller
|
* SystemPermissionInstaller
|
||||||
*/
|
*/
|
||||||
public static class AndroidNotCompatibleException extends Exception {
|
public static class InstallFailedException extends Exception {
|
||||||
|
|
||||||
private static final long serialVersionUID = -8343133906463328027L;
|
private static final long serialVersionUID = -8343133906463328027L;
|
||||||
|
|
||||||
public AndroidNotCompatibleException(Throwable cause) {
|
public InstallFailedException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InstallFailedException(Throwable cause) {
|
||||||
super(cause);
|
super(cause);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,7 +82,7 @@ public abstract class Installer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Installer(Context context, PackageManager pm, InstallerCallback callback)
|
Installer(Context context, PackageManager pm, InstallerCallback callback)
|
||||||
throws AndroidNotCompatibleException {
|
throws InstallFailedException {
|
||||||
this.mContext = context;
|
this.mContext = context;
|
||||||
this.mPm = pm;
|
this.mPm = pm;
|
||||||
this.mCallback = callback;
|
this.mCallback = callback;
|
||||||
@ -104,7 +108,7 @@ public abstract class Installer {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
return new PrivilegedInstaller(activity, pm, callback);
|
return new PrivilegedInstaller(activity, pm, callback);
|
||||||
} catch (AndroidNotCompatibleException e) {
|
} catch (InstallFailedException e) {
|
||||||
Log.e(TAG, "Android not compatible with SystemInstaller!", e);
|
Log.e(TAG, "Android not compatible with SystemInstaller!", e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -119,7 +123,7 @@ public abstract class Installer {
|
|||||||
Utils.debugLog(TAG, "try default installer for Android >= 4");
|
Utils.debugLog(TAG, "try default installer for Android >= 4");
|
||||||
|
|
||||||
return new DefaultSdk14Installer(activity, pm, callback);
|
return new DefaultSdk14Installer(activity, pm, callback);
|
||||||
} catch (AndroidNotCompatibleException e) {
|
} catch (InstallFailedException e) {
|
||||||
Log.e(TAG, "Android not compatible with DefaultInstallerSdk14!", e);
|
Log.e(TAG, "Android not compatible with DefaultInstallerSdk14!", e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -128,7 +132,7 @@ public abstract class Installer {
|
|||||||
Utils.debugLog(TAG, "try default installer for Android < 4");
|
Utils.debugLog(TAG, "try default installer for Android < 4");
|
||||||
|
|
||||||
return new DefaultInstaller(activity, pm, callback);
|
return new DefaultInstaller(activity, pm, callback);
|
||||||
} catch (AndroidNotCompatibleException e) {
|
} catch (InstallFailedException e) {
|
||||||
Log.e(TAG, "Android not compatible with DefaultInstaller!", e);
|
Log.e(TAG, "Android not compatible with DefaultInstaller!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,7 +141,7 @@ public abstract class Installer {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void installPackage(File apkFile, String packageName) throws AndroidNotCompatibleException {
|
public void installPackage(File apkFile, String packageName) throws InstallFailedException {
|
||||||
// check if file exists...
|
// check if file exists...
|
||||||
if (!apkFile.exists()) {
|
if (!apkFile.exists()) {
|
||||||
Log.e(TAG, "Couldn't find file " + apkFile + " to install.");
|
Log.e(TAG, "Couldn't find file " + apkFile + " to install.");
|
||||||
@ -172,7 +176,7 @@ public abstract class Installer {
|
|||||||
installPackageInternal(apkFile);
|
installPackageInternal(apkFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deletePackage(String packageName) throws AndroidNotCompatibleException {
|
public void deletePackage(String packageName) throws InstallFailedException {
|
||||||
// check if package exists before proceeding...
|
// check if package exists before proceeding...
|
||||||
try {
|
try {
|
||||||
mPm.getPackageInfo(packageName, 0);
|
mPm.getPackageInfo(packageName, 0);
|
||||||
@ -201,10 +205,10 @@ public abstract class Installer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void installPackageInternal(File apkFile)
|
protected abstract void installPackageInternal(File apkFile)
|
||||||
throws AndroidNotCompatibleException;
|
throws InstallFailedException;
|
||||||
|
|
||||||
protected abstract void deletePackageInternal(String packageName)
|
protected abstract void deletePackageInternal(String packageName)
|
||||||
throws AndroidNotCompatibleException;
|
throws InstallFailedException;
|
||||||
|
|
||||||
public abstract boolean handleOnActivityResult(int requestCode, int resultCode, Intent data);
|
public abstract boolean handleOnActivityResult(int requestCode, int resultCode, Intent data);
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ public class PrivilegedInstaller extends Installer {
|
|||||||
public static final int IS_EXTENSION_INSTALLED_PERMISSIONS_PROBLEM = 3;
|
public static final int IS_EXTENSION_INSTALLED_PERMISSIONS_PROBLEM = 3;
|
||||||
|
|
||||||
public PrivilegedInstaller(Activity activity, PackageManager pm,
|
public PrivilegedInstaller(Activity activity, PackageManager pm,
|
||||||
InstallerCallback callback) throws AndroidNotCompatibleException {
|
InstallerCallback callback) throws InstallFailedException {
|
||||||
super(activity, pm, callback);
|
super(activity, pm, callback);
|
||||||
this.mActivity = activity;
|
this.mActivity = activity;
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ public class PrivilegedInstaller extends Installer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void installPackageInternal(File apkFile) throws AndroidNotCompatibleException {
|
protected void installPackageInternal(File apkFile) throws InstallFailedException {
|
||||||
Uri packageUri = Uri.fromFile(apkFile);
|
Uri packageUri = Uri.fromFile(apkFile);
|
||||||
int count = newPermissionCount(packageUri);
|
int count = newPermissionCount(packageUri);
|
||||||
if (count < 0) {
|
if (count < 0) {
|
||||||
@ -171,7 +171,7 @@ public class PrivilegedInstaller extends Installer {
|
|||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
doInstallPackageInternal(packageUri);
|
doInstallPackageInternal(packageUri);
|
||||||
} catch (AndroidNotCompatibleException e) {
|
} catch (InstallFailedException e) {
|
||||||
mCallback.onError(InstallerCallback.OPERATION_INSTALL,
|
mCallback.onError(InstallerCallback.OPERATION_INSTALL,
|
||||||
InstallerCallback.ERROR_CODE_OTHER);
|
InstallerCallback.ERROR_CODE_OTHER);
|
||||||
}
|
}
|
||||||
@ -194,7 +194,7 @@ public class PrivilegedInstaller extends Installer {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doInstallPackageInternal(final Uri packageURI) throws AndroidNotCompatibleException {
|
private void doInstallPackageInternal(final Uri packageURI) throws InstallFailedException {
|
||||||
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);
|
||||||
@ -238,7 +238,7 @@ public class PrivilegedInstaller extends Installer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void deletePackageInternal(final String packageName)
|
protected void deletePackageInternal(final String packageName)
|
||||||
throws AndroidNotCompatibleException {
|
throws InstallFailedException {
|
||||||
ApplicationInfo appInfo;
|
ApplicationInfo appInfo;
|
||||||
try {
|
try {
|
||||||
appInfo = mPm.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
|
appInfo = mPm.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
|
||||||
@ -273,7 +273,7 @@ public class PrivilegedInstaller extends Installer {
|
|||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
try {
|
try {
|
||||||
doDeletePackageInternal(packageName);
|
doDeletePackageInternal(packageName);
|
||||||
} catch (AndroidNotCompatibleException e) {
|
} catch (InstallFailedException e) {
|
||||||
mCallback.onError(InstallerCallback.OPERATION_DELETE,
|
mCallback.onError(InstallerCallback.OPERATION_DELETE,
|
||||||
InstallerCallback.ERROR_CODE_OTHER);
|
InstallerCallback.ERROR_CODE_OTHER);
|
||||||
}
|
}
|
||||||
@ -293,7 +293,7 @@ public class PrivilegedInstaller extends Installer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void doDeletePackageInternal(final String packageName)
|
private void doDeletePackageInternal(final String packageName)
|
||||||
throws AndroidNotCompatibleException {
|
throws InstallFailedException {
|
||||||
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);
|
||||||
@ -344,7 +344,7 @@ public class PrivilegedInstaller extends Installer {
|
|||||||
final Uri packageUri = data.getData();
|
final Uri packageUri = data.getData();
|
||||||
try {
|
try {
|
||||||
doInstallPackageInternal(packageUri);
|
doInstallPackageInternal(packageUri);
|
||||||
} catch (AndroidNotCompatibleException e) {
|
} catch (InstallFailedException e) {
|
||||||
mCallback.onError(InstallerCallback.OPERATION_INSTALL,
|
mCallback.onError(InstallerCallback.OPERATION_INSTALL,
|
||||||
InstallerCallback.ERROR_CODE_OTHER);
|
InstallerCallback.ERROR_CODE_OTHER);
|
||||||
}
|
}
|
||||||
|
@ -814,7 +814,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}).installPackage(apkFile, packageName);
|
}).installPackage(apkFile, packageName);
|
||||||
localBroadcastManager.unregisterReceiver(downloadCompleteReceiver);
|
localBroadcastManager.unregisterReceiver(downloadCompleteReceiver);
|
||||||
} catch (Installer.AndroidNotCompatibleException e) {
|
} catch (Installer.InstallFailedException e) {
|
||||||
// TODO: Handle exception properly
|
// TODO: Handle exception properly
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user