Commit Graph

9435 Commits

Author SHA1 Message Date
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
Steven Moreland
ad22cbc2a1 Merge "Parcel: markForBinder" am: 0f2729a96e
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1816536

Change-Id: I50a013497eb5368d05fe05055a506f8de00f3890
2021-09-08 00:41:59 +00:00
Steven Moreland
0f2729a96e Merge "Parcel: markForBinder" 2021-09-08 00:29:29 +00:00
Hall Liu
1c8976b843 Expose requestModemActivityInfo
Expose requestModemActivityInfo in TelephonyManager using the Executor +
Consumer pattern, and modify clients to use it.

Test: atest TelephonyManagerTest#testRequestModemActivityInfo
Fixes: 170427831
Change-Id: I7e8134c8058017b888c324a9f85d473fc3cdd8f5
Merged-In: I7e8134c8058017b888c324a9f85d473fc3cdd8f5
2021-09-07 15:30:36 -07:00
Hall Liu
f4fe3ac665 Update and expose ModemActivityInfo
Update ModemActivityInfo to present a nicer API surface and expose it as
a SystemApi. Also change clients in BatteryStats to match the new
surface.

This is part 1. Part 2 will modify the methods in TelephonyManager to
use a more up-to-standards threading model.

Bug: 170427831
Test: atest ModemActivityInfoTest
Change-Id: I762ed949342861c75d94eafce88335e7bd8c9139
Merged-In: I762ed949342861c75d94eafce88335e7bd8c9139
2021-09-07 11:40:55 -07:00
Bernardo Rufino
82a0a22b30 Merge "Don't throw for LazyValue in Parcel.hasFileDescriptors()" am: 6ae29f70d7
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1818898

Change-Id: Ie6cb56a29e544e50803144a4ac533c29f35d6c06
2021-09-06 10:31:57 +00:00
Bernardo Rufino
c087f62482 Don't throw for LazyValue in Parcel.hasFileDescriptors()
In aosp/1819733 we extracted Parcel.hasFileDescriptor() for types
produced by Parcel.writeValue() and consumed by Parcel.readValue() out
of Bundle into Parcel. It's supposed to handle LazyValue too.

However, we put a check to verify that it was a type supported by
readValue()/writeValue() by retrieving the VAL_XXX type of the value via
Parcel.getValueType(), however, that method throws for LazyValue since
we don't actually write that special type on the wire. However, we still
want Parcel.hasFileDescriptor() to support it, so moving the check into
a last 'else' statement, making sure we don't throw in case the value is
a LazyValue.

Bug: 195622897
Bug: 198433827
Test: atest CtsNetTestCases android.net.cts.CaptivePortalTest#testCaptivePortalIsNotDefaultNetwork
Change-Id: I1e6ec122557c12e74db6890e1631fec3cefe31f6
2021-09-06 08:51:21 +01:00
Steven Moreland
580ab91411 Parcel: markForBinder
Allow Parcel data to be dependent on the binder in question. This
exposes the API in Java which is previously only available in native.

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: I134b6e23da83699195a8f075b9f50b6409ecff86
2021-09-03 11:50:58 -07:00
Bernardo Rufino
872f7a88e5 Merge "Lazy bundle" am: 93b4b55ee7
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1787847

Change-Id: I36812425c05b2849d15082f5c73c52a81ad1b423
2021-08-31 10:08:39 +00:00
Bernardo Rufino
93b4b55ee7 Merge "Lazy bundle" 2021-08-31 09:18:47 +00:00
Bernardo Rufino
9ca6a5e21a Lazy bundle
Implement lazy deserialization for custom types in bundle:
* Parcelable (VAL_PARCELABLE)
* Serializable (VAL_SERIALIZABLE)
* Parcelable array (VAL_PARCELABLEARRAY)
* Lists (VAL_LIST)
* Sparse array (VAL_SPARSEARRAY)
* Bundle (VAL_BUNDLE)

This enhances security, makes bundles more robust to deserialization
errors and avoid deserializing unneeded objects in some cases*, for more
details check go/lazy-bundle.

To do that, we prefix those types with their length when writing them on
the wire. Map serialization and deserialization now happens inside
Bundle (instead of calling Parcel's readArrayMapInternal() /
writeArrayMapInternal()) and we use an intermediary object - LazyValue -
that holds information about the position and length of the value we
will deserialize when queried.

So, there are basically 3 states:

1. We received the bundle but haven't queried anything about it (not
   even isEmpty()): in this case the original parcel is held inside and
   we haven't attempted any deserialization (except for the metadata at
   the beginning such as the magic, etc)

2. We queried something on it (eg. isEmpty()): Now we deserialize the
   bundle skipping the custom values above (we're able to do this now
   with the length written on the wire) and instead placing LazyValue
   objects for them in the map.

3. We query one of the lazy values: Now, we deserialize the object
   represented by LazyValue and replace it on the map.

Since after (2) LazyValue objects are the only ones holding references
to the original Parcel, when all LazyValues are deserialized, the
original Parcel is available for GC.

Inside bundle now we differentiate between unparcel(itemwise = true) and
unparcel(itemwise = false) where the first also deserializes each item
(such that there are no LazyValues in the map). This is because some
operations such as kindofEquals() need all items deserialized.

I had to break a few methods in parcel into multiple methods in parcel
to be able to control the format in bundle. They are all @hide.

* In quick local experiments, counting the bytes that didn't need to be
deserialized after the change. Roughly 10% of bytes from custom-type
items in Bundle are not deserialized in the testing scenario (if I
haven't messed up the stats :). That's on a sdk_gphone_x86_64_arm64 a
few minutes after boot. Check
https://screenshot.googleplex.com/53uXrrqDMYahzg3, stats collection is
on ag/15403076.

Test: atest -d android.os.cts.ParcelTest android.os.cts.BundleTest android.os.BundleTest android.os.ParcelTest
Test: Boot device
Bug: 195622897
Change-Id: Icfe8880cad00c3cd2afcbe4b92400ad4579e680e
2021-08-27 14:53:24 +01:00
Treehugger Robot
4cef59a768 Merge "ServiceManager APIs for Wi-Fi mainline module" am: 0ce930a02e
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1768620

Change-Id: I2591edfe683ccab7fd482c342dc88630a9561bb4
2021-08-23 19:49:51 +00:00
Steven Moreland
ce81994f5f ServiceManager APIs for Wi-Fi mainline module
ServiceManager.waitForDeclaredService and .isDeclared needed for Wi-Fi mainline module.

Test: boot
Change-Id: I9e82dd1a6663396f1c79bc3f27c36711b0b6f3eb
2021-08-20 22:21:35 +00:00
Treehugger Robot
b2cb2c7994 Merge "Add SharedMemory.fromFileDescriptor" am: d079236881
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1775625

Change-Id: I5464155029ddbc1e8391ae1717bbc91cb48522a3
2021-08-20 05:08:13 +00:00
Keun young Park
39c4f40746 Add SharedMemory.fromFileDescriptor
- Rename existing SharedMemory.create and make it public
- Passed file is now detached after creating shared memory and is
  not usable any more.

Bug: 188780895
CTS-Coverage-Bug: 197226773
Test: atest com.android.car.internal.test.LargeParcelableJavaStableAIDLTest
      (runs only in auto. will add matching CTS tests for non-auto devices)

(This combines two CL in internal tree, so Change-Id and Merged-In id are
different)
Change-Id: I8a634062d10ff0c114f3add1d2a5e8056f17b788
Merged-In: I11381e78580b97982b25a52aa06f2192def7353f
2021-08-20 01:18:11 +00:00
Steven Moreland
df10c51e95 Merge "ServiceManager: waitForService uses allowBlocking" am: b801a513d1 am: 726c374fa3
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1793027

Change-Id: I79e5443b356906fcb0787f8c286af7bb520326a1
2021-08-11 17:39:13 +00:00
Steven Moreland
726c374fa3 Merge "ServiceManager: waitForService uses allowBlocking" am: b801a513d1
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1793027

Change-Id: I18fff5e8d3e5c7e308b218ab95450f9a10593d38
2021-08-11 17:23:15 +00:00
Steven Moreland
d247e417a2 ServiceManager: waitForService uses allowBlocking
For parity with getService and checkService.

Bug: 194806512
Test: boot
Change-Id: Iecc3f1c6d6ae9bee94252281b416d62f3bf30afd
2021-08-11 17:16:32 +00:00
Brian Carlstrom
988b01f450 Merge "Remove spammy convertToModernFd log" into sc-dev am: eac1d5a41c
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15472605

Change-Id: I3d105222d3211943c4f0dd7d948d3989c3c7d866
2021-08-08 20:59:14 +00:00