Clearing data from another application

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 .: - (

+5
source share
2 answers

The method you specify is not a static method, so to call it you will need an instance ActivityManagerthat will be the most difficult part, even if you have root privileges. I can not help it.

IPackageDataObserver, , API refrection:

        Class ipdoClass = Class.forName("android.content.pm.IPackageDataObserver");
        Object observer = Proxy.newProxyInstance(
                MyApp.class.getClassLoader(), new Class[]{ipdoClass}, 
                        new InvocationHandler() {

            public Object invoke(Object proxy, Method method, Object[] args) 
                    throws Throwable {
                Log.i("Proxy", method.getName() + ": " + Arrays.toString(args));
                return null;
            }
        });
+2

, (CLEAR_APP_USER_DATA) .

0

All Articles