Revert "Revert "Migrate unsafe parcel APIs in framework-minus-apex""

This reverts commit 7fe4f60b74.

Reintroducing ag/16366278 since it seems unrelated to b/214053959 (more details on b/214053959#comment55).

Original commit message:

Migrate unsafe parcel APIs in framework-minus-apex

Migrate the following unsafe parcel APIs in framework-minus-apex:
* Parcel.readSerializable()
* Parcel.readArrayList()
* Parcel.readList()
* Parcel.readParcelable()
* Parcel.readParcelableList()
* Parcel.readSparseArray()

This CL was generated by applying lint fixes that infer the expected
type from the caller code and provide that as the type parameter
(ag/16365240).

A few observations:
* In some classes we couldn't migrate because the class also belonged to
another build module whose min SDK wasn't current (as is the case for
framework-minus-apex), hence I suppressed the lint check
(since I'll eventually submit the lint check to the tree).
* In some cases, I needed to do the cast in
https://stackoverflow.com/a/1080525/5765705 to make the compiler happy
since there isn't another way of providing a class of type
Class<MyClassWithGenerics<T>>.
* In the readSerializable() case, the new API also requires the class
loader, that was inferred to by InferredClass.class.getClassLoader().
* Note that automatic formatting and import rely on running hooked up
to the IDE, which wasn't the case here.

Bug: 195622897
Change-Id: I272432e6e082a973f7a50492ec35d79c2b577c93
Test: TH passes
This commit is contained in:
Bernardo Rufino
2022-01-14 17:35:36 +00:00
parent f765d93862
commit 2ace102c5e
5 changed files with 10 additions and 10 deletions

View File

@@ -75,7 +75,7 @@ public final class DataUsageRequest implements Parcelable {
@Override @Override
public DataUsageRequest createFromParcel(Parcel in) { public DataUsageRequest createFromParcel(Parcel in) {
int requestId = in.readInt(); int requestId = in.readInt();
NetworkTemplate template = in.readParcelable(null); NetworkTemplate template = in.readParcelable(null, android.net.NetworkTemplate.class);
long thresholdInBytes = in.readLong(); long thresholdInBytes = in.readLong();
DataUsageRequest result = new DataUsageRequest(requestId, template, DataUsageRequest result = new DataUsageRequest(requestId, template,
thresholdInBytes); thresholdInBytes);

View File

@@ -267,14 +267,14 @@ public final class IpSecConfig implements Parcelable {
mMode = in.readInt(); mMode = in.readInt();
mSourceAddress = in.readString(); mSourceAddress = in.readString();
mDestinationAddress = in.readString(); mDestinationAddress = in.readString();
mNetwork = (Network) in.readParcelable(Network.class.getClassLoader()); mNetwork = (Network) in.readParcelable(Network.class.getClassLoader(), android.net.Network.class);
mSpiResourceId = in.readInt(); mSpiResourceId = in.readInt();
mEncryption = mEncryption =
(IpSecAlgorithm) in.readParcelable(IpSecAlgorithm.class.getClassLoader()); (IpSecAlgorithm) in.readParcelable(IpSecAlgorithm.class.getClassLoader(), android.net.IpSecAlgorithm.class);
mAuthentication = mAuthentication =
(IpSecAlgorithm) in.readParcelable(IpSecAlgorithm.class.getClassLoader()); (IpSecAlgorithm) in.readParcelable(IpSecAlgorithm.class.getClassLoader(), android.net.IpSecAlgorithm.class);
mAuthenticatedEncryption = mAuthenticatedEncryption =
(IpSecAlgorithm) in.readParcelable(IpSecAlgorithm.class.getClassLoader()); (IpSecAlgorithm) in.readParcelable(IpSecAlgorithm.class.getClassLoader(), android.net.IpSecAlgorithm.class);
mEncapType = in.readInt(); mEncapType = in.readInt();
mEncapSocketResourceId = in.readInt(); mEncapSocketResourceId = in.readInt();
mEncapRemotePort = in.readInt(); mEncapRemotePort = in.readInt();

View File

@@ -81,7 +81,7 @@ public final class IpSecUdpEncapResponse implements Parcelable {
status = in.readInt(); status = in.readInt();
resourceId = in.readInt(); resourceId = in.readInt();
port = in.readInt(); port = in.readInt();
fileDescriptor = in.readParcelable(ParcelFileDescriptor.class.getClassLoader()); fileDescriptor = in.readParcelable(ParcelFileDescriptor.class.getClassLoader(), android.os.ParcelFileDescriptor.class);
} }
@android.annotation.NonNull @android.annotation.NonNull

View File

@@ -73,9 +73,9 @@ public final class NetworkStateSnapshot implements Parcelable {
/** @hide */ /** @hide */
public NetworkStateSnapshot(@NonNull Parcel in) { public NetworkStateSnapshot(@NonNull Parcel in) {
mNetwork = in.readParcelable(null); mNetwork = in.readParcelable(null, android.net.Network.class);
mNetworkCapabilities = in.readParcelable(null); mNetworkCapabilities = in.readParcelable(null, android.net.NetworkCapabilities.class);
mLinkProperties = in.readParcelable(null); mLinkProperties = in.readParcelable(null, android.net.LinkProperties.class);
mSubscriberId = in.readString(); mSubscriberId = in.readString();
mLegacyType = in.readInt(); mLegacyType = in.readInt();
} }

View File

@@ -60,7 +60,7 @@ public final class UnderlyingNetworkInfo implements Parcelable {
mOwnerUid = in.readInt(); mOwnerUid = in.readInt();
mIface = in.readString(); mIface = in.readString();
List<String> underlyingIfaces = new ArrayList<>(); List<String> underlyingIfaces = new ArrayList<>();
in.readList(underlyingIfaces, null /*classLoader*/); in.readList(underlyingIfaces, null /*classLoader*/, java.lang.String.class);
mUnderlyingIfaces = Collections.unmodifiableList(underlyingIfaces); mUnderlyingIfaces = Collections.unmodifiableList(underlyingIfaces);
} }