Skip to content

Fireperf aqs sessionmanager phase2#7997

Open
jrodiz wants to merge 7 commits intofirebase:fireperf-aqsfrom
jrodiz:fireperf-aqs-sessionmanager-phase2
Open

Fireperf aqs sessionmanager phase2#7997
jrodiz wants to merge 7 commits intofirebase:fireperf-aqsfrom
jrodiz:fireperf-aqs-sessionmanager-phase2

Conversation

@jrodiz
Copy link
Copy Markdown
Contributor

@jrodiz jrodiz commented Mar 30, 2026

Summary

Phase 2 of the SessionManager dependency-injection migration for Firebase Performance.

This continues the work started in #7675 (Phase 1: RemoteConfigManager refactor + SessionManager refactor groundwork) by fully eliminating the SessionManager.getInstance() static singleton in favor of Dagger-managed construction and explicit dependency passing.

Changes

  • Remove SessionManager static singleton — Delete the private no-arg constructor and getInstance(). The Dagger component factory in FirebasePerfRegistrar now constructs SessionManager directly, and it is provided as a proper DI component.
  • Thread SessionManager through AppStateMonitor — Add getInstance(SessionManager) seeded-init overload so FirebasePerfEarly injects the DI-managed instance at startup. Add getSessionManager() accessor for downstream consumers.
  • Remove SessionManager.getInstance() from Trace — Resolve SessionManager via AppStateMonitor.getSessionManager() (with a safe fallback for tests). The Parcel deserialization path uses TransportManager.getInstance().getSessionManager().
  • Remove SessionManager.getInstance() from NetworkRequestMetricBuilder — Obtain SessionManager via AppStateMonitor.getInstance().getSessionManager().
  • Add getSessionManager() to TransportManager — Thread SessionManager through initializeForTest() so tests can supply the correct
    instance.
  • Update all tests — Adapt FirebasePerfRegistrarTest, FirebasePerformanceTest, AppStartTraceTest, TraceTest,
    NetworkRequestMetricBuilderTest, and TransportManagerTest to use the new DI-based patterns instead of the removed singleton.

Motivation
Removing the static singleton makes SessionManager's lifecycle explicit and testable, eliminates hidden global state, and aligns with the broader AQS (Android Quality Sessions) migration where session identity is provided by Firebase Sessions rather than managed internally.

jrodiz added 6 commits March 23, 2026 12:32
Delete the private no-arg constructor and static getInstance() method.
The Dagger component factory in FirebasePerfRegistrar now constructs a
fresh SessionManager(GaugeManager, PerfSession) instead of delegating
to the singleton accessor.

Add null-guards for gaugeManager in setApplicationContext,
stopGaugeCollectionIfSessionRunningTooLong, logGaugeMetadataIfCollectionEnabled,
and startOrStopCollectingGauges to support test-only SessionManager
instances that are constructed with a null GaugeManager.

Remove the testInstanceCreation unit test whose invariant is now
maintained by the DI container rather than the class itself.
…artTrace pattern

Add getInstance(SessionManager) seeded-init overload so FirebasePerfEarly
can inject the DI-managed SessionManager at startup. The no-arg
getInstance() remains as a safe "get-after-init" fallback (creates its own
SessionManager if called before early init, e.g. in tests or
AppStateUpdateHandler).

Add getSessionManager() accessor and resetInstance() @VisibleForTesting
helper to support test isolation.

Update FirebasePerfEarly to call getInstance(sessionManager) instead of
the no-arg version.
…() to TransportManager

Trace's 5-arg convenience constructor now resolves SessionManager via
sessionManagerFrom(appStateMonitor), which delegates to
AppStateMonitor.getSessionManager() and falls back to a no-gauge
instance when called in tests with a mocked AppStateMonitor.

Trace's Parcel deserialization constructor now uses
TransportManager.getInstance().getSessionManager() instead of
SessionManager.getInstance(). This is safe because Parcel deserialization
always occurs after FirebasePerfEarly has initialized the SDK.

Add getSessionManager() accessor to TransportManager and thread
sessionManager through initializeForTest() so test helpers can supply the
correct instance.
The private single-arg constructor now obtains SessionManager via
AppStateMonitor.getInstance().getSessionManager() instead of calling
SessionManager.getInstance(). AppStateMonitor.getInstance() is safe here
because FirebasePerfEarly (eager component) always seeds it before any
network request can be intercepted by user code.
- FirebasePerfRegistrarTest: update component count (3→4) and
  dependency assertions to include SessionManager
- FirebasePerformanceTest: construct spy SessionManager directly instead
  of spying on the now-deleted getInstance() return value
- AppStartTraceTest: use base-class sessionManager field in @after reset
  instead of SessionManager.getInstance()
- TraceTest: pre-seed AppStateMonitor with the test sessionManager in
  setUp; use sessionManager.updatePerfSession() in session-addition test
- NetworkRequestMetricBuilderTest: same AppStateMonitor pre-seed pattern;
  use sessionManager.updatePerfSession() in session-addition test
- TransportManagerTest: replace all SessionManager.getInstance() calls
  with the base-class sessionManager field; initializeForTest() now
  accepts and sets the sessionManager parameter
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

@tejasd tejasd self-requested a review April 1, 2026 15:53
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.

1 participant