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/drm/DrmInfoEvent.java | |
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/drm/DrmInfoEvent.java')
-rwxr-xr-x | drm/java/android/drm/DrmInfoEvent.java | 40 |
1 files changed, 36 insertions, 4 deletions
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); + } + } } } |