@Override public void onCreate() { super.onCreate(); // get internal methods via reflection try { Class<?>[] installTypes = { Uri.class, IPackageInstallObserver.class, int.class, String.class, }; Class<?>[] deleteTypes = { String.class, IPackageDeleteObserver.class, int.class, }; PackageManager pm = getPackageManager(); mInstallMethod = pm.getClass().getMethod("installPackage", installTypes); mDeleteMethod = pm.getClass().getMethod("deletePackage", deleteTypes); } catch (NoSuchMethodException e) { Log.e(TAG, "Android not compatible!", e); stopSelf(); } }
/** * Silently uninstalls the app resides in the provided URI. * @param context - Application context. * @param packageName - App package name. */ public static void silentUninstallApp(Context context, String packageName) { if (packageName != null && packageName.contains(PACKAGE_PREFIX)) { packageName = packageName.replace(PACKAGE_PREFIX, ""); } final String _packageName = packageName; PackageManager pm = context.getPackageManager(); IPackageDeleteObserver observer = new IPackageDeleteObserver() { @Override public void packageDeleted(String s, int i) throws RemoteException { Log.d(TAG, _packageName + " deleted successfully."); } @Override public IBinder asBinder() { return null; } }; pm.deletePackage(packageName, observer, DELETE_ALL_USERS); }
public SystemInstaller(Context context, PackageManager pm, InstallerCallback callback) throws AndroidNotCompatibleException { super(context, pm, callback); // create internal callbacks mInstallObserver = new PackageInstallObserver(); mDeleteObserver = new PackageDeleteObserver(); try { Class<?>[] installTypes = new Class[] { Uri.class, IPackageInstallObserver.class, int.class, String.class }; Class<?>[] deleteTypes = new Class[] { String.class, IPackageDeleteObserver.class, int.class }; mInstallMethod = mPm.getClass().getMethod("installPackage", installTypes); mDeleteMethod = mPm.getClass().getMethod("deletePackage", deleteTypes); } catch (NoSuchMethodException e) { throw new AndroidNotCompatibleException(e); } }
public ApplicationManager(Context context) throws SecurityException, NoSuchMethodException { observer = new PackageInstallObserver(); observerdelete = new PackageDeleteObserver(); pm = context.getPackageManager(); Class<?>[] types = new Class[] {Uri.class, IPackageInstallObserver.class, int.class, String.class}; Class<?>[] uninstalltypes = new Class[] {String.class, IPackageDeleteObserver.class, int.class}; method = pm.getClass().getMethod("installPackage", types); uninstallmethod = pm.getClass().getMethod("deletePackage", uninstalltypes); }
public static void uninstallPackage(PackageManager pm, String pkg) { try { Method m = pm.getClass().getDeclaredMethod("deletePackage", String.class, IPackageDeleteObserver.class, int.class); m.invoke(pm, pkg, null, /* DELETE_ALL_USERS */ 2); } catch (Exception e) { Timber.e(e, "could not call deletePackage via reflection"); } }
/** @hide */ @Override public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) { mBase.deletePackage(packageName, observer, flags); }
/** @hide */ @RequiresPermission(Manifest.permission.DELETE_PACKAGES) @Override public void deletePackageAsUser(String packageName, IPackageDeleteObserver observer, int flags, int userId) { mBase.deletePackageAsUser(packageName, observer, flags, userId); }
@Override public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) { }