Merge "Fix NullPointerException in PIA when installing from Files app" into udc-dev
This commit is contained in:
@@ -77,7 +77,21 @@ public class InstallStart extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final ApplicationInfo sourceInfo = getSourceInfo(callingPackage);
|
final ApplicationInfo sourceInfo = getSourceInfo(callingPackage);
|
||||||
final int originatingUid = getOriginatingUid(sourceInfo);
|
// Uid of the source package, coming from ActivityManager
|
||||||
|
int callingUid = getLaunchedFromUid();
|
||||||
|
if (callingUid == Process.INVALID_UID) {
|
||||||
|
// Cannot reach ActivityManager. Aborting install.
|
||||||
|
Log.e(LOG_TAG, "Could not determine the launching uid.");
|
||||||
|
}
|
||||||
|
// Uid of the source package, with a preference to uid from ApplicationInfo
|
||||||
|
final int originatingUid = sourceInfo != null ? sourceInfo.uid : callingUid;
|
||||||
|
|
||||||
|
if (callingUid == Process.INVALID_UID && sourceInfo == null) {
|
||||||
|
mAbortInstall = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isDocumentsManager = checkPermission(Manifest.permission.MANAGE_DOCUMENTS,
|
||||||
|
-1, callingUid) == PackageManager.PERMISSION_GRANTED;
|
||||||
boolean isTrustedSource = false;
|
boolean isTrustedSource = false;
|
||||||
if (sourceInfo != null && sourceInfo.isPrivilegedApp()) {
|
if (sourceInfo != null && sourceInfo.isPrivilegedApp()) {
|
||||||
isTrustedSource = intent.getBooleanExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, false) || (
|
isTrustedSource = intent.getBooleanExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, false) || (
|
||||||
@@ -86,7 +100,8 @@ public class InstallStart extends Activity {
|
|||||||
== PackageManager.PERMISSION_GRANTED);
|
== PackageManager.PERMISSION_GRANTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isTrustedSource && originatingUid != Process.INVALID_UID) {
|
if (!isTrustedSource && !isSystemDownloadsProvider(callingUid) && !isDocumentsManager
|
||||||
|
&& originatingUid != Process.INVALID_UID) {
|
||||||
final int targetSdkVersion = getMaxTargetSdkVersionForUid(this, originatingUid);
|
final int targetSdkVersion = getMaxTargetSdkVersionForUid(this, originatingUid);
|
||||||
if (targetSdkVersion < 0) {
|
if (targetSdkVersion < 0) {
|
||||||
Log.w(LOG_TAG, "Cannot get target sdk version for uid " + originatingUid);
|
Log.w(LOG_TAG, "Cannot get target sdk version for uid " + originatingUid);
|
||||||
@@ -144,7 +159,7 @@ public class InstallStart extends Activity {
|
|||||||
|
|
||||||
if (packageUri != null
|
if (packageUri != null
|
||||||
&& packageUri.getScheme().equals(ContentResolver.SCHEME_CONTENT)
|
&& packageUri.getScheme().equals(ContentResolver.SCHEME_CONTENT)
|
||||||
&& canPackageQuery(originatingUid, packageUri)) {
|
&& canPackageQuery(callingUid, packageUri)) {
|
||||||
// [IMPORTANT] This path is deprecated, but should still work. Only necessary
|
// [IMPORTANT] This path is deprecated, but should still work. Only necessary
|
||||||
// features should be added.
|
// features should be added.
|
||||||
|
|
||||||
@@ -213,41 +228,6 @@ public class InstallStart extends Activity {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the originating uid if possible, or {@link Process#INVALID_UID} if not available
|
|
||||||
*
|
|
||||||
* @param sourceInfo The source of this installation
|
|
||||||
* @return The UID of the installation source or INVALID_UID
|
|
||||||
*/
|
|
||||||
private int getOriginatingUid(@Nullable ApplicationInfo sourceInfo) {
|
|
||||||
// The originating uid from the intent. We only trust/use this if it comes from either
|
|
||||||
// the document manager app or the downloads provider
|
|
||||||
final int uidFromIntent = getIntent().getIntExtra(Intent.EXTRA_ORIGINATING_UID,
|
|
||||||
Process.INVALID_UID);
|
|
||||||
|
|
||||||
final int callingUid;
|
|
||||||
if (sourceInfo != null) {
|
|
||||||
callingUid = sourceInfo.uid;
|
|
||||||
} else {
|
|
||||||
callingUid = getLaunchedFromUid();
|
|
||||||
if (callingUid == Process.INVALID_UID) {
|
|
||||||
// Cannot reach ActivityManager. Aborting install.
|
|
||||||
Log.e(LOG_TAG, "Could not determine the launching uid.");
|
|
||||||
mAbortInstall = true;
|
|
||||||
return Process.INVALID_UID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (checkPermission(Manifest.permission.MANAGE_DOCUMENTS, -1, callingUid)
|
|
||||||
== PackageManager.PERMISSION_GRANTED) {
|
|
||||||
return uidFromIntent;
|
|
||||||
}
|
|
||||||
if (isSystemDownloadsProvider(callingUid)) {
|
|
||||||
return uidFromIntent;
|
|
||||||
}
|
|
||||||
// We don't trust uid from the intent. Use the calling uid instead.
|
|
||||||
return callingUid;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isSystemDownloadsProvider(int uid) {
|
private boolean isSystemDownloadsProvider(int uid) {
|
||||||
final ProviderInfo downloadProviderPackage = getPackageManager().resolveContentProvider(
|
final ProviderInfo downloadProviderPackage = getPackageManager().resolveContentProvider(
|
||||||
DOWNLOADS_AUTHORITY, 0);
|
DOWNLOADS_AUTHORITY, 0);
|
||||||
@@ -261,8 +241,7 @@ public class InstallStart extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private boolean canPackageQuery(int originatingUid, Uri packageUri) {
|
private boolean canPackageQuery(int callingUid, Uri packageUri) {
|
||||||
String callingPackage = mPackageManager.getPackagesForUid(originatingUid)[0];
|
|
||||||
ProviderInfo info = mPackageManager.resolveContentProvider(packageUri.getAuthority(),
|
ProviderInfo info = mPackageManager.resolveContentProvider(packageUri.getAuthority(),
|
||||||
PackageManager.ComponentInfoFlags.of(0));
|
PackageManager.ComponentInfoFlags.of(0));
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
@@ -270,11 +249,20 @@ public class InstallStart extends Activity {
|
|||||||
}
|
}
|
||||||
String targetPackage = info.packageName;
|
String targetPackage = info.packageName;
|
||||||
|
|
||||||
try {
|
String[] callingPackages = mPackageManager.getPackagesForUid(callingUid);
|
||||||
return mPackageManager.canPackageQuery(callingPackage, targetPackage);
|
if (callingPackages == null) {
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
for (String callingPackage: callingPackages) {
|
||||||
|
try {
|
||||||
|
if (mPackageManager.canPackageQuery(callingPackage, targetPackage)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isCallerSessionOwner(int originatingUid, int sessionId) {
|
private boolean isCallerSessionOwner(int originatingUid, int sessionId) {
|
||||||
|
|||||||
Reference in New Issue
Block a user