Search in sources :

Example 16 with WebViewProviderResponse

use of android.webkit.WebViewProviderResponse in project android_frameworks_base by crdroidandroid.

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) {
    }
}
Also used : WebViewProviderInfo(android.webkit.WebViewProviderInfo) WebViewProviderResponse(android.webkit.WebViewProviderResponse) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 17 with WebViewProviderResponse

use of android.webkit.WebViewProviderResponse in project android_frameworks_base by crdroidandroid.

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);
    mWebViewUpdateServiceImpl.prepareWebViewInSystemServer();
    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);
}
Also used : WebViewProviderResponse(android.webkit.WebViewProviderResponse)

Example 18 with WebViewProviderResponse

use of android.webkit.WebViewProviderResponse in project android_frameworks_base by crdroidandroid.

the class WebViewUpdateServiceTest method testFailWaitingForRelro.

public void testFailWaitingForRelro() {
    WebViewProviderInfo[] packages = new WebViewProviderInfo[] { new WebViewProviderInfo("packagename", "", true, true, null) };
    setupWithPackages(packages);
    setEnabledAndValidPackageInfos(packages);
    mWebViewUpdateServiceImpl.prepareWebViewInSystemServer();
    Mockito.verify(mTestSystemImpl).onWebViewProviderChanged(Mockito.argThat(new IsPackageInfoWithName(packages[0].packageName)));
    // Never call notifyRelroCreation()
    WebViewProviderResponse response = mWebViewUpdateServiceImpl.waitForAndGetProvider();
    assertEquals(WebViewFactory.LIBLOAD_FAILED_WAITING_FOR_RELRO, response.status);
}
Also used : WebViewProviderInfo(android.webkit.WebViewProviderInfo) WebViewProviderResponse(android.webkit.WebViewProviderResponse)

Example 19 with WebViewProviderResponse

use of android.webkit.WebViewProviderResponse in project android_frameworks_base by crdroidandroid.

the class WebViewUpdateServiceTest method testPreparationRunsIffNewPackage.

public void testPreparationRunsIffNewPackage() {
    String primaryPackage = "primary";
    String fallbackPackage = "fallback";
    WebViewProviderInfo[] packages = new WebViewProviderInfo[] { new WebViewProviderInfo(primaryPackage, "", true, /* default available */
    false, /* fallback */
    null), new WebViewProviderInfo(fallbackPackage, "", true, /* default available */
    true, /* fallback */
    null) };
    setupWithPackages(packages, true);
    mTestSystemImpl.setPackageInfo(createPackageInfo(primaryPackage, true, /* enabled */
    true, /* valid */
    true, /* installed */
    null, /* signatures */
    10));
    mTestSystemImpl.setPackageInfo(createPackageInfo(fallbackPackage, true, /* enabled */
    true, /* valid */
    true));
    mWebViewUpdateServiceImpl.prepareWebViewInSystemServer();
    checkPreparationPhasesForPackage(primaryPackage, 1);
    Mockito.verify(mTestSystemImpl, Mockito.times(1)).enablePackageForUser(Mockito.eq(fallbackPackage), Mockito.eq(false), /* enable */
    Matchers.anyInt());
    mWebViewUpdateServiceImpl.packageStateChanged(primaryPackage, WebViewUpdateService.PACKAGE_ADDED_REPLACED, 0);
    mWebViewUpdateServiceImpl.packageStateChanged(primaryPackage, WebViewUpdateService.PACKAGE_ADDED_REPLACED, 1);
    mWebViewUpdateServiceImpl.packageStateChanged(primaryPackage, WebViewUpdateService.PACKAGE_ADDED_REPLACED, 2);
    // package still has the same update-time so we shouldn't run preparation here
    Mockito.verify(mTestSystemImpl, Mockito.times(1)).onWebViewProviderChanged(Mockito.argThat(new IsPackageInfoWithName(primaryPackage)));
    Mockito.verify(mTestSystemImpl, Mockito.times(1)).enablePackageForUser(Mockito.eq(fallbackPackage), Mockito.eq(false), /* enable */
    Matchers.anyInt());
    // Ensure we can still load the package
    WebViewProviderResponse response = mWebViewUpdateServiceImpl.waitForAndGetProvider();
    assertEquals(WebViewFactory.LIBLOAD_SUCCESS, response.status);
    assertEquals(primaryPackage, response.packageInfo.packageName);
    mTestSystemImpl.setPackageInfo(createPackageInfo(primaryPackage, true, /* enabled */
    true, /* valid */
    true, /* installed */
    null, /* signatures */
    20));
    mWebViewUpdateServiceImpl.packageStateChanged(primaryPackage, WebViewUpdateService.PACKAGE_ADDED_REPLACED, 0);
    // The package has now changed - ensure that we have run the preparation phase a second time
    checkPreparationPhasesForPackage(primaryPackage, 2);
    mTestSystemImpl.setPackageInfo(createPackageInfo(primaryPackage, true, /* enabled */
    true, /* valid */
    true, /* installed */
    null, /* signatures */
    50));
    // Receive intent for different user
    mWebViewUpdateServiceImpl.packageStateChanged(primaryPackage, WebViewUpdateService.PACKAGE_ADDED_REPLACED, 2);
    checkPreparationPhasesForPackage(primaryPackage, 3);
}
Also used : WebViewProviderInfo(android.webkit.WebViewProviderInfo) WebViewProviderResponse(android.webkit.WebViewProviderResponse)

Example 20 with WebViewProviderResponse

use of android.webkit.WebViewProviderResponse in project android_frameworks_base by crdroidandroid.

the class WebViewUpdateServiceTest method testFailListingEmptyWebviewPackages.

public void testFailListingEmptyWebviewPackages() {
    WebViewProviderInfo[] packages = new WebViewProviderInfo[0];
    setupWithPackages(packages);
    setEnabledAndValidPackageInfos(packages);
    mWebViewUpdateServiceImpl.prepareWebViewInSystemServer();
    Mockito.verify(mTestSystemImpl, Mockito.never()).onWebViewProviderChanged(Matchers.anyObject());
    WebViewProviderResponse response = mWebViewUpdateServiceImpl.waitForAndGetProvider();
    assertEquals(WebViewFactory.LIBLOAD_FAILED_LISTING_WEBVIEW_PACKAGES, response.status);
}
Also used : WebViewProviderInfo(android.webkit.WebViewProviderInfo) WebViewProviderResponse(android.webkit.WebViewProviderResponse)

Aggregations

WebViewProviderResponse (android.webkit.WebViewProviderResponse)36 WebViewProviderInfo (android.webkit.WebViewProviderInfo)28 MediumTest (android.test.suitebuilder.annotation.MediumTest)5 Test (org.junit.Test)5 CountDownLatch (java.util.concurrent.CountDownLatch)4