Skip to content

Remove FLAG_FULLSCREEN and replace with WindowInsetsController call#10

Open
cranberry-platypus wants to merge 2 commits intoswe-productivity:mainfrom
cranberry-platypus:remove-deprecated-flag-fullscreen
Open

Remove FLAG_FULLSCREEN and replace with WindowInsetsController call#10
cranberry-platypus wants to merge 2 commits intoswe-productivity:mainfrom
cranberry-platypus:remove-deprecated-flag-fullscreen

Conversation

@cranberry-platypus
Copy link
Copy Markdown

Purpose / Description

Addresses deprecation of FLAG_FULLSCREEN in API 30

Fixes

Fixes #6

Approach

Replaces usage of FLAG_FULLSCREEN with 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.

  • 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

Copy link
Copy Markdown
Collaborator

@david-allison david-allison left a comment

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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).

@david-allison david-allison self-assigned this Apr 8, 2026
- Moved status bar code to compat package
- Added comment with explination of code
- Remove commented out annotation
@cranberry-platypus
Copy link
Copy Markdown
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FLAG_FULLSCREEN deprecation in API 30

2 participants