16

I'm using method freeStorageAndNotify() with permission android.permission.CLEAR_APP_CACHE to delete system cache of all installed applications. But the method started throwing InvocationTargetException from the android marshmallow 6.0 version. After googling the issues I found the same issue as reported here: Android M reflection method freeStorageAndNotify exception So here the conclusion was, freeStorageAndNotify() stopped working since google has raised the method's signature level now to signature|system.

But now the question is how other third-party apps like 'Clean master' are still able to delete system cache of all installed applications by taking accessibility permission from the user for 6.0 devices?

Shehan Dhaleesha
  • 627
  • 1
  • 10
  • 30
Audumbar
  • 404
  • 5
  • 16

3 Answers3

0

I don't think that 'Clean master' actually uses Accessibility Permissions to clean installed apps cache. But, if you're interested, this goal can be achieved by using AccessibilityService in your application. Within your class that extends AccessibilityService you have this callback:

    @Override
    public void onAccessibilityEvent(AccessibilityEvent aEvent) {
       AccessibilityNodeInfo rootNode = aEvent.getSource();
       //...
    }

Here you can invoke rootNode.findAccessibilityNodeInfosByViewId() or rootNode.findAccessibilityNodeInfosByText(), it will return all matching AccessibilityNodeInfo objects (sub-nodes) in tree. Then, you just need to detect which of them is Button (node.getClassName()) and call subNode.performAction(AccessibilityNodeInfo.ACTION_CLICK).

On Android M, you first need to to open system's App Info screen (you can find instructions here How can I start android application info screen programmatically?) for the concrete app and, by the scheme described above, perform sequential clicks on the buttons "Storage" —> "Clear cache".

In order to clear cache for all installed apps you probably have to iterate through the all installed apps (List<ApplicationInfo> installedApplications = context.getPackageManager.getInstalledApplications(0);) and repeat the procedure mentioned above.

stone
  • 274
  • 4
  • 8
-1

The system cleaner I'm using has access to the STORAGE permissions. This permission gives the app authority to clear any data in the shared external storage directory.

http://developer.android.com/reference/android/Manifest.permission_group.html#STORAGE

I don't think any 3rd party app can actually clear system cache anymore unless the device is rooted and the app is designed for rooted devices.

clean Master permission

clean Master asking for permission

Aaron Franco
  • 1,560
  • 1
  • 14
  • 19
-4

those apps only do the same thing all the time. use it on an old device and a new device the results are the same. the only help i have seen is that they can kill or restart some background processes, not to clean the cache. therefore no API can restrict their trick..

njihia
  • 9
  • 2