[utils] add support for isRunningInTestLab flag

This commit is contained in:
Salakar
2019-02-20 01:52:05 +00:00
parent bef20f76eb
commit 70fb9afe02
5 changed files with 47 additions and 34 deletions

View File

@@ -19,6 +19,7 @@ package io.invertase.firebase.utils;
import android.app.Activity;
import android.content.IntentSender;
import android.provider.Settings;
import android.util.Log;
import com.facebook.react.bridge.Arguments;
@@ -32,16 +33,32 @@ import com.google.android.gms.common.GoogleApiAvailability;
import java.util.HashMap;
import java.util.Map;
import io.invertase.firebase.app.ReactNativeFirebaseApp;
import io.invertase.firebase.common.ReactNativeFirebaseModule;
import io.invertase.firebase.common.SharedUtils;
public class ReactNativeFirebaseUtilsModule extends ReactNativeFirebaseModule {
private static final String TAG = "Utils";
private static final String FIREBASE_TEST_LAB = "firebase.test.lab";
ReactNativeFirebaseUtilsModule(ReactApplicationContext reactContext) {
super(reactContext, TAG);
}
/**
* Is this app running in Firebase Test Lab
*
* @return Boolean
*/
private static Boolean isRunningInTestLab() {
String testLabSetting = Settings.System.getString(
ReactNativeFirebaseApp.getApplicationContext().getContentResolver(),
FIREBASE_TEST_LAB
);
return "true".equals(testLabSetting);
}
@ReactMethod
public void androidGetPlayServicesStatus(Promise promise) {
promise.resolve(getPlayServicesStatusMap());
@@ -53,16 +70,12 @@ public class ReactNativeFirebaseUtilsModule extends ReactNativeFirebaseModule {
@ReactMethod
public void androidPromptForPlayServices() {
int status = isGooglePlayServicesAvailable();
GoogleApiAvailability gapi = GoogleApiAvailability.getInstance();
if (
status != ConnectionResult.SUCCESS &&
GoogleApiAvailability.getInstance().isUserResolvableError(status)
) {
if (status != ConnectionResult.SUCCESS && gapi.isUserResolvableError(status)) {
Activity activity = getActivity();
if (activity != null) {
GoogleApiAvailability.getInstance()
.getErrorDialog(activity, status, status)
.show();
gapi.getErrorDialog(activity, status, status).show();
}
}
}
@@ -129,8 +142,8 @@ public class ReactNativeFirebaseUtilsModule extends ReactNativeFirebaseModule {
@Override
public Map<String, Object> getConstants() {
Map<String, Object> constants = new HashMap<>();
constants.put("isRunningInTestLab", isRunningInTestLab());
constants.put("androidPlayServices", getPlayServicesStatusMap());
constants.put("isFirebaseTestLab", SharedUtils.isFirebaseTestLab());
return constants;
}
}

View File

@@ -22,23 +22,11 @@ describe('utils()', () => {
should.exist(app.utils);
app.utils().app.should.equal(app);
});
});
// removing as pending if module.options.hasMultiAppSupport = true
xit('supports multiple apps', async () => {
firebase.utils().app.name.should.equal('[DEFAULT]');
firebase
.utils(firebase.app('secondaryFromNative'))
.app.name.should.equal('secondaryFromNative');
firebase
.app('secondaryFromNative')
.utils()
.app.name.should.equal('secondaryFromNative');
describe('isRunningInTestLab', () => {
it('returns true or false', () => {
should.equal(firebase.utils().isRunningInTestLab, false);
});
});
describe('aMethod()', () => {
// TODO
});
});

View File

@@ -30,7 +30,12 @@ export namespace Utils {
export interface Statics {}
export interface Module extends ReactNativeFirebaseModule {
/**
* Returns true if this app is running inside a Firebase Test Lab environment. Always returns false on iOS.
*
* @android
*/
isRunningInTestLab: boolean;
}
}
@@ -68,12 +73,9 @@ declare module '@react-native-firebase/utils' {
declare module '@react-native-firebase/app-types' {
interface ReactNativeFirebaseNamespace {
/**
* Utils integrates across Firebase features and provides
* you with unlimited reporting for up to 500 distinct events
* that you can define using the Firebase SDK. Utils reports
* help you understand clearly how your users behave, which enables
* you to make informed decisions regarding app marketing and
* performance optimizations.
* Utils provides a collection of utilities to aid in using Firebase
* and related services inside React Native, e.g. Test Lab helpers
* and Google Play Services version helpers.
*/
utils: ReactNativeFirebaseModuleAndStatics<
Utils.Module,

View File

@@ -21,6 +21,8 @@ import {
getFirebaseRoot,
} from '@react-native-firebase/app/lib/internal';
import { isIOS } from '@react-native-firebase/common';
import version from './version';
const statics = {};
@@ -30,7 +32,10 @@ const namespace = 'utils';
const nativeModuleName = 'RNFBUtilsModule';
class FirebaseUtilsModule extends FirebaseModule {
get isRunningInTestLab() {
if (isIOS) return false;
return this.native.isRunningInTestLab;
}
}
// import { SDK_VERSION } from '@react-native-firebase/utils';

View File

@@ -21,7 +21,12 @@ import type { ReactNativeFirebaseModule } from '@react-native-firebase/app-types
export interface Statics {}
export interface Module extends ReactNativeFirebaseModule {
/**
* Returns true if this app is running inside a Firebase Test Lab environment. Always returns false on iOS.
*
* @android
*/
isRunningInTestLab: boolean;
}
declare module '@react-native-firebase/utils' {