Search in sources :

Example 36 with WebViewProviderInfo

use of android.webkit.WebViewProviderInfo in project android_frameworks_base by DirtyUnicorns.

the class WebViewUpdateServiceImpl method isFallbackPackage.

boolean isFallbackPackage(String packageName) {
    if (packageName == null || !mSystemInterface.isFallbackLogicEnabled())
        return false;
    WebViewProviderInfo[] webviewPackages = mSystemInterface.getWebViewPackages();
    WebViewProviderInfo fallbackProvider = getFallbackProvider(webviewPackages);
    return (fallbackProvider != null && packageName.equals(fallbackProvider.packageName));
}
Also used : WebViewProviderInfo(android.webkit.WebViewProviderInfo)

Example 37 with WebViewProviderInfo

use of android.webkit.WebViewProviderInfo in project android_frameworks_base by DirtyUnicorns.

the class WebViewUpdateServiceImpl method handleNewUser.

/**
     * Called when a new user has been added to update the state of its fallback package.
     */
void handleNewUser(int userId) {
    if (!mSystemInterface.isFallbackLogicEnabled())
        return;
    WebViewProviderInfo[] webviewProviders = mSystemInterface.getWebViewPackages();
    WebViewProviderInfo fallbackProvider = getFallbackProvider(webviewProviders);
    if (fallbackProvider == null)
        return;
    mSystemInterface.enablePackageForUser(fallbackProvider.packageName, !existsValidNonFallbackProvider(webviewProviders), userId);
}
Also used : WebViewProviderInfo(android.webkit.WebViewProviderInfo)

Example 38 with WebViewProviderInfo

use of android.webkit.WebViewProviderInfo in project android_frameworks_base by DirtyUnicorns.

the class WebViewUpdateServiceImpl method updateFallbackStateOnPackageChange.

/**
     * Handle the enabled-state of our fallback package, i.e. if there exists some non-fallback
     * package that is valid (and available by default) then disable the fallback package,
     * otherwise, enable the fallback package.
     */
private void updateFallbackStateOnPackageChange(String changedPackage, int changedState) {
    if (!mSystemInterface.isFallbackLogicEnabled())
        return;
    WebViewProviderInfo[] webviewProviders = mSystemInterface.getWebViewPackages();
    // A package was changed / updated / downgraded, early out if it is not one of the
    // webview packages that are available by default.
    boolean changedPackageAvailableByDefault = false;
    for (WebViewProviderInfo provider : webviewProviders) {
        if (provider.packageName.equals(changedPackage)) {
            if (provider.availableByDefault) {
                changedPackageAvailableByDefault = true;
            }
            break;
        }
    }
    if (!changedPackageAvailableByDefault)
        return;
    updateFallbackState(webviewProviders, false);
}
Also used : WebViewProviderInfo(android.webkit.WebViewProviderInfo)

Example 39 with WebViewProviderInfo

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

Example 40 with WebViewProviderInfo

use of android.webkit.WebViewProviderInfo in project android_frameworks_base by DirtyUnicorns.

the class WebViewUpdateServiceTest method checkRecoverAfterFailListingWebviewPackages.

/**
     * Test that we can recover correctly from failing to list WebView packages.
     * settingsChange: whether to fail during changeProviderAndSetting or packageStateChanged
     */
public void checkRecoverAfterFailListingWebviewPackages(boolean settingsChange) {
    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) };
    checkCertainPackageUsedAfterWebViewBootPreparation(firstPackage, packages);
    // Make both packages invalid so that we fail listing WebView packages
    mTestSystemImpl.setPackageInfo(createPackageInfo(firstPackage, true, /* enabled */
    false, /* valid */
    true));
    mTestSystemImpl.setPackageInfo(createPackageInfo(secondPackage, true, /* enabled */
    false, /* valid */
    true));
    // Change package to hit the webview packages listing problem.
    if (settingsChange) {
        mWebViewUpdateServiceImpl.changeProviderAndSetting(secondPackage);
    } else {
        mWebViewUpdateServiceImpl.packageStateChanged(secondPackage, WebViewUpdateService.PACKAGE_ADDED_REPLACED, 0);
    }
    WebViewProviderResponse response = mWebViewUpdateServiceImpl.waitForAndGetProvider();
    assertEquals(WebViewFactory.LIBLOAD_FAILED_LISTING_WEBVIEW_PACKAGES, response.status);
    // Make second package valid and verify that we can load it again
    mTestSystemImpl.setPackageInfo(createPackageInfo(secondPackage, true, /* enabled */
    true, /* valid */
    true));
    mWebViewUpdateServiceImpl.packageStateChanged(secondPackage, WebViewUpdateService.PACKAGE_ADDED_REPLACED, 0);
    checkPreparationPhasesForPackage(secondPackage, 1);
}
Also used : WebViewProviderInfo(android.webkit.WebViewProviderInfo) WebViewProviderResponse(android.webkit.WebViewProviderResponse)

Aggregations

WebViewProviderInfo (android.webkit.WebViewProviderInfo)61 WebViewProviderResponse (android.webkit.WebViewProviderResponse)28 MediumTest (android.test.suitebuilder.annotation.MediumTest)8 Test (org.junit.Test)8 BroadcastReceiver (android.content.BroadcastReceiver)4 Context (android.content.Context)4 Intent (android.content.Intent)4 IntentFilter (android.content.IntentFilter)4 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)4 Signature (android.content.pm.Signature)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 DialogInterface (android.content.DialogInterface)1 OnClickListener (android.content.DialogInterface.OnClickListener)1 RemoteException (android.os.RemoteException)1 ArrayList (java.util.ArrayList)1