summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Fuller <nfuller@google.com>2015-02-06 10:03:08 +0000
committerNeil Fuller <nfuller@google.com>2015-02-06 17:34:37 +0000
commitd950ad034ceeec0024bc299b542d2b6154ac4dd3 (patch)
treea6ff84debf74c4e4ca0141411cfcd3761e3cab4e
parentc565a5675ac33d97d5c1caed7a5629412997fb4a (diff)
downloadframeworks_base-d950ad034ceeec0024bc299b542d2b6154ac4dd3.zip
frameworks_base-d950ad034ceeec0024bc299b542d2b6154ac4dd3.tar.gz
frameworks_base-d950ad034ceeec0024bc299b542d2b6154ac4dd3.tar.bz2
Avoid static initialization of Layout from TextUtils
This works around a bug in standalone (e.g. non-Zygote) runtimes when a device is attached to a host that is running DDM. There is a race condition: When the runtime receives a HELLO from DDM it calls TextUtils.isEmpty(). Calling any TextUtils methods statically initializes Layout. Layout has dependencies on other classes, which in turn have dependencies on native methods that are not always registered when the call takes place. Registration and DDM handling are done in separate threads. This is not a fix, merely a workaround until the race can be resolved. Bug: 18081539 (cherry-picked from commit d29bdb266d54b4551f42776bb790e80147a279d0) Change-Id: Id0d8578eab9e59d479a7c1b2e7ea1890ac0c8de6
-rw-r--r--core/java/android/text/Layout.java6
-rw-r--r--core/java/android/text/StaticLayout.java2
-rw-r--r--core/java/android/text/TextUtils.java9
3 files changed, 9 insertions, 8 deletions
diff --git a/core/java/android/text/Layout.java b/core/java/android/text/Layout.java
index 2b53c48..b84c3aa 100644
--- a/core/java/android/text/Layout.java
+++ b/core/java/android/text/Layout.java
@@ -1754,8 +1754,8 @@ public abstract class Layout {
private char getEllipsisChar(TextUtils.TruncateAt method) {
return (method == TextUtils.TruncateAt.END_SMALL) ?
- ELLIPSIS_TWO_DOTS[0] :
- ELLIPSIS_NORMAL[0];
+ TextUtils.ELLIPSIS_TWO_DOTS[0] :
+ TextUtils.ELLIPSIS_NORMAL[0];
}
private void ellipsize(int start, int end, int line,
@@ -1952,6 +1952,4 @@ public abstract class Layout {
/* package */ static final Directions DIRS_ALL_RIGHT_TO_LEFT =
new Directions(new int[] { 0, RUN_LENGTH_MASK | RUN_RTL_FLAG });
- /* package */ static final char[] ELLIPSIS_NORMAL = { '\u2026' }; // this is "..."
- /* package */ static final char[] ELLIPSIS_TWO_DOTS = { '\u2025' }; // this is ".."
}
diff --git a/core/java/android/text/StaticLayout.java b/core/java/android/text/StaticLayout.java
index e82057c..2853b01 100644
--- a/core/java/android/text/StaticLayout.java
+++ b/core/java/android/text/StaticLayout.java
@@ -652,7 +652,7 @@ public class StaticLayout extends Layout {
float ellipsisWidth = paint.measureText(
(where == TextUtils.TruncateAt.END_SMALL) ?
- ELLIPSIS_TWO_DOTS : ELLIPSIS_NORMAL, 0, 1);
+ TextUtils.ELLIPSIS_TWO_DOTS : TextUtils.ELLIPSIS_NORMAL, 0, 1);
int ellipsisStart = 0;
int ellipsisCount = 0;
int len = lineEnd - lineStart;
diff --git a/core/java/android/text/TextUtils.java b/core/java/android/text/TextUtils.java
index 8a8c6d8..48bb5dd 100644
--- a/core/java/android/text/TextUtils.java
+++ b/core/java/android/text/TextUtils.java
@@ -63,9 +63,12 @@ import java.util.regex.Pattern;
public class TextUtils {
private static final String TAG = "TextUtils";
- private static final String ELLIPSIS = new String(Layout.ELLIPSIS_NORMAL);
- private static final String ELLIPSIS_TWO_DOTS = new String(Layout.ELLIPSIS_TWO_DOTS);
+ /* package */ static final char[] ELLIPSIS_NORMAL = { '\u2026' }; // this is "..."
+ private static final String ELLIPSIS_STRING = new String(ELLIPSIS_NORMAL);
+
+ /* package */ static final char[] ELLIPSIS_TWO_DOTS = { '\u2025' }; // this is ".."
+ private static final String ELLIPSIS_TWO_DOTS_STRING = new String(ELLIPSIS_TWO_DOTS);
private TextUtils() { /* cannot be instantiated */ }
@@ -1085,7 +1088,7 @@ public class TextUtils {
EllipsizeCallback callback) {
return ellipsize(text, paint, avail, where, preserveLength, callback,
TextDirectionHeuristics.FIRSTSTRONG_LTR,
- (where == TruncateAt.END_SMALL) ? ELLIPSIS_TWO_DOTS : ELLIPSIS);
+ (where == TruncateAt.END_SMALL) ? ELLIPSIS_TWO_DOTS_STRING : ELLIPSIS_STRING);
}
/**