Skip to content

Commit 13d428e

Browse files
author
rich cannings
committed
Send more information to verifiers
Send package name, version code and the uid of the application requesting the install to package verifiers. Bug: 7164155 Change-Id: I2464dc5d4551f60b4f38f7982495a8920c83e1cd
1 parent a87826c commit 13d428e

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

core/java/android/content/pm/PackageManager.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,22 @@ public NameNotFoundException(String name) {
11501150
public static final String EXTRA_VERIFICATION_INSTALL_FLAGS
11511151
= "android.content.pm.extra.VERIFICATION_INSTALL_FLAGS";
11521152

1153+
/**
1154+
* Extra field name for the uid of who is requesting to install
1155+
* the package.
1156+
*
1157+
* @hide
1158+
*/
1159+
public static final String EXTRA_VERIFICATION_INSTALLER_UID
1160+
= "android.content.pm.extra.VERIFICATION_INSTALLER_UID";
1161+
1162+
/**
1163+
* Extra field name for the package name of a package pending verification.
1164+
*
1165+
* @hide
1166+
*/
1167+
public static final String EXTRA_VERIFICATION_PACKAGE_NAME
1168+
= "android.content.pm.extra.VERIFICATION_PACKAGE_NAME";
11531169
/**
11541170
* Extra field name for the result of a verification, either
11551171
* {@link #VERIFICATION_ALLOW}, or {@link #VERIFICATION_REJECT}.
@@ -1158,6 +1174,14 @@ public NameNotFoundException(String name) {
11581174
public static final String EXTRA_VERIFICATION_RESULT
11591175
= "android.content.pm.extra.VERIFICATION_RESULT";
11601176

1177+
/**
1178+
* Extra field name for the version code of a package pending verification.
1179+
*
1180+
* @hide
1181+
*/
1182+
public static final String EXTRA_VERIFICATION_VERSION_CODE
1183+
= "android.content.pm.extra.VERIFICATION_VERSION_CODE";
1184+
11611185
/**
11621186
* Retrieve overall information about an application package that is
11631187
* installed on the system.

core/java/android/content/pm/VerificationParams.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public class VerificationParams implements Parcelable {
3939
/** HTTP referrer URI associated with the originatingURI. */
4040
private final Uri mReferrer;
4141

42+
/** UID of application requesting the install */
43+
private int mInstallerUid;
44+
4245
/**
4346
* An object that holds the digest of the package which can be used to
4447
* verify ownership.
@@ -63,6 +66,7 @@ public VerificationParams(Uri verificationURI, Uri originatingURI, Uri referrer,
6366
mOriginatingURI = originatingURI;
6467
mReferrer = referrer;
6568
mManifestDigest = manifestDigest;
69+
mInstallerUid = -1;
6670
}
6771

6872
public Uri getVerificationURI() {
@@ -81,6 +85,15 @@ public ManifestDigest getManifestDigest() {
8185
return mManifestDigest;
8286
}
8387

88+
/** @return -1 when not set */
89+
public int getInstallerUid() {
90+
return mInstallerUid;
91+
}
92+
93+
public void setInstallerUid(int uid) {
94+
mInstallerUid = uid;
95+
}
96+
8497
@Override
8598
public int describeContents() {
8699
return 0;
@@ -126,6 +139,10 @@ public boolean equals(Object o) {
126139
return false;
127140
}
128141

142+
if (mInstallerUid != other.mInstallerUid) {
143+
return false;
144+
}
145+
129146
return true;
130147
}
131148

@@ -137,6 +154,7 @@ public int hashCode() {
137154
hash += 7 * (mOriginatingURI==null?1:mOriginatingURI.hashCode());
138155
hash += 11 * (mReferrer==null?1:mReferrer.hashCode());
139156
hash += 13 * (mManifestDigest==null?1:mManifestDigest.hashCode());
157+
hash += 17 * mInstallerUid;
140158

141159
return hash;
142160
}
@@ -153,6 +171,8 @@ public String toString() {
153171
sb.append(mReferrer.toString());
154172
sb.append(",mManifestDigest=");
155173
sb.append(mManifestDigest.toString());
174+
sb.append(",mInstallerUid=");
175+
sb.append(mInstallerUid);
156176
sb.append('}');
157177

158178
return sb.toString();
@@ -164,6 +184,7 @@ public void writeToParcel(Parcel dest, int flags) {
164184
dest.writeParcelable(mOriginatingURI, 0);
165185
dest.writeParcelable(mReferrer, 0);
166186
dest.writeParcelable(mManifestDigest, 0);
187+
dest.writeInt(mInstallerUid);
167188
}
168189

169190

@@ -172,6 +193,7 @@ private VerificationParams(Parcel source) {
172193
mOriginatingURI = source.readParcelable(Uri.class.getClassLoader());
173194
mReferrer = source.readParcelable(Uri.class.getClassLoader());
174195
mManifestDigest = source.readParcelable(ManifestDigest.class.getClassLoader());
196+
mInstallerUid = source.readInt();
175197
}
176198

177199
public static final Parcelable.Creator<VerificationParams> CREATOR =

core/tests/coretests/src/android/content/pm/VerificationParamsTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class VerificationParamsTest extends AndroidTestCase {
3434
private final static String ORIGINATING_URI_STRING = "http://originating.uri/path";
3535
private final static String REFERRER_STRING = "http://referrer.uri/path";
3636
private final static byte[] DIGEST_BYTES = "fake digest".getBytes();
37+
private final static int INSTALLER_UID = 42;
3738

3839
private final static Uri VERIFICATION_URI = Uri.parse(VERIFICATION_URI_STRING);
3940
private final static Uri ORIGINATING_URI = Uri.parse(ORIGINATING_URI_STRING);
@@ -115,6 +116,18 @@ public void testEquals_ManifestDigest_Failure() throws Exception {
115116
assertFalse(params1.equals(params2));
116117
}
117118

119+
public void testEquals_InstallerUid_Failure() throws Exception {
120+
VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI,
121+
REFERRER, MANIFEST_DIGEST);
122+
123+
VerificationParams params2 = new VerificationParams(
124+
Uri.parse(VERIFICATION_URI_STRING), Uri.parse(ORIGINATING_URI_STRING),
125+
Uri.parse(REFERRER_STRING), new ManifestDigest(DIGEST_BYTES));
126+
params2.setInstallerUid(INSTALLER_UID);
127+
128+
assertFalse(params1.equals(params2));
129+
}
130+
118131
public void testHashCode_Success() throws Exception {
119132
VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI,
120133
REFERRER, MANIFEST_DIGEST);
@@ -168,4 +181,16 @@ public void testHashCode_ManifestDigest_Failure() throws Exception {
168181

169182
assertFalse(params1.hashCode() == params2.hashCode());
170183
}
184+
185+
public void testHashCode_InstallerUid_Failure() throws Exception {
186+
VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI,
187+
REFERRER, MANIFEST_DIGEST);
188+
189+
VerificationParams params2 = new VerificationParams(
190+
Uri.parse(VERIFICATION_URI_STRING), Uri.parse(ORIGINATING_URI_STRING),
191+
Uri.parse(REFERRER_STRING), new ManifestDigest("a different digest".getBytes()));
192+
params2.setInstallerUid(INSTALLER_UID);
193+
194+
assertFalse(params1.hashCode() == params2.hashCode());
195+
}
171196
}

services/java/com/android/server/pm/PackageManagerService.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5664,6 +5664,8 @@ public void installPackageWithVerificationAndEncryption(Uri packageURI,
56645664
filteredFlags = flags & ~PackageManager.INSTALL_FROM_ADB;
56655665
}
56665666

5667+
verificationParams.setInstallerUid(uid);
5668+
56675669
final Message msg = mHandler.obtainMessage(INIT_COPY);
56685670
msg.obj = new InstallParams(packageURI, observer, filteredFlags, installerPackageName,
56695671
verificationParams, encryptionParams, user);
@@ -6428,6 +6430,12 @@ public void handleStartCopy() throws RemoteException {
64286430

64296431
verification.putExtra(PackageManager.EXTRA_VERIFICATION_INSTALL_FLAGS, flags);
64306432

6433+
verification.putExtra(PackageManager.EXTRA_VERIFICATION_PACKAGE_NAME,
6434+
pkgLite.packageName);
6435+
6436+
verification.putExtra(PackageManager.EXTRA_VERIFICATION_VERSION_CODE,
6437+
pkgLite.versionCode);
6438+
64316439
if (verificationParams != null) {
64326440
if (verificationParams.getVerificationURI() != null) {
64336441
verification.putExtra(PackageManager.EXTRA_VERIFICATION_URI,
@@ -6441,6 +6449,10 @@ public void handleStartCopy() throws RemoteException {
64416449
verification.putExtra(Intent.EXTRA_REFERRER,
64426450
verificationParams.getReferrer());
64436451
}
6452+
if (verificationParams.getInstallerUid() >= 0) {
6453+
verification.putExtra(PackageManager.EXTRA_VERIFICATION_INSTALLER_UID,
6454+
verificationParams.getInstallerUid());
6455+
}
64446456
}
64456457

64466458
final PackageVerificationState verificationState = new PackageVerificationState(

0 commit comments

Comments
 (0)