卸载应用程序,默默地系统priveleges应用程序、系统、priveleges

2023-09-12 07:09:59 作者:\猥琐男变男神

我的应用程序具有系统priveleges。这将是内部的固件,现在它位于/系统/应用程序

My app have system priveleges. It will be inside firmware, now it's located at /system/app

我能够静默安装的应用程序与这篇文章

I was able to install apps silently with this post

install /卸载的APK编程(PackageManager VS意图)

示例应用程序,它的工作原理

http://paulononaka.word$p$pss.com/2011/07/02/how-to-install-a-application-in-background-on-android/

但我还是无法卸载应用同样的方式。我试图用reflecion像如安装例子。

But I still can't uninstall apps the same way. I tried to use reflecion like as in the installation example.

public ApplicationManager(Context context) throws SecurityException, NoSuchMethodException {

    observer = new PackageInstallObserver();
    pm = context.getPackageManager();

    Class<?>[] types = new Class[] {Uri.class, IPackageInstallObserver.class, int.class, String.class};
    Class<?>[] uninstalltypes = new Class[] {String.class, IPackageInstallObserver.class, int.class};
    method = pm.getClass().getMethod("installPackage", types);
    uninstallmethod = pm.getClass().getMethod("deletePackage", uninstalltypes);
}


public void uninstallPackage(String packagename) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
        uninstallmethod.invoke(pm, new Object[] {packagename, observer, 0});
    }
    public void installPackage(Uri apkFile) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
        method.invoke(pm, new Object[] {apkFile, observer, INSTALL_REPLACE_EXISTING, null});
    }

我添加uninstallPackage方法和编辑ApplicationManager方法。还是不能得到这个工作。

I have added uninstallPackage method and edited ApplicationManager method. Still cant get this working.

当我运行它,我得到没有找到方法(在调用deletePackage行)。

When I run it I get method not found (on the invoke "deletePackage" line).

在这里是行不通的我改变的项目: https://dl.dropbox.com/u/1928109/InstallInBackgroundSample.zip

下面是功能的描述:http://www.androidjavadoc.com/1.0_r1_src/android/content/pm/PackageManager.html#deletePackage(java.lang.String, android.content.pm.IPackageDeleteObserver,INT)

Here is an description of function: http://www.androidjavadoc.com/1.0_r1_src/android/content/pm/PackageManager.html#deletePackage(java.lang.String, android.content.pm.IPackageDeleteObserver, int)

参数都OK。好像我应该指定DeletePackageObserver类而不是InstallPackageObserver。但我不知道该怎么做(我没有这样的类)。

Parameters are ok. Seems like I should specify DeletePackageObserver class instead of InstallPackageObserver. But I don't know how to do that (I don't have such class).

感谢

推荐答案

下面是我做的:

ApplicationManager.java(更改部分):

private PackageInstallObserver observer;
private PackageDeleteObserver observerdelete;
private PackageManager pm;
private Method method;
private Method uninstallmethod;

 class PackageDeleteObserver extends IPackageDeleteObserver.Stub { 

    public void packageDeleted(String packageName, int returnCode) throws RemoteException {
        /*if (onInstalledPackaged != null) {
            onInstalledPackaged.packageInstalled(packageName, returnCode);
        }*/
    }
}
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 void uninstallPackage(String packagename) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
uninstallmethod.invoke(pm, new Object[] {packagename, observerdelete, 0});
}

PackageDeleteObserver.java(在android.content.pm):

package android.content.pm;

public interface IPackageDeleteObserver extends android.os.IInterface {

    public abstract static class Stub extends android.os.Binder implements android.content.pm.IPackageDeleteObserver {
        public Stub() {
            throw new RuntimeException("Stub!");
        }

        public static android.content.pm.IPackageDeleteObserver asInterface(android.os.IBinder obj) {
            throw new RuntimeException("Stub!");
        }

        public android.os.IBinder asBinder() {
            throw new RuntimeException("Stub!");
        }

        public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags)
                throws android.os.RemoteException {
            throw new RuntimeException("Stub!");
        }
    }

    public abstract void packageDeleted(java.lang.String packageName, int returnCode)
            throws android.os.RemoteException;
}

另外不要忘记添加的权限来体现

<uses-permission android:name="android.permission.DELETE_PACKAGES"/>

工作示例项目(APK需要被放置在/系统/应用程序上的设备路径): http://www.mediafire.com/file/no4buw54ed6vuzo/DeleteInBackgroundSample.zip

Working sample project (apk need to be placed in "/system/app" path on device): http://www.mediafire.com/file/no4buw54ed6vuzo/DeleteInBackgroundSample.zip

 
精彩推荐
图片推荐