Merge "Better errors in PackageManagerTests" into gingerbread
This commit is contained in:
@ -167,8 +167,7 @@ public class PackageManagerTests extends AndroidTestCase {
|
|||||||
return ipm;
|
return ipm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean invokeInstallPackage(Uri packageURI, int flags,
|
public boolean invokeInstallPackage(Uri packageURI, int flags, GenericReceiver receiver) {
|
||||||
GenericReceiver receiver) throws Exception {
|
|
||||||
PackageInstallObserver observer = new PackageInstallObserver();
|
PackageInstallObserver observer = new PackageInstallObserver();
|
||||||
final boolean received = false;
|
final boolean received = false;
|
||||||
mContext.registerReceiver(receiver, receiver.filter);
|
mContext.registerReceiver(receiver, receiver.filter);
|
||||||
@ -180,11 +179,15 @@ public class PackageManagerTests extends AndroidTestCase {
|
|||||||
getPm().installPackage(packageURI, observer, flags, null);
|
getPm().installPackage(packageURI, observer, flags, null);
|
||||||
long waitTime = 0;
|
long waitTime = 0;
|
||||||
while((!observer.isDone()) && (waitTime < MAX_WAIT_TIME) ) {
|
while((!observer.isDone()) && (waitTime < MAX_WAIT_TIME) ) {
|
||||||
|
try {
|
||||||
observer.wait(WAIT_TIME_INCR);
|
observer.wait(WAIT_TIME_INCR);
|
||||||
waitTime += WAIT_TIME_INCR;
|
waitTime += WAIT_TIME_INCR;
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Log.i(TAG, "Interrupted during sleep", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(!observer.isDone()) {
|
if(!observer.isDone()) {
|
||||||
throw new Exception("Timed out waiting for packageInstalled callback");
|
fail("Timed out waiting for packageInstalled callback");
|
||||||
}
|
}
|
||||||
if (observer.returnCode != PackageManager.INSTALL_SUCCEEDED) {
|
if (observer.returnCode != PackageManager.INSTALL_SUCCEEDED) {
|
||||||
Log.i(TAG, "Failed to install with error code = " + observer.returnCode);
|
Log.i(TAG, "Failed to install with error code = " + observer.returnCode);
|
||||||
@ -193,11 +196,15 @@ public class PackageManagerTests extends AndroidTestCase {
|
|||||||
// Verify we received the broadcast
|
// Verify we received the broadcast
|
||||||
waitTime = 0;
|
waitTime = 0;
|
||||||
while((!receiver.isDone()) && (waitTime < MAX_WAIT_TIME) ) {
|
while((!receiver.isDone()) && (waitTime < MAX_WAIT_TIME) ) {
|
||||||
|
try {
|
||||||
receiver.wait(WAIT_TIME_INCR);
|
receiver.wait(WAIT_TIME_INCR);
|
||||||
waitTime += WAIT_TIME_INCR;
|
waitTime += WAIT_TIME_INCR;
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Log.i(TAG, "Interrupted during sleep", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(!receiver.isDone()) {
|
if(!receiver.isDone()) {
|
||||||
throw new Exception("Timed out waiting for PACKAGE_ADDED notification");
|
fail("Timed out waiting for PACKAGE_ADDED notification");
|
||||||
}
|
}
|
||||||
return receiver.received;
|
return receiver.received;
|
||||||
}
|
}
|
||||||
@ -207,7 +214,7 @@ public class PackageManagerTests extends AndroidTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void invokeInstallPackageFail(Uri packageURI, int flags, int result) throws Exception {
|
public void invokeInstallPackageFail(Uri packageURI, int flags, int result) {
|
||||||
PackageInstallObserver observer = new PackageInstallObserver();
|
PackageInstallObserver observer = new PackageInstallObserver();
|
||||||
try {
|
try {
|
||||||
// Wait on observer
|
// Wait on observer
|
||||||
@ -215,11 +222,15 @@ public class PackageManagerTests extends AndroidTestCase {
|
|||||||
getPm().installPackage(packageURI, observer, flags, null);
|
getPm().installPackage(packageURI, observer, flags, null);
|
||||||
long waitTime = 0;
|
long waitTime = 0;
|
||||||
while((!observer.isDone()) && (waitTime < MAX_WAIT_TIME) ) {
|
while((!observer.isDone()) && (waitTime < MAX_WAIT_TIME) ) {
|
||||||
|
try {
|
||||||
observer.wait(WAIT_TIME_INCR);
|
observer.wait(WAIT_TIME_INCR);
|
||||||
waitTime += WAIT_TIME_INCR;
|
waitTime += WAIT_TIME_INCR;
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Log.i(TAG, "Interrupted during sleep", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(!observer.isDone()) {
|
if(!observer.isDone()) {
|
||||||
throw new Exception("Timed out waiting for packageInstalled callback");
|
fail("Timed out waiting for packageInstalled callback");
|
||||||
}
|
}
|
||||||
assertEquals(observer.returnCode, result);
|
assertEquals(observer.returnCode, result);
|
||||||
}
|
}
|
||||||
@ -265,7 +276,7 @@ public class PackageManagerTests extends AndroidTestCase {
|
|||||||
Environment.getExternalStorageDirectory().getPath());
|
Environment.getExternalStorageDirectory().getPath());
|
||||||
sdSize = (long)sdStats.getAvailableBlocks() *
|
sdSize = (long)sdStats.getAvailableBlocks() *
|
||||||
(long)sdStats.getBlockSize();
|
(long)sdStats.getBlockSize();
|
||||||
// TODO check for thesholds here
|
// TODO check for thresholds here
|
||||||
return pkgLen <= sdSize;
|
return pkgLen <= sdSize;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -368,12 +379,21 @@ public class PackageManagerTests extends AndroidTestCase {
|
|||||||
assertFalse((info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0);
|
assertFalse((info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0);
|
||||||
assertTrue(info.nativeLibraryDir.startsWith(dataDir.getPath()));
|
assertTrue(info.nativeLibraryDir.startsWith(dataDir.getPath()));
|
||||||
} else if (rLoc == INSTALL_LOC_SD){
|
} else if (rLoc == INSTALL_LOC_SD){
|
||||||
assertTrue((info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0);
|
assertTrue("Application flags (" + info.flags
|
||||||
assertTrue(srcPath.startsWith(SECURE_CONTAINERS_PREFIX));
|
+ ") should contain FLAG_EXTERNAL_STORAGE",
|
||||||
assertTrue(publicSrcPath.startsWith(SECURE_CONTAINERS_PREFIX));
|
(info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0);
|
||||||
assertTrue(info.nativeLibraryDir.startsWith(SECURE_CONTAINERS_PREFIX));
|
assertTrue("The APK path (" + srcPath + ") should start with "
|
||||||
|
+ SECURE_CONTAINERS_PREFIX, srcPath
|
||||||
|
.startsWith(SECURE_CONTAINERS_PREFIX));
|
||||||
|
assertTrue("The public APK path (" + publicSrcPath + ") should start with "
|
||||||
|
+ SECURE_CONTAINERS_PREFIX, publicSrcPath
|
||||||
|
.startsWith(SECURE_CONTAINERS_PREFIX));
|
||||||
|
assertTrue("The native library path (" + info.nativeLibraryDir
|
||||||
|
+ ") should start with " + SECURE_CONTAINERS_PREFIX,
|
||||||
|
info.nativeLibraryDir.startsWith(SECURE_CONTAINERS_PREFIX));
|
||||||
} else {
|
} else {
|
||||||
// TODO handle error. Install should have failed.
|
// TODO handle error. Install should have failed.
|
||||||
|
fail("Install should have failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (NameNotFoundException e) {
|
} catch (NameNotFoundException e) {
|
||||||
@ -544,8 +564,6 @@ public class PackageManagerTests extends AndroidTestCase {
|
|||||||
// Verify installed information
|
// Verify installed information
|
||||||
assertInstall(pkg, flags, expInstallLocation);
|
assertInstall(pkg, flags, expInstallLocation);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
failStr("Failed with exception : " + e);
|
|
||||||
} finally {
|
} finally {
|
||||||
if (cleanUp) {
|
if (cleanUp) {
|
||||||
cleanUpInstall(ip);
|
cleanUpInstall(ip);
|
||||||
|
Reference in New Issue
Block a user