-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
refactor: mount receivers #16714
base: main
Are you sure you want to change the base?
refactor: mount receivers #16714
Conversation
If you really want the function to accept a flag, I could still accept a flag, and do a xor with the EXPORTED flag |
The patch above uses |
d90bdc8
to
77f766b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this works locally on an API23 emulator even (have to do some manual clicking because of the outdated-webview-check popup, during test)
this picks cleanly to release-2.18 in case we need it
@david-allison with limited time and having already reviewed it I'm not sure on the value of splitting the refactor to a commit. It appears to work in local testing, I'd merge as is but you've got a pending reject, so back to you |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, still appears to be incomplete, when I change the targetSdk in versions lib and attempt to run ./gradlew jacocoTestReport
with an API34 emulator running, I see this:
Process: com.ichi2.anki.debug, PID: 7566
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ichi2.anki.debug/com.ichi2.anki.FilteredDeckOptions}: java.lang.SecurityException: com.ichi2.anki.debug: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3782)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3922)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:205)
at android.os.Looper.loop(Looper.java:294)
at android.app.ActivityThread.main(ActivityThread.java:8177)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
Caused by: java.lang.SecurityException: com.ichi2.anki.debug: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts
at android.os.Parcel.createExceptionOrNull(Parcel.java:3057)
at android.os.Parcel.createException(Parcel.java:3041)
at android.os.Parcel.readException(Parcel.java:3024)
at android.os.Parcel.readException(Parcel.java:2966)
at android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(IActivityManager.java:5684)
at java.lang.reflect.Method.invoke(Native Method)
at leakcanary.ServiceWatcher$install$4$2.invoke(ServiceWatcher.kt:93)
at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
at $Proxy4.registerReceiverWithFeature(Unknown Source)
at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1852)
at android.app.ContextImpl.registerReceiver(ContextImpl.java:1792)
at android.app.ContextImpl.registerReceiver(ContextImpl.java:1780)
at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:755)
at com.ichi2.ui.AppCompatPreferenceActivity.registerExternalStorageListener(AppCompatPreferenceActivity.kt:288)
at com.ichi2.anki.FilteredDeckOptions.onCreate(FilteredDeckOptions.kt:211)
at android.app.Activity.performCreate(Activity.java:8595)
at android.app.Activity.performCreate(Activity.java:8573)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1456)
at androidx.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:766)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3764)
... 12 more
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.am.ActivityManagerService.registerReceiverWithFeature(ActivityManagerService.java:13927)
at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2570)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2720)
at android.os.Binder.execTransactInternal(Binder.java:1339)
at android.os.Binder.execTransact(Binder.java:1275)
Agreed - refactor would be better as a PR |
The force push didn't seem to have applied the patch. I'll move the 'snipe' into another PR, so this PR can focus on the refactoring |
77f766b
to
f5e66cc
Compare
Yeah, I did the force push after seeing your request for import and before seeing that actually, your code worked on all supported version. |
I'll wait until the urgent PR is merged to solve the merge conflict and do the refactor |
For posterity: d90bdc8 |
This comment was marked as outdated.
This comment was marked as outdated.
f5e66cc
to
6527bef
Compare
One comment, from memory the rest of the code was good and I'll approve once |
6527bef
to
b71ddcc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you test this:
- I want to confirm that moving from one receiver to two won't cause problems and that mounting/unmounting are handled in the
DeckPicker
Other than testing, LGTM
unmountReceiver = object : BroadcastReceiver() { | ||
override fun registerExternalStorageListener() { | ||
super.registerExternalStorageListener() | ||
if (mountReceiver == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: invert if and return early
Hello 👋, this PR has had no activity for more than 2 weeks and needs a reply from the author. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically |
b71ddcc
to
cf8d770
Compare
I rewrote it so that to refactor the code. There is a map from action name to the actual action to execute , and that's the only part that is open |
Hello 👋, this PR has had no activity for more than 2 weeks and needs a reply from the author. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically |
cf8d770
to
34a2c9f
Compare
This ensure that the same receiver appears in all activities and not just the few one where the code was essentially copy pasted. The Deck Picker also listen for mounting, so I renamed its receiver as a `mountReceiver` instead
34a2c9f
to
38a39d5
Compare
This ensure there is no change in behaviour.
I checked whether we could try to not export the download of decks, but it does not works.
The app does not crash on api 24 on simulator.
There was a slight problem, with variables that could potentially be null. To ensure the type checker agreed with the code, without using
!!
, I had to rewrite some of the logic.I also ensured that some of the code that was copy/pasted in various activity now entirely belong to AnkiActivity. As a side effect, all activities that used to listen to the "unmount" notification and finished, will now also show a toast when the card gets unmounted. Currently it was only the deck picker.