Fix PackageInstaller failure when called from different user

This change checks across all users for the calling uid when doing the
permission check.

Test: Will test in droidfood
Bug: 153868618
Change-Id: Ic599315444212119ce4cb9ac1b06147e9cf19ef3
This commit is contained in:
Evan Severson
2020-04-15 12:44:39 -07:00
parent b86e5a77a1
commit 0461f6fd4d

View File

@@ -30,13 +30,17 @@ import android.content.pm.IPackageManager;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.content.pm.UserInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.UserManager;
import android.permission.IPermissionManager;
import android.util.Log;
import java.util.List;
/**
* Select which activity is the first visible activity of the installation and forward the intent to
* it.
@@ -47,6 +51,7 @@ public class InstallStart extends Activity {
private static final String DOWNLOADS_AUTHORITY = "downloads";
private IPackageManager mIPackageManager;
private IPermissionManager mIPermissionManager;
private UserManager mUserManager;
private boolean mAbortInstall = false;
@Override
@@ -54,6 +59,7 @@ public class InstallStart extends Activity {
super.onCreate(savedInstanceState);
mIPackageManager = AppGlobals.getPackageManager();
mIPermissionManager = AppGlobals.getPermissionManager();
mUserManager = getSystemService(UserManager.class);
Intent intent = getIntent();
String callingPackage = getCallingPackage();
@@ -144,13 +150,16 @@ public class InstallStart extends Activity {
if (packages == null) {
return false;
}
final List<UserInfo> users = mUserManager.getUsers();
for (String packageName : packages) {
try {
if (uid == getPackageManager().getPackageUid(packageName, 0)) {
return true;
for (UserInfo user : users) {
try {
if (uid == getPackageManager().getPackageUidAsUser(packageName, user.id)) {
return true;
}
} catch (PackageManager.NameNotFoundException e) {
// Ignore and try the next package
}
} catch (PackageManager.NameNotFoundException e) {
// Ignore and try the next package
}
}
} catch (RemoteException rexc) {