Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.InstallSourceInfo;
import android.net.Uri;
import android.os.Build;
import android.util.Log;
Expand Down Expand Up @@ -220,7 +221,24 @@ private boolean isPlayServicesAvailable() {

private boolean appInstalledBySupportedStore() {
final List<String> validInstallers = new ArrayList<>(Arrays.asList("com.android.vending"));
final String installer = context.getPackageManager().getInstallerPackageName(context.getPackageName());
final PackageManager pm = context.getPackageManager();
final String pkg = context.getPackageName();
String installer = null;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { // API 30+
try {
InstallSourceInfo info = pm.getInstallSourceInfo(pkg);
if (info != null) {
installer = info.getInstallingPackageName();
if (installer == null) installer = info.getInitiatingPackageName();
}
} catch (PackageManager.NameNotFoundException ignored) { }
} else {
@SuppressWarnings("deprecation")
String legacy = pm.getInstallerPackageName(pkg);
installer = legacy;
}

Log.i(TAG, "appInstalledBySupportedStore: installer: " + installer);
return installer != null && validInstallers.contains(installer);
}
Expand Down