Installer: define all methods as abstract that need to be implemented in subclasses

This commit is contained in:
Dominik Schürmann 2014-05-11 02:13:27 +02:00
parent 04577d213c
commit df696ed81e
6 changed files with 44 additions and 32 deletions

View File

@ -20,6 +20,7 @@
package org.fdroid.fdroid.installer; package org.fdroid.fdroid.installer;
import java.io.File; import java.io.File;
import java.util.List;
import android.app.Activity; import android.app.Activity;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
@ -49,9 +50,7 @@ public class DefaultInstaller extends Installer {
private static final int REQUEST_CODE_DELETE = 1; private static final int REQUEST_CODE_DELETE = 1;
@Override @Override
public void installPackage(File apkFile) throws AndroidNotCompatibleException { public void installPackageInternal(File apkFile) throws AndroidNotCompatibleException {
super.installPackage(apkFile);
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),
@ -64,9 +63,7 @@ public class DefaultInstaller extends Installer {
} }
@Override @Override
public void deletePackage(String packageName) throws AndroidNotCompatibleException { public void deletePackageInternal(String packageName) throws AndroidNotCompatibleException {
super.deletePackage(packageName);
PackageInfo pkgInfo = null; PackageInfo pkgInfo = null;
try { try {
pkgInfo = mPm.getPackageInfo(packageName, 0); pkgInfo = mPm.getPackageInfo(packageName, 0);
@ -109,4 +106,10 @@ public class DefaultInstaller extends Installer {
return false; return false;
} }
@Override
protected void installPackageInternal(List<File> apkFiles) throws AndroidNotCompatibleException {
// TODO Auto-generated method stub
}
} }

View File

@ -20,6 +20,7 @@
package org.fdroid.fdroid.installer; package org.fdroid.fdroid.installer;
import java.io.File; import java.io.File;
import java.util.List;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.Activity; import android.app.Activity;
@ -53,9 +54,7 @@ public class DefaultInstallerSdk14 extends Installer {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
public void installPackage(File apkFile) throws AndroidNotCompatibleException { public void installPackageInternal(File apkFile) throws AndroidNotCompatibleException {
super.installPackage(apkFile);
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));
@ -76,9 +75,7 @@ public class DefaultInstallerSdk14 extends Installer {
} }
@Override @Override
public void deletePackage(String packageName) throws AndroidNotCompatibleException { public void deletePackageInternal(String packageName) throws AndroidNotCompatibleException {
super.deletePackage(packageName);
PackageInfo pkgInfo = null; PackageInfo pkgInfo = null;
try { try {
pkgInfo = mPm.getPackageInfo(packageName, 0); pkgInfo = mPm.getPackageInfo(packageName, 0);
@ -138,4 +135,10 @@ public class DefaultInstallerSdk14 extends Installer {
return false; return false;
} }
@Override
protected void installPackageInternal(List<File> apkFiles) throws AndroidNotCompatibleException {
// TODO Auto-generated method stub
}
} }

View File

@ -77,7 +77,7 @@ abstract public class Installer {
public static final int OPERATION_INSTALL = 1; public static final int OPERATION_INSTALL = 1;
public static final int OPERATION_DELETE = 2; public static final int OPERATION_DELETE = 2;
public static final int ERROR_CODE_CANCELED = 1; public static final int ERROR_CODE_CANCELED = 1;
public static final int ERROR_CODE_OTHER = 2; public static final int ERROR_CODE_OTHER = 2;
@ -199,7 +199,7 @@ abstract public class Installer {
return; return;
} }
// extended class now actually installs the package installPackageInternal(apkFile);
} }
public void installPackage(List<File> apkFiles) throws AndroidNotCompatibleException { public void installPackage(List<File> apkFiles) throws AndroidNotCompatibleException {
@ -211,7 +211,7 @@ abstract public class Installer {
} }
} }
// extended class now actually installs the package installPackageInternal(apkFiles);
} }
public void deletePackage(String packageName) throws AndroidNotCompatibleException { public void deletePackage(String packageName) throws AndroidNotCompatibleException {
@ -223,9 +223,18 @@ abstract public class Installer {
return; return;
} }
// extended class now actually deletes the package deletePackageInternal(packageName);
} }
protected abstract void installPackageInternal(File apkFile)
throws AndroidNotCompatibleException;
protected abstract void installPackageInternal(List<File> apkFiles)
throws AndroidNotCompatibleException;
protected abstract void deletePackageInternal(String packageName)
throws AndroidNotCompatibleException;
public abstract boolean handleOnActivityResult(int requestCode, int resultCode, Intent data); public abstract boolean handleOnActivityResult(int requestCode, int resultCode, Intent data);
public abstract boolean supportsUnattendedOperations(); public abstract boolean supportsUnattendedOperations();

View File

@ -52,9 +52,7 @@ public class RootInstaller extends Installer {
} }
@Override @Override
public void installPackage(final File apkFile) throws AndroidNotCompatibleException { public void installPackageInternal(final File apkFile) throws AndroidNotCompatibleException {
super.installPackage(apkFile);
rootSession = createShellBuilder().open(new Shell.OnCommandResultListener() { rootSession = createShellBuilder().open(new Shell.OnCommandResultListener() {
// Callback to report whether the shell was successfully // Callback to report whether the shell was successfully
@ -77,9 +75,7 @@ public class RootInstaller extends Installer {
} }
@Override @Override
public void installPackage(final List<File> apkFiles) throws AndroidNotCompatibleException { public void installPackageInternal(final List<File> apkFiles) throws AndroidNotCompatibleException {
super.installPackage(apkFiles);
rootSession = createShellBuilder().open(new Shell.OnCommandResultListener() { rootSession = createShellBuilder().open(new Shell.OnCommandResultListener() {
// Callback to report whether the shell was successfully // Callback to report whether the shell was successfully
@ -102,9 +98,7 @@ public class RootInstaller extends Installer {
} }
@Override @Override
public void deletePackage(final String packageName) throws AndroidNotCompatibleException { public void deletePackageInternal(final String packageName) throws AndroidNotCompatibleException {
super.deletePackage(packageName);
rootSession = createShellBuilder().open(new Shell.OnCommandResultListener() { rootSession = createShellBuilder().open(new Shell.OnCommandResultListener() {
// Callback to report whether the shell was successfully // Callback to report whether the shell was successfully

View File

@ -21,6 +21,7 @@ package org.fdroid.fdroid.installer;
import java.io.File; import java.io.File;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.List;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -124,9 +125,7 @@ public class SystemPermissionInstaller extends Installer {
} }
@Override @Override
public void installPackage(File apkFile) throws AndroidNotCompatibleException { public void installPackageInternal(File apkFile) throws AndroidNotCompatibleException {
super.installPackage(apkFile);
Uri packageURI = Uri.fromFile(apkFile); Uri packageURI = Uri.fromFile(apkFile);
try { try {
mInstallMethod.invoke(mPm, new Object[] { mInstallMethod.invoke(mPm, new Object[] {
@ -138,9 +137,7 @@ public class SystemPermissionInstaller extends Installer {
} }
@Override @Override
public void deletePackage(String packageName) throws AndroidNotCompatibleException { public void deletePackageInternal(String packageName) throws AndroidNotCompatibleException {
super.deletePackage(packageName);
try { try {
mDeleteMethod.invoke(mPm, new Object[] { mDeleteMethod.invoke(mPm, new Object[] {
packageName, mDeleteObserver, 0 packageName, mDeleteObserver, 0
@ -466,4 +463,10 @@ public class SystemPermissionInstaller extends Installer {
* failed to delete the package since the user is restricted. * failed to delete the package since the user is restricted.
*/ */
public static final int DELETE_FAILED_USER_RESTRICTED = -3; public static final int DELETE_FAILED_USER_RESTRICTED = -3;
@Override
protected void installPackageInternal(List<File> apkFiles) throws AndroidNotCompatibleException {
// TODO Auto-generated method stub
}
} }

View File

@ -60,7 +60,7 @@ public class CanUpdateAppsFragment extends AppListFragment {
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
mUpdateAllButton.setOnClickListener(new OnClickListener() { mUpdateAllButton.setOnClickListener(new OnClickListener() {
@Override @Override