-
Notifications
You must be signed in to change notification settings - Fork 624
[Fireperf][AASA] FirstDrawDoneListener
#4041
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
Conversation
Coverage Report 1Affected Products
Test Logs
Notes |
Size Report 1Affected Products
Test Logs
Notes |
FirstDrawDownListener
FirstDrawDoneListener
// Handle bug prior to API 26 where OnDrawListener from the floating ViewTreeObserver is not | ||
// merged into the real ViewTreeObserver. | ||
// https://android.googlesource.com/platform/frameworks/base/+/9f8ec54244a5e0343b9748db3329733f259604f3 | ||
if (Build.VERSION.SDK_INT >= 26 |
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: I recommend flipping the cases around so we are checking for special cases first then falling through to the default. This also moves the comment to be close to the specific case it's referring to.
if (Build.VERSION.SDK_INT < 26 && (!view.getViewTreeObserver().isAlive() || view.getWindowToken() == null) {
view.addOnAttachStateChangeListener(...)
return;
}
view.getViewTreeObserver()....
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.
Done
assertThat(listOfListeners).isNotNull(); | ||
assertThat(listOfListeners.size()).isEqualTo(1); | ||
|
||
// OnDrawListener is not registered, it is delayed for later |
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 we test that it is registered later on a state change?
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 don't see a way to do it because View
class doesn't have public View.dispatchAttachView()
unlike the other listeners we have for ViewTreeObserver
(ViewTreeObserver.dispatchOnDraw()
and ViewTreeObserver.dispatchOnGlobalLayout()
), and although there's a private View.dispatchAttachView()
it uses parameter classes that are also not visible to us.
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.
+1 to Raymond's ask. Currently, the test does not do much validate the listener registration for API < 26.
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.
Figured out a way to do it through reflection, PTAL @visumickey @raymondlam
} | ||
|
||
@Test | ||
@Config(sdk = 26) |
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 we have a test for un-registering itself in Config(sdk=25) for both OnAttachStateChangeListener and OnDrawListener?
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 only added @Config(sdk = 26)
for this test because it uses reflection, so I don't know if in the future Android will change field names or refactor ViewTreeObserver
.
The < API 26 bug is that adding OnDrawListeners
to ViewTreeObserver
doesn't work, it has nothing to do with removing or the listener itself, so I don't think we need to test unregistering for 2 different versions.
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.
For the < API 26 bug, we should be making sure that we have a test to make sure that if we do register a View.OnAttachStateChangeListener
, that it is unregistered once onViewAttachedToWindow
is called. Otherwise, we could change the code to leave it registered and the tests would still pass.
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, I see what you mean. That is difficult for the same reason as the other comment: View
class doesn't have public, easy to use dispatchXYZ()
methods like ViewTreeObserver
does.
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 use a FakeView or mock the View object? This way you have access to the listeners and can trigger the interfaces directly.
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.
Added a check at the last line of registerForNextDraw_delaysAddingListenerForAPIsBelow26()
.
/test smoke-tests |
|
||
@Override | ||
public void onDraw() { | ||
// Prevent 2nd draw and on from triggering onDraw |
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: Fix comment. The comment is a bit hard to parse.
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.
reworded, PTAL @visumickey
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package com.google.firebase.perf.util; |
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: Is there a better package where we drop this in? Util is too open and overtime this has becomes a drop off of different kind of classes. Since this is in the context of app start measurements, can we find a better place for this class? If it is hard to find, let catch up offline on the package structure.
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 don't know where else to drop this in. I don't want to drop it in /metrics
which is where AppStartTrace
and other Trace metrics live in, because that would allow AppStartTrace
access to some package-private methods that should not be allowed to use apart from testing. I only want AppStartTrace
(the consumer of FirstDrawDoneListener
) to use public static factory to register and create FirstDrawDoneListener
.
firebase-perf/src/test/java/com/google/firebase/perf/util/FirstDrawDoneListenerTest.java
Show resolved
Hide resolved
assertThat(listOfListeners).isNotNull(); | ||
assertThat(listOfListeners.size()).isEqualTo(1); | ||
|
||
// OnDrawListener is not registered, it is delayed for later |
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.
+1 to Raymond's ask. Currently, the test does not do much validate the listener registration for API < 26.
/test check-coverage-changed |
* WIP * handler * handle bug prior to api 26 * tests * copyright * improve tests * comment fix * improve tests * comment * backport View.isAttachedToWindow() * improved registerForNextDraw_delaysAddingListenerForAPIsBelow26 * remove LayoutChangeListener * add check to mmake sure OnAttachStateChangeListener removes itself * mcreate helper isAliveAndAttached * improve test with Robolectric ShadowLooper
b/243538554