我正在开发一个支持静默卸载其他 apk 的应用程序。我的设备已植根,应用程序位于 /system/app 下,通过反射我可以使用 deletePackage 方法来实现这一点。但是在deletePackage方法的实现中,出现了异常。异常信息如下:
09-20 10:16:02.242: E/JavaBinder(1943): *** Uncaught remote exception! (Exceptions are not yet supported across processes.)
09-20 10:16:02.242: E/JavaBinder(1943): java.lang.AbstractMethodError: abstract method not implemented
09-20 10:16:02.242: E/JavaBinder(1943): at android.content.pm.IPackageDeleteObserver$Stub.packageDeleted(IPackageDeleteObserver.java)
09-20 10:16:02.242: E/JavaBinder(1943): at android.content.pm.IPackageDeleteObserver$Stub.onTransact(IPackageDeleteObserver.java:57)
09-20 10:16:02.242: E/JavaBinder(1943): at android.os.Binder.execTransact(Binder.java:338)
09-20 10:16:02.242: E/JavaBinder(1943): at dalvik.system.NativeStart.run(Native Method)
09-20 10:16:02.242: W/dalvikvm(1943): threadid=9: thread exiting with uncaught exception (group=0x40a461f8)
09-20 10:16:02.242: E/AndroidRuntime(1943): FATAL EXCEPTION: Binder Thread #1
09-20 10:16:02.242: E/AndroidRuntime(1943): java.lang.AbstractMethodError: abstract method not implemented
09-20 10:16:02.242: E/AndroidRuntime(1943): at android.content.pm.IPackageDeleteObserver$Stub.packageDeleted(IPackageDeleteObserver.java)
09-20 10:16:02.242: E/AndroidRuntime(1943): at android.content.pm.IPackageDeleteObserver$Stub.onTransact(IPackageDeleteObserver.java:57)
09-20 10:16:02.242: E/AndroidRuntime(1943): at android.os.Binder.execTransact(Binder.java:338)
09-20 10:16:02.242: E/AndroidRuntime(1943): at dalvik.system.NativeStart.run(Native Method)
相关代码:
public void onBackgroundUninstallClick(View v) {
PackageDeleteObserver observer = new PackageDeleteObserver();
if (mPackageManager != null/* && mUninstallPackage != null*/) {
try {
mPackageManager.deletePackage("com.example.android.imagedownloader", observer, 0);
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
class PackageDeleteObserver extends IPackageDeleteObserver.Stub {
public void packageDeleted(boolean succeeded) throws RemoteException {
Log.i(TAG, "packageDeleted");
Message msg = mHandler.obtainMessage(UNINSTALL_COMPLETE);
msg.arg1 = succeeded ? SUCCEEDED : FAILED;
mHandler.sendMessage(msg);
}
}
IPackageDeleteObserver.aidl code :
package android.content.pm;
interface IPackageDeleteObserver {
void packageDeleted(boolean flag);
}