Search in sources :

Example 51 with WebViewProviderInfo

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

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 52 with WebViewProviderInfo

use of android.webkit.WebViewProviderInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WebViewImplementation method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (!UserManager.get(this).isAdminUser()) {
        finish();
        return;
    }
    mWebViewUpdateService = IWebViewUpdateService.Stub.asInterface(ServiceManager.getService("webviewupdate"));
    try {
        WebViewProviderInfo[] providers = mWebViewUpdateService.getValidWebViewPackages();
        if (providers == null) {
            Log.e(TAG, "No WebView providers available");
            finish();
            return;
        }
        String currentValue = mWebViewUpdateService.getCurrentWebViewPackageName();
        if (currentValue == null) {
            currentValue = "";
        }
        int currentIndex = -1;
        ArrayList<String> options = new ArrayList<>();
        final ArrayList<String> values = new ArrayList<>();
        for (WebViewProviderInfo provider : providers) {
            if (Utils.isPackageEnabled(this, provider.packageName)) {
                options.add(provider.description);
                values.add(provider.packageName);
                if (currentValue.contentEquals(provider.packageName)) {
                    currentIndex = values.size() - 1;
                }
            }
        }
        new AlertDialog.Builder(this).setTitle(R.string.select_webview_provider_dialog_title).setSingleChoiceItems(options.toArray(new String[0]), currentIndex, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                try {
                    mWebViewUpdateService.changeProviderAndSetting(values.get(which));
                } catch (RemoteException e) {
                    Log.w(TAG, "Problem reaching webviewupdate service", e);
                }
                finish();
            }
        }).setNegativeButton(android.R.string.cancel, null).setOnCancelListener(this).setOnDismissListener(this).show();
    } catch (RemoteException e) {
        Log.w(TAG, "Problem reaching webviewupdate service", e);
        finish();
    }
}
Also used : DialogInterface(android.content.DialogInterface) WebViewProviderInfo(android.webkit.WebViewProviderInfo) ArrayList(java.util.ArrayList) OnClickListener(android.content.DialogInterface.OnClickListener) RemoteException(android.os.RemoteException)

Example 53 with WebViewProviderInfo

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

the class WebViewUpdateService method onStart.

@Override
public void onStart() {
    mWebViewUpdatedReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
            switch(intent.getAction()) {
                case Intent.ACTION_PACKAGE_REMOVED:
                    // run the update-logic twice.
                    if (intent.getExtras().getBoolean(Intent.EXTRA_REPLACING))
                        return;
                    mImpl.packageStateChanged(packageNameFromIntent(intent), PACKAGE_REMOVED, userId);
                    break;
                case Intent.ACTION_PACKAGE_CHANGED:
                    // entire package, not just a component
                    if (entirePackageChanged(intent)) {
                        mImpl.packageStateChanged(packageNameFromIntent(intent), PACKAGE_CHANGED, userId);
                    }
                    break;
                case Intent.ACTION_PACKAGE_ADDED:
                    mImpl.packageStateChanged(packageNameFromIntent(intent), (intent.getExtras().getBoolean(Intent.EXTRA_REPLACING) ? PACKAGE_ADDED_REPLACED : PACKAGE_ADDED), userId);
                    break;
                case Intent.ACTION_USER_ADDED:
                    mImpl.handleNewUser(userId);
                    break;
            }
        }
    };
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_PACKAGE_ADDED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    filter.addDataScheme("package");
    // Make sure we only receive intents for WebView packages from our config file.
    for (WebViewProviderInfo provider : mImpl.getWebViewPackages()) {
        filter.addDataSchemeSpecificPart(provider.packageName, PatternMatcher.PATTERN_LITERAL);
    }
    getContext().registerReceiverAsUser(mWebViewUpdatedReceiver, UserHandle.ALL, filter, null, /* broadcast permission */
    null);
    IntentFilter userAddedFilter = new IntentFilter();
    userAddedFilter.addAction(Intent.ACTION_USER_ADDED);
    getContext().registerReceiverAsUser(mWebViewUpdatedReceiver, UserHandle.ALL, userAddedFilter, null, /* broadcast permission */
    null);
    publishBinderService("webviewupdate", new BinderService(), true);
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) WebViewProviderInfo(android.webkit.WebViewProviderInfo) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 54 with WebViewProviderInfo

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

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 55 with WebViewProviderInfo

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

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)

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