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

Commit 99042d05 authored by Edgar Arriaga's avatar Edgar Arriaga
Browse files

Pin webview to memory

Bug: 307594624
Test: dumpsys pinner verify pinned ranges updating webview and enabling
disabling flags.

Change-Id: I5fe3f03f0a8c0eb5b101d75d1bf1449b54050519
parent 586efa0c
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -45,6 +45,10 @@ per-file res/values/config_device_idle.xml = file:/apex/jobscheduler/OWNERS
# Wear
per-file res/*-watch/* = file:/WEAR_OWNERS

# Peformance
per-file res/values/config.xml = file:/PERFORMANCE_OWNERS
per-file res/values/symbols.xml = file:/PERFORMANCE_OWNERS

# PowerProfile
per-file res/xml/power_profile.xml = file:/BATTERY_STATS_OWNERS
per-file res/xml/power_profile_test.xml = file:/BATTERY_STATS_OWNERS
+3 −0
Original line number Diff line number Diff line
@@ -4336,6 +4336,9 @@
    <!-- True if assistant app should be pinned via Pinner Service -->
    <bool name="config_pinnerAssistantApp">false</bool>

    <!-- Bytes that the PinnerService will pin for WebView -->
    <integer name="config_pinnerWebviewPinBytes">0</integer>

    <!-- Number of days preloaded file cache should be preserved on a device before it can be
         deleted -->
    <integer name="config_keepPreloadsMinDays">7</integer>
+1 −0
Original line number Diff line number Diff line
@@ -3376,6 +3376,7 @@
  <java-symbol type="bool" name="config_pinnerCameraApp" />
  <java-symbol type="bool" name="config_pinnerHomeApp" />
  <java-symbol type="bool" name="config_pinnerAssistantApp" />
  <java-symbol type="integer" name="config_pinnerWebviewPinBytes" />

  <java-symbol type="string" name="config_doubleTouchGestureEnableFile" />

+242 −73

File changed.

Preview size limit exceeded, changes collapsed.

+36 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.server.webkit;

import android.annotation.Nullable;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.Signature;
@@ -29,8 +30,12 @@ import android.webkit.WebViewFactory;
import android.webkit.WebViewProviderInfo;
import android.webkit.WebViewProviderResponse;

import com.android.server.LocalServices;
import com.android.server.PinnerService;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
@@ -88,6 +93,8 @@ class WebViewUpdateServiceImpl {
    private static final int MULTIPROCESS_SETTING_ON_VALUE = Integer.MAX_VALUE;
    private static final int MULTIPROCESS_SETTING_OFF_VALUE = Integer.MIN_VALUE;

    private static final String PIN_GROUP = "webview";

    private final SystemInterface mSystemInterface;
    private final Context mContext;

@@ -332,6 +339,34 @@ class WebViewUpdateServiceImpl {
        return newPackage;
    }

    private void pinWebviewIfRequired(ApplicationInfo appInfo) {
        PinnerService pinnerService = LocalServices.getService(PinnerService.class);
        int webviewPinQuota = pinnerService.getWebviewPinQuota();
        if (webviewPinQuota <= 0) {
            return;
        }

        pinnerService.unpinGroup(PIN_GROUP);

        ArrayList<String> apksToPin = new ArrayList<>();
        boolean pinSharedFirst = appInfo.metaData.getBoolean("PIN_SHARED_LIBS_FIRST", true);
        for (String sharedLib : appInfo.sharedLibraryFiles) {
            apksToPin.add(sharedLib);
        }
        apksToPin.add(appInfo.sourceDir);
        if (!pinSharedFirst) {
            // We want to prioritize pinning of the native library that is most likely used by apps
            // which in some build flavors live in the main apk and as a shared library for others.
            Collections.reverse(apksToPin);
        }
        for (String apk : apksToPin) {
            if (webviewPinQuota <= 0) {
                break;
            }
            int bytesPinned = pinnerService.pinFile(apk, webviewPinQuota, appInfo, PIN_GROUP);
            webviewPinQuota -= bytesPinned;
        }
    }
    /**
     * This is called when we change WebView provider, either when the current provider is
     * updated or a new provider is chosen / takes precedence.
@@ -340,6 +375,7 @@ class WebViewUpdateServiceImpl {
        synchronized (mLock) {
            mAnyWebViewInstalled = true;
            if (mNumRelroCreationsStarted == mNumRelroCreationsFinished) {
                pinWebviewIfRequired(newPackage.applicationInfo);
                mCurrentWebViewPackage = newPackage;

                // The relro creations might 'finish' (not start at all) before