Search in sources :

Example 1 with ConfigResolver

use of com.google.firebase.perf.config.ConfigResolver in project firebase-android-sdk by firebase.

the class AppStateMonitorTest method screenTrace_perfMonDeactivated_traceNotCreated.

@Test
public void screenTrace_perfMonDeactivated_traceNotCreated() {
    AppStateMonitor monitor = new AppStateMonitor(transportManager, clock);
    Activity activityWithNonHardwareAcceleratedView = createFakeActivity(/* isHardwareAccelerated =*/
    true);
    ConfigResolver configResolver = ConfigResolver.getInstance();
    configResolver.setDeviceCacheManager(new DeviceCacheManager(new FakeDirectExecutorService()));
    Bundle bundle = new Bundle();
    bundle.putBoolean("firebase_performance_collection_deactivated", true);
    configResolver.setMetadataBundle(new ImmutableBundle(bundle));
    // Developer has enabled Performance Monitoring during runtime.
    configResolver.setIsPerformanceCollectionEnabled(true);
    // Assert that screen trace has not been created.
    monitor.onActivityStarted(activityWithNonHardwareAcceleratedView);
    assertThat(monitor.getActivity2ScreenTrace()).isEmpty();
    // Confirm that this doesn't throw an exception.
    monitor.onActivityStopped(activityWithNonHardwareAcceleratedView);
}
Also used : ConfigResolver(com.google.firebase.perf.config.ConfigResolver) Bundle(android.os.Bundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) Activity(android.app.Activity) DeviceCacheManager(com.google.firebase.perf.config.DeviceCacheManager) FakeDirectExecutorService(com.google.testing.timing.FakeDirectExecutorService) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) Test(org.junit.Test)

Example 2 with ConfigResolver

use of com.google.firebase.perf.config.ConfigResolver in project firebase-android-sdk by firebase.

the class AppStateMonitorTest method setUp.

@Before
public void setUp() {
    currentTime = 0;
    initMocks(this);
    doAnswer((Answer<Timer>) invocationOnMock -> new Timer(currentTime)).when(clock).getTime();
    activity1 = createFakeActivity(/* isHardwareAccelerated= */
    true);
    activity2 = createFakeActivity(/* isHardwareAccelerated= */
    true);
    DeviceCacheManager.clearInstance();
    ConfigResolver.clearInstance();
    ConfigResolver configResolver = ConfigResolver.getInstance();
    configResolver.setDeviceCacheManager(new DeviceCacheManager(new FakeDirectExecutorService()));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockitoAnnotations.initMocks(org.mockito.MockitoAnnotations.initMocks) Context(android.content.Context) TraceMetric(com.google.firebase.perf.v1.TraceMetric) ActivityController(org.robolectric.android.controller.ActivityController) Bundle(android.os.Bundle) ArgumentMatchers.nullable(org.mockito.ArgumentMatchers.nullable) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Captor(org.mockito.Captor) Answer(org.mockito.stubbing.Answer) DeviceCacheManager(com.google.firebase.perf.config.DeviceCacheManager) Constants(com.google.firebase.perf.util.Constants) PerfSession(com.google.firebase.perf.v1.PerfSession) ArgumentCaptor(org.mockito.ArgumentCaptor) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) WeakReference(java.lang.ref.WeakReference) FirebasePerformanceTestBase(com.google.firebase.perf.FirebasePerformanceTestBase) GaugeManager(com.google.firebase.perf.session.gauges.GaugeManager) ConfigResolver(com.google.firebase.perf.config.ConfigResolver) Before(org.junit.Before) FirebasePerformanceInitializer(com.google.firebase.perf.FirebasePerformanceInitializer) Timer(com.google.firebase.perf.util.Timer) NetworkRequestMetricBuilder(com.google.firebase.perf.metrics.NetworkRequestMetricBuilder) FOREGROUND_BACKGROUND(com.google.firebase.perf.v1.ApplicationProcessState.FOREGROUND_BACKGROUND) Clock(com.google.firebase.perf.util.Clock) Robolectric(org.robolectric.Robolectric) Trace(com.google.firebase.perf.metrics.Trace) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Truth.assertThat(com.google.common.truth.Truth.assertThat) FakeDirectExecutorService(com.google.testing.timing.FakeDirectExecutorService) TransportManager(com.google.firebase.perf.transport.TransportManager) Mockito.verify(org.mockito.Mockito.verify) SessionManager(com.google.firebase.perf.session.SessionManager) RobolectricTestRunner(org.robolectric.RobolectricTestRunner) Mockito.never(org.mockito.Mockito.never) Application(android.app.Application) LayoutParams(android.view.WindowManager.LayoutParams) Assert(org.junit.Assert) Activity(android.app.Activity) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) ConfigResolver(com.google.firebase.perf.config.ConfigResolver) Timer(com.google.firebase.perf.util.Timer) DeviceCacheManager(com.google.firebase.perf.config.DeviceCacheManager) FakeDirectExecutorService(com.google.testing.timing.FakeDirectExecutorService) Before(org.junit.Before)

Example 3 with ConfigResolver

use of com.google.firebase.perf.config.ConfigResolver in project firebase-android-sdk by firebase.

the class FirebasePerfProvider method attachInfo.

@Override
public void attachInfo(Context context, ProviderInfo info) {
    // super.attachInfo calls onCreate(). Fail as early as possible.
    checkContentProviderAuthority(info);
    super.attachInfo(context, info);
    // Initialize ConfigResolver early for accessing device caching layer.
    ConfigResolver configResolver = ConfigResolver.getInstance();
    configResolver.setContentProviderContext(getContext());
    AppStateMonitor appStateMonitor = AppStateMonitor.getInstance();
    appStateMonitor.registerActivityLifecycleCallbacks(getContext());
    appStateMonitor.registerForAppColdStart(new FirebasePerformanceInitializer());
    AppStartTrace appStartTrace = AppStartTrace.getInstance();
    appStartTrace.registerActivityLifecycleCallbacks(getContext());
    mainHandler.post(new AppStartTrace.StartFromBackgroundRunnable(appStartTrace));
    // In the case of cold start, we create a session and start collecting gauges as early as
    // possible.
    // There is code in SessionManager that prevents us from resetting the session twice in case
    // of app cold start.
    SessionManager.getInstance().initializeGaugeCollection();
}
Also used : ConfigResolver(com.google.firebase.perf.config.ConfigResolver) AppStartTrace(com.google.firebase.perf.metrics.AppStartTrace) AppStateMonitor(com.google.firebase.perf.application.AppStateMonitor) FirebasePerformanceInitializer(com.google.firebase.perf.FirebasePerformanceInitializer)

Example 4 with ConfigResolver

use of com.google.firebase.perf.config.ConfigResolver in project firebase-android-sdk by firebase.

the class PerfSessionTest method shouldCollectGaugesAndEvents_perfMonDisabledAtBuildtime_verbosityDependsOnRuntime.

@Test
public void shouldCollectGaugesAndEvents_perfMonDisabledAtBuildtime_verbosityDependsOnRuntime() {
    ConfigResolver configResolver = ConfigResolver.getInstance();
    // Developer disables Performance collection at AndroidManifest.
    Bundle bundle = new Bundle();
    bundle.putFloat("sessions_sampling_percentage", 100f);
    bundle.putBoolean("firebase_performance_collection_enabled", false);
    configResolver.setMetadataBundle(new ImmutableBundle(bundle));
    // By default, session is not verbose if developer disabled performance monitoring at build
    // time.
    assertThat(PerfSession.shouldCollectGaugesAndEvents()).isFalse();
    // Case #1: developer has enabled Performance Monitoring during runtime.
    configResolver.setIsPerformanceCollectionEnabled(true);
    assertThat(PerfSession.shouldCollectGaugesAndEvents()).isTrue();
    // Case #2: developer has disabled Performance Monitoring during runtime.
    configResolver.setIsPerformanceCollectionEnabled(false);
    assertThat(PerfSession.shouldCollectGaugesAndEvents()).isFalse();
}
Also used : ConfigResolver(com.google.firebase.perf.config.ConfigResolver) Bundle(android.os.Bundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) Test(org.junit.Test)

Example 5 with ConfigResolver

use of com.google.firebase.perf.config.ConfigResolver in project firebase-android-sdk by firebase.

the class PerfSessionTest method shouldCollectGaugesAndEvents_perfMonDisabledAtRuntime_sessionNotVerbose.

@Test
public void shouldCollectGaugesAndEvents_perfMonDisabledAtRuntime_sessionNotVerbose() {
    ConfigResolver configResolver = ConfigResolver.getInstance();
    Bundle bundle = new Bundle();
    bundle.putFloat("sessions_sampling_percentage", 100f);
    configResolver.setMetadataBundle(new ImmutableBundle(bundle));
    // By default, session is verbose if developer has set 100% of session verbosity.
    assertThat(PerfSession.shouldCollectGaugesAndEvents()).isTrue();
    // Case #1: developer has disabled Performance Monitoring during runtime.
    configResolver.setIsPerformanceCollectionEnabled(false);
    assertThat(PerfSession.shouldCollectGaugesAndEvents()).isFalse();
    // Case #2: developer has enabled Performance Monitoring during runtime.
    configResolver.setIsPerformanceCollectionEnabled(true);
    assertThat(PerfSession.shouldCollectGaugesAndEvents()).isTrue();
}
Also used : ConfigResolver(com.google.firebase.perf.config.ConfigResolver) Bundle(android.os.Bundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) ImmutableBundle(com.google.firebase.perf.util.ImmutableBundle) Test(org.junit.Test)

Aggregations

ConfigResolver (com.google.firebase.perf.config.ConfigResolver)8 Test (org.junit.Test)6 Bundle (android.os.Bundle)5 ImmutableBundle (com.google.firebase.perf.util.ImmutableBundle)5 DeviceCacheManager (com.google.firebase.perf.config.DeviceCacheManager)4 FakeDirectExecutorService (com.google.testing.timing.FakeDirectExecutorService)4 Before (org.junit.Before)3 Activity (android.app.Activity)2 Context (android.content.Context)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 FirebasePerformanceInitializer (com.google.firebase.perf.FirebasePerformanceInitializer)2 FirebasePerformanceTestBase (com.google.firebase.perf.FirebasePerformanceTestBase)2 AppStateMonitor (com.google.firebase.perf.application.AppStateMonitor)2 SessionManager (com.google.firebase.perf.session.SessionManager)2 GaugeManager (com.google.firebase.perf.session.gauges.GaugeManager)2 TransportManager (com.google.firebase.perf.transport.TransportManager)2 Clock (com.google.firebase.perf.util.Clock)2 Constants (com.google.firebase.perf.util.Constants)2 Timer (com.google.firebase.perf.util.Timer)2 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)2