summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Koh <justinkoh@google.com>2014-06-11 19:33:46 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-06-11 19:33:46 +0000
commit41a2c47e65a406534a2e4473da2f9ef35d0b04ce (patch)
tree468be3deb95f4964fdf68de590ab81e92d80db66
parent69b8b79a4f68643bf1defcdedb935bf7c20f038d (diff)
parent44195b4f90d035533c879672891e7e169972d95d (diff)
am 44195b4f: am 42c53fd6: Merge "Catch OperationUnsupportedException when linkifying using WebView" into klp-modular-dev
* commit '44195b4f90d035533c879672891e7e169972d95d': Catch OperationUnsupportedException when linkifying using WebView
-rw-r--r--core/java/android/text/util/Linkify.java53
1 files changed, 30 insertions, 23 deletions
diff --git a/core/java/android/text/util/Linkify.java b/core/java/android/text/util/Linkify.java
index deb138d43563..c1341e16f803 100644
--- a/core/java/android/text/util/Linkify.java
+++ b/core/java/android/text/util/Linkify.java
@@ -465,32 +465,39 @@ public class Linkify {
String address;
int base = 0;
- while ((address = WebView.findAddress(string)) != null) {
- int start = string.indexOf(address);
+ try {
+ while ((address = WebView.findAddress(string)) != null) {
+ int start = string.indexOf(address);
- if (start < 0) {
- break;
- }
+ if (start < 0) {
+ break;
+ }
- LinkSpec spec = new LinkSpec();
- int length = address.length();
- int end = start + length;
-
- spec.start = base + start;
- spec.end = base + end;
- string = string.substring(end);
- base += end;
-
- String encodedAddress = null;
-
- try {
- encodedAddress = URLEncoder.encode(address,"UTF-8");
- } catch (UnsupportedEncodingException e) {
- continue;
- }
+ LinkSpec spec = new LinkSpec();
+ int length = address.length();
+ int end = start + length;
- spec.url = "geo:0,0?q=" + encodedAddress;
- links.add(spec);
+ spec.start = base + start;
+ spec.end = base + end;
+ string = string.substring(end);
+ base += end;
+
+ String encodedAddress = null;
+
+ try {
+ encodedAddress = URLEncoder.encode(address,"UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ continue;
+ }
+
+ spec.url = "geo:0,0?q=" + encodedAddress;
+ links.add(spec);
+ }
+ } catch (UnsupportedOperationException e) {
+ // findAddress may fail with an unsupported exception on platforms without a WebView.
+ // In this case, we will not append anything to the links variable: it would have died
+ // in WebView.findAddress.
+ return;
}
}