Commit Graph

9453 Commits

Author SHA1 Message Date
Steven Moreland
b146c8bedb Merge "getBlobAshmemSize -> getOpenAshmemSize" 2021-10-14 17:43:16 +00:00
Hao Ke
d6f306117a Merge "Add “@throws BadParcelableException” to the JavaDoc of new API methods that throw the exception." 2021-10-14 17:30:43 +00:00
Hao Ke
f98489f1c0 Add “@throws BadParcelableException” to the JavaDoc of new API methods that throw the exception.
Test: atest -d android.os.cts.ParcelTest
Bug: b/203004511
Change-Id: I24bf7314e63015d46ab478ec8c44ecf22857bac2
2021-10-14 15:31:37 +00:00
Steven Moreland
4760ca91de getBlobAshmemSize -> getOpenAshmemSize
This API returns the total size of all ashmem memory that is in FDs that
is owned by a Parcel object. It was renamed a while ago, but the name
was never updated in Java.

Bug: 202029388
Test: atest android.app.NotificationTest
Change-Id: Icc428063083110952cf3951721d69cbb919429b1
2021-10-13 11:01:35 -07:00
Bernardo Rufino
ef5365a7f6 Merge "Add range-based Parcel.hasFileDescriptors(offset, length)" 2021-10-13 15:34:32 +00:00
Michael Wright
313839a2d9 Update haptics OWNERS
Change-Id: I265d27cdb721616bf56c3b34c9d239b3e962e98c
2021-10-12 14:29:03 +00:00
Bernardo Rufino
172c97db77 Add range-based Parcel.hasFileDescriptors(offset, length)
To be used by lazy values in bundle. I ended up opening up as public API
for apps to use it too because I saw no reason not to, can change if
folks prefer it to be @hide though.

Test: atest -d android.os.cts.ParcelTest android.os.cts.BundleTest android.os.BundleTest android.os.ParcelTest
Bug: 195622897
Change-Id: I7bf580f94313669fe67998b32b2723544c594cde
2021-10-08 15:11:32 +01:00
Xin Li
c03b0fa033 Merge "Merge Android 12" 2021-10-07 23:50:15 +00:00
Bernardo Rufino
40e22dc991 Improve Bundle/PersistableBundle docs
around equals(), hashCode(), toString()

Test: TH passes
Bug: 122589814
Bug: 62611412
Bug: 122589479
Change-Id: Ia644e437f9b5642228c2a7138b0518f73ef2996c
2021-10-06 15:25:33 +00:00
Treehugger Robot
3aaf984908 Merge "Avoid full unparcelling where possible in Bundle" am: 3ad4ecc296
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1842226

Change-Id: I0aef93d99d83f20b22753e8e1d41cfb5c4b5cdce
2021-10-06 12:25:47 +00:00
Treehugger Robot
3ad4ecc296 Merge "Avoid full unparcelling where possible in Bundle" 2021-10-06 12:06:59 +00:00
Bernardo Rufino
3f3c3a02c2 Merge "Change defusing for lazy bundles" am: fdd1771a4a
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1842142

Change-Id: Ia156038712d6a25acfea8aaa6ac1d257afa95345
2021-10-06 08:57:27 +00:00
Bernardo Rufino
fdd1771a4a Merge "Change defusing for lazy bundles" 2021-10-06 08:43:17 +00:00
Bernardo Rufino
9e26212dac Avoid full unparcelling where possible in Bundle
and put a warning where it's not possible. This is to make sure we know
when to touch bundles provided by apps.

In this CL:
* deepCopy() now doesn't deserialize lazy objects before copying. It
  doesn't copy them either, it merely passes them into the new map as
  the same reference. This works because we implemented fine-grained
  locking into each lazy value, so concurrent access won't be a problem.
  Furthermore, LazyValue caches the deserialized object, so we'd still
  honor the contract of deepCopy() that "Other types of objects (such
  as Parcelable or Serializable) are referenced as-is and not copied in
  any way". I had to perform one extra check in the synchronized block
  in LazyValue to guarantee this (double-checked locking), I explain
  that in the comments.
* Removed filterValues() and codepaths that used it. This was created
  with the purpose of removing items whose classes weren't available to
  the system to prevent crashes coming from full deserialization. This
  is not a concern anymore with lazy bundle, hence we can remove the
  codepaths altogether (see email for more details).
* Put warnings in javadoc of getMap() and PeristableBundle().

Test: Boots
Test: atest -d android.os.cts.ParcelTest android.os.cts.BundleTest android.os.BundleTest android.os.ParcelTest
Bug: 195622897
Change-Id: I14bb6a7874814f42cbcc6b5fd372c42752aa74c8
2021-10-05 13:39:36 +01:00
Bernardo Rufino
0c5074ede7 Change defusing for lazy bundles
With lazy bundle, exceptions thrown by deserialization of custom items
moved from being thrown in initializeFromParcelLocked() (when the bundle
is first touched) to being thrown in getValueAt() (whenever the item is
retrieved), which means they were escaping the defuse logic that caught
those exceptions. So, now also catching these exceptions in
getValueAt(), however, here we can be much less drastic, instead of
erasing the bundle, we can simply remove the bad element.

This also means we don't need to log wtf in initializeFromParcelLocked()
if sShouldDefuse = true but the bundle is not marked as defusable, since
touching the bundle doesn't carry the same consequences as before
go/lazy-bundle. So, I moved that log to unparcel(itemwise = true), ie.
whenever the entire bundle is deserialized on purpose.

Now, 2 types of defusing can happen:
1. If the (custom) item we're retrieving caused the exception, we'll
   remove the item and return null.
2. If the exception was raised during partial deserialization, that is,
   during the read of the map and its basic types (while skipping custom
   types), the map will be left empty. I believe only manually written
   parcels would cause this type of exception and if an exception is
   raised here it will also be raised in the final destination too,
   afaict. Because of this, we can now touch app-provided bundles
   without fear of clobbering the data on its way to the final
   destination.

Following conversation on previous CL, narrowed exception raised in case
of unknown type to be BadParcelableException.

Test: atest -d android.os.cts.ParcelTest android.os.cts.BundleTest android.os.BundleTest android.os.ParcelTest
Bug: 195622897
Change-Id: I4746140f63482a9ea475aac25897a447737393e4
2021-10-05 11:40:13 +01:00
Steven Moreland
9a7bbf9367 Merge "Parcel: obtain(IBinder) as API" am: e869287a7b
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1817684

Change-Id: I2655c1c2b74b0501912fa4e90f5655db682b2932
2021-10-04 21:14:21 +00:00
Steven Moreland
e869287a7b Merge "Parcel: obtain(IBinder) as API" 2021-10-04 20:55:08 +00:00
Steven Moreland
c861533254 Parcel: obtain(IBinder) as API
There are two main usecases for this:
- provide an alternative route to implement features like markSensitive
  (which requires only 1 function call per class, rather than a
    function call and flag per transaction type)
- support RPC format transactions

Bug: 175814583
Test: atest android.os.ParcelTest, boot, manual
Change-Id: Ibaacc27a125a31e18d4b5889d05d12cc18d05624
2021-10-01 14:51:18 -07:00
Bernardo Rufino
e9ffc7f08f Merge "Correct Parcel value types" am: 861d2e12cb
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1838973

Change-Id: I0ad34ad29a54cf58ac37ec347a59b45a59959ea1
2021-10-01 09:58:17 +00:00
Bernardo Rufino
5539926c4a Correct Parcel value types
* Bundle supports types char, char[], short[], float[] which were
  falling back to serializable handling in Parcel because readValue()
  didn't have specific support for those types. Adding support in Parcel
  to avoid the need for length-prefixing and to improve performance.
  Curiously some of those had read/write methods already.
* Updated Bundle to just pull the types above from the map since those
  won't be lazy values anymore.
* We were missing a few custom type containers in our list of
  length-prefixed types and we were listing Bundle unnecessarily as
  length-prefixed since Bundle itself is already length-prefixed and
  copies the correspondent section of the parcel internally.

Test: atest -d android.os.cts.ParcelTest android.os.cts.BundleTest android.os.BundleTest android.os.ParcelTest
Bug: 195622897
Change-Id: I1e15d59d883311685ffa32ece1f5a00e01bf6aea
2021-10-01 09:07:49 +01:00
Hao Ke
e01e2ae588 Merge "Adding typed Parcel read/write APIs." am: d3199a6084
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1832336

Change-Id: I8a2341eef230f078c53b31a03478fa30e3774147
2021-09-30 21:31:36 +00:00
Hao Ke
d3199a6084 Merge "Adding typed Parcel read/write APIs." 2021-09-30 21:13:54 +00:00
Steven Moreland
73c85c59f7 Merge "Parcel: markForBinder -> obtain(IBinder)" am: fb7a6db2a2
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1840654

Change-Id: Ibde592b1d34c2e7143c961c7d2e2029d0fbfd82f
2021-09-30 18:16:37 +00:00
Steven Moreland
fb7a6db2a2 Merge "Parcel: markForBinder -> obtain(IBinder)" 2021-09-30 17:59:47 +00:00
Sam Gilbert
182a0a144e Merge "Fix writeToParcel parameter nullability" am: 55fb62a515
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1840533

Change-Id: Ieabc166af0086501cc638cffa7dc6f5960f67172
2021-09-30 17:24:46 +00:00
Sam Gilbert
55fb62a515 Merge "Fix writeToParcel parameter nullability" 2021-09-30 17:08:19 +00:00
Hao Ke
8a86e7d51e Adding typed Parcel read/write APIs.
Description:

Added replacements of `readList`, `readParcelable` and
`readParcelableCreator` APIs.

To avoid unexpected types of objects being unparcelled,
ideally clients would use the readTypedXXX() methods that
take the parcelable creator. However, this won’t be an option
for use cases involving deserializing children objects
inherited from non-final parcelable or serializable objects.
Currently out of ~4k parcelable classes, only ~1.5k
are marked as “final” in the platform. Hence it would be
necessary to introduce new replacements that take
an extra Class<T> parameter and before deserializing
we check that the class written on the wire is the
same or a descendant from the one provided as argument.

Doing so could enhance the security of Parcel deserialization,
More details can be found at go/safer-parcel.

Test: atest -d android.os.cts.ParcelTest
Bug: 195622897
Change-Id: Ie9a4cb4c3d6f1805b14df7b703aef43e2993d459
2021-09-30 16:31:16 +00:00
Bernardo Rufino
d60218eb45 Merge "Log.wtf in mismatch + tests" am: 1cdbc7cbd1
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1837194

Change-Id: I185410ce82ca057b6767d5ca0ff0368f046a1dff
2021-09-30 10:31:03 +00:00
Steven Moreland
8c15362858 Parcel: markForBinder -> obtain(IBinder)
So that the API more closely matches intended usage, as requested.

Bug: 175814583
Test: aidl_integration_test
Change-Id: I2fb5f2d5059d7f9cd9e034a4d0d2e7aa63692067
2021-09-29 16:17:45 -07:00
Sam Gilbert
e3e9e3f6d4 Fix writeToParcel parameter nullability
Test: Existing tests
Bug: 144855352
Change-Id: Id3e0de043eee77e1dadf3b4db5d6d4bddd9e8247
2021-09-29 13:54:34 -04:00
Bernardo Rufino
95ace87925 Log.wtf in mismatch + tests
Log mismatches as wtf to be able track those. Also added unit tests
around kindofEquals() and r/w mismatches.

Test: atest -d android.os.cts.ParcelTest android.os.cts.BundleTest android.os.BundleTest android.os.ParcelTest
Bug: 195622897
Change-Id: I361dd144b23975eedc8b19ed65457a1c5405936e
2021-09-29 13:51:43 +01:00
Treehugger Robot
6b6d1da5f3 Merge "VintfObject.getHalNamesAndVersions report AIDL version number." am: c39842abd9
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1832955

Change-Id: Ib31bb867e346fb693b7c2c1aeace30f8946eb469
2021-09-24 01:20:43 +00:00
Yifan Hong
8804125b5b Merge "Add owners for VINTF." am: ec854a738f
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1835453

Change-Id: I59ba7ecbdaf201d6ea66bdf003efe2510a3ee8ee
2021-09-24 01:19:55 +00:00
Yifan Hong
de452e49af VintfObject.getHalNamesAndVersions report AIDL version number.
Tests that rely on this API does not attempt
to parse it, but rather treat this as an opaque
string and upload them.

Test: pass
Bug: 200729012
Change-Id: I025e2602ab506ad009ce48d6329a230f12f1060c
2021-09-23 13:21:35 -07:00
Yifan Hong
4510a23652 Add owners for VINTF.
Test: pass
Change-Id: I24b73fd00bafd8a3c2fdfdecc1c00179a18b2e89
2021-09-23 13:21:35 -07:00
Bernardo Rufino
278a00a8d3 Merge "Synchronize in LazyValue.get()" am: 92b71e564f
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1829879

Change-Id: I75902d42568bc7e7f18033ab8f228ff2cbc94058
2021-09-23 17:04:39 +00:00
Bernardo Rufino
92b71e564f Merge "Synchronize in LazyValue.get()" 2021-09-23 16:48:49 +00:00
Devin Moore
5ae740f8eb Merge "ServiceManagerNative: add getConnectionInfo" am: e731e209d3
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1823886

Change-Id: Ib67c5cc25b23d8f75d96c845ffdc63d7a6e61ec9
2021-09-22 16:42:41 +00:00
Devin Moore
e731e209d3 Merge "ServiceManagerNative: add getConnectionInfo" 2021-09-22 16:25:48 +00:00
Bernardo Rufino
9293dca91c Synchronize in LazyValue.get()
When we use Bundle's copy constructor we perform a shallow copy of the
underlying map, so lazy values are the same across the original and the
clone. So, if we're accessing the same item backed by a lazy value in 2
different threads, each one accessing a different bundle (the original
and the clone), both would have to synchronize on a common lock.

Although Bundle is not thread-safe, we should keep the expectation that
the client only needs to properly synchronize access to one bundle, not
more. To achieve this, we synchronize on the original parcel held by
LazyValue in get(), this removes the need for the above.

Note that after we produce the lazy values and put them in the map, we
don't have a reference to mParcelledData anymore inside the Bundle, the
only objects holding a reference to that parcel are the lazy values.

Also fixed some stuff in LazyValue:
* Fixed condition inside LazyValue that used mObject == null as
  signal for "not deserialized" state since mObject can be null, so
  switched to mSource != null.
* Made mSource volatile and adjusted operations to always check it
  before, ensuring visibility of itself and mObject via happens-before.
  This works because after checking mSource, if that's null, mObject is
  guaranteed to be visible and valid, if it's not null, we can use it
  since we're in the serialized state and this works even if another
  thread deserializes in between as long as we hold on to a reference of
  mSource in a local because the parcel is still valid.
* Remove the recycling of mValueParcel, otherwise we'd need locking to
  ensure whatever was using it was still using a valid object. Decided
  to just remove recycling for now since the plan is to remove
  mValueParcel entirely when we add comparison and hasFileDescriptor()
  methods that operate on a range to Parcel.

Bug: 195622897
Test: atest -d android.os.cts.ParcelTest android.os.cts.BundleTest
      android.os.BundleTest android.os.ParcelTest
Test: More tests coming
Change-Id: I501c91f505950338b23e7837e55f89b2f63ff93a
2021-09-22 11:58:24 +01:00
Treehugger Robot
4f564346de Merge "New API for getting enabledcomponent" am: bca93eafe5
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1818892

Change-Id: I46736aedc7df2d8e6926414adb9b48748386393d
2021-09-14 18:34:16 +00:00
wescande
29dbede144 New API for getting enabledcomponent
Bluetooth can no longer call SystemConfig and need to use the manager.

Bug: 190440540
Bug: 199279027
Test: Manual
Tag: #refactor
Change-Id: I065ab407c83cd2edf2244e4170496b0979ac562c
2021-09-14 16:11:19 +00:00
Devin Moore
e7864e38d1 ServiceManagerNative: add getConnectionInfo
Check vintf manifest for connection info for a given service.

Test: build
Bug: 198207801

Change-Id: Ic9b4277de2bf13c429ba4921f1196b921b2a47de
2021-09-10 22:55:07 +00:00
Bernardo Rufino
075952fa51 Merge "Use appendFrom in LazyValue.writeToParcel()" am: 730b6cfbc1
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1821492

Change-Id: I62192f0e179540552fec8e124581c717c867f09e
2021-09-09 10:06:40 +00:00
Bernardo Rufino
730b6cfbc1 Merge "Use appendFrom in LazyValue.writeToParcel()" 2021-09-09 09:48:13 +00:00
Treehugger Robot
2582d481d3 Merge "ServiceManager: doc comment" am: 882bac800d
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1821336

Change-Id: If34eef18cf1586fe2fefdfe7e1e7666514c47108
2021-09-09 00:05:01 +00:00
Treehugger Robot
882bac800d Merge "ServiceManager: doc comment" 2021-09-08 23:44:36 +00:00
Steven Moreland
dc7cae65cf ServiceManager: doc comment
A couple words on this for ya!

Fixes: 197629711
Test: N/A
Change-Id: I4fbaacb6e123c042919c03f11a0403e041d23a56
2021-09-08 11:34:38 -07:00
Sarah Chin
e34b1b8735 Merge "Expose requestModemActivityInfo" 2021-09-08 16:12:28 +00:00
Bernardo Rufino
5e5d776906 Use appendFrom in LazyValue.writeToParcel()
Due to lazy bundle, we can now have bundles touching the original parcel
(used to create the bundle in the first place) during serialization.
This can lead to races within the same bundle or across bundles when
the same is copied.

Both these cases happen in notification manager when it's about to post
notification for its listeners. In summary, it notifies all the
listeners in oneway calls and the listeners make a call back to
system_server to retrieve the notification. These calls back can race
and lead to the bug observed in http://b/198355758#comment12.

In order to avoid that we use appendFrom(mSource, mPosition) in
LazyValue.writeToParcel() since that method doesn't change or use the
cursor of mSource. We only ever write to mSource before creating all the
LazyValues, so there can't be any r/w races.

Test: 1. Attach debugger to system server and put log breakpoints in
         racy lines in Parcel$LazyValue.writeToParcel
      2. atest -d CtsHostsideNetworkTests:com.android.cts.net.HostsideRestrictBackgroundNetworkTests#testDozeModeMetered_enabledButWhitelistedOnNotificationAction
      3. Observe no crashes
Test: 1. Attach debugger as in previous "Test:" line
      2. Create a notification with a parcelable extra, post it
      3. Observe no crashes
Bug: 195622897
Bug: 198355758
Test: atest -d android.os.cts.ParcelTest android.os.cts.BundleTest android.os.BundleTest android.os.ParcelTest
Change-Id: I02f890d22910c69e29e791b55d3655962a6dddfd
2021-09-08 09:19:58 +01:00