summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Tobias Sargeant <tobiasjs@google.com> 2017-01-19 14:03:09 +0000
committer Tobias Sargeant <tobiasjs@google.com> 2017-01-22 18:59:12 +0000
commitd10e4af0988b478f57dd90196ee105a94129a93b (patch)
treef2211bc2b3354ffcf43c3b5c5609ccfd97961c9d
parentdaca8ee6a5b1c47bea2b61b952d2107bf560e229 (diff)
WebView: Add the definition of the renderer importance API.
The renderer importance API is used to specify how important out-of-process WebView renderer services are for the purposes of OOM killing and scheduling with respect to the binding application. This allows an application to - for example - specify that renderers can be killed while the application is not in the foreground, thus cleaning up additional resources. Bug: 30824898 Test: Tests await Chromium change. Change-Id: I6dca3d427d6cdb5cb7e0be6f7fb8ece64bd24af9
-rw-r--r--api/current.txt7
-rw-r--r--api/system-current.txt10
-rw-r--r--api/test-current.txt7
-rw-r--r--core/java/android/webkit/RenderProcessGoneDetail.java11
-rw-r--r--core/java/android/webkit/WebView.java91
-rw-r--r--core/java/android/webkit/WebViewProvider.java6
6 files changed, 132 insertions, 0 deletions
diff --git a/api/current.txt b/api/current.txt
index 725f1f057c76..21f547912bc1 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -46575,6 +46575,7 @@ package android.webkit {
public abstract class RenderProcessGoneDetail {
ctor public RenderProcessGoneDetail();
method public abstract boolean didCrash();
+ method public abstract int rendererPriorityAtExit();
}
public class ServiceWorkerClient {
@@ -46991,6 +46992,8 @@ package android.webkit {
method public deprecated java.lang.String[] getHttpAuthUsernamePassword(java.lang.String, java.lang.String);
method public java.lang.String getOriginalUrl();
method public int getProgress();
+ method public boolean getRendererPriorityWaivedWhenNotVisible();
+ method public int getRendererRequestedPriority();
method public deprecated float getScale();
method public android.webkit.WebSettings getSettings();
method public java.lang.String getTitle();
@@ -47038,6 +47041,7 @@ package android.webkit {
method public deprecated void setMapTrackballToArrowKeys(boolean);
method public void setNetworkAvailable(boolean);
method public deprecated void setPictureListener(android.webkit.WebView.PictureListener);
+ method public void setRendererPriorityPolicy(int, boolean);
method public deprecated void setVerticalScrollbarOverlay(boolean);
method public void setWebChromeClient(android.webkit.WebChromeClient);
method public static void setWebContentsDebuggingEnabled(boolean);
@@ -47047,6 +47051,9 @@ package android.webkit {
method public void zoomBy(float);
method public boolean zoomIn();
method public boolean zoomOut();
+ field public static final int RENDERER_PRIORITY_BOUND = 1; // 0x1
+ field public static final int RENDERER_PRIORITY_IMPORTANT = 2; // 0x2
+ field public static final int RENDERER_PRIORITY_WAIVED = 0; // 0x0
field public static final java.lang.String SCHEME_GEO = "geo:0,0?q=";
field public static final java.lang.String SCHEME_MAILTO = "mailto:";
field public static final java.lang.String SCHEME_TEL = "tel:";
diff --git a/api/system-current.txt b/api/system-current.txt
index 0b5040a847d1..afc3d0928592 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -49907,6 +49907,7 @@ package android.webkit {
public abstract class RenderProcessGoneDetail {
ctor public RenderProcessGoneDetail();
method public abstract boolean didCrash();
+ method public abstract int rendererPriorityAtExit();
}
public class ServiceWorkerClient {
@@ -50362,6 +50363,8 @@ package android.webkit {
method public deprecated java.lang.String[] getHttpAuthUsernamePassword(java.lang.String, java.lang.String);
method public java.lang.String getOriginalUrl();
method public int getProgress();
+ method public boolean getRendererPriorityWaivedWhenNotVisible();
+ method public int getRendererRequestedPriority();
method public deprecated float getScale();
method public android.webkit.WebSettings getSettings();
method public java.lang.String getTitle();
@@ -50410,6 +50413,7 @@ package android.webkit {
method public deprecated void setMapTrackballToArrowKeys(boolean);
method public void setNetworkAvailable(boolean);
method public deprecated void setPictureListener(android.webkit.WebView.PictureListener);
+ method public void setRendererPriorityPolicy(int, boolean);
method public deprecated void setVerticalScrollbarOverlay(boolean);
method public void setWebChromeClient(android.webkit.WebChromeClient);
method public static void setWebContentsDebuggingEnabled(boolean);
@@ -50420,6 +50424,9 @@ package android.webkit {
method public boolean zoomIn();
method public boolean zoomOut();
field public static final java.lang.String DATA_REDUCTION_PROXY_SETTING_CHANGED = "android.webkit.DATA_REDUCTION_PROXY_SETTING_CHANGED";
+ field public static final int RENDERER_PRIORITY_BOUND = 1; // 0x1
+ field public static final int RENDERER_PRIORITY_IMPORTANT = 2; // 0x2
+ field public static final int RENDERER_PRIORITY_WAIVED = 0; // 0x0
field public static final java.lang.String SCHEME_GEO = "geo:0,0?q=";
field public static final java.lang.String SCHEME_MAILTO = "mailto:";
field public static final java.lang.String SCHEME_TEL = "tel:";
@@ -50641,6 +50648,8 @@ package android.webkit {
method public abstract java.lang.String[] getHttpAuthUsernamePassword(java.lang.String, java.lang.String);
method public abstract java.lang.String getOriginalUrl();
method public abstract int getProgress();
+ method public abstract boolean getRendererPriorityWaivedWhenNotVisible();
+ method public abstract int getRendererRequestedPriority();
method public abstract float getScale();
method public abstract android.webkit.WebViewProvider.ScrollDelegate getScrollDelegate();
method public abstract android.webkit.WebSettings getSettings();
@@ -50695,6 +50704,7 @@ package android.webkit {
method public abstract void setMapTrackballToArrowKeys(boolean);
method public abstract void setNetworkAvailable(boolean);
method public abstract void setPictureListener(android.webkit.WebView.PictureListener);
+ method public abstract void setRendererPriorityPolicy(int, boolean);
method public abstract void setVerticalScrollbarOverlay(boolean);
method public abstract void setWebChromeClient(android.webkit.WebChromeClient);
method public abstract void setWebViewClient(android.webkit.WebViewClient);
diff --git a/api/test-current.txt b/api/test-current.txt
index f5212327900a..621045a89baf 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -46873,6 +46873,7 @@ package android.webkit {
public abstract class RenderProcessGoneDetail {
ctor public RenderProcessGoneDetail();
method public abstract boolean didCrash();
+ method public abstract int rendererPriorityAtExit();
}
public class ServiceWorkerClient {
@@ -47289,6 +47290,8 @@ package android.webkit {
method public deprecated java.lang.String[] getHttpAuthUsernamePassword(java.lang.String, java.lang.String);
method public java.lang.String getOriginalUrl();
method public int getProgress();
+ method public boolean getRendererPriorityWaivedWhenNotVisible();
+ method public int getRendererRequestedPriority();
method public deprecated float getScale();
method public android.webkit.WebSettings getSettings();
method public java.lang.String getTitle();
@@ -47336,6 +47339,7 @@ package android.webkit {
method public deprecated void setMapTrackballToArrowKeys(boolean);
method public void setNetworkAvailable(boolean);
method public deprecated void setPictureListener(android.webkit.WebView.PictureListener);
+ method public void setRendererPriorityPolicy(int, boolean);
method public deprecated void setVerticalScrollbarOverlay(boolean);
method public void setWebChromeClient(android.webkit.WebChromeClient);
method public static void setWebContentsDebuggingEnabled(boolean);
@@ -47345,6 +47349,9 @@ package android.webkit {
method public void zoomBy(float);
method public boolean zoomIn();
method public boolean zoomOut();
+ field public static final int RENDERER_PRIORITY_BOUND = 1; // 0x1
+ field public static final int RENDERER_PRIORITY_IMPORTANT = 2; // 0x2
+ field public static final int RENDERER_PRIORITY_WAIVED = 0; // 0x0
field public static final java.lang.String SCHEME_GEO = "geo:0,0?q=";
field public static final java.lang.String SCHEME_MAILTO = "mailto:";
field public static final java.lang.String SCHEME_TEL = "tel:";
diff --git a/core/java/android/webkit/RenderProcessGoneDetail.java b/core/java/android/webkit/RenderProcessGoneDetail.java
index 77d85963ce2d..1c793993909d 100644
--- a/core/java/android/webkit/RenderProcessGoneDetail.java
+++ b/core/java/android/webkit/RenderProcessGoneDetail.java
@@ -32,4 +32,15 @@ public abstract class RenderProcessGoneDetail {
* system.
**/
public abstract boolean didCrash();
+
+ /**
+ * Returns the renderer priority that was set at the time that the
+ * renderer exited. This may be greater than the priority that
+ * any individual {@link WebView} requested using
+ * {@link WebView#setRendererPriorityPolicy}.
+ *
+ * @return the priority of the renderer at exit.
+ **/
+ @WebView.RendererPriority
+ public abstract int rendererPriorityAtExit();
}
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index f98c099f053f..1e7cddfcda92 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -16,6 +16,7 @@
package android.webkit;
+import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.annotation.Widget;
@@ -60,6 +61,8 @@ import android.widget.AbsoluteLayout;
import java.io.BufferedWriter;
import java.io.File;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
import java.util.Map;
/**
@@ -2151,6 +2154,94 @@ public class WebView extends AbsoluteLayout
return mProvider.findHierarchyView(className, hashCode);
}
+ /** @hide */
+ @IntDef({
+ RENDERER_PRIORITY_WAIVED,
+ RENDERER_PRIORITY_BOUND,
+ RENDERER_PRIORITY_IMPORTANT
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface RendererPriority {}
+
+ /**
+ * The renderer associated with this WebView is bound with
+ * {@link Context#BIND_WAIVE_PRIORITY}. At this priority level
+ * {@link WebView} renderers will be strong targets for out of memory
+ * killing.
+ *
+ * Use with {@link #setRendererPriorityPolicy}.
+ */
+ public static final int RENDERER_PRIORITY_WAIVED = 0;
+ /**
+ * The renderer associated with this WebView is bound with
+ * the default priority for services.
+ *
+ * Use with {@link #setRendererPriorityPolicy}.
+ */
+ public static final int RENDERER_PRIORITY_BOUND = 1;
+ /**
+ * The renderer associated with this WebView is bound with
+ * {@link Context#BIND_IMPORTANT}.
+ *
+ * Use with {@link #setRendererPriorityPolicy}.
+ */
+ public static final int RENDERER_PRIORITY_IMPORTANT = 2;
+
+ /**
+ * Set the renderer priority policy for this {@link WebView}. The
+ * priority policy will be used to determine whether an out of
+ * process renderer should be considered to be a target for OOM
+ * killing.
+ *
+ * Because a renderer can be associated with more than one
+ * WebView, the final priority it is computed as the maximum of
+ * any attached WebViews. When a WebView is destroyed it will
+ * cease to be considerered when calculating the renderer
+ * priority. Once no WebViews remain associated with the renderer,
+ * the priority of the renderer will be reduced to
+ * {@link #RENDERER_PRIORITY_WAIVED}.
+ *
+ * The default policy is to set the priority to
+ * {@link #RENDERER_PRIORITY_IMPORTANT} regardless of visibility,
+ * and this should not be changed unless the caller also handles
+ * renderer crashes with
+ * {@link WebViewClient#onRenderProcessGone}. Any other setting
+ * will result in WebView renderers being killed by the system
+ * more aggressively than the application.
+ *
+ * @param rendererRequestedPriority the minimum priority at which
+ * this WebView desires the renderer process to be bound.
+ * @param waivedWhenNotVisible if true, this flag specifies that
+ * when this WebView is not visible, it will be treated as
+ * if it had requested a priority of
+ * {@link #RENDERER_PRIORITY_WAIVED}.
+ */
+ public void setRendererPriorityPolicy(
+ @RendererPriority int rendererRequestedPriority,
+ boolean waivedWhenNotVisible) {
+ mProvider.setRendererPriorityPolicy(rendererRequestedPriority, waivedWhenNotVisible);
+ }
+
+ /**
+ * Get the requested renderer priority for this WebView.
+ *
+ * @return the requested renderer priority policy.
+ */
+ @RendererPriority
+ public int getRendererRequestedPriority() {
+ return mProvider.getRendererRequestedPriority();
+ }
+
+ /**
+ * Return whether this WebView requests a priority of
+ * {@link #RENDERER_PRIORITY_WAIVED} when not visible.
+ *
+ * @return whether this WebView requests a priority of
+ * {@link #RENDERER_PRIORITY_WAIVED} when not visible.
+ */
+ public boolean getRendererPriorityWaivedWhenNotVisible() {
+ return mProvider.getRendererPriorityWaivedWhenNotVisible();
+ }
//-------------------------------------------------------------------------
// Interface for WebView providers
//-------------------------------------------------------------------------
diff --git a/core/java/android/webkit/WebViewProvider.java b/core/java/android/webkit/WebViewProvider.java
index dd1b0d2d17a4..ffc18b1e9c36 100644
--- a/core/java/android/webkit/WebViewProvider.java
+++ b/core/java/android/webkit/WebViewProvider.java
@@ -269,6 +269,12 @@ public interface WebViewProvider {
public View findHierarchyView(String className, int hashCode);
+ public void setRendererPriorityPolicy(int rendererRequestedPriority, boolean waivedWhenNotVisible);
+
+ public int getRendererRequestedPriority();
+
+ public boolean getRendererPriorityWaivedWhenNotVisible();
+
//-------------------------------------------------------------------------
// Provider internal methods
//-------------------------------------------------------------------------