Skip to content

Commit 706e8ba

Browse files
author
rich cannings
committed
Pass URLs to package verifiers
This change passes the originating URL and accompanied referrer to package verifiers, when available. Bug: 6544677 Change-Id: I9ebc71bc13f549bd88267e444816151a99bda000
1 parent 99de245 commit 706e8ba

File tree

11 files changed

+523
-24
lines changed

11 files changed

+523
-24
lines changed

api/current.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5838,7 +5838,7 @@ package android.content {
58385838
field public static final java.lang.String EXTRA_KEY_EVENT = "android.intent.extra.KEY_EVENT";
58395839
field public static final java.lang.String EXTRA_LOCAL_ONLY = "android.intent.extra.LOCAL_ONLY";
58405840
field public static final java.lang.String EXTRA_NOT_UNKNOWN_SOURCE = "android.intent.extra.NOT_UNKNOWN_SOURCE";
5841-
field public static final java.lang.String EXTRA_ORIGINATING_URL = "android.intent.extra.ORIGINATING_URL";
5841+
field public static final java.lang.String EXTRA_ORIGINATING_URI = "android.intent.extra.ORIGINATING_URI";
58425842
field public static final java.lang.String EXTRA_PHONE_NUMBER = "android.intent.extra.PHONE_NUMBER";
58435843
field public static final java.lang.String EXTRA_REFERRER = "android.intent.extra.REFERRER";
58445844
field public static final java.lang.String EXTRA_REMOTE_INTENT_TOKEN = "android.intent.extra.remote_intent_token";

cmds/pm/src/com/android/commands/pm/Pm.java

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import android.content.pm.PermissionGroupInfo;
3737
import android.content.pm.PermissionInfo;
3838
import android.content.pm.UserInfo;
39+
import android.content.pm.VerificationParams;
3940
import android.content.res.AssetManager;
4041
import android.content.res.Resources;
4142
import android.net.Uri;
@@ -787,6 +788,8 @@ private void runInstall() {
787788
String macAlgo = null;
788789
byte[] macKey = null;
789790
byte[] tag = null;
791+
String originatingUriString = null;
792+
String referrer = null;
790793

791794
while ((opt=nextOption()) != null) {
792795
if (opt.equals("-l")) {
@@ -850,6 +853,20 @@ private void runInstall() {
850853
showUsage();
851854
return;
852855
}
856+
} else if (opt.equals("--originating-uri")) {
857+
originatingUriString = nextOptionData();
858+
if (originatingUriString == null) {
859+
System.err.println("Error: must supply argument for --originating-uri");
860+
showUsage();
861+
return;
862+
}
863+
} else if (opt.equals("--referrer")) {
864+
referrer = nextOptionData();
865+
if (referrer == null) {
866+
System.err.println("Error: must supply argument for --referrer");
867+
showUsage();
868+
return;
869+
}
853870
} else {
854871
System.err.println("Error: Unknown option: " + opt);
855872
showUsage();
@@ -897,6 +914,20 @@ private void runInstall() {
897914

898915
final Uri apkURI;
899916
final Uri verificationURI;
917+
final Uri originatingURI;
918+
final Uri referrerURI;
919+
920+
if (originatingUriString != null) {
921+
originatingURI = Uri.parse(originatingUriString);
922+
} else {
923+
originatingURI = null;
924+
}
925+
926+
if (referrer != null) {
927+
referrerURI = Uri.parse(referrer);
928+
} else {
929+
referrerURI = null;
930+
}
900931

901932
// Populate apkURI, must be present
902933
final String apkFilePath = nextArg();
@@ -920,8 +951,11 @@ private void runInstall() {
920951

921952
PackageInstallObserver obs = new PackageInstallObserver();
922953
try {
923-
mPm.installPackageWithVerification(apkURI, obs, installFlags, installerPackageName,
924-
verificationURI, null, encryptionParams);
954+
VerificationParams verificationParams = new VerificationParams(verificationURI,
955+
originatingURI, referrerURI, null);
956+
957+
mPm.installPackageWithVerificationAndEncryption(apkURI, obs, installFlags,
958+
installerPackageName, verificationParams, encryptionParams);
925959

926960
synchronized (obs) {
927961
while (!obs.finished) {
@@ -1441,7 +1475,8 @@ private static void showUsage() {
14411475
System.err.println(" pm list libraries");
14421476
System.err.println(" pm path PACKAGE");
14431477
System.err.println(" pm install [-l] [-r] [-t] [-i INSTALLER_PACKAGE_NAME] [-s] [-f]");
1444-
System.err.println(" [--algo <algorithm name> --key <key-in-hex> --iv <IV-in-hex>] PATH");
1478+
System.err.println(" [--algo <algorithm name> --key <key-in-hex> --iv <IV-in-hex>]");
1479+
System.err.println(" [--originating-uri <URI>] [--referrer <URI>] PATH");
14451480
System.err.println(" pm uninstall [-k] PACKAGE");
14461481
System.err.println(" pm clear PACKAGE");
14471482
System.err.println(" pm enable PACKAGE_OR_COMPONENT");

core/java/android/app/ApplicationPackageManager.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import android.content.pm.ServiceInfo;
4444
import android.content.pm.ManifestDigest;
4545
import android.content.pm.UserInfo;
46+
import android.content.pm.VerificationParams;
4647
import android.content.pm.VerifierDeviceIdentity;
4748
import android.content.res.Resources;
4849
import android.content.res.XmlResourceParser;
@@ -983,6 +984,18 @@ public void installPackageWithVerification(Uri packageURI, IPackageInstallObserv
983984
}
984985
}
985986

987+
@Override
988+
public void installPackageWithVerificationAndEncryption(Uri packageURI,
989+
IPackageInstallObserver observer, int flags, String installerPackageName,
990+
VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) {
991+
try {
992+
mPM.installPackageWithVerificationAndEncryption(packageURI, observer, flags,
993+
installerPackageName, verificationParams, encryptionParams);
994+
} catch (RemoteException e) {
995+
// Should never happen!
996+
}
997+
}
998+
986999
@Override
9871000
public void verifyPendingInstall(int id, int response) {
9881001
try {

core/java/android/content/Intent.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@
571571
* <li> {@link #EXTRA_INITIAL_INTENTS}
572572
* <li> {@link #EXTRA_INTENT}
573573
* <li> {@link #EXTRA_KEY_EVENT}
574-
* <li> {@link #EXTRA_ORIGINATING_URL}
574+
* <li> {@link #EXTRA_ORIGINATING_URI}
575575
* <li> {@link #EXTRA_PHONE_NUMBER}
576576
* <li> {@link #EXTRA_REFERRER}
577577
* <li> {@link #EXTRA_REMOTE_INTENT_TOKEN}
@@ -1288,17 +1288,17 @@ public static Intent createChooser(Intent target, CharSequence title) {
12881288
= "android.intent.extra.NOT_UNKNOWN_SOURCE";
12891289

12901290
/**
1291-
* Used as a string extra field with {@link #ACTION_INSTALL_PACKAGE} and
1292-
* {@link #ACTION_VIEW} to indicate the URL from which the local APK in the Intent
1291+
* Used as a URI extra field with {@link #ACTION_INSTALL_PACKAGE} and
1292+
* {@link #ACTION_VIEW} to indicate the URI from which the local APK in the Intent
12931293
* data field originated from.
12941294
*/
1295-
public static final String EXTRA_ORIGINATING_URL
1296-
= "android.intent.extra.ORIGINATING_URL";
1295+
public static final String EXTRA_ORIGINATING_URI
1296+
= "android.intent.extra.ORIGINATING_URI";
12971297

12981298
/**
1299-
* Used as a string extra field with {@link #ACTION_INSTALL_PACKAGE} and
1300-
* {@link #ACTION_VIEW} to indicate the HTTP referrer associated with the Intent
1301-
* data field or {@link #EXTRA_ORIGINATING_URL}.
1299+
* Used as a URI extra field with {@link #ACTION_INSTALL_PACKAGE} and
1300+
* {@link #ACTION_VIEW} to indicate the HTTP referrer URI associated with the Intent
1301+
* data field or {@link #EXTRA_ORIGINATING_URI}.
13021302
*/
13031303
public static final String EXTRA_REFERRER
13041304
= "android.intent.extra.REFERRER";

core/java/android/content/pm/IPackageManager.aidl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import android.content.pm.PermissionInfo;
3939
import android.content.pm.ResolveInfo;
4040
import android.content.pm.ServiceInfo;
4141
import android.content.pm.UserInfo;
42+
import android.content.pm.VerificationParams;
4243
import android.content.pm.VerifierDeviceIdentity;
4344
import android.net.Uri;
4445
import android.os.ParcelFileDescriptor;
@@ -362,6 +363,11 @@ interface IPackageManager {
362363
int flags, in String installerPackageName, in Uri verificationURI,
363364
in ManifestDigest manifestDigest, in ContainerEncryptionParams encryptionParams);
364365

366+
void installPackageWithVerificationAndEncryption(in Uri packageURI,
367+
in IPackageInstallObserver observer, int flags, in String installerPackageName,
368+
in VerificationParams verificationParams,
369+
in ContainerEncryptionParams encryptionParams);
370+
365371
void verifyPendingInstall(int id, int verificationCode);
366372

367373
VerifierDeviceIdentity getVerifierDeviceIdentity();

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,6 +2226,37 @@ public abstract void installPackageWithVerification(Uri packageURI,
22262226
Uri verificationURI, ManifestDigest manifestDigest,
22272227
ContainerEncryptionParams encryptionParams);
22282228

2229+
/**
2230+
* Similar to
2231+
* {@link #installPackage(Uri, IPackageInstallObserver, int, String)} but
2232+
* with an extra verification information provided.
2233+
*
2234+
* @param packageURI The location of the package file to install. This can
2235+
* be a 'file:' or a 'content:' URI.
2236+
* @param observer An observer callback to get notified when the package
2237+
* installation is complete.
2238+
* {@link IPackageInstallObserver#packageInstalled(String, int)}
2239+
* will be called when that happens. observer may be null to
2240+
* indicate that no callback is desired.
2241+
* @param flags - possible values: {@link #INSTALL_FORWARD_LOCK},
2242+
* {@link #INSTALL_REPLACE_EXISTING}, {@link #INSTALL_ALLOW_TEST}
2243+
* .
2244+
* @param installerPackageName Optional package name of the application that
2245+
* is performing the installation. This identifies which market
2246+
* the package came from.
2247+
* @param verificationParams an object that holds signal information to
2248+
* assist verification. May be {@code null}.
2249+
* @param encryptionParams if the package to be installed is encrypted,
2250+
* these parameters describing the encryption and authentication
2251+
* used. May be {@code null}.
2252+
*
2253+
* @hide
2254+
*/
2255+
public abstract void installPackageWithVerificationAndEncryption(Uri packageURI,
2256+
IPackageInstallObserver observer, int flags, String installerPackageName,
2257+
VerificationParams verificationParams,
2258+
ContainerEncryptionParams encryptionParams);
2259+
22292260
/**
22302261
* Allows a package listening to the
22312262
* {@link Intent#ACTION_PACKAGE_NEEDS_VERIFICATION package verification
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright 2012, The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package android.content.pm;
18+
19+
parcelable VerificationParams;

0 commit comments

Comments
 (0)