use of com.google.firebase.perf.config.DeviceCacheManager in project firebase-android-sdk by firebase.
the class FirebasePerformanceTest method initializeFirebasePerformancePreferences.
/**
* Creates a FirebasePerformance instance in a way that imitates the given manifest metadata or
* sharedPreferences are present.
*
* @param metadataFireperfForceDeactivatedKey The value for the metadata key {@link
* #FIREPERF_FORCE_DEACTIVATED_KEY}. If null is passed, this key value pair will not be added
* to the bundle.
* @param metadataFireperfEnabledKey The value for the metadata key {@link #FIREPERF_ENABLED_KEY}.
* If null is passed, this key value pair will not be added to the bundle.
* @param sharedPreferencesEnabledDisabledKey The value for the sharedPreferences key {@link
* Constants#ENABLE_DISABLE}. If null is passed, this key value pair will not be added to the
* sharedPreferences.
* @param firebaseRemoteConfigProvider The {@link Provider} for FirebaseRemoteConfig instance.
* @return The FirebasePerformance instance initialized as if the given manifest metadata or
* sharedPreferences are present.
*/
private FirebasePerformance initializeFirebasePerformancePreferences(Boolean metadataFireperfForceDeactivatedKey, Boolean metadataFireperfEnabledKey, Boolean sharedPreferencesEnabledDisabledKey, Provider<RemoteConfigComponent> firebaseRemoteConfigProvider, Provider<TransportFactory> transportFactoryProvider) {
DeviceCacheManager deviceCacheManager = new DeviceCacheManager(fakeDirectExecutorService);
deviceCacheManager.setContext(ApplicationProvider.getApplicationContext());
if (sharedPreferencesEnabledDisabledKey != null) {
deviceCacheManager.setValue(Constants.ENABLE_DISABLE, sharedPreferencesEnabledDisabledKey);
}
spyConfigResolver.setDeviceCacheManager(deviceCacheManager);
Bundle bundle = new Bundle();
if (metadataFireperfEnabledKey != null) {
bundle.putBoolean(FIREPERF_ENABLED_KEY, metadataFireperfEnabledKey);
}
if (metadataFireperfForceDeactivatedKey != null) {
bundle.putBoolean(FIREPERF_FORCE_DEACTIVATED_KEY, metadataFireperfForceDeactivatedKey);
}
Context context = ApplicationProvider.getApplicationContext();
shadowOf(context.getPackageManager()).getInternalMutablePackageInfo(context.getPackageName()).applicationInfo.metaData.putAll(bundle);
return new FirebasePerformance(FirebaseApp.getInstance(), firebaseRemoteConfigProvider, mock(FirebaseInstallationsApi.class), transportFactoryProvider, spyRemoteConfigManager, spyConfigResolver, spySessionManager);
}
use of com.google.firebase.perf.config.DeviceCacheManager 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);
}
use of com.google.firebase.perf.config.DeviceCacheManager 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()));
}
use of com.google.firebase.perf.config.DeviceCacheManager in project firebase-android-sdk by firebase.
the class PerfSessionTest method setUp.
@Before
public void setUp() {
initMocks(this);
DeviceCacheManager.clearInstance();
ConfigResolver.clearInstance();
appContext.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit().clear().commit();
ConfigResolver configResolver = ConfigResolver.getInstance();
configResolver.setApplicationContext(appContext);
configResolver.setDeviceCacheManager(new DeviceCacheManager(new FakeDirectExecutorService()));
}
use of com.google.firebase.perf.config.DeviceCacheManager in project firebase-android-sdk by firebase.
the class TraceTest method setUp.
@Before
public void setUp() {
currentTime = 1;
initMocks(this);
doAnswer((Answer<Timer>) invocationOnMock -> new Timer(currentTime)).when(mockClock).getTime();
arguments = ArgumentCaptor.forClass(TraceMetric.class);
DeviceCacheManager.clearInstance();
ConfigResolver.clearInstance();
appContext.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit().clear().commit();
ConfigResolver configResolver = ConfigResolver.getInstance();
configResolver.setDeviceCacheManager(new DeviceCacheManager(new FakeDirectExecutorService()));
configResolver.setApplicationContext(appContext);
}
Aggregations