Skip to content

Commit 41f79a1

Browse files
fadidurahCopilot
andauthored
Add onRenderProcessGone override to webview logic, Fixes AB#3405900 (#2788)
We do not gracefully handle webview process crashes, which can cause ANRs for calling activitties (LTW bug: https://dev.azure.com/microsoft/OS/_workitems/edit/59756442). In this PR we override the webview method onRenderProcessGone to handle what to do if webview no longer is able to render content, where we send the error to the callback rather than having an uncaught exception. [AB#3405900](https://identitydivision.visualstudio.com/fac9d424-53d2-45c0-91b5-ef6ba7a6bf26/_workitems/edit/3405900) --------- Co-authored-by: Copilot <[email protected]>
1 parent c4a2edc commit 41f79a1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

common/src/main/java/com/microsoft/identity/common/internal/ui/webview/OAuth2WebViewClient.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import android.os.Build;
3232
import android.view.View;
3333
import android.webkit.HttpAuthHandler;
34+
import android.webkit.RenderProcessGoneDetail;
3435
import android.webkit.SslErrorHandler;
3536
import android.webkit.WebResourceError;
3637
import android.webkit.WebResourceRequest;
@@ -218,6 +219,26 @@ public void onPageFinished(final WebView view,
218219
view.setVisibility(View.VISIBLE);
219220
}
220221

222+
/**
223+
* Handles WebView render process crashes or terminations. Previously, a WebView render process crash could cause
224+
* the calling application to crash as well, because the Broker was not handling the crash and packaging it into an exception.
225+
*
226+
* Overriding this method allows us to gracefully handle WebView render process crashes by sending an error to the callback object
227+
* when the render process is gone, preventing the application from crashing.
228+
* @param view webview in question
229+
* @param detail minor details about the render process being lost
230+
* @return whether or not we handled the crash
231+
*/
232+
@Override
233+
@RequiresApi(api = Build.VERSION_CODES.O)
234+
public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) {
235+
// Handle render process crash
236+
// TODO: This should probably have a more specific error code, but we'll need to ask OneAuth to add new handling for it.
237+
sendErrorToCallback(view, ERROR_UNKNOWN, "WebView render process gone, crashed? : " + detail.didCrash());
238+
239+
return true; // Indicate we handled the crash
240+
}
241+
221242
@Override
222243
public void onPageStarted(final WebView view,
223244
final String url,

0 commit comments

Comments
 (0)