Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
Fix 'No Activity found' crash for invalid web urls.
Browse files Browse the repository at this point in the history
- LEARNER-3191
- On analysis of crash logs it seems that the crash occurs when:
1) a URI is not recognizable by both the app and the Android system
2) the app doesn't recognize a particular marketing url due to null
reference of 'actionListener' in
'URLInterceptorWebViewClient.parseRecognizedLinkAndCallListener'
callback.
In this fix we have made sure to avoid these possible scenarios.
  • Loading branch information
farhan committed May 23, 2019
1 parent 8cf0f2d commit 2e7cf8a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
2 changes: 2 additions & 0 deletions OpenEdXMobile/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
<string name="you_are_now_enrolled">You are now enrolled in this course.</string>
<!-- Error message shown when dashboard cannot be shown from course detail view -->
<string name="cannot_show_dashboard">Unable to show dashboard.</string>
<!-- Error message shown when browser cannot handle request for given web url -->
<string name="cannot_open_url" tools:ignore="MissingTranslation">Unable to open web page.</string>

<!-- Subjects Discovery -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
loadUrl(getInitialUrl());
setWebViewActionListener();
loadUrl(getInitialUrl());
if (null != savedInstanceState) {
lastClickEnrollCourseId = savedInstanceState.getString(INSTANCE_COURSE_ID);
lastClickEnrollEmailOptIn = savedInstanceState.getBoolean(INSTANCE_EMAIL_OPT_IN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
loadUrl(getInitialUrl());
setWebViewActionListener();
loadUrl(getInitialUrl());
}

public void setWebViewActionListener() {
Expand Down
18 changes: 14 additions & 4 deletions OpenEdXMobile/src/main/java/org/edx/mobile/util/BrowserUtil.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package org.edx.mobile.util;

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.support.v4.app.FragmentActivity;
import android.text.TextUtils;
import android.widget.Toast;

import com.google.inject.Inject;

import org.edx.mobile.R;
import org.edx.mobile.core.IEdxEnvironment;
import org.edx.mobile.logger.Logger;
import org.edx.mobile.module.analytics.AnalyticsRegistry;
Expand Down Expand Up @@ -87,10 +90,17 @@ private static void openInBrowser(FragmentActivity context, String url) {
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse(url));
context.startActivity(intent);

AnalyticsRegistry analyticsRegistry = environment.getAnalyticsRegistry();
analyticsRegistry.trackBrowserLaunched(url);
try {
context.startActivity(intent);
AnalyticsRegistry analyticsRegistry = environment.getAnalyticsRegistry();
analyticsRegistry.trackBrowserLaunched(url);
} catch (ActivityNotFoundException e) {
Toast.makeText(context, R.string.cannot_open_url, Toast.LENGTH_SHORT).show();

// Send non-fatal exception
logger.error(new Exception(String.format("No activity found (browser cannot handle request) for this url: %s, error:\n", url)
+ e.getMessage()), true);
}
}

public static boolean isUrlOfHost(String url, String host) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setWebViewActionListener();
// Check for search query in extras
String searchQueryExtra = null;
String searchUrl = null;
Expand All @@ -74,7 +75,6 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
if (!EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().register(this);
}
setWebViewActionListener();
}

public void setWebViewActionListener() {
Expand Down

0 comments on commit 2e7cf8a

Please sign in to comment.