I am writing an application that should clear the personal data of any other application. If you are interested in a use case, then it will stand next to the MDM / MAM client. I would like to selectively erase application data (compared to completely wiping the device).
The following API call has appeared in the Android source code.
ActivityManager.clearApplicationUserData(String packageName,IPackageDataObserverobserver)
The odd part is that it is not really available to you as part of the SDK. (So ββan eclipse will give you hell for trying to use it). However he is present(see here ), you can call it through reflection. However, I still cannot understand the IPackageDataObserver interface .
Is there a better way to do this? I know this can be done since I saw how products like MaaS360 do selective data wiping of applications.
Any suggestions?
UPDATE
According to what @lechlukasz described below ... the following code may execute ... but you will finally land on a SecurityException, as the package manager cancels the CLEAR_APP_USER_DATA permission when installing the application.
Class<?> iPackageDataObserverClass= Class.forName("android.content.pm.IPackageDataObserver");
Class<ActivityManager> activityManagerClass=ActivityManager.class;
ActivityManager activityManager=(ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
Method clearDataMethod=activityManagerClass.getMethods()[0];
Object iPackageDataObserverObject = Proxy.newProxyInstance(
MyApp.class.getClassLoader(), new Class[]{iPackageDataObserverClass},
new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
Log.i("Proxy", method.getName() + ": " + Arrays.toString(args));
return null;
}
});
clearDataMethod.invoke(activityManager, "com.example.test",iPackageDataObserverObject);
Thus, this works as the method can be called. Unlucky that you can actually clear the data .: - (
source
share