关于通过Android AIDL强制停止套餐

时间:2012-08-15 06:34:59

标签: android aidl

可以通过AIDL清除缓存,那么关于forcestop函数呢?

我试过了,但失败了。有人这么做过吗?

在我的包中添加aidl文件:

IActivityManager.aidl
package android.app; 
oneway interface IActivityManager { 
     void forceStopPackage(String packageName);
}

实现IActivityManager,但我无法得到它的对象:

import android.app.IActivityManager;
class ActivityManagerProxy implements IActivityManager
{

    public ActivityManagerProxy(IBinder remote)
    {
        mRemote = remote;
    }

    public IBinder asBinder()
    {
        return mRemote;
    }

    public void forceStopPackage(String packageName) throws RemoteException
    {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(descriptor);
        data.writeString(packageName);
        mRemote.transact(FORCE_STOP_PACKAGE_TRANSACTION, data, reply, 0);
        reply.readException();
        data.recycle();
        reply.recycle();
    }

    private IBinder mRemote;
}

1 个答案:

答案 0 :(得分:1)

由于在自己的进程中运行的ActivityManagerService只检查了IPC调用者的权限,所以不可能。您必须持有FORCE_STOP_PACKAGES权限才能调用此方法。