Frozen-Developers / android-cache-cleaner

[DEPRECATED] Open-source cache cleaner for Android
MIT License
162 stars 68 forks source link

getPackageSizeInfoAsUser() is not working in Android O #53

Open h777arsh opened 7 years ago

h777arsh commented 7 years ago

Shame on you for calling the hidden API getPackageSizeInfoAsUser(). Shame!

W/System.err: java.lang.reflect.InvocationTargetException
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at com.frozendevs.cache.cleaner.model.CleanerService$TaskScan.doInBackground(CleanerService.java:92)
W/System.err:     at com.frozendevs.cache.cleaner.model.CleanerService$TaskScan.doInBackground(CleanerService.java:66)
W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:333)
W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
W/System.err:     at java.lang.Thread.run(Thread.java:764)
I/ActivityManager: Displayed com.frozendevs.cache.cleaner/.activity.CleanerActivity: +162ms
W/System.err: Caused by: java.lang.NullPointerException: Attempt to read from field 'long android.content.pm.PackageStats.externalCacheSize' on a null object reference
W/System.err:     at com.frozendevs.cache.cleaner.model.CleanerService$TaskScan.addPackage(CleanerService.java:145)
W/System.err:     at com.frozendevs.cache.cleaner.model.CleanerService$TaskScan.access$400(CleanerService.java:66)
W/System.err:     at com.frozendevs.cache.cleaner.model.CleanerService$TaskScan$1.onGetStatsCompleted(CleanerService.java:102)
W/System.err:     at android.app.ApplicationPackageManager.getPackageSizeInfoAsUser(ApplicationPackageManager.java:2166)
W/System.err:     at android.content.pm.PackageManager.getPackageSizeInfo(PackageManager.java:5065)
W/System.err:   ... 9 more
lubo commented 7 years ago

Slow your roll, @h777arsh. We know using hidden API is bad, yet it was pretty much the only option. We appreciate that you've reported the issue but please, don't point your finger at anybody unless you bring something to the table yourself. Also, pull requests are welcome.

h777arsh commented 7 years ago

Hi, Thanks for Fast reply. Actually that "Shame" error is from google not by me. I just posted log. sorry, if i offended you. I'm just saying that reflection is not working in android oreo, so do you have any idea?

lubo commented 7 years ago

Actually, the log points to this line. So, the reflection itself is probably working just fine and the problem seems to be getPackageSizeInfo() being unable to retrieve the stats for a particular application (more info regarding this issue is in README). The root cause might be that onGetStatsCompleted() provides pStats = null on Oreo. I'd try to find out value of the succeeded for that application and if it's false, then it just not properly handled in addPackage().

h777arsh commented 7 years ago

Okay, I tried with succeeded, but unfortunately it never called, i got exception mGetPackageSizeInfoMethod.invoke() on this line about java.lang.reflect.InvocationTargetException, and i got this exception on every installed app, so may be problem is in reflection. I'm looking right now, if i can find anything i'll post here.

Thank you

coolavdhesh commented 6 years ago

Any solution for this till now @h777arsh @lubo ? thanks

UttamPanchasara commented 6 years ago

Any update on this?

saquib3705 commented 6 years ago

As getPackageSizeInfoAsUser() is not working in Android O because it has been deprecated in oreo so I used StorageStatsManager to fetch app information. Enable Usage Access Settings to access the cache file.

kartikdrag commented 5 years ago

Still doesn't work please try to review it once

rk8339811 commented 5 years ago

Hi, @saquib3705 your solution looks interesting. Can you please elaborate more on this. It would be really helpful.

kartikdrag commented 5 years ago

Hello to all I have solutions to it that one is android accessibility. If we achieve this one we can clean that dammed cache in oreo version. Please let me know if one of us already have this method.

On Sun, 19 May 2019, 3:35 pm rk8339811 <notifications@github.com wrote:

Hi, @saquib3705 https://github.com/saquib3705 your solution looks interesting. Can you please elaborate more on this. It would be really helpful.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Frozen-Developers/android-cache-cleaner/issues/53?email_source=notifications&email_token=AFCXV2CFWUHKAPTGPR45533PWEQ6RA5CNFSM4D2HUEJ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODVW64DQ#issuecomment-493743630, or mute the thread https://github.com/notifications/unsubscribe-auth/AFCXV2FZ3CQ6VTE5YCNSKBDPWEQ6RANCNFSM4D2HUEJQ .

rk8339811 commented 5 years ago

Hi @kartikdrag You solution is what I am in search of right now. Do you have any idea on how to code that solution? Or do have reference to any other example or app whose developer can help us? It would be great if we could dig more into it and find a solution and make it publically available not only here but in other places also such as StackOverflow. As I have seen this issue persists from quite a long time.