-
Notifications
You must be signed in to change notification settings - Fork 6k
Fix Android T deprecated WindowManager INCORRECT_CONTEXT_USAGE #28774
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
Can this provide a That appears to be the only parameter required by the |
Yeah, good catch, I'll modify to remove WindowManager from VsyncWaiter |
VsyncWaiter.getInstance((WindowManager) appContext.getSystemService(Context.WINDOW_SERVICE)) | ||
.init(); | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
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.
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 check is specifically making sure the new code is used only for API 23+ which is when the display API was added. I guess it could be gated to only apply to T and above, I have no strong opinions either way. End goal is just to obtain the FPS float.
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.
ah ok, that's fine too then
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.
Gating at 23 is more likely to have better test coverage as most of our testing is with API 30 and below (as of now), making this safer in the long run. I'll leave it as is.
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.
The display API was actually added in 17. I'd like to change this, is there any good reason not to?
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.
Or at least, all of the display code we're using :)
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.
I'm changing this in #29800 - please add comments if it needs to be at 23 for some reason I'm missing.
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.
That should hav ebeen #29800....
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.
I see now - getSystemService was using the API 23 call instead of the one compatible with API 17. Fixing that upstream in my PR.
final Display primaryDisplay = dm.getDisplay(Display.DEFAULT_DISPLAY); | ||
VsyncWaiter.getInstance(primaryDisplay.getRefreshRate()).init(); | ||
} else { | ||
VsyncWaiter.getInstance( |
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.
Factor the duplicated VsyncWaiter.getInstance().init()
calls out of the if/else blocks.
} | ||
return instance; | ||
} | ||
|
||
@NonNull private final WindowManager windowManager; | ||
@NonNull private final float fps; |
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: @NonNull
can be removed
@@ -41,15 +39,14 @@ public void doFrame(long frameTimeNanos) { | |||
} | |||
}; | |||
|
|||
private VsyncWaiter(@NonNull WindowManager windowManager) { | |||
this.windowManager = windowManager; | |||
private VsyncWaiter(@NonNull float fps) { |
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.
ditto in private constructor & in the getter above
FlutterLoader flutterLoader = new FlutterLoader(mockFlutterJNI); | ||
|
||
assertFalse(flutterLoader.initialized()); | ||
flutterLoader.startInitialization(RuntimeEnvironment.application); |
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.
can it also ensure that context.getSystemService(Context.WINDOW_SERVIC)
isn't called?
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.
LGTM
This pull request is not suitable for automatic merging in its current state.
|
Formatting Version Gate Formatting
Remove extra import Remove extra var
Formatting formatting
Landing, LUCI redness is due to SkParagraph testing. |
…cWaiter takes FPS float (flutter/engine#28774)
Internal bug: b/199439780
Android T enforces not using an application context to get a WidowManager.