Disable analytics in firebase test lab

I'm also keeping analytics disabled by default.
This commit is contained in:
Vishesh Handa
2019-06-02 17:12:22 +02:00
parent 2bfd6ea199
commit f3b73df119
5 changed files with 51 additions and 20 deletions

View File

@ -49,5 +49,6 @@
</activity>
<meta-data android:name="google_analytics_adid_collection_enabled" android:value="false" />
<meta-data android:name="firebase_analytics_collection_enabled" android:value="false" />
</application>
</manifest>

View File

@ -1,6 +1,8 @@
package io.gitjournal.gitjournal;
import android.content.Context;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.WindowManager;
@ -38,7 +40,8 @@ public class MainActivity extends FlutterActivity implements MethodCallHandler {
@Override
public void onMethodCall(MethodCall call, Result result) {
final String filesDir = PathUtils.getFilesDir(getApplicationContext());
Context context = getApplicationContext();
final String filesDir = PathUtils.getFilesDir(context);
final String sshKeysLocation = filesDir + "/ssh";
final String privateKeyPath = sshKeysLocation + "/id_rsa";
final String publicKeyPath = sshKeysLocation + "/id_rsa.pub";
@ -242,6 +245,20 @@ public class MainActivity extends FlutterActivity implements MethodCallHandler {
result.success(filePath);
return;
} else if (call.method.equals("shouldEnableAnalytics")) {
boolean shouldBe = true;
String testLabSetting =
Settings.System.getString(context.getContentResolver(), "firebase.test.lab");
if ("true".equals(testLabSetting)) {
shouldBe = false;
}
if (BuildConfig.DEBUG) {
shouldBe = false;
}
result.success(shouldBe);
return;
}
result.notImplemented();

View File

@ -7,6 +7,7 @@ import 'package:journal/screens/home_screen.dart';
import 'package:journal/screens/settings_screen.dart';
import 'package:journal/settings.dart';
import 'package:journal/state_container.dart';
import 'package:journal/utils.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'screens/githostsetup_screens.dart';
@ -35,24 +36,7 @@ class JournalApp extends StatelessWidget {
print("onBoardingCompleted: $onBoardingCompleted");
print(" ------------------ ");
//
// Check if in debugMode or not a real device
//
assert(JournalApp.isInDebugMode = true);
try {
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
if (androidInfo.isPhysicalDevice == false) {
print("Not running in a physcial device");
JournalApp.isInDebugMode = true;
}
} catch (e) {
print(e);
}
if (JournalApp.isInDebugMode) {
JournalApp.analytics.setAnalyticsCollectionEnabled(false);
}
_enableAnalyticsIfPossible();
if (localGitRepoConfigured == false) {
// FIXME: What about exceptions!
@ -81,6 +65,29 @@ class JournalApp extends StatelessWidget {
));
}
static void _enableAnalyticsIfPossible() async {
//
// Check if in debugMode or not a real device
//
assert(JournalApp.isInDebugMode = true);
try {
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
if (androidInfo.isPhysicalDevice == false) {
print("Not running in a physcial device");
JournalApp.isInDebugMode = true;
}
} catch (e) {
print(e);
}
bool should = (JournalApp.isInDebugMode == false);
should = should && (await shouldEnableAnalytics());
print("Analytics Collection: $should");
JournalApp.analytics.setAnalyticsCollectionEnabled(should);
}
static FirebaseAnalytics analytics = FirebaseAnalytics();
static FirebaseAnalyticsObserver observer =
FirebaseAnalyticsObserver(analytics: analytics);

View File

@ -20,6 +20,12 @@ Future<String> getVersionString() async {
return versionText;
}
Future<bool> shouldEnableAnalytics() async {
const _platform = const MethodChannel('gitjournal.io/git');
final bool result = await _platform.invokeMethod('shouldEnableAnalytics');
return result;
}
/// adb logcat
/// Returns the file path where the logs were dumped
Future<String> dumpAppLogs() async {

View File

@ -1,6 +1,6 @@
name: journal
description: A Journaling App Built on top of Git
version: 1.1.5+10
version: 1.1.6+10
dependencies:
flutter: