Skip to content

Commit

Permalink
App/Service: Introduce the isRunningOnEmulator property
Browse files Browse the repository at this point in the history
This patch introduces a property to check that the app is running
on the Android Emulator.

Signed-off-by: Wook Song <[email protected]>
  • Loading branch information
wooksong committed Jun 3, 2024
1 parent beea612 commit 532bb30
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.content.pm.PackageManager
import android.content.pm.ServiceInfo
import android.net.ConnectivityManager
import android.os.Binder
import android.os.Build
import android.os.Handler
import android.os.HandlerThread
import android.os.IBinder
Expand Down Expand Up @@ -53,6 +54,27 @@ class MainService : Service() {

private val TAG = "MainService"
private val binder = LocalBinder()
private val isRunningOnEmulator: Boolean
get() = (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic"))
|| Build.FINGERPRINT.startsWith("generic")
|| Build.FINGERPRINT.startsWith("unknown")
|| Build.HARDWARE.contains("goldfish")
|| Build.HARDWARE.contains("ranchu")
|| Build.MODEL.contains("google_sdk")
|| Build.MODEL.contains("Emulator")
|| Build.MODEL.contains("Android SDK built for x86")
|| Build.MANUFACTURER.contains("Genymotion")
|| Build.PRODUCT.contains("sdk_google")
|| Build.PRODUCT.contains("google_sdk")
|| Build.PRODUCT.contains("sdk")
|| Build.PRODUCT.contains("sdk_x86")
|| Build.PRODUCT.contains("sdk_gphone64_arm64")
|| Build.PRODUCT.contains("vbox86p")
|| Build.PRODUCT.contains("emulator")
|| Build.PRODUCT.contains("simulator")
|| Build.PRODUCT == "sdk_gphone64_arm64"
|| Build.FINGERPRINT == "robolectric"
|| Build.MANUFACTURER.contains("Geny")
private lateinit var serviceHandler : MainHandler
private lateinit var serviceLooper : Looper
private lateinit var handlerThread: HandlerThread
Expand Down

0 comments on commit 532bb30

Please sign in to comment.