From 414a873a8efd10150eccb1ea2288fbb60789edf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20Wr=C3=B3tniak?= Date: Thu, 1 Aug 2019 02:07:16 +0200 Subject: [PATCH] Disable Hyperion on Firebase Test Lab --- library/src/main/AndroidManifest.xml | 12 +++++- .../foqa/HyperionDisableProvider.kt | 41 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 library/src/main/java/pl/droidsonroids/foqa/HyperionDisableProvider.kt diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml index e5980e5..2bb2118 100644 --- a/library/src/main/AndroidManifest.xml +++ b/library/src/main/AndroidManifest.xml @@ -1 +1,11 @@ - \ No newline at end of file + + + + + + \ No newline at end of file diff --git a/library/src/main/java/pl/droidsonroids/foqa/HyperionDisableProvider.kt b/library/src/main/java/pl/droidsonroids/foqa/HyperionDisableProvider.kt new file mode 100644 index 0000000..652631c --- /dev/null +++ b/library/src/main/java/pl/droidsonroids/foqa/HyperionDisableProvider.kt @@ -0,0 +1,41 @@ +package pl.droidsonroids.foqa + +import android.content.ComponentName +import android.content.ContentProvider +import android.content.ContentValues +import android.content.Context +import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED +import android.content.pm.PackageManager.DONT_KILL_APP +import android.content.pm.ProviderInfo +import android.net.Uri +import android.provider.Settings +import com.willowtreeapps.hyperion.core.internal.HyperionInitProvider + +class HyperionDisableProvider : ContentProvider() { + + override fun onCreate() = true + + override fun attachInfo(context: Context, info: ProviderInfo?) { + super.attachInfo(context, info) + if (isRunningOnFirebaseTestLab(context)) { + disableHyperion(context) + } + } + + private fun isRunningOnFirebaseTestLab(context: Context) = Settings.System.getString(context.contentResolver, "firebase.test.lab") == "true" + + private fun disableHyperion(context: Context) { + val hyperionInitProvider = ComponentName(context, HyperionInitProvider::class.java) + context.packageManager.setComponentEnabledSetting(hyperionInitProvider, COMPONENT_ENABLED_STATE_DISABLED, DONT_KILL_APP) + } + + override fun insert(uri: Uri, values: ContentValues?): Nothing? = null + + override fun query(uri: Uri, projection: Array?, selection: String?, selectionArgs: Array?, sortOrder: String?): Nothing? = null + + override fun update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array?) = 0 + + override fun delete(uri: Uri, selection: String?, selectionArgs: Array?) = 0 + + override fun getType(uri: Uri): Nothing? = null +} \ No newline at end of file