Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3d736682 authored by Ziad Youssef's avatar Ziad Youssef
Browse files

Attempt WebView install during start-up

Verified that the package gets installed after reboot after
uninstalling using adb.

Test:  atest com.android.server.webkit.WebViewUpdateServiceTest

Bug: 308907090
Change-Id: I5d2a3a7f62f61049115a1456023c23e32a37521b
parent 0a00842b
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.app.AppGlobals;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.UserInfo;
@@ -224,6 +225,21 @@ public class SystemImpl implements SystemInterface {
        }
    }

    @Override
    public void installExistingPackageForAllUsers(Context context, String packageName) {
        UserManager userManager = context.getSystemService(UserManager.class);
        for (UserInfo userInfo : userManager.getUsers()) {
            installPackageForUser(packageName, userInfo.id);
        }
    }

    private void installPackageForUser(String packageName, int userId) {
        final Context context = AppGlobals.getInitialApplication();
        final Context contextAsUser = context.createContextAsUser(UserHandle.of(userId), 0);
        final PackageInstaller installer = contextAsUser.getPackageManager().getPackageInstaller();
        installer.installExistingPackage(packageName, PackageManager.INSTALL_REASON_UNKNOWN, null);
    }

    @Override
    public boolean systemIsDebuggable() {
        return Build.IS_DEBUGGABLE;
+1 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ public interface SystemInterface {
    public void killPackageDependents(String packageName);

    public void enablePackageForAllUsers(Context context, String packageName, boolean enable);
    public void installExistingPackageForAllUsers(Context context, String packageName);

    public boolean systemIsDebuggable();
    public PackageInfo getPackageInfoForProvider(WebViewProviderInfo configInfo)
+7 −5
Original line number Diff line number Diff line
@@ -211,14 +211,16 @@ class WebViewUpdateServiceImpl2 implements WebViewUpdateServiceInterface {
            }

            if (repairNeeded) {
                // We didn't find a valid WebView implementation. Try explicitly re-enabling the
                // default package for all users in case it was disabled, even if we already did the
                // one-time migration before. If this actually changes the state, we will see the
                // PackageManager broadcast shortly and try again.
                // We didn't find a valid WebView implementation. Try explicitly re-installing and
                // re-enabling the default package for all users in case it was disabled, even if we
                // already did the one-time migration before. If this actually changes the state, we
                // will see the PackageManager broadcast shortly and try again.
                Slog.w(
                        TAG,
                        "No provider available for all users, trying to enable "
                        "No provider available for all users, trying to install and enable "
                                + mDefaultProvider.packageName);
                mSystemInterface.installExistingPackageForAllUsers(
                        mContext, mDefaultProvider.packageName);
                mSystemInterface.enablePackageForAllUsers(
                        mContext, mDefaultProvider.packageName, true);
            }
+18 −0
Original line number Diff line number Diff line
@@ -83,6 +83,13 @@ public class TestSystemImpl implements SystemInterface {
        }
    }

    @Override
    public void installExistingPackageForAllUsers(Context context, String packageName) {
        for (int userId : mUsers) {
            installPackageForUser(packageName, userId);
        }
    }

    private void enablePackageForUser(String packageName, boolean enable, int userId) {
        Map<Integer, PackageInfo> userPackages = mPackages.get(packageName);
        if (userPackages == null) {
@@ -93,6 +100,17 @@ public class TestSystemImpl implements SystemInterface {
        setPackageInfoForUser(userId, packageInfo);
    }

    private void installPackageForUser(String packageName, int userId) {
        Map<Integer, PackageInfo> userPackages = mPackages.get(packageName);
        if (userPackages == null) {
            return;
        }
        PackageInfo packageInfo = userPackages.get(userId);
        packageInfo.applicationInfo.flags |= ApplicationInfo.FLAG_INSTALLED;
        packageInfo.applicationInfo.privateFlags &= (~ApplicationInfo.PRIVATE_FLAG_HIDDEN);
        setPackageInfoForUser(userId, packageInfo);
    }

    @Override
    public boolean systemIsDebuggable() { return mIsDebuggable; }

+25 −0
Original line number Diff line number Diff line
@@ -1549,6 +1549,31 @@ public class WebViewUpdateServiceTest {
                        Matchers.anyObject(), Mockito.eq(testPackage), Mockito.eq(true));
    }

    @Test
    @RequiresFlagsEnabled("android.webkit.update_service_v2")
    public void testDefaultWebViewPackageInstalling() {
        String testPackage = "testDefault";
        WebViewProviderInfo[] packages =
                new WebViewProviderInfo[] {
                    new WebViewProviderInfo(
                            testPackage,
                            "",
                            true /* default available */,
                            false /* fallback */,
                            null)
                };
        setupWithPackages(packages);
        mTestSystemImpl.setPackageInfo(
                createPackageInfo(
                        testPackage, true /* enabled */, true /* valid */, false /* installed */));

        // Check that the boot time logic tries to install the default package.
        runWebViewBootPreparationOnMainSync();
        Mockito.verify(mTestSystemImpl)
                .installExistingPackageForAllUsers(
                        Matchers.anyObject(), Mockito.eq(testPackage));
    }

    private void testDefaultPackageChosen(PackageInfo packageInfo) {
        WebViewProviderInfo[] packages =
                new WebViewProviderInfo[] {