Better error handling in privileged installer

This commit is contained in:
Dominik Schürmann 2016-05-28 21:23:34 +03:00
parent bb273cd2f5
commit c5f9070370
2 changed files with 25 additions and 21 deletions

View File

@ -35,7 +35,7 @@ import org.fdroid.fdroid.Utils;
/** /**
* A transparent activity as a wrapper around AOSP's PackageInstaller Intents * A transparent activity as a wrapper around AOSP's PackageInstaller Intents
*/ */
public class AndroidInstallerActivity extends FragmentActivity { public class DefaultInstallerActivity extends FragmentActivity {
public static final String TAG = "AndroidInstallerAct"; public static final String TAG = "AndroidInstallerAct";
public static final String ACTION_INSTALL_PACKAGE = "org.fdroid.fdroid.INSTALL_PACKAGE"; public static final String ACTION_INSTALL_PACKAGE = "org.fdroid.fdroid.INSTALL_PACKAGE";

View File

@ -39,8 +39,6 @@ import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.privileged.IPrivilegedCallback; import org.fdroid.fdroid.privileged.IPrivilegedCallback;
import org.fdroid.fdroid.privileged.IPrivilegedService; import org.fdroid.fdroid.privileged.IPrivilegedService;
import java.io.File;
/** /**
* Installer based on using internal hidden APIs of the Android OS, which are * Installer based on using internal hidden APIs of the Android OS, which are
* protected by the permissions * protected by the permissions
@ -133,8 +131,7 @@ public class PrivilegedInstaller extends Installer {
synchronized (mutex) { synchronized (mutex) {
try { try {
mutex.wait(3000); mutex.wait(3000);
} catch (InterruptedException e) { } catch (InterruptedException ignored) {
// don't care
} }
} }
@ -147,7 +144,15 @@ public class PrivilegedInstaller extends Installer {
@Override @Override
protected void installPackage(final Uri uri, Uri originatingUri, String packageName) { protected void installPackage(final Uri uri, final Uri originatingUri, String packageName) {
final Uri sanitizedUri;
try {
sanitizedUri = Installer.prepareApkFile(mContext, uri, packageName);
} catch (Installer.InstallFailedException e) {
Log.e(TAG, "prepareApkFile failed", e);
return;
}
ServiceConnection mServiceConnection = new ServiceConnection() { ServiceConnection mServiceConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName name, IBinder service) { public void onServiceConnected(ComponentName name, IBinder service) {
@ -156,20 +161,20 @@ public class PrivilegedInstaller extends Installer {
IPrivilegedCallback callback = new IPrivilegedCallback.Stub() { IPrivilegedCallback callback = new IPrivilegedCallback.Stub() {
@Override @Override
public void handleResult(String packageName, int returnCode) throws RemoteException { public void handleResult(String packageName, int returnCode) throws RemoteException {
// TODO: propagate other return codes? // TODO: propagate other return codes!
if (returnCode == INSTALL_SUCCEEDED) { if (returnCode == INSTALL_SUCCEEDED) {
Utils.debugLog(TAG, "Install succeeded"); Utils.debugLog(TAG, "Install succeeded");
// mCallback.onSuccess(InstallerCallback.OPERATION_INSTALL); sendBroadcastInstall(uri, originatingUri, ACTION_INSTALL_COMPLETE);
} else { } else {
Log.e(TAG, "Install failed with returnCode " + returnCode); Log.e(TAG, "Install failed with returnCode " + returnCode);
// mCallback.onError(InstallerCallback.OPERATION_INSTALL, sendBroadcastInstall(uri, originatingUri, ACTION_INSTALL_INTERRUPTED,
// InstallerCallback.ERROR_CODE_OTHER); "Install failed with returnCode " + returnCode);
} }
} }
}; };
try { try {
privService.installPackage(uri, INSTALL_REPLACE_EXISTING, null, callback); privService.installPackage(sanitizedUri, INSTALL_REPLACE_EXISTING, null, callback);
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, "RemoteException", e); Log.e(TAG, "RemoteException", e);
} }
@ -201,8 +206,8 @@ public class PrivilegedInstaller extends Installer {
if (isSystem && !isUpdate) { if (isSystem && !isUpdate) {
// Cannot remove system apps unless we're uninstalling updates // Cannot remove system apps unless we're uninstalling updates
// mCallback.onError(InstallerCallback.OPERATION_DELETE, sendBroadcastUninstall(packageName, ACTION_UNINSTALL_INTERRUPTED,
// InstallerCallback.ERROR_CODE_OTHER); "Cannot remove system apps unless we're uninstalling updates");
return; return;
} }
@ -213,6 +218,7 @@ public class PrivilegedInstaller extends Installer {
messageId = R.string.uninstall_confirm; messageId = R.string.uninstall_confirm;
} }
// TODO: move this to methods in activity/ Installer with activity context!
final AlertDialog.Builder builder = new AlertDialog.Builder(mContext); final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setTitle(appInfo.loadLabel(mPm)); builder.setTitle(appInfo.loadLabel(mPm));
builder.setIcon(appInfo.loadIcon(mPm)); builder.setIcon(appInfo.loadIcon(mPm));
@ -223,8 +229,8 @@ public class PrivilegedInstaller extends Installer {
try { try {
doDeletePackageInternal(packageName); doDeletePackageInternal(packageName);
} catch (InstallFailedException e) { } catch (InstallFailedException e) {
// mCallback.onError(InstallerCallback.OPERATION_DELETE, sendBroadcastUninstall(packageName, ACTION_UNINSTALL_INTERRUPTED,
// InstallerCallback.ERROR_CODE_OTHER); "uninstall failed");
} }
} }
}); });
@ -233,8 +239,7 @@ public class PrivilegedInstaller extends Installer {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
dialog.cancel(); dialog.cancel();
// mCallback.onError(InstallerCallback.OPERATION_DELETE, sendBroadcastUninstall(packageName, ACTION_UNINSTALL_INTERRUPTED);
// InstallerCallback.ERROR_CODE_CANCELED);
} }
}); });
builder.setMessage(messageId); builder.setMessage(messageId);
@ -253,12 +258,11 @@ public class PrivilegedInstaller extends Installer {
// TODO: propagate other return codes? // TODO: propagate other return codes?
if (returnCode == DELETE_SUCCEEDED) { if (returnCode == DELETE_SUCCEEDED) {
Utils.debugLog(TAG, "Delete succeeded"); Utils.debugLog(TAG, "Delete succeeded");
sendBroadcastUninstall(packageName, ACTION_UNINSTALL_COMPLETE);
// mCallback.onSuccess(InstallerCallback.OPERATION_DELETE);
} else { } else {
Log.e(TAG, "Delete failed with returnCode " + returnCode); Log.e(TAG, "Delete failed with returnCode " + returnCode);
// mCallback.onError(InstallerCallback.OPERATION_DELETE, sendBroadcastUninstall(packageName, ACTION_UNINSTALL_INTERRUPTED,
// InstallerCallback.ERROR_CODE_OTHER); "Uninstall failed with returnCode " + returnCode);
} }
} }
}; };