summaryrefslogtreecommitdiffstats
path: root/core/java/android/content
diff options
context:
space:
mode:
authorNeil Fuller <nfuller@google.com>2015-04-20 14:39:00 +0100
committerNeil Fuller <nfuller@google.com>2015-04-21 11:32:44 +0100
commit44e440cc7e834de7811f005998acb32716835b00 (patch)
tree1e4ca5bbbf42ec1a2e757ca608ee7b0698967a26 /core/java/android/content
parent452d6acb8042c52fe8e8ddbddc2c0b784d4724d8 (diff)
downloadframeworks_base-44e440cc7e834de7811f005998acb32716835b00.zip
frameworks_base-44e440cc7e834de7811f005998acb32716835b00.tar.gz
frameworks_base-44e440cc7e834de7811f005998acb32716835b00.tar.bz2
Add checks for types in Parcel / avoid class initialization
Make Parcel more stringent to avoid initializing classes that are not related to Parcelable. Two new checks: 1) That the class found on the stream implements Parcelable. 2) That the type of the CREATOR field declared on the class found on the stream actually implements Parcelable.Creator. For (1) the new check that a class in the stream is actually Parcelable. This will affect handling of invalid streams or code that didn't obey the requirements. For (2) this change could break some apps that had a CREATOR field in a Parcelable class that was not declared to be (at least) a Parcelable.Creator: it is no longer sufficient for the type to implement Parcelable.Creator, the field must be declared as such. This change includes doc updates for Parcelable to make the requirement around the declared type of the CREATOR field more concrete. This change also makes the generics slightly tidier/explicit, annotates code as unchecked where needed and removes some assumptions that can not be guaranteed with Java's type system and the current definitions. For example, there's no guarantee right now that Parcelable.Creator returns objects that are actually Parcelable, or that the CREATOR object associated with a Parcelable will return objects of the surrounding class. The first we can't do something about without breaking the public API (due to implementations like TextUtils.CHAR_SEQUENCE_CREATOR). The second is currently typically implicitly enforced with an implicit cast in the (app's) calling code (e.g. callers to readParcelable() that causes a language-introduced cast to the type expected). A larger refactoring of Parcel would be required to ensure that the class that is produced by Creator is of a type compatible with the class that declared CREATOR, and is not a goal for this change. A fix is included for a class that doesn't implement Parcelable like it should and would probably fail check (1). Bug: 1171613 Change-Id: I31d07516efee29a320e80f4bc4f96aaac628f81c
Diffstat (limited to 'core/java/android/content')
-rw-r--r--core/java/android/content/pm/PackageCleanItem.java2
-rw-r--r--core/java/android/content/pm/ParceledListSlice.java3
2 files changed, 3 insertions, 2 deletions
diff --git a/core/java/android/content/pm/PackageCleanItem.java b/core/java/android/content/pm/PackageCleanItem.java
index b1896aa..e1656d6 100644
--- a/core/java/android/content/pm/PackageCleanItem.java
+++ b/core/java/android/content/pm/PackageCleanItem.java
@@ -20,7 +20,7 @@ import android.os.Parcel;
import android.os.Parcelable;
/** @hide */
-public class PackageCleanItem {
+public class PackageCleanItem implements Parcelable {
public final int userId;
public final String packageName;
public final boolean andCode;
diff --git a/core/java/android/content/pm/ParceledListSlice.java b/core/java/android/content/pm/ParceledListSlice.java
index 335a45e..e5c2203 100644
--- a/core/java/android/content/pm/ParceledListSlice.java
+++ b/core/java/android/content/pm/ParceledListSlice.java
@@ -55,6 +55,7 @@ public class ParceledListSlice<T extends Parcelable> implements Parcelable {
mList = list;
}
+ @SuppressWarnings("unchecked")
private ParceledListSlice(Parcel p, ClassLoader loader) {
final int N = p.readInt();
mList = new ArrayList<T>(N);
@@ -63,7 +64,7 @@ public class ParceledListSlice<T extends Parcelable> implements Parcelable {
return;
}
- Parcelable.Creator<T> creator = p.readParcelableCreator(loader);
+ Parcelable.Creator<?> creator = p.readParcelableCreator(loader);
Class<?> listElementClass = null;
int i = 0;