Add functionality to detect if Player is running in emulator (BlueStacks)

Some of our players started to play our Android game using an Android emulator (BlueStacks) on PC.

I would like to detect it to set a custom metadata field in the CrashReportHandler, to filter Cloud Diagnostics reports based on whether the game is running in an emulator.

Please add functionality to detect whether an Android Player is running in an emulator.

If there is functionality in Unity to get this information already, please let me know. I didn’t find any API for it yet.

PS: Related to this post .

1 Like

Did you try looking at the Unity - Scripting API: SystemInfo.deviceName and Unity - Scripting API: SystemInfo.deviceModel.

Maybe you can use that?

1 Like

Thank you for the reply.

I added a test that displays the information gathered from SystemInfo. Everything looks pretty device’ish to me, expect for perhaps GraphicsDeviceID and GraphicsDeviceVendorID, which are both 0. However, I’m not sure whether these are also 0 for other Android devices. Do you know if these can be 0 on real Android devices too?

EDIT/UPDATE: (some) real devices also report 0 for GraphicsDeviceID and GraphicsDeviceVendorID.

Here is the SystemInfo dump running in BlueStacks:

7688245--961768--upload_2021-11-26_7-1-21.jpg

7688245--961771--upload_2021-11-26_7-1-38.jpg

Sadly I do not know, this would require checking.

This feature would be really useful. I’m also receiving some crash reports really suspicious to be running on an emulator and I have no way to know if that’s the case.
Building for iOS in our case.

1 Like

I would also like to see a feature detecting Android emulation.

This might work. Haven’t tested it, but the equivalent code works in Java.

public static class DeviceSpy
{

  private static readonly string[] s_BlueStacksDirSigs =
  {
    "/sdcard/windows/BstSharedFolder",
    "/mnt/windows/BstSharedFolder",
  };

  public static bool IsRunningBlueStacks()
  {
    foreach (string dir in s_BlueStacksDirSigs)
      if (System.IO.Directory.Exists(dir))
        return true;

    return false;
  }
}

Note that I only know this works with BlueStacks 4 and 5. (I just have yet to test anything else.)

I have no idea if this works with the cloud version, however I’m pretty sure that unless you publish your game to the BlueStacks game center yourself, you shouldn’t need to worry about the cloud version running your game.

Also, the “windows” directory is still named as such even on the Mac version (I just verified).

Let me know if this works for you!
:spades: LP

2 Likes

I can confirm that this code works on BlueStacks v5.5. Here is a shortened version of it using linq:

using System.Linq;

public static class DeviceSpy
{

  private static readonly string[] s_BlueStacksDirSigs =
  {
       "/sdcard/windows/BstSharedFolder",
       "/mnt/windows/BstSharedFolder",
  };

  public static bool IsRunningBlueStacks()
  {
      return s_BlueStacksDirSigs.Any(System.IO.Directory.Exists);
  }
}
1 Like

Thank you for the reply. I can confirm it works in BlueStacks 5.5.

I also found that some (but probably not all) Unity Cloud Diagnostics reports have com.bluestacks.BstCommandProcessor as install_store in the Meta Data. I guess it’s set when you install the APK from file, instead over the store.