Remove FLAG_FULLSCREEN and replace with WindowInsetsController call#10
Conversation
david-allison
left a comment
There was a problem hiding this comment.
This fails during testing: Attempt to invoke virtual method 'android.view.WindowInsetsController com.android.internal.policy.DecorView.getWindowInsetsController()' on a null object reference
./adb shell monkey -p com.ichi2.anki.debug -v 500
FATAL EXCEPTION: main
Process: com.ichi2.anki.debug, PID: 22340
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ichi2.anki.debug/com.ichi2.anki.DeckPicker}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.WindowInsetsController com.android.internal.policy.DecorView.getWindowInsetsController()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3645)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3782)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:138)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7924)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.WindowInsetsController com.android.internal.policy.DecorView.getWindowInsetsController()' on a null object reference
at com.android.internal.policy.PhoneWindow.getInsetsController(PhoneWindow.java:3959)
at com.ichi2.anki.AnkiActivity.onCreate(AnkiActivity.kt:147)
at com.ichi2.anki.DeckPicker.onCreate(DeckPicker.kt:516)
at android.app.Activity.performCreate(Activity.java:8342)
at android.app.Activity.performCreate(Activity.java:8321)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1417)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3626)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3782)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:138)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7924)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
ACRA caught a RuntimeException for com.ichi2.anki.debug
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ichi2.anki.debug/com.ichi2.anki.DeckPicker}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.WindowInsetsController com.android.internal.policy.DecorView.getWindowInsetsController()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3645)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3782)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:138)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7924)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.WindowInsetsController com.android.internal.policy.DecorView.getWindowInsetsController()' on a null object reference
at com.android.internal.policy.PhoneWindow.getInsetsController(PhoneWindow.java:3959)
at com.ichi2.anki.AnkiActivity.onCreate(AnkiActivity.kt:147)
at com.ichi2.anki.DeckPicker.onCreate(DeckPicker.kt:516)
at android.app.Activity.performCreate(Activity.java:8342)
at android.app.Activity.performCreate(Activity.java:8321)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1417)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3626)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3782)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:138)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7924)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
| } | ||
|
|
||
| @Suppress("deprecation") // #9332: UI Visibility -> Insets | ||
| // @Suppress("deprecation") // #9332: UI Visibility -> Insets |
There was a problem hiding this comment.
no need to comment out lines, that's what git history is for 😃, could you update the PR to remove this
| WindowManager.LayoutParams.FLAG_FULLSCREEN, | ||
| WindowManager.LayoutParams.FLAG_FULLSCREEN, | ||
| ) | ||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { |
There was a problem hiding this comment.
Please move this into com.ichi2.[anki.]compat along with other compat code
Compat just moved packages on main
| @@ -141,12 +143,18 @@ open class AnkiActivity( | |||
| super.onCreate(savedInstanceState) | |||
| // Disable the notifications bar if running under the test monkey. | |||
There was a problem hiding this comment.
Context (please add a comment):
In ~2020, the issue with the money was that it could pull down on the status bar, and start interacting with real apps on a physical device 😅
This was a quick hack to get it back on track in an emulator-based context
There was a problem hiding this comment.
Interestingly, I'm not sure if this is a full fix for the monkey on a physical device (I had a similar issue on my physical device, although iirc it was triggered by the app crashing).
- Moved status bar code to compat package - Added comment with explination of code - Remove commented out annotation
|
I've resolved most of the issues you mentioned. I think the null check I added should solve the crashing issue, but I can't easily re-create it for testing. The app usually crashes with a memory allocator error on my physical device when the monkey is started. |
Purpose / Description
Addresses deprecation of
FLAG_FULLSCREENin API 30Fixes
Fixes #6
Approach
Replaces usage of
FLAG_FULLSCREENwith recommended method to remove the status bar.How Has This Been Tested?
This PR has not been tested - the relevant code is only called when Android's Monkey is used,
or the app is loaded in a FirebaseTestLab. I can't reproduce either of these environments (Monkey
fairly reliably triggers some kind of memory leak detection on my device - and crashed my launcher
the last time I tried it), but I'm fairly confident the change will function as expected.
This being said, I'm not sure what the value of disabling the status bar is in either of these
cases is.
Learning (optional, can help others)
https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_FULLSCREEN
https://developer.android.com/develop/ui/views/layout/immersive
Checklist
Please, go through these checks before submitting the PR.