use of android.webkit.WebViewProviderResponse in project android_frameworks_base by crdroidandroid.
the class WebViewUpdateServiceTest method testNotifyRelroDoesntCrashIfNoPackages.
/**
* Timing dependent test where we verify that the list of valid webview packages becoming empty
* at a certain point doesn't crash us or break our state.
*/
public void testNotifyRelroDoesntCrashIfNoPackages() {
String firstPackage = "first";
String secondPackage = "second";
WebViewProviderInfo[] packages = new WebViewProviderInfo[] { new WebViewProviderInfo(firstPackage, "", true, /* default available */
false, /* fallback */
null), new WebViewProviderInfo(secondPackage, "", true, /* default available */
false, /* fallback */
null) };
setupWithPackages(packages);
// Add (enabled and valid) package infos for each provider
setEnabledAndValidPackageInfos(packages);
mWebViewUpdateServiceImpl.prepareWebViewInSystemServer();
Mockito.verify(mTestSystemImpl).onWebViewProviderChanged(Mockito.argThat(new IsPackageInfoWithName(firstPackage)));
// Change provider during relro creation to enter a state where we are
// waiting for relro creation to complete just to re-run relro creation.
// (so that in next notifyRelroCreationCompleted() call we have to list webview packages)
mWebViewUpdateServiceImpl.changeProviderAndSetting(secondPackage);
// Make packages invalid to cause exception to be thrown
mTestSystemImpl.setPackageInfo(createPackageInfo(firstPackage, true, /* enabled */
false, /* valid */
true, /* installed */
null, /* signatures */
0));
mTestSystemImpl.setPackageInfo(createPackageInfo(secondPackage, true, /* enabled */
false, /* valid */
true));
// This shouldn't throw an exception!
mWebViewUpdateServiceImpl.notifyRelroCreationCompleted();
WebViewProviderResponse response = mWebViewUpdateServiceImpl.waitForAndGetProvider();
assertEquals(WebViewFactory.LIBLOAD_FAILED_LISTING_WEBVIEW_PACKAGES, response.status);
// Now make a package valid again and verify that we can switch back to that
mTestSystemImpl.setPackageInfo(createPackageInfo(firstPackage, true, /* enabled */
true, /* valid */
true, /* installed */
null, /* signatures */
1));
mWebViewUpdateServiceImpl.packageStateChanged(firstPackage, WebViewUpdateService.PACKAGE_ADDED_REPLACED, 0);
// Ensure we use firstPackage
checkPreparationPhasesForPackage(firstPackage, 2);
}
use of android.webkit.WebViewProviderResponse in project platform_frameworks_base by android.
the class WebViewUpdateServiceTest method testFailListingInvalidWebviewPackage.
@Test
public void testFailListingInvalidWebviewPackage() {
WebViewProviderInfo wpi = new WebViewProviderInfo("package", "", true, true, null);
WebViewProviderInfo[] packages = new WebViewProviderInfo[] { wpi };
setupWithPackages(packages);
mTestSystemImpl.setPackageInfo(createPackageInfo(wpi.packageName, true, /* enabled */
false, /* valid */
true));
runWebViewBootPreparationOnMainSync();
Mockito.verify(mTestSystemImpl, Mockito.never()).onWebViewProviderChanged(Matchers.anyObject());
WebViewProviderResponse response = mWebViewUpdateServiceImpl.waitForAndGetProvider();
assertEquals(WebViewFactory.LIBLOAD_FAILED_LISTING_WEBVIEW_PACKAGES, response.status);
// Verify that we can recover from failing to list webview packages.
mTestSystemImpl.setPackageInfo(createPackageInfo(wpi.packageName, true, /* enabled */
true, /* valid */
true));
mWebViewUpdateServiceImpl.packageStateChanged(wpi.packageName, WebViewUpdateService.PACKAGE_ADDED_REPLACED, 0);
checkPreparationPhasesForPackage(wpi.packageName, 1);
}
use of android.webkit.WebViewProviderResponse in project platform_frameworks_base by android.
the class WebViewUpdateServiceTest method checkChangingProviderDuringRelroCreation.
private void checkChangingProviderDuringRelroCreation(boolean settingsChange) {
String firstPackage = "first";
String secondPackage = "second";
WebViewProviderInfo[] packages = new WebViewProviderInfo[] { new WebViewProviderInfo(firstPackage, "", true, false, null), new WebViewProviderInfo(secondPackage, "", true, false, null) };
setupWithPackages(packages);
if (settingsChange) {
// Have all packages be enabled, so that we can change provider however we want to
setEnabledAndValidPackageInfos(packages);
} else {
// Have all packages be disabled so that we can change one to enabled later
for (WebViewProviderInfo wpi : packages) {
mTestSystemImpl.setPackageInfo(createPackageInfo(wpi.packageName, false, /* enabled */
true, /* valid */
true));
}
}
CountDownLatch countdown = new CountDownLatch(1);
runWebViewBootPreparationOnMainSync();
Mockito.verify(mTestSystemImpl).onWebViewProviderChanged(Mockito.argThat(new IsPackageInfoWithName(firstPackage)));
assertEquals(firstPackage, mWebViewUpdateServiceImpl.getCurrentWebViewPackageName());
new Thread(new Runnable() {
@Override
public void run() {
WebViewProviderResponse threadResponse = mWebViewUpdateServiceImpl.waitForAndGetProvider();
assertEquals(WebViewFactory.LIBLOAD_SUCCESS, threadResponse.status);
assertEquals(secondPackage, threadResponse.packageInfo.packageName);
// Verify that we killed the first package
Mockito.verify(mTestSystemImpl).killPackageDependents(Mockito.eq(firstPackage));
countdown.countDown();
}
}).start();
try {
// Let the new thread run / be blocked
Thread.sleep(500);
} catch (InterruptedException e) {
}
if (settingsChange) {
mWebViewUpdateServiceImpl.changeProviderAndSetting(secondPackage);
} else {
// Switch provider by enabling the second one
mTestSystemImpl.setPackageInfo(createPackageInfo(secondPackage, true, /* enabled */
true, /* valid */
true));
mWebViewUpdateServiceImpl.packageStateChanged(secondPackage, WebViewUpdateService.PACKAGE_CHANGED, 0);
}
mWebViewUpdateServiceImpl.notifyRelroCreationCompleted();
// first package done, should start on second
Mockito.verify(mTestSystemImpl).onWebViewProviderChanged(Mockito.argThat(new IsPackageInfoWithName(secondPackage)));
mWebViewUpdateServiceImpl.notifyRelroCreationCompleted();
// second package done, the other thread should now be unblocked
try {
countdown.await();
} catch (InterruptedException e) {
}
}
use of android.webkit.WebViewProviderResponse in project platform_frameworks_base by android.
the class WebViewUpdateServiceTest method checkCertainPackageUsedAfterWebViewBootPreparation.
private void checkCertainPackageUsedAfterWebViewBootPreparation(String expectedProviderName, WebViewProviderInfo[] webviewPackages, int numRelros) {
setupWithPackages(webviewPackages, true, numRelros);
// Add (enabled and valid) package infos for each provider
setEnabledAndValidPackageInfos(webviewPackages);
runWebViewBootPreparationOnMainSync();
Mockito.verify(mTestSystemImpl).onWebViewProviderChanged(Mockito.argThat(new IsPackageInfoWithName(expectedProviderName)));
for (int n = 0; n < numRelros; n++) {
mWebViewUpdateServiceImpl.notifyRelroCreationCompleted();
}
WebViewProviderResponse response = mWebViewUpdateServiceImpl.waitForAndGetProvider();
assertEquals(WebViewFactory.LIBLOAD_SUCCESS, response.status);
assertEquals(expectedProviderName, response.packageInfo.packageName);
}
use of android.webkit.WebViewProviderResponse in project android_frameworks_base by DirtyUnicorns.
the class WebViewUpdateServiceTest method checkChangingProviderDuringRelroCreation.
private void checkChangingProviderDuringRelroCreation(boolean settingsChange) {
String firstPackage = "first";
String secondPackage = "second";
WebViewProviderInfo[] packages = new WebViewProviderInfo[] { new WebViewProviderInfo(firstPackage, "", true, false, null), new WebViewProviderInfo(secondPackage, "", true, false, null) };
setupWithPackages(packages);
if (settingsChange) {
// Have all packages be enabled, so that we can change provider however we want to
setEnabledAndValidPackageInfos(packages);
} else {
// Have all packages be disabled so that we can change one to enabled later
for (WebViewProviderInfo wpi : packages) {
mTestSystemImpl.setPackageInfo(createPackageInfo(wpi.packageName, false, /* enabled */
true, /* valid */
true));
}
}
CountDownLatch countdown = new CountDownLatch(1);
mWebViewUpdateServiceImpl.prepareWebViewInSystemServer();
Mockito.verify(mTestSystemImpl).onWebViewProviderChanged(Mockito.argThat(new IsPackageInfoWithName(firstPackage)));
assertEquals(firstPackage, mWebViewUpdateServiceImpl.getCurrentWebViewPackageName());
new Thread(new Runnable() {
@Override
public void run() {
WebViewProviderResponse threadResponse = mWebViewUpdateServiceImpl.waitForAndGetProvider();
assertEquals(WebViewFactory.LIBLOAD_SUCCESS, threadResponse.status);
assertEquals(secondPackage, threadResponse.packageInfo.packageName);
// Verify that we killed the first package
Mockito.verify(mTestSystemImpl).killPackageDependents(Mockito.eq(firstPackage));
countdown.countDown();
}
}).start();
try {
// Let the new thread run / be blocked
Thread.sleep(500);
} catch (InterruptedException e) {
}
if (settingsChange) {
mWebViewUpdateServiceImpl.changeProviderAndSetting(secondPackage);
} else {
// Switch provider by enabling the second one
mTestSystemImpl.setPackageInfo(createPackageInfo(secondPackage, true, /* enabled */
true, /* valid */
true));
mWebViewUpdateServiceImpl.packageStateChanged(secondPackage, WebViewUpdateService.PACKAGE_CHANGED, 0);
}
mWebViewUpdateServiceImpl.notifyRelroCreationCompleted();
// first package done, should start on second
Mockito.verify(mTestSystemImpl).onWebViewProviderChanged(Mockito.argThat(new IsPackageInfoWithName(secondPackage)));
mWebViewUpdateServiceImpl.notifyRelroCreationCompleted();
// second package done, the other thread should now be unblocked
try {
countdown.await();
} catch (InterruptedException e) {
}
}
Aggregations