Skip to content

Commit 7646c77

Browse files
rich canningsAndroid (Google) Code Review
authored andcommitted
Merge "Allow verifiers to extend timeout" into jb-mr1-dev
2 parents f1d9f89 + d9ef3e5 commit 7646c77

File tree

7 files changed

+112
-10
lines changed

7 files changed

+112
-10
lines changed

api/current.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6532,6 +6532,7 @@ package android.content.pm {
65326532
method public abstract void setComponentEnabledSetting(android.content.ComponentName, int, int);
65336533
method public abstract void setInstallerPackageName(java.lang.String, java.lang.String);
65346534
method public abstract void verifyPendingInstall(int, int);
6535+
method public abstract void extendVerificationTimeout(int, int, long);
65356536
field public static final int COMPONENT_ENABLED_STATE_DEFAULT = 0; // 0x0
65366537
field public static final int COMPONENT_ENABLED_STATE_DISABLED = 2; // 0x2
65376538
field public static final int COMPONENT_ENABLED_STATE_DISABLED_USER = 3; // 0x3
@@ -6602,6 +6603,7 @@ package android.content.pm {
66026603
field public static final int SIGNATURE_UNKNOWN_PACKAGE = -4; // 0xfffffffc
66036604
field public static final int VERIFICATION_ALLOW = 1; // 0x1
66046605
field public static final int VERIFICATION_REJECT = -1; // 0xffffffff
6606+
field public static final long MAXIMUM_VERIFICATION_TIMEOUT = 360000L; // 0x36ee80L
66056607
}
66066608

66076609
public static class PackageManager.NameNotFoundException extends android.util.AndroidException {
@@ -21371,6 +21373,7 @@ package android.test.mock {
2137121373
method public void setComponentEnabledSetting(android.content.ComponentName, int, int);
2137221374
method public void setInstallerPackageName(java.lang.String, java.lang.String);
2137321375
method public void verifyPendingInstall(int, int);
21376+
method public void extendVerificationTimeout(int, int, long);
2137421377
}
2137521378

2137621379
public class MockResources extends android.content.res.Resources {

core/java/android/app/ApplicationPackageManager.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,16 @@ public void verifyPendingInstall(int id, int response) {
10051005
}
10061006
}
10071007

1008+
@Override
1009+
public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
1010+
long millisecondsToDelay) {
1011+
try {
1012+
mPM.extendVerificationTimeout(id, verificationCodeAtTimeout, millisecondsToDelay);
1013+
} catch (RemoteException e) {
1014+
// Should never happen!
1015+
}
1016+
}
1017+
10081018
@Override
10091019
public void setInstallerPackageName(String targetPackage,
10101020
String installerPackageName) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ interface IPackageManager {
370370
in ContainerEncryptionParams encryptionParams);
371371

372372
void verifyPendingInstall(int id, int verificationCode);
373+
void extendVerificationTimeout(int id, int verificationCodeAtTimeout, long millisecondsToDelay);
373374

374375
VerifierDeviceIdentity getVerifierDeviceIdentity();
375376

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,14 @@ public NameNotFoundException(String name) {
761761
*/
762762
public static final int VERIFICATION_REJECT = -1;
763763

764+
/**
765+
* Can be used as the {@code millisecondsToDelay} argument for
766+
* {@link PackageManager#extendVerificationTimeout}. This is the
767+
* maximum time {@code PackageManager} waits for the verification
768+
* agent to return (in milliseconds).
769+
*/
770+
public static final long MAXIMUM_VERIFICATION_TIMEOUT = 60*60*1000;
771+
764772
/**
765773
* Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: The device's
766774
* audio pipeline is low-latency, more suitable for audio applications sensitive to delays or
@@ -2273,6 +2281,33 @@ public abstract void installPackageWithVerificationAndEncryption(Uri packageURI,
22732281
*/
22742282
public abstract void verifyPendingInstall(int id, int verificationCode);
22752283

2284+
/**
2285+
* Allows a package listening to the
2286+
* {@link Intent#ACTION_PACKAGE_NEEDS_VERIFICATION package verification
2287+
* broadcast} to extend the default timeout for a response and declare what
2288+
* action to perform after the timeout occurs. The response must include
2289+
* the {@code verificationCodeAtTimeout} which is one of
2290+
* {@link PackageManager#VERIFICATION_ALLOW} or
2291+
* {@link PackageManager#VERIFICATION_REJECT}.
2292+
*
2293+
* This method may only be called once per package id. Additional calls
2294+
* will have no effect.
2295+
*
2296+
* @param id pending package identifier as passed via the
2297+
* {@link PackageManager#EXTRA_VERIFICATION_ID} Intent extra
2298+
* @param verificationCodeAtTimeout either
2299+
* {@link PackageManager#VERIFICATION_ALLOW} or
2300+
* {@link PackageManager#VERIFICATION_REJECT}.
2301+
* @param millisecondsToDelay the amount of time requested for the timeout.
2302+
* Must be positive and less than
2303+
* {@link PackageManager#MAXIMUM_VERIFICATION_TIMEOUT}.
2304+
*
2305+
* @throws IllegalArgumentException if {@code millisecondsToDelay} is out
2306+
* of bounds or {@code verificationCodeAtTimeout} is unknown.
2307+
*/
2308+
public abstract void extendVerificationTimeout(int id,
2309+
int verificationCodeAtTimeout, long millisecondsToDelay);
2310+
22762311
/**
22772312
* Change the installer associated with a given package. There are limitations
22782313
* on how the installer package can be changed; in particular:

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

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -780,28 +780,28 @@ void doHandleMessage(Message msg) {
780780
final int verificationId = msg.arg1;
781781
final PackageVerificationState state = mPendingVerification.get(verificationId);
782782

783-
if (state != null) {
783+
if ((state != null) && !state.timeoutExtended()) {
784784
final InstallArgs args = state.getInstallArgs();
785785
Slog.i(TAG, "Verification timed out for " + args.packageURI.toString());
786786
mPendingVerification.remove(verificationId);
787787

788788
int ret = PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE;
789789

790790
if (getDefaultVerificationResponse() == PackageManager.VERIFICATION_ALLOW) {
791-
Slog.i(TAG, "Continuing with installation of " + args.packageURI.toString());
792-
state.setVerifierResponse(Binder.getCallingUid(), PackageManager.VERIFICATION_ALLOW_WITHOUT_SUFFICIENT);
793-
try {
794-
ret = args.copyApk(mContainerService, true);
795-
} catch (RemoteException e) {
796-
Slog.e(TAG, "Could not contact the ContainerService");
797-
}
791+
Slog.i(TAG, "Continuing with installation of "
792+
+ args.packageURI.toString());
793+
state.setVerifierResponse(Binder.getCallingUid(),
794+
PackageManager.VERIFICATION_ALLOW_WITHOUT_SUFFICIENT);
795+
try {
796+
ret = args.copyApk(mContainerService, true);
797+
} catch (RemoteException e) {
798+
Slog.e(TAG, "Could not contact the ContainerService");
799+
}
798800
}
799801

800802
processPendingInstall(args, ret);
801-
802803
mHandler.sendEmptyMessage(MCS_UNBIND);
803804
}
804-
805805
break;
806806
}
807807
case PACKAGE_VERIFIED: {
@@ -5393,6 +5393,32 @@ public void verifyPendingInstall(int id, int verificationCode) throws RemoteExce
53935393
mHandler.sendMessage(msg);
53945394
}
53955395

5396+
@Override
5397+
public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
5398+
long millisecondsToDelay) {
5399+
final PackageVerificationState state = mPendingVerification.get(id);
5400+
final PackageVerificationResponse response = new PackageVerificationResponse(
5401+
verificationCodeAtTimeout, Binder.getCallingUid());
5402+
5403+
if ((millisecondsToDelay > PackageManager.MAXIMUM_VERIFICATION_TIMEOUT)
5404+
|| (millisecondsToDelay < 0)) {
5405+
throw new IllegalArgumentException("millisecondsToDelay is out of bounds.");
5406+
}
5407+
if ((verificationCodeAtTimeout != PackageManager.VERIFICATION_ALLOW)
5408+
|| (verificationCodeAtTimeout != PackageManager.VERIFICATION_REJECT)) {
5409+
throw new IllegalArgumentException("verificationCodeAtTimeout is unknown.");
5410+
}
5411+
5412+
if ((state != null) && !state.timeoutExtended()) {
5413+
state.extendTimeout();
5414+
5415+
final Message msg = mHandler.obtainMessage(PACKAGE_VERIFIED);
5416+
msg.arg1 = id;
5417+
msg.obj = response;
5418+
mHandler.sendMessageDelayed(msg, millisecondsToDelay);
5419+
}
5420+
}
5421+
53965422
private ComponentName matchComponentForVerifier(String packageName,
53975423
List<ResolveInfo> receivers) {
53985424
ActivityInfo targetReceiver = null;

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class PackageVerificationState {
4343

4444
private boolean mRequiredVerificationPassed;
4545

46+
private boolean mExtendedTimeout;
47+
4648
/**
4749
* Create a new package verification state where {@code requiredVerifierUid}
4850
* is the user ID for the package that must reply affirmative before things
@@ -55,6 +57,7 @@ public PackageVerificationState(int requiredVerifierUid, InstallArgs args) {
5557
mRequiredVerifierUid = requiredVerifierUid;
5658
mArgs = args;
5759
mSufficientVerifierUids = new SparseBooleanArray();
60+
mExtendedTimeout = false;
5861
}
5962

6063
public InstallArgs getInstallArgs() {
@@ -146,4 +149,22 @@ public boolean isInstallAllowed() {
146149

147150
return true;
148151
}
152+
153+
/**
154+
* Extend the timeout for this Package to be verified.
155+
*/
156+
public void extendTimeout() {
157+
if (!mExtendedTimeout) {
158+
mExtendedTimeout = true;
159+
}
160+
}
161+
162+
/**
163+
* Returns whether the timeout was extended for verification.
164+
*
165+
* @return {@code true} if a timeout was already extended.
166+
*/
167+
public boolean timeoutExtended() {
168+
return mExtendedTimeout;
169+
}
149170
}

test-runner/src/android/test/mock/MockPackageManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,12 @@ public void verifyPendingInstall(int id, int verificationCode) {
536536
throw new UnsupportedOperationException();
537537
}
538538

539+
@Override
540+
public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
541+
long millisecondsToDelay) {
542+
throw new UnsupportedOperationException();
543+
}
544+
539545
/**
540546
* @hide
541547
*/

0 commit comments

Comments
 (0)