diff --git a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserApplication.java b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserApplication.java index 21519c3d0b..645970da9f 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserApplication.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserApplication.java @@ -27,6 +27,7 @@ import org.mozilla.vrbrowser.utils.BitmapCache; import org.mozilla.vrbrowser.utils.EnvironmentsManager; import org.mozilla.vrbrowser.utils.LocaleUtils; +import org.mozilla.vrbrowser.utils.SystemUtils; public class VRBrowserApplication extends Application implements AppServicesProvider { @@ -42,6 +43,13 @@ public class VRBrowserApplication extends Application implements AppServicesProv @Override public void onCreate() { super.onCreate(); + + if (!SystemUtils.isMainProcess(this)) { + return; + } + + TelemetryWrapper.init(this, EngineProvider.INSTANCE.getDefaultClient(this)); + GleanMetricsService.init(this, EngineProvider.INSTANCE.getDefaultClient(this)); } protected void onActivityCreate(@NonNull Context activityContext) { @@ -53,9 +61,6 @@ protected void onActivityCreate(@NonNull Context activityContext) { mAppExecutors = new AppExecutors(); mBitmapCache = new BitmapCache(this, mAppExecutors.diskIO(), mAppExecutors.mainThread()); mEnvironmentsManager = new EnvironmentsManager(activityContext); - - TelemetryWrapper.init(this, EngineProvider.INSTANCE.getDefaultClient(this)); - GleanMetricsService.init(this, EngineProvider.INSTANCE.getDefaultClient(this)); } @Override diff --git a/app/src/common/shared/org/mozilla/vrbrowser/utils/SystemUtils.java b/app/src/common/shared/org/mozilla/vrbrowser/utils/SystemUtils.java index 959cc8a04d..eb0cd5c4a3 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/utils/SystemUtils.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/utils/SystemUtils.java @@ -1,9 +1,11 @@ package org.mozilla.vrbrowser.utils; +import android.app.ActivityManager; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; +import android.os.Process; import android.util.Log; import androidx.annotation.NonNull; @@ -113,4 +115,16 @@ public static void clearCrashFiles(@NonNull Context context, final ArrayList + processInfo.pid == pid && processInfo.processName.equals(context.getPackageName())); + } + } diff --git a/app/src/test/java/org/mozilla/vrbrowser/GleanMetricsServiceTest.kt b/app/src/test/java/org/mozilla/vrbrowser/GleanMetricsServiceTest.kt index 338ce9a23a..f49d49186c 100644 --- a/app/src/test/java/org/mozilla/vrbrowser/GleanMetricsServiceTest.kt +++ b/app/src/test/java/org/mozilla/vrbrowser/GleanMetricsServiceTest.kt @@ -18,7 +18,7 @@ import org.robolectric.annotation.Config @RunWith(RobolectricTestRunner::class) -@Config(manifest = Config.NONE) +@Config(manifest = Config.NONE, application = TestApplication::class) class GleanMetricsServiceTest { @get:Rule @@ -26,7 +26,7 @@ class GleanMetricsServiceTest { @Before fun setup() { - val app = ApplicationProvider.getApplicationContext() + val app = ApplicationProvider.getApplicationContext() // We use the HttpURLConnectionClient for tests as the GeckoWebExecutor based client needs // full GeckoRuntime initialization and it crashes in the test environment. val client = HttpURLConnectionClient() diff --git a/app/src/test/java/org/mozilla/vrbrowser/TestApplication.kt b/app/src/test/java/org/mozilla/vrbrowser/TestApplication.kt new file mode 100644 index 0000000000..be6ff5d3cb --- /dev/null +++ b/app/src/test/java/org/mozilla/vrbrowser/TestApplication.kt @@ -0,0 +1,5 @@ +package org.mozilla.vrbrowser + +import android.app.Application + +class TestApplication: Application() \ No newline at end of file