How do I know if a game has been downloaded from Google Play?

Hello everyone, in order to implement some functions in my game, I need to find out where the game was downloaded from, from the official google play, or from torrent sites with hacked apk, no one knows how to check this?

I found something similar for unity, no one knows how to write it on UE4

public static boolean isPackageInstaller(Context appContext) {

String installerPackageName = appContext.getPackageManager().getInstallerPackageName(appContext.getPackageName());

return installerPackageName != null && installerPackageName.equals("com.android.vending");

}