Skip to content

Fix FrameMetrics NPE #4284

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

Merged
merged 1 commit into from
Nov 8, 2022
Merged

Fix FrameMetrics NPE #4284

merged 1 commit into from
Nov 8, 2022

Conversation

leotianlizhan
Copy link
Contributor

Copy of #4184 due to CLA issues (Jeremy leaving).

Investigation

Let's take a look at Android's source code, in android.view.View.
The exception was thrown from findFrameMetricsObserver, inside removeFrameMetricsListener
image
image
Since this null check didn't exists, this triggers NPE when mFrameMetricsObserver is uninitialized. Jeremy found that this was fixed in later Android versions. Why then, is mFrameMetricsObserver uninitialized? It's because addFrameMetricsListener fails silently!
image

Conclusion

So overall, this is the same issue caused by the view not being hardware-accelerated. The correct error message is hidden away because addFrameMetricsListener fails silently, that's why we should catch them both and use the same error message. The developer's provided crash versions also lines up with when Android fixed it: the above reference fix was made in 2019, and Android 7, 8, 9 are all before 2019, with Android 10 releasing in 2019 thus fixing the issue. There is no crash before Android 7 because as Rosario pointed out, FrameMetrics was added in Android 7 (API 24).

@google-oss-bot
Copy link
Contributor

Coverage Report 1

Affected Products

  • firebase-perf

    Overall coverage changed from ? (62cfd00) to 71.11% (7ab6531) by ?.

    102 individual files with coverage change

    FilenameBase (62cfd00)Merge (7ab6531)Diff
    AddTrace.java?0.00%?
    AndroidApplicationInfo.java?34.71%?
    AndroidApplicationInfoOrBuilder.java?0.00%?
    AndroidLogger.java?100.00%?
    AndroidMemoryReading.java?38.36%?
    AndroidMemoryReadingOrBuilder.java?0.00%?
    ApplicationInfo.java?45.00%?
    ApplicationInfoOrBuilder.java?0.00%?
    ApplicationProcessState.java?73.91%?
    AppStartTrace.java?85.19%?
    AppStateMonitor.java?86.71%?
    AppStateUpdateHandler.java?92.86%?
    Clock.java?100.00%?
    ConfigResolver.java?93.19%?
    ConfigurationConstants.java?97.86%?
    ConfigurationFlag.java?100.00%?
    ConsoleUrlGenerator.java?37.50%?
    Constants.java?95.65%?
    Counter.java?90.91%?
    CpuGaugeCollector.java?92.77%?
    CpuMetricReading.java?39.33%?
    CpuMetricReadingOrBuilder.java?0.00%?
    DaggerFirebasePerformanceComponent.java?100.00%?
    DeviceCacheManager.java?76.03%?
    FirebasePerfApplicationInfoValidator.java?92.86%?
    FirebasePerfGaugeMetricValidator.java?100.00%?
    FirebasePerfHttpClient.java?93.85%?
    FirebasePerfMetricProto.java?0.00%?
    FirebasePerfNetworkValidator.java?86.67%?
    FirebasePerfOkHttpClient.java?44.90%?
    FirebasePerformance.java?79.12%?
    FirebasePerformanceAttributable.java?0.00%?
    FirebasePerformanceComponent.java?0.00%?
    FirebasePerformanceInitializer.java?33.33%?
    FirebasePerformanceModule.java?100.00%?
    FirebasePerformanceModule_ProvidesConfigResolverFactory.java?100.00%?
    FirebasePerformanceModule_ProvidesFirebaseAppFactory.java?100.00%?
    FirebasePerformanceModule_ProvidesFirebaseInstallationsFactory.java?100.00%?
    FirebasePerformanceModule_ProvidesRemoteConfigComponentFactory.java?100.00%?
    FirebasePerformanceModule_ProvidesRemoteConfigManagerFactory.java?100.00%?
    FirebasePerformanceModule_ProvidesSessionManagerFactory.java?100.00%?
    FirebasePerformanceModule_ProvidesTransportFactoryProviderFactory.java?100.00%?
    FirebasePerformance_Factory.java?100.00%?
    FirebasePerfProvider.java?76.92%?
    FirebasePerfRegistrar.java?100.00%?
    FirebasePerfTraceValidator.java?85.87%?
    FirebasePerfUrlConnection.java?44.26%?
    FirstDrawDoneListener.java?85.19%?
    FlgTransport.java?83.33%?
    FragmentStateMonitor.java?94.87%?
    FrameMetricsCalculator.java?96.77%?
    FrameMetricsRecorder.java?76.32%?
    GaugeManager.java?98.41%?
    GaugeMetadata.java?26.17%?
    GaugeMetadataManager.java?77.78%?
    GaugeMetadataOrBuilder.java?0.00%?
    GaugeMetric.java?39.47%?
    GaugeMetricOrBuilder.java?0.00%?
    HttpMetric.java?92.65%?
    ImmutableBundle.java?100.00%?
    InstrHttpInputStream.java?92.86%?
    InstrHttpOutputStream.java?98.00%?
    InstrHttpsURLConnection.java?94.32%?
    InstrHttpURLConnection.java?93.42%?
    InstrumentApacheHttpResponseHandler.java?100.00%?
    InstrumentOkHttpEnqueueCallback.java?100.00%?
    InstrURLConnectionBase.java?94.86%?
    LogWrapper.java?23.08%?
    MemoryGaugeCollector.java?91.38%?
    NetworkConnectionInfo.java?0.00%?
    NetworkConnectionInfoOrBuilder.java?0.00%?
    NetworkRequestMetric.java?49.16%?
    NetworkRequestMetricBuilder.java?95.97%?
    NetworkRequestMetricBuilderUtil.java?75.00%?
    NetworkRequestMetricOrBuilder.java?0.00%?
    Optional.java?86.67%?
    PendingPerfEvent.java?100.00%?
    PerfMetric.java?33.67%?
    PerfMetricOrBuilder.java?0.00%?
    PerfMetricValidator.java?93.55%?
    PerfSession.java?93.22%?
    PerfSessionOrBuilder.java?0.00%?
    Rate.java?100.00%?
    RateLimiter.java?90.77%?
    RemoteConfigManager.java?91.79%?
    ResourceType.java?0.00%?
    ScreenTraceUtil.java?94.12%?
    SessionAwareObject.java?0.00%?
    SessionManager.java?100.00%?
    SessionVerbosity.java?68.42%?
    StorageUnit.java?57.89%?
    Timer.java?90.63%?
    Trace.java?96.67%?
    TraceMetric.java?43.14%?
    TraceMetricBuilder.java?100.00%?
    TraceMetricOrBuilder.java?0.00%?
    TransportInfo.java?0.00%?
    TransportInfoOrBuilder.java?0.00%?
    TransportManager.java?94.88%?
    URLAllowlist.java?94.44%?
    URLWrapper.java?0.00%?
    Utils.java?78.57%?

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/eQI4LYfv4f.html

@github-actions
Copy link
Contributor

github-actions bot commented Nov 4, 2022

Unit Test Results

  51 files   -    344    51 suites   - 344   1m 27s ⏱️ - 18m 0s
974 tests  - 3 756  974 ✔️  - 3 734  0 💤  - 22  0 ±0 
974 runs   - 3 772  974 ✔️  - 3 750  0 💤  - 22  0 ±0 

Results for commit a2d96b1. ± Comparison against base commit 62cfd00.

@google-oss-bot
Copy link
Contributor

Size Report 1

Affected Products

  • firebase-perf

    TypeBase (62cfd00)Merge (7ab6531)Diff
    aar311 kB311 kB+161 B (+0.1%)
    apk (aggressive)1.03 MB1.03 MB+32 B (+0.0%)
    apk (release)2.47 MB2.47 MB+108 B (+0.0%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/1TatLPM6o6.html

if (ex instanceof NullPointerException && Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
// Re-throw above API 28, since the NPE is fixed in API 29:
// https://android.googlesource.com/platform/frameworks/base/+/140ff5ea8e2d99edc3fbe63a43239e459334c76b
throw ex;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the intent to notify the developers of the exception during development? Interesting to see a pattern where we throw and exception in a catch module.

@leotianlizhan leotianlizhan merged commit 92af27d into master Nov 8, 2022
@leotianlizhan leotianlizhan deleted the hardware-accel-fix branch November 8, 2022 04:10
davidmotson pushed a commit that referenced this pull request Nov 28, 2022
@firebase firebase locked and limited conversation to collaborators Dec 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants