Commit Graph

620 Commits

Author SHA1 Message Date
Chris Wren
d9f3d9edc0 Don't WTF when reading empty data from the eventlog
Bug: 33446064
Fixes: 33446064
Test: run cts -m CtsUtilTestCases -t android.util.cts.EventLogTest
Change-Id: I4951202cd7d6ca441700b7122cfa3aae2167c7b0
2016-12-19 12:51:34 -05:00
Joe Onorato
be5378574b Merge changes from topic 'proto convenience methods'
* changes:
  ProtoOutputStream convenience methods.
  Give protoc-gen-javastream the ability to output multiple java files.
2016-12-08 02:39:50 +00:00
Svetoslav Ganov
74c9983e80 Fix vulnerability in MemoryIntArray
MemoryIntArray was using the size of the undelying
ashmem region to mmap the data but the ashmem size
can be changed until the former is memory mapped.
Since we use the ashmem region size for boundary
checking and memory unmapping if it does not match
the size used while mapping an attacker can force
the system to unmap memory or to access undefined
memory and crash.

Also we were passing the memory address where the
ashmem region is mapped in the owner process to
support cases where the client can pass back the
MemoryIntArray instance. This allows an attacker
to put invalid address and cause arbitrary memory
to be freed.

Now we no longer support passing back the instance
to the owner process (the passed back instance is
read only), so no need to pass the memory adress
of the owner's mapping, thus not allowing freeing
arbitrary memory.

Further, we now check the memory mapped size against
the size of the underlying ashmem region after we do
the memory mapping (to fix the ahsmem size) and if
an attacker changed the size under us we throw.

Tests: Updated the tests and they pass.

bug:33039926
bug:33042690

Change-Id: Ib8e50afcdb5475123968572ac9696e8ed4031631
2016-12-07 22:43:56 +00:00
Joe Onorato
fb9f736a3c ProtoOutputStream convenience methods.
- Add a set of write methods to ProtoOutputStream that figure out the type.
  The other methods are doing all the type checking anyway, so this won't be
  much slower, and it's way easier to use.  The expected java type casts
  that people would do anyway happen inside.
- Add writeObject and writeRepeatedObject methods that write a pre-encoded
  object.
- Add a constructor that takes an OutputStream, and a flush() method.  Right
  now, all the data gets flushed at the end, but given this API it would be
  possible to write smaller chunks at the object boundaries and do more
  sophisticated buffering.

Test: CTS
Change-Id: Ieb852092d3d65812c81139558151de9e3f467dc8
2016-12-07 13:24:54 -08:00
Tomasz Mikolajewski
6c686c4dd3 Merge "Fix crashing StrictJarFile due to doubled closing." am: 68ea36243d am: 15cd392108 am: 3199d58939
am: 37541865f3

Change-Id: Iae24b046178c00e4e8cda7ee1dc25c993ef38c0b
2016-12-07 02:09:12 +00:00
Tomasz Mikolajewski
3199d58939 Merge "Fix crashing StrictJarFile due to doubled closing." am: 68ea36243d
am: 15cd392108

Change-Id: I63034776a185682f11ea736b0d37a4b3be31bc47
2016-12-07 01:54:13 +00:00
Treehugger Robot
68ea36243d Merge "Fix crashing StrictJarFile due to doubled closing." 2016-12-07 01:40:48 +00:00
Tomasz Mikolajewski
b061fc2bb5 Fix crashing StrictJarFile due to doubled closing.
If the constuctor throws, then the handles would be closed without
setting "closed" to true. As a result, the finalizer would close
the handles again, which would cause a crash on the native side.

Test: Unit tests are no longer flaky.
Bug: 33301253
Change-Id: I527ba38d5d65ce844258d894441d4fe16bac6e23
2016-12-06 10:05:05 +09:00
Tobias Thierer
57723684f4 Merge "Migrate StrictJarVerifier and ShortcutPackageInfo to java.util.Base64" am: 1e498a96c1 am: 6e2d3fa82f am: 386ba42ec5
am: 589ff8395d

Change-Id: I0861533c48a0eaa1972c95eb796b53dd0b2f3b8e
2016-12-05 09:52:58 +00:00
Tobias Thierer
386ba42ec5 Merge "Migrate StrictJarVerifier and ShortcutPackageInfo to java.util.Base64" am: 1e498a96c1
am: 6e2d3fa82f

Change-Id: I925b0ca87bbd0f3be3f03865f70cafaaa1ef25ba
2016-12-05 09:39:55 +00:00
Tobias Thierer
6e2d3fa82f Merge "Migrate StrictJarVerifier and ShortcutPackageInfo to java.util.Base64"
am: 1e498a96c1

Change-Id: I28b8deadc9386b8772bd94870809213fdddad7e6
2016-12-05 09:35:10 +00:00
Tobias Thierer
9f00d71787 Migrate StrictJarVerifier and ShortcutPackageInfo to java.util.Base64
Previously, they weres using libcore.io.Base64, which is @deprecated.

The two implementations' encoders produce the exact same result.

The two implementations' decoders' behavior differs for malformed
input:
 - In case of error, libcore.io.Base64.decode() returns null while
   java.util.Base64.getDecoder().decode() throws.
 - java.util.Base64 tends to be stricter about rejecting malformed
   input; specifically, it allows neither whitespace nor unexpected
   '=' characters (should only occur in the padding) whereas
   libcore.io.Base64.decode() leniently allows them throughout the
   input.
 - if the input terminates prematurely, libcore.io.Base64 tends to
   return fewer bytes (stops at a four byte boundary).

The behavior differences for malformed Base64 encoded data should
not affect ShortcutPackageInfo because it should only need to deal
with XML attribute values written by itself, which are well-formed.
Note that this CL does not lead to any known changes of the encoding
step, so values written by earlier versions should not cause problems
when read by later versions of ShortcutPackageInfo.

StrictJarVerifier may now reject or behave differently for .jar /
.zip files with malformed attribute values but this seems okay since,
per its name, it is meant to be strict. For example, after this CL,
StrictJarVerifier will no longer accept algorithm + "-Digest"
attribute values with extra whitespace or padding characters as valid.

Test: Confirmed that the two implementations' encoders produce the
      same result by running the following code just before this CL:
      assertEquals(
          libcore.io.Base64.encode(allBytes()),
          Base64.getEncoder().encodeToString(allBytes()));
      where allBytes() returns a byte[] with values (byte) 0 .. (byte) 255
Test: Test that phone still boots after flashing code that includes
      this CL.
Test: CtsLibcoreTestCases

Bug: 31292683

Change-Id: I775d32f329f693514a8f14d87e1ef0d7a757e6c3
2016-12-02 16:20:53 +00:00
Romain Guy
68bd5fdd1a Introduce android.graphics.ColorSpace
This class can be used to define color spaces. A color space has a color model
and a profile connection space (CIE XYZ D50). This implementation can be used
to query various properties of RGB color spaces or perform conversions between
various color spaces (RGB, XYZ and Lab).

Refer to the documentation for more details.

Test: cts-tradefed run singleCommand cts-dev --module CtsGraphicsTestCases --test android.graphics.cts.ColorSpaceTest
Bug: 32984164
Change-Id: Ie2117c1212c1375a7d403d3c1afaf73d7c2e0b47
2016-11-23 18:10:04 -08:00
Fyodor Kupolov
5237f47b82 Use push/peek/pop for operations on stack
Test: manual - device boots, metrics are logged to system/event log
Bug: 32780225
Change-Id: If7e51c50767d8fd9d5da44f61dbc5bfe56196894
2016-11-22 11:02:07 -08:00
Fyodor Kupolov
3235e0c2ee Additional boot metrics
Extracted duration measurement functionality into BootTimingTraceLog.
It is now shared between system_server and zygote.

Log the following metrics to tron:
- boot_zygote_init - Time in milliseconds to boot into Zygote init stage.
- boot_android_init - Time in milliseconds to boot into Android init stage.

Test: manual - device boots, metrics are logged to system/event log
Bug: 32780225
Bug: 31115337
Change-Id: I600ac7fc83d35fa226ac92c37cc4b19192b25f59
2016-11-21 17:17:34 -08:00
Romain Guy
5d7e2352e7 Add @HalfFloat annotation for fp16 data types stored in shorts
This CL has a companion CL to add the @HalfFloat annotation to the
support library.

Test: cts-tradefed run singleCommand cts-dev --module CtsUtilTestCases --test android.util.cts.HalfTest
Bug: 29940137
Change-Id: I4e1dc456687c1c026437150e9cc94a54f3264d4e
2016-11-14 09:27:26 -08:00
Romain Guy
12ae9a0736 Improve support for half floats and expose as public API
Half floats (often called fp16) are commonly used to store floating
point data efficiently without having to use lossy compression schemes.

Half floats are commonly used in the following cases:
- Wide gamut colors
- Meshes (OpenGL and Vulkan)
- HDR images/textures
- Lookup tables as textures (OpenGL and Vulkan), particularly
  in physically-based renderers
- Maching learning/compute

OpenGL and Renderscript both provide Java language APIs that accept
half floats but the platform offers no support to create fp16 values
from fp32 data. The Half class is an IEEE 754 compliant implementation
of half floats that can be used to feed OpenGL and Renderscript properly
encoded values. A comprehensive series of test is also added to CTS.

Test: cts-tradefed run singleCommand cts-dev --module CtsUtilTestCases --test android.util.cts.HalfTest
Bug: 29940137

Change-Id: I908bde7b3c6f65f7a24e0ab5652be4d16cc0358d
2016-11-08 17:58:54 -08:00
Tomasz Mikolajewski
de915e3ade Merge "Add support for opening JAR/ZIP files via FD." am: 7f64c195f7
am: 4c65d49a92

Change-Id: I534e70f5218e0f9be73d919a4c9dd509211729f8
2016-11-02 00:39:45 +00:00
Tomasz Mikolajewski
4c65d49a92 Merge "Add support for opening JAR/ZIP files via FD."
am: 7f64c195f7

Change-Id: I88af6f42ccd5e6edafa57fd0f147f676da8aa096
2016-11-02 00:34:47 +00:00
Tomasz Mikolajewski
6c3df1543c Add support for opening JAR/ZIP files via FD.
Test: Upcoming change in DocumentsUI uses this feature.
Bug: 31783726
Change-Id: Ia74e9bdb66722dfb2855380375a99cc94d288b2e
(cherry picked from commit 5a5c44a2e3)
2016-11-01 09:25:59 +09:00
Tomasz Mikolajewski
7182514d8b Merge "Add support for opening JAR/ZIP files via FD." 2016-10-31 05:55:54 +00:00
Tomasz Mikolajewski
5a5c44a2e3 Add support for opening JAR/ZIP files via FD.
Test: Upcoming change in DocumentsUI uses this feature.
Bug: 31783726
Change-Id: Ia74e9bdb66722dfb2855380375a99cc94d288b2e
2016-10-28 11:23:20 +09:00
Romain Guy
de0a3a893f Add a half-precision floating point type
Denormals are fully supported.

This will be useful to store wide-gamut colors in a compact form
(a full RGBA color can be stored in a long using half floats for
each component).

Test: cts-tradefed run singleCommand cts-dev --module CtsUtilTestCases --test android.util.cts.HalfTest
Change-Id: I7e071edd2b66fdf6b375ce0e3e1a72ec3fb635b5
2016-10-22 02:26:32 -07:00
Adam Lesinski
5dc0782254 Update DisplayMetrics even on default display am: 4309721843 am: dab7950d80
am: d7ec1ea697

Change-Id: Iad9907c77fb1b7b81073150807d6f18a75a24d6e
2016-10-14 22:49:40 +00:00
Adam Lesinski
d7ec1ea697 Update DisplayMetrics even on default display am: 4309721843
am: dab7950d80

Change-Id: I8bb2c9c303380abd3e1a54af68b8a8f7da3225f7
2016-10-14 22:41:35 +00:00
Adam Lesinski
4309721843 Update DisplayMetrics even on default display
Fix a bug where the DisplayMetrics wouldn't be updated for a Resources
object on the default display. Since multi-window, we want to update
all Resources.

This didn't always manifest itself due to recreation of assets, which
would force an update of DisplayMetrics. Re-use of an AssetManager from
the cache would expose the bug.

Bug:32133693
Bug:31998629
Test: cts-tradefed run cts --module CtsServicesHostTestCases
Change-Id: Ic51ab82710517b87eb995ccf982085dba876ad58
2016-10-14 18:16:18 +00:00
Joe Onorato
6c9547d8e1 Add android.util.proto package as an @TestApi.
The classes there add a way for the platform to write out
protocol buffers that doesn't require lots of small objects,
generate code, and extra copying.

Includes the plugin for protoc to generate the constants.

Test: proto cts tests

Change-Id: I6385c198cecda9ac6fa533151609e3ace341af01
2016-10-12 16:37:18 -07:00
Hugo Benichi
de310dba78 Better LocalLog
This patch fixes the following issues in LocalLog:
  - reverseDump() uses a descending iterator with linear complexity
    instead of a quadratic loop using get(index) on a linked list.
  - reverseDump() is added to ReadOnlyLocalLog.
  - synchronized section in log() is restricted to mutation of internal
    list.
  - formatting of the log message does not create an internal
    StringBuilder.
  - the instance variable mNow is removed: it was only used inside log()
    as a local variable.
  - remaining instance variables are qualified with final.
  - the linked list is replaced by a fixed capacity array-backed queue.

Test: added unit tests
Change-Id: I1a54f0ad26dd35448d3297ea24df1fd626d20ef3
2016-10-11 09:54:19 +09:00
John Reck
32995223a8 Convert utils fastjni -> @FastNative
Test: builds & boots, refactor no behavior change
Change-Id: Ieb569a70fd05b88a8d2bd7b285099c1fc1888a75
2016-10-10 07:59:25 -07:00
Svet Ganov
5d09c998a0 Backup account access grants
Sync adapters without an account access cannot run until the
user approves the account access (for the case the account
access is not allowed by other policy such as being singed
with the same cert as the authenticator). If the sync adapter
does not have permission to access the account we ask the
user to grant access and take a note. This CL adds backup
for the explicit user grants.

bug:31162498

Change-Id: I31e3f3d010475352c7c54255ac2d3a2fed4d0c72
2016-09-21 14:01:02 +00:00
Svet Ganov
171b77b91e [DO NOT MERGE] Backup account access grants am: 72ed12c55f
am: 0dc4ff0753

Change-Id: Ic6ad395f958b2e09d66467f41bd40e84c34851b9
2016-09-10 00:28:50 +00:00
Svet Ganov
72ed12c55f [DO NOT MERGE] Backup account access grants
Sync adapters without an account access cannot run until the
user approves the account access (for the case the account
access is not allowed by other policy such as being singed
with the same cert as the authenticator). If the sync adapter
does not have permission to access the account we ask the
user to grant access and take a note. This CL adds backup
for the explicit user grants.

bug:31162498

Change-Id: I31e3f3d010475352c7c54255ac2d3a2fed4d0c72
2016-09-09 10:16:57 -07:00
Svetoslav Ganov
388d08b6e3 resolve merge conflicts of a2c1196 to master
Change-Id: I221f03e2cda9e677199698d492d16788c25c9e96
2016-08-31 18:02:57 -07:00
Svetoslav Ganov
a2c1196dc2 Properly close fd backing a MemoryIntArray am: fe2462f3a6
am: b7be22cdaf

Change-Id: Ie598d2310fff4d72f618ecfa9e2efae78c595a10
2016-08-31 01:04:00 +00:00
Svetoslav Ganov
b7be22cdaf Properly close fd backing a MemoryIntArray
am: fe2462f3a6

Change-Id: Iaf35af209d210ba0aa6239bdeb0c81a079d25543
2016-08-31 00:56:32 +00:00
TreeHugger Robot
43896cbc02 Merge "Properly close fd backing a MemoryIntArray" into nyc-mr1-dev 2016-08-31 00:49:42 +00:00
Svetoslav Ganov
fe2462f3a6 Properly close fd backing a MemoryIntArray
Use ParcelFileDescriptor only as an IPC transport
to make sure MemoryIntArray manges its backing fd.

Bug:30310689

Change-Id: Ib3cc13ef4ae2a744e5f7a96099570e0431847bce
2016-08-30 02:26:19 +00:00
TreeHugger Robot
65bbb6fb09 Merge "resolve merge conflicts of 5827257 to master" 2016-08-29 21:46:44 +00:00
Colin Cross
649bfd3dc3 resolve merge conflicts of 5827257 to master
Change-Id: I0077b6991584fc33dcb1ca1aadb634ce930fef3a
2016-08-29 12:50:47 -07:00
Svet Ganov
9d723d3d57 Polish MemoryIntArray
1. Add close guard
2. Adopt instead of clone the ahsmem fd to fix a dangling fd
3. Clear only the return flag when writing fd to parcel
4. Immediately destroy remote MemoryIntArray if stale
5. Throw Java exception if someone closed the fd under us

Change-Id: I85533fec336c40e3380e10d5448e18c9616ec341
2016-08-29 10:51:08 -07:00
Dianne Hackborn
5827257521 Try to mitigate issue #31016187: system_server crash in ArraySet. am: 92aa4b2ba3
am: d43d248848

Change-Id: Ie499c3b715325c23fc5b85442f742453df14e471
2016-08-25 17:30:33 +00:00
Dianne Hackborn
92aa4b2ba3 Try to mitigate issue #31016187: system_server crash in ArraySet.
Instead of crashing, log a wtf and recover.  This is not a problem
in ArraySet, but caused by someone else using an ArraySet without
protecting access to it.  So whoever is calling at this point is
not the cause, and it isn't worthwhile to let them crash.

Change-Id: Iaefa4315b620c9fe24b31507e4aa47a8525c8540
2016-08-25 10:12:02 -07:00
Aurimas Liutikas
f2a45b269d Clean up style issues in ArraySet.
Clean up style issues in preparation to copying ArraySet
implementation to support library.

Fixed:
- Missing spaces around operators, casting
- Added curly braces around if statements that span multiple lines
- Renamed static variables to follow sFoo instead of mFoo
- Moved = to the previous line

Bug: 19109652
Change-Id: Id9a985723b158f51811b3cd796613d0e26fd7e61
2016-08-19 16:36:19 -07:00
Philip P. Moltmann
a01bda837b Allow calls to TimedRemoteCaller in parallel.
Before the second thread canceled the call from the first thread as the
awaitedSequenceId was set to the second thread.

Change-Id: I7de709dee260a009761e0a3e73f3fe0695d2da2a
2016-08-12 14:19:18 -07:00
Neil Fuller
35f46b890d Merge "Add a finalize() method to StrictJarFile" am: d0c0c8dcab am: 2ffb7ebae2 am: f952f52013
am: ce78eb6b45

Change-Id: Ic622fe2adabfed18a6481f8d32685e37f3fe24b0
2016-08-09 11:07:17 +00:00
Neil Fuller
ce78eb6b45 Merge "Add a finalize() method to StrictJarFile" am: d0c0c8dcab am: 2ffb7ebae2
am: f952f52013

Change-Id: I0a621a83670f326d218fe3f77bc5fe9bbad6ea6c
2016-08-09 11:02:07 +00:00
Neil Fuller
f952f52013 Merge "Add a finalize() method to StrictJarFile" am: d0c0c8dcab
am: 2ffb7ebae2

Change-Id: Ie947e8447ecd8e9a61b6d1115174180e41d74311
2016-08-09 10:54:32 +00:00
Neil Fuller
2ffb7ebae2 Merge "Add a finalize() method to StrictJarFile"
am: d0c0c8dcab

Change-Id: Iccab49c98b105aff6105e21274fbc099d10ecb55
2016-08-09 10:49:58 +00:00
Neil Fuller
b69f61472a Add a finalize() method to StrictJarFile
Bug: 25896372
Test: Booted device, installed CTS apps
Test: run cts --class android.util.cts.StrictJarFileTest
Change-Id: I35e238dadd48d2c4ca53ac37a4c5aacdd471a93a
2016-07-29 14:26:35 +01:00
Tejas Khorana
0a7b51a28f Merge "indexOfValue now uses .equals (cont.)" 2016-07-18 20:02:11 +00:00