Commit Graph

800 Commits

Author SHA1 Message Date
Romain Guy
b3a9bc038d Prevent possible memory leak in SpanSet
If SpanSet.init() is called several times in a row with different
values, it is possible to change "numberOfSpans" in a way that
will prevent SpanSet.recycle() from nulling out all the spans.

This can lead to memory leaks of large objects through spans
references. User @piwai reported this leak:

     com.squareup.marketfont.MarketSpan
     `-[1] of array android.text.style.CharacterStyle[]
       `-spans of object android.text.SpanSet
         `-mCharacterStyleSpanSet of object android.text.TextLine
           `-[1] of array android.text.TextLine[]
             `-sCached of class android.text.TextLine

The MarketSpan instance is kept alive through a recycled TextLine
which itself contains a SpanSet.

Change-Id: Idfb2233ca16895dbe735c312662eaf0b4a2ecd65
2015-04-07 11:07:05 -07:00
Alan Viverette
7506f499b5 Merge "Fix to crash when clicking text link without view activity" 2015-03-25 16:35:37 +00:00
Andreas Gampe
610b2c778c Frameworks/base: Fix trivial equals implementation
The comparator's equal implementation doesn't satisfy the constraints
of an equals method, namely being reflexive. Use the standard Object
implementation instead.

Bug: 19797138
Change-Id: I74f888e99533e1945aab7ab10fe8ee3ded6388f4
2015-03-17 20:24:45 +00:00
Tao Bao
6d8886ac46 resolved conflicts for merge of e1e1cd9d to lmp-mr1-dev-plus-aosp
Change-Id: If01cb9c91c4f980d422896aa5ebe713f540d4fd1
2015-02-11 22:32:05 -08:00
Tao Bao
67bfa0b083 Use ICU for relative time formatting
Rewrite the DateUtils' relative time formatting APIs
(getRelativeTimeSpanString, getRelativeDateTimeString) to use ICU ones.
Two APIs that take withPreposition parameter are not changed. Because
(a) ICU doesn't provide functionality to format preposition; (b) They
are not really computing relative time but instead calling
formatDateRange() to get the absolute time/date string.

Bug: 19146457
Bug: 5252772
Change-Id: Iea8d699d63cc4438513910da66d038912e44fb8d
2015-02-11 17:50:21 -08:00
Neil Fuller
c63efbd928 am 022cf57f: am a08934cf: am f789d45b: Merge "Avoid static initialization of Layout from TextUtils" into lmp-mr1-dev
* commit '022cf57f82e40a103c4a48c083a59d7fa4936668':
  Avoid static initialization of Layout from TextUtils
2015-02-06 17:51:05 +00:00
Neil Fuller
d950ad034c 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 d29bdb266d)

Change-Id: Id0d8578eab9e59d479a7c1b2e7ea1890ac0c8de6
2015-02-06 17:34:37 +00:00
Neil Fuller
d29bdb266d 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
Change-Id: If1bd3de6597bc93da381c8f86dacf40156449561
2015-02-06 10:29:54 +00:00
Igor Viarheichyk
6f9f1d4b3b Use constants instead of resources for ellipsis.
All supported locales use only U+2025 and U+2026 to represent
ellipses, and it will unlikely change in future. Given translated
resources are inconsistent and often use three dots it is safer
to use constants instead of resources.

(cherry-pick of ed0daa93e48d38e54a7ad1c99c461510a4c07599.)

Bug: 18542179
Change-Id: I51a6cb903f62f739fbadd6b78e5765c0028d641a
2015-01-29 15:00:13 -08:00
Svet Ganov
605ba80277 am 2004fdf8: am 830f39ad: Merge "Fixing a memory leak: activities are leaked." into lmp-mr1-dev
* commit '2004fdf8e54daa84a8c4da20909f81f37add66d5':
  Fixing a memory leak: activities are leaked.
2015-01-16 22:25:01 +00:00
Svet Ganov
893d6fe48d Fixing a memory leak: activities are leaked.
TextLine was not fully cleared before recycling it which leads to
activity leaks if the activity happens: to register a text watcher.

bug:19045507

Change-Id: Ife0f7ce29865bd30ca2dfe8795023f51f275d659
2015-01-16 18:14:36 +00:00
Raph Levien
d946753aa4 am 3ac280c9: am 078ce5fc: Merge "Revert "Change Linkify leniency to VALID"" into lmp-mr1-dev
* commit '3ac280c93bdebe4ca698e9a2e3d6d2daf3598e7a':
  Revert "Change Linkify leniency to VALID"
2014-12-17 23:19:25 +00:00
Raph Levien
047e816fe2 Revert "Change Linkify leniency to VALID"
This reverts commit 9dfe86d410.

That change moved the lenience from POSSIBLE to VALID, which eliminated
false positive links, especially 4 digit phone numbers, but caused
significant false negatives, leading to CTS test failures
(android.text.util.cts.LinkifyTest#testAddLinks7 in particular).

The true fix requires new functionality to validate phone numbers in
a mobile context. In the meantime, the best solution is to revert.

Bug: 18708556
2014-12-17 14:31:39 -08:00
Daniel 2 Olofsson
7bd9b7f73d Fix to crash when clicking text link without view activity
A generated quick link to telephone number gets clicked and
crashes if corresponding activity doesn't exist in device.
It attempts to open up an activity to view content which will
in turn generate an uncaught ActivityNotFoundException.
Solved by catching exception when launching activity for the
specified content.

Change-Id: I47364519f1eceb5b978b29382107deae1891c7da
2014-12-10 00:40:53 +00:00
Raph Levien
1918d0276a am 8aa97d26: am 238efad0: Merge "Change Linkify leniency to VALID" into lmp-mr1-dev
* commit '8aa97d26e48cb86398e3f7df8103379564f16082':
  Change Linkify leniency to VALID
2014-12-08 19:13:14 +00:00
Raph Levien
b9d21d623f am 8de4fb2f: am 2f0e6f0c: Merge "Fix off-by-one error in computeEllipsis" into lmp-mr1-dev
* commit '8de4fb2fe53ed7707500d9cdf737953bed3dec7e':
  Fix off-by-one error in computeEllipsis
2014-12-08 19:09:18 +00:00
Raph Levien
238efad04b Merge "Change Linkify leniency to VALID" into lmp-mr1-dev 2014-12-05 02:14:52 +00:00
Raph Levien
9dfe86d410 Change Linkify leniency to VALID
The linkify logic used POSSIBLE as its leniency setting, which resulted
in false positives such as 4-digit years being interpreted as phone
numbers. Changing to VALID as per recommendation of libphonenumber
people, which fixes this problem.

Bug: 18489494
Change-Id: I77d330285de46de2fdda22daed41392106ec6ddd
2014-12-04 14:42:38 -08:00
Raph Levien
0e3c5e8272 Fix off-by-one error in computeEllipsis
In the Truncate.MIDDLE case, when the line is less than half the layout
width, the computeEllipsis logic could go past the left edge of the
string. This patch fixes the off-by-one and avoids the resulting index
out of bounds crash, and also changes the behavior so that when
ellipsizing at the middle, the string to the end of the paragraph is
taken into account.

Bug: 18508627
Change-Id: I24be09c23a5aa158791a9717419307613b8a22e8
2014-12-04 22:32:48 +00:00
Jorim Jaggi
0da89b7640 resolved conflicts for merge of f0fc23a1 to lmp-mr1-dev-plus-aosp
Change-Id: I8f1dbae2ecd14ae4e51a9e86eb6d36dd56a48be1
2014-11-25 15:34:56 +01:00
Narayan Kamath
43395d677b am 68e9af7b: am 1d84709c: Merge "Stop reading Settings.System.DATE_FORMAT."
* commit '68e9af7ba0b846768036f268d719f3d2a333ffca':
  Stop reading Settings.System.DATE_FORMAT.
2014-11-24 16:19:04 +00:00
Narayan Kamath
f91f06a599 Stop reading Settings.System.DATE_FORMAT.
Also, move over DateFormat.getInstance(SHORT) instead of
LocaleData.shortDateFormat4 (which forces 4 digit years).
Based on an analysis of git history, there seems to be no
real motiviation for using 4 digit years.

If anyone in the platform complains loudly, we could look at
using a skeleton pattern instead of just replacing 'y' with 'yy'.

If third party apps are affected, we could add a targetSdkversion
based check and revert to the old behaviour for older targetSdks.

bug: 18388178
bug: 18322220
Change-Id: Ieab2b41691958a2e668d382c5a6b3d9aaf741ed2
2014-11-24 16:05:19 +00:00
Selim Cinek
9c4a707912 Fixed several time related states for secondary users
The 24 hour setting was not respected correctly. Also
fixed a bug where the next alarm would not display itself
in the QS panel.

Bug: 16239208
Change-Id: I89734f783912dead5831db49db53fba04dbf54ee
2014-11-21 18:25:30 +01:00
Chris Craik
de81cf0c31 am 22e8e8ef: am bde9ffbd: Merge "Fix missing ellipsis when just one character is truncated" into lmp-mr1-dev
* commit '22e8e8ef57ecef6fe7b3489c3c16babfda017435':
  Fix missing ellipsis when just one character is truncated
2014-11-18 22:25:39 +00:00
Raph Levien
396879f3f8 Fix missing ellipsis when just one character is truncated
The "moreChars" test in StaticLayout's generate method would evaluate to
false when the last character in a word caused the break. This in turn
suppressed the ellipsis in this case. The proposed fix is always to set
moreChars true in the code path where the line is broken because more
text wouldn't fit.

Bug: 17738112
Change-Id: Ifa1a69841ca952da4d1937dc8326778179b026b3
2014-11-17 12:32:06 -08:00
Adrian Roos
34c45bb953 am b2a6c7b8: am 418f4ed0: Merge "Round charging indication to nearest minute" into lmp-mr1-dev
* commit 'b2a6c7b83f894922663e7144048264af96239a1e':
  Round charging indication to nearest minute
2014-11-06 16:31:43 +00:00
Adrian Roos
874b35b836 Round charging indication to nearest minute
Bug: 18177374
Change-Id: I4eb7fcac83398a4d8432bf092d8d91506646b5a1
2014-11-05 16:11:10 +01:00
Narayan Kamath
f2196a6ed5 am 6220810b: am 78a3b7d5: Merge "Remove deprecated DateFormat APIs." into lmp-mr1-dev
* commit '6220810b8167deee7bf2577f5136736473cbea1c':
  Remove deprecated DateFormat APIs.
2014-11-04 10:08:53 +00:00
Narayan Kamath
9d68b3c839 Remove deprecated DateFormat APIs.
bug: 18074066
Change-Id: I99cef45105c9f25075c596cf4f52ec5573565596
2014-11-03 16:01:32 +00:00
Elliott Hughes
64a1a901dc am 87ce99ca: am ced7ebdb: Merge "Migrate off timeFormat12 and timeFormat24."
* commit '87ce99ca7243e4556a6cfe9f42cc51531301e979':
  Migrate off timeFormat12 and timeFormat24.
2014-10-29 17:13:38 +00:00
Elliott Hughes
87ce99ca72 am ced7ebdb: Merge "Migrate off timeFormat12 and timeFormat24."
* commit 'ced7ebdb1d522b4206e2048b278554ca841aeaba':
  Migrate off timeFormat12 and timeFormat24.
2014-10-28 04:39:24 +00:00
Neil Fuller
a021e92218 resolved conflicts for merge of 12260ad7 to lmp-mr1-dev-plus-aosp
Change-Id: Ie2222794208475216941289cf062e05ca9c75e0f
2014-10-24 11:36:46 +01:00
Elliott Hughes
ced7ebdb1d Merge "Migrate off timeFormat12 and timeFormat24." 2014-10-23 18:21:56 +00:00
Elliott Hughes
f7d5e0a53e Migrate off timeFormat12 and timeFormat24.
libcore now offers a wider variety of 12-/24-hour time formats,
so be more specific about which one we want here.

(cherry-pick of 85f60d3a03b5b5d9a0e8b8a138eb85a6b53a1eca.)

Bug: 10361358
Change-Id: I846ab7a6f84cd49e876ad21e9366aff1600e0530
2014-10-23 11:18:21 -07:00
Neil Fuller
bbf8871e1c Deprecating FloatMath and Time
Bug: https://code.google.com/p/android/issues/detail?id=36199
Bug: https://code.google.com/p/android/issues/detail?id=37653
Bug: https://code.google.com/p/android/issues/detail?id=42750
Bug: https://code.google.com/p/android/issues/detail?id=61137
Bug: https://code.google.com/p/android/issues/detail?id=74754
Bug: https://code.google.com/p/android/issues/detail?id=76386
Bug: https://code.google.com/p/android/issues/detail?id=76439
Bug: https://code.google.com/p/android/issues/detail?id=77836
Change-Id: Ic9b57d8a575f93b2258a5481df0ed6b3a952f636
2014-10-23 13:13:05 +01:00
Neil Fuller
12f427d0b5 am 1802567a: am e4625cc1: Merge "Fix Time docs to document various error cases"
* commit '1802567a79b2fc94aa1dff387cd55db8521cdca6':
  Fix Time docs to document various error cases
2014-10-15 16:05:56 +00:00
Neil Fuller
8ee062122f am 1802567a: am e4625cc1: Merge "Fix Time docs to document various error cases"
* commit '1802567a79b2fc94aa1dff387cd55db8521cdca6':
  Fix Time docs to document various error cases
2014-10-15 16:05:55 +00:00
Neil Fuller
e4625cc1a8 Merge "Fix Time docs to document various error cases" 2014-10-15 15:56:06 +00:00
Neil Fuller
7079f2003c Fix Time docs to document various error cases
Bug: https://code.google.com/p/android/issues/detail?id=76386
Change-Id: Ibb71405b70453d5abaf45426ec4e36261b6695cf
2014-10-15 12:08:05 +01:00
Newton Allen
df2b8a1cb9 am 58f75627: am 94f5155d: am c68aad9f: am d84ce32b: Merge "Fix some documentation typos." into lmp-dev
* commit '58f75627d195082e263f6d6d8e3c46c6d0970e63':
  Fix some documentation typos.
2014-10-02 19:43:39 +00:00
Newton Allen
408f7534ef am d84ce32b: Merge "Fix some documentation typos." into lmp-dev
* commit 'd84ce32bd2d7c3cebac15545504f4fec464a6956':
  Fix some documentation typos.
2014-10-02 16:46:03 +00:00
Neil Fuller
c2a0b4482d resolved conflicts for merge of ee665151 to lmp-mr1-dev-plus-aosp
Change-Id: I2588c65b7a9fa43f968151a206924a804f0595a7
2014-10-02 14:32:37 +01:00
Neil Fuller
f7cf5d43aa resolved conflicts for merge of ee665151 to lmp-dev-plus-aosp
Change-Id: I97671e62de26919e391dbb2686511584c59ab990
2014-10-02 11:48:08 +01:00
Neil Fuller
33253a4baa Switch from FloatMath -> Math and Math.hypot where possible
The motivation is an API change: FloatMath is going to be
deprecated and/or removed. Performance is not the goal of
this change.

That said...

Math is faster than FloatMath with AOT compilation.

While making the change, occurances of:

{Float}Math.sqrt(x * x + y * y) and
{Float}Math.sqrt({Float}Math.pow(x, 2) + {Float}Math.pow(y, 2))

have been replaced with:

{(float)} Math.hypot(x, y)

Right now there is no runtime intrinsic for hypot so is not faster
in all cases for AOT compilation:

Math.sqrt(x * x + y * y) is faster than Math.hypot(x, y) with
AOT, but all other combinations of FloatMath, use of pow() etc.
are slower than hypot().

hypot() has the advantage of being self documenting and
could be optimized in future. None of the behavior differences
around NaN and rounding appear to be important for the cases
looked at: they all assume results and arguments are in range
and usually the results are cast to float.

Different implementations measured on hammerhead / L:

AOT compiled:

[FloatMath.hypot(x, y)]
benchmark=Hypot_FloatMathHypot} 633.85 ns; σ=0.32 ns @ 3 trials

[FloatMath.sqrt(x*x + y*y)]
benchmark=Hypot_FloatMathSqrtMult} 684.17 ns; σ=4.83 ns @ 3 trials

[FloatMath.sqrt(FloatMath.pow(x, 2) + FloatMath.pow(y, 2))]
benchmark=Hypot_FloatMathSqrtPow} 1270.65 ns; σ=12.20 ns @ 6 trials

[(float) Math.hypot(x, y)]
benchmark=Hypot_MathHypot} 96.80 ns; σ=0.05 ns @ 3 trials

[(float) Math.sqrt(x*x + y*y)]
benchmark=Hypot_MathSqrtMult} 23.97 ns; σ=0.01 ns @ 3 trials

[(float) Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2))]
benchmark=Hypot_MathSqrtPow} 156.19 ns; σ=0.12 ns @ 3 trials

Interpreter:

benchmark=Hypot_FloatMathHypot} 1180.54 ns; σ=5.13 ns @ 3 trials
benchmark=Hypot_FloatMathSqrtMult} 1121.05 ns; σ=3.80 ns @ 3 trials
benchmark=Hypot_FloatMathSqrtPow} 3327.14 ns; σ=7.33 ns @ 3 trials
benchmark=Hypot_MathHypot} 856.57 ns; σ=1.41 ns @ 3 trials
benchmark=Hypot_MathSqrtMult} 1028.92 ns; σ=9.11 ns @ 3 trials
benchmark=Hypot_MathSqrtPow} 2539.47 ns; σ=24.44 ns @ 3 trials

Bug: https://code.google.com/p/android/issues/detail?id=36199
Change-Id: I06c91f682095e627cb547d60d936ef87941be692
2014-10-01 14:04:15 +01:00
Newton Allen
8f8a11b7fa Fix some documentation typos.
Change-Id: I747a0ade5c7b9c45d4465bf327952338bbc1cfaa
(cherry picked from commit 4465d1a03e)
2014-09-30 02:52:26 +00:00
Elliott Hughes
69eb21074f am 4fec1b48: am 600ca140: Merge "Use constants instead of resources for ellipsis."
* commit '4fec1b488759a89732af151e21a89aa6693ba9bf':
  Use constants instead of resources for ellipsis.
2014-09-19 23:16:52 +00:00
Elliott Hughes
212998ce62 am 4fec1b48: am 600ca140: Merge "Use constants instead of resources for ellipsis."
* commit '4fec1b488759a89732af151e21a89aa6693ba9bf':
  Use constants instead of resources for ellipsis.
2014-09-19 23:02:14 +00:00
Elliott Hughes
600ca140e2 Merge "Use constants instead of resources for ellipsis." 2014-09-19 22:02:45 +00:00
Igor Viarheichyk
ed0daa93e4 Use constants instead of resources for ellipsis.
All supported locales use only U+2025 and U+2026 to represent
ellipses, and it will unlikely change in future. Given translated
resources are inconsistent and often use three dots it is safer
to use constants instead of resources.

Change-Id: I51a6cb903f62f739fbadd6b78e5765c0028d641a
2014-09-19 22:02:08 +00:00
Elliott Hughes
4656e69bf3 resolved conflicts for merge of 2008cff7 to lmp-dev-plus-aosp
Change-Id: I5148eda624e8504f12dbc1288cd4a7a5b7c10850
2014-09-08 13:08:43 -07:00