-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable Hyperion on Firebase Test Lab
- Loading branch information
Showing
2 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
<manifest package="pl.droidsonroids.foqa"/> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="pl.droidsonroids.foqa"> | ||
|
||
<application> | ||
<provider | ||
android:name=".HyperionDisableProvider" | ||
android:authorities="${applicationId}.hyperionDisableProvider" | ||
android:exported="false" | ||
android:initOrder="-2147483648" /> | ||
</application> | ||
</manifest> |
41 changes: 41 additions & 0 deletions
41
library/src/main/java/pl/droidsonroids/foqa/HyperionDisableProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String>?, selection: String?, selectionArgs: Array<String>?, sortOrder: String?): Nothing? = null | ||
|
||
override fun update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<String>?) = 0 | ||
|
||
override fun delete(uri: Uri, selection: String?, selectionArgs: Array<String>?) = 0 | ||
|
||
override fun getType(uri: Uri): Nothing? = null | ||
} |