Browser Embedded Incorrectly & Expressive Message (BEI-EM)

ECn Categories > Browser Embedded Incorrectly & Expressive Message (BEI-EM)

The application shows to the user an activity where an embedded browser displays an error message instead of the expected content. Nevertheless, at the same time the app shows a clear message (regarding the connectivity issue) when displaying the activity.

Amount of Issues App List
2 (A44) Materialistic

Examples

Materialistic

Category:
News & Magazines
v 3.1
Scenario: Read news without network connection for the first time

The following code snippets show the classes and files that are involved in the generation of the previuos issue.

In order to see how this issue is generated, we need to review all the flow event. First, as it can be seen in the following snippet there two important actions that are being executed. Specifically, at lines 183-184 there is a validation of connection and due to connectionless state of the test a Snackbar is generated with the text of the “R.string.offline_notice”. Before that, at line 177 the “bindData” method is called.

app/src/main/java/io/github/hidroh/materialistic/ItemActivity.java

     if (mItem != null) {
177.     bindData(mItem);
     } else if (!TextUtils.isEmpty(mItemId)) {
         mItemManager.getItem(mItemId,
             getIntent().getIntExtra(EXTRA_CACHE_MODE, ItemManager.MODE_DEFAULT),
             new ItemResponseListener(this));
     }
183. if (!AppUtils.hasConnection(this)) {
184.     Snackbar.make(mCoordinatorLayout, R.string.offline_notice, Snackbar.LENGTH_LONG).show();
     }

Now, when reviewing the code in “bindData” method it can be found that between lines 407-413 the url from the news is being processed and the “openWebUrlExternal” is called with the news url as a parameter.

app/src/main/java/io/github/hidroh/materialistic/ItemActivity.java

351.private void bindData(@Nullable final WebItem story) {
    ...
        if (story.isStoryType() && mExternalBrowser && !hasText) {
            TextView buttonArticle = (TextView) findViewById(R.id.button_article);
            buttonArticle.setVisibility(View.VISIBLE);
            buttonArticle.setOnClickListener(v ->
411.            AppUtils.openWebUrlExternal(ItemActivity.this,
412.                story, story.getUrl(), mCustomTabsDelegate.getSession()));
        }

Continuing, when the event flow gets into “openWebUrlExternal” method, there is a validation of the conection state in order to try to open the url using the resources of the “OfflineWebActivity”.

app/src/main/java/io/github/hidroh/materialistic/AppUtils.java

    public static void openWebUrlExternal(
      Context context, @Nullable WebItem item,
      String url, @Nullable CustomTabsSession session) {
98.     if (!hasConnection(context)) {
99.         context.startActivity(new Intent(context, OfflineWebActivity.class)
100.            .putExtra(OfflineWebActivity.EXTRA_URL, url));
            return;
        }

Finally, when the intent gets into this class, on the “onCreate” method at line 77 the url is loaded in a webView. However due to connectionless state the url will not load. Therefore the user will see both the message of connectionless state and the error thrown by the webView.

app/src/main/java/io/github/hidroh/materialistic/OfflineWebActivity.java

38. protected void onCreate(Bundle savedInstanceState) {
    ...
77.     webView.loadUrl(url);