Code cleanup and simplifications

This commit is contained in:
Dominik Schürmann 2015-01-19 15:45:23 +01:00 committed by Hans-Christoph Steiner
parent 70b392996c
commit 521218a45c
4 changed files with 26 additions and 38 deletions

View File

@ -64,26 +64,24 @@ public class DefaultInstaller extends Installer {
@Override
protected void installPackageInternal(List<File> apkFiles) throws AndroidNotCompatibleException {
// TODO Auto-generated method stub
// not used
}
@Override
protected void deletePackageInternal(String packageName) throws AndroidNotCompatibleException {
PackageInfo pkgInfo = null;
try {
pkgInfo = mPm.getPackageInfo(packageName, 0);
PackageInfo pkgInfo = mPm.getPackageInfo(packageName, 0);
Uri uri = Uri.fromParts("package", pkgInfo.packageName, null);
Intent intent = new Intent(Intent.ACTION_DELETE, uri);
try {
mActivity.startActivityForResult(intent, REQUEST_CODE_DELETE);
} catch (ActivityNotFoundException e) {
throw new AndroidNotCompatibleException(e);
}
} catch (NameNotFoundException e) {
// already checked in super class
}
Uri uri = Uri.fromParts("package", pkgInfo.packageName, null);
Intent intent = new Intent(Intent.ACTION_DELETE, uri);
try {
mActivity.startActivityForResult(intent, REQUEST_CODE_DELETE);
} catch (ActivityNotFoundException e) {
throw new AndroidNotCompatibleException(e);
}
}
@Override

View File

@ -76,27 +76,25 @@ public class DefaultInstallerSdk14 extends Installer {
@Override
protected void installPackageInternal(List<File> apkFiles) throws AndroidNotCompatibleException {
// TODO Auto-generated method stub
// not used
}
@Override
protected void deletePackageInternal(String packageName) throws AndroidNotCompatibleException {
PackageInfo pkgInfo = null;
try {
pkgInfo = mPm.getPackageInfo(packageName, 0);
PackageInfo pkgInfo = mPm.getPackageInfo(packageName, 0);
Uri uri = Uri.fromParts("package", pkgInfo.packageName, null);
Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, uri);
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
try {
mActivity.startActivityForResult(intent, REQUEST_CODE_DELETE);
} catch (ActivityNotFoundException e) {
throw new AndroidNotCompatibleException(e);
}
} catch (NameNotFoundException e) {
// already checked in super class
}
Uri uri = Uri.fromParts("package", pkgInfo.packageName, null);
Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, uri);
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
try {
mActivity.startActivityForResult(intent, REQUEST_CODE_DELETE);
} catch (ActivityNotFoundException e) {
throw new AndroidNotCompatibleException(e);
}
}
@Override

View File

@ -190,11 +190,7 @@ abstract public class Installer {
(checkInstallPermission == PackageManager.PERMISSION_GRANTED
&& checkDeletePermission == PackageManager.PERMISSION_GRANTED);
if (permissionsGranted) {
return true;
} else {
return false;
}
return permissionsGranted;
}
public void installPackage(File apkFile) throws AndroidNotCompatibleException {

View File

@ -128,9 +128,8 @@ public class SystemInstaller extends Installer {
protected void installPackageInternal(File apkFile) throws AndroidNotCompatibleException {
Uri packageURI = Uri.fromFile(apkFile);
try {
mInstallMethod.invoke(mPm, new Object[] {
packageURI, mInstallObserver, INSTALL_REPLACE_EXISTING, null
});
mInstallMethod.invoke(mPm, packageURI, mInstallObserver,
INSTALL_REPLACE_EXISTING, null);
} catch (Exception e) {
throw new AndroidNotCompatibleException(e);
}
@ -138,16 +137,13 @@ public class SystemInstaller extends Installer {
@Override
protected void installPackageInternal(List<File> apkFiles) throws AndroidNotCompatibleException {
// TODO Auto-generated method stub
// not used
}
@Override
protected void deletePackageInternal(String packageName) throws AndroidNotCompatibleException {
try {
mDeleteMethod.invoke(mPm, new Object[] {
packageName, mDeleteObserver, 0
});
mDeleteMethod.invoke(mPm, packageName, mDeleteObserver, 0);
} catch (Exception e) {
throw new AndroidNotCompatibleException(e);
}