diff options
author | James Dong <jdong@google.com> | 2012-02-23 15:01:46 -0800 |
---|---|---|
committer | James Dong <jdong@google.com> | 2012-02-24 15:50:41 -0800 |
commit | e82f055e3eb1b0b3daf87bc14258fa65568b4f8a (patch) | |
tree | 7df4c2eea446d74f44ea3f8f67db58eac5cf8959 /drm/java/android | |
parent | 2d77b5332ac4ef5b252fbd8f56a195e0fce03292 (diff) | |
download | frameworks_base-e82f055e3eb1b0b3daf87bc14258fa65568b4f8a.zip frameworks_base-e82f055e3eb1b0b3daf87bc14258fa65568b4f8a.tar.gz frameworks_base-e82f055e3eb1b0b3daf87bc14258fa65568b4f8a.tar.bz2 |
Only allow valid types to be used in DrmErrorEvent and DrmInfoEvent
o This patch will prevent applications from abusing the API by using
arbitrary int value for DrmErrorEvent or DrmInfoEvent types.
o We should have not defined some type constants in the super/base
class, DrmEvent.
Change-Id: Id0bb12caa8ce471cb6951cc2b5d37ea408f90063
Diffstat (limited to 'drm/java/android')
-rwxr-xr-x | drm/java/android/drm/DrmErrorEvent.java | 30 | ||||
-rwxr-xr-x | drm/java/android/drm/DrmEvent.java | 4 | ||||
-rwxr-xr-x | drm/java/android/drm/DrmInfoEvent.java | 40 |
3 files changed, 66 insertions, 8 deletions
diff --git a/drm/java/android/drm/DrmErrorEvent.java b/drm/java/android/drm/DrmErrorEvent.java index 2cb82e6..c61819d 100755 --- a/drm/java/android/drm/DrmErrorEvent.java +++ b/drm/java/android/drm/DrmErrorEvent.java @@ -24,6 +24,10 @@ import java.util.HashMap; * */ public class DrmErrorEvent extends DrmEvent { + + // Please add newly defined type constants to the end of the list, + // and modify checkTypeValidity() accordingly. + /** * Something went wrong installing the rights. */ @@ -60,28 +64,46 @@ public class DrmErrorEvent extends DrmEvent { */ public static final int TYPE_ACQUIRE_DRM_INFO_FAILED = 2008; + // Add more type constants here... + + // FIXME: + // We may want to add a user-defined type constant, such as + // TYPE_VENDOR_SPECIFIC_FAILED, to take care vendor specific use + // cases. + + /** * Creates a <code>DrmErrorEvent</code> object with the specified parameters. * * @param uniqueId Unique session identifier. - * @param type Type of the event. Could be any of the event types defined above. - * @param message Message description. + * @param type Type of the event. Must be any of the event types defined above. + * @param message Message description. It can be null. */ public DrmErrorEvent(int uniqueId, int type, String message) { super(uniqueId, type, message); + checkTypeValidity(type); } /** * Creates a <code>DrmErrorEvent</code> object with the specified parameters. * * @param uniqueId Unique session identifier. - * @param type Type of the event. Could be any of the event types defined above. + * @param type Type of the event. Must be any of the event types defined above. * @param message Message description. * @param attributes Attributes for extensible information. Could be any - * information provided by the plug-in. + * information provided by the plug-in. It can be null. */ public DrmErrorEvent(int uniqueId, int type, String message, HashMap<String, Object> attributes) { super(uniqueId, type, message, attributes); + checkTypeValidity(type); + } + + private void checkTypeValidity(int type) { + if (type < TYPE_RIGHTS_NOT_INSTALLED || + type > TYPE_ACQUIRE_DRM_INFO_FAILED) { + final String msg = "Unsupported type: " + type; + throw new IllegalArgumentException(msg); + } } } diff --git a/drm/java/android/drm/DrmEvent.java b/drm/java/android/drm/DrmEvent.java index 4053eb3..1a19f5c 100755 --- a/drm/java/android/drm/DrmEvent.java +++ b/drm/java/android/drm/DrmEvent.java @@ -23,6 +23,10 @@ import java.util.HashMap; * */ public class DrmEvent { + + // Please do not add type constants in this class. More event type constants + // should go to DrmInfoEvent or DrmErrorEvent classes. + /** * All of the rights information associated with all DRM schemes have been successfully removed. */ diff --git a/drm/java/android/drm/DrmInfoEvent.java b/drm/java/android/drm/DrmInfoEvent.java index 67aa0a9..2826dce 100755 --- a/drm/java/android/drm/DrmInfoEvent.java +++ b/drm/java/android/drm/DrmInfoEvent.java @@ -24,6 +24,10 @@ import java.util.HashMap; * */ public class DrmInfoEvent extends DrmEvent { + + // Please add newly defined type constants to the end of the list, + // and modify checkTypeValidity() accordingly. + /** * The registration has already been done by another account ID. */ @@ -50,29 +54,57 @@ public class DrmInfoEvent extends DrmEvent { */ public static final int TYPE_RIGHTS_REMOVED = 6; + // Add more type constants here... + + // FIXME: + // We may want to add a user-defined type constant, such as + // TYPE_VENDOR_SPECIFIC, to take care vendor specific use + // cases. + /** * Creates a <code>DrmInfoEvent</code> object with the specified parameters. * * @param uniqueId Unique session identifier. - * @param type Type of the event. Could be any of the event types defined above. - * @param message Message description. + * @param type Type of the event. Must be any of the event types defined above, + * or the constants defined in {@link DrmEvent}. + * @param message Message description. It can be null. */ public DrmInfoEvent(int uniqueId, int type, String message) { super(uniqueId, type, message); + checkTypeValidity(type); } /** * Creates a <code>DrmInfoEvent</code> object with the specified parameters. * * @param uniqueId Unique session identifier. - * @param type Type of the event. Could be any of the event types defined above. - * @param message Message description. + * @param type Type of the event. Must be any of the event types defined above, + * or the constants defined in {@link DrmEvent} + * @param message Message description. It can be null. * @param attributes Attributes for extensible information. Could be any * information provided by the plug-in. */ public DrmInfoEvent(int uniqueId, int type, String message, HashMap<String, Object> attributes) { super(uniqueId, type, message, attributes); + checkTypeValidity(type); + } + + /* + * Check the validity of the given type. + * To overcome a design flaw, we need also accept the type constants + * defined in super class, DrmEvent. + */ + private void checkTypeValidity(int type) { + if (type < TYPE_ALREADY_REGISTERED_BY_ANOTHER_ACCOUNT || + type > TYPE_RIGHTS_REMOVED) { + + if (type != TYPE_ALL_RIGHTS_REMOVED && + type != TYPE_DRM_INFO_PROCESSED) { + final String msg = "Unsupported type: " + type; + throw new IllegalArgumentException(msg); + } + } } } |