Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(manage-space): crash if getPackageSizeInfo fails #17413

Merged
merged 1 commit into from
Nov 11, 2024

Conversation

david-allison
Copy link
Member

@david-allison david-allison commented Nov 10, 2024

On a (knockoff?) API 25 phone, getPackageSizeInfo failed with

java.lang.NoSuchMethodException: getPackageSizeInfo [class java.lang.String, interface b.a]
	at java.lang.Class.getMethod(Class.java:1981)
	at java.lang.Class.getMethod(Class.java:1637)
	at com.ichi2.anki.ui.windows.managespace.FileUtilsKt.getUserDataAndCacheSizeUsingGetPackageSizeInfo(FileUtils.kt:115)

Fixes

Approach

  • handling the exception
  • documenting the exception

How Has This Been Tested?

I modified the code to throw an exception

Screenshot 2024-11-10 at 17 14 48
  • button still worked

Checklist

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

On a (knockoff?) API 25 phone, `getPackageSizeInfo` failed with

```
java.lang.NoSuchMethodException: getPackageSizeInfo [class java.lang.String, interface b.a]
	at java.lang.Class.getMethod(Class.java:1981)
	at java.lang.Class.getMethod(Class.java:1637)
	at com.ichi2.anki.ui.windows.managespace.FileUtilsKt.getUserDataAndCacheSizeUsingGetPackageSizeInfo(FileUtils.kt:115)
```

We fix this via:

* handling the exception
* documenting the exception

Fixes 17387
@@ -38,6 +38,7 @@ import kotlin.coroutines.resume
/**
* Get the size of user data and cache for the current package, in bytes.
* This should amount to the sum of User data and Cache in App info -> Storage and cache.
* @throws NoSuchMethodException occasionally on some phones < [Build.VERSION_CODES.O] (#17387)
Copy link
Member Author

@david-allison david-allison Nov 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I link the version code so this will be seen when we upgrade the minSdk

Copy link
Member

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works for me

@mikehardy mikehardy added Review High Priority Request for high priority review Needs Second Approval Has one approval, one more approval to merge labels Nov 10, 2024
Copy link
Member

@lukstbit lukstbit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lukstbit lukstbit added Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) and removed Needs Review Needs Second Approval Has one approval, one more approval to merge labels Nov 11, 2024
@lukstbit lukstbit added this pull request to the merge queue Nov 11, 2024
Merged via the queue into ankidroid:main with commit 3ed3bda Nov 11, 2024
12 checks passed
@github-actions github-actions bot added this to the 2.20 Release milestone Nov 11, 2024
@github-actions github-actions bot removed Review High Priority Request for high priority review Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) labels Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ManageSpaceActivity: NoSuchMethodException: getPackageSizeInfo
3 participants