From f70c9346d6097be6967d0901830b00b84ae02a87 Mon Sep 17 00:00:00 2001 From: Fyodor Kupolov Date: Thu, 21 May 2015 15:06:44 -0700 Subject: [PATCH] Use factory methods for RestrictionEntry As per API council request, factory methods should be used instead of using boolean. Bug: 21343772 Change-Id: Ia0889e46916f4ed7edb942217880cdf9c27771c2 --- api/current.txt | 3 ++- api/system-current.txt | 3 ++- .../android/content/RestrictionEntry.java | 25 ++++++++++++++++++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/api/current.txt b/api/current.txt index e6ddd639bcb98..8468d37132121 100644 --- a/api/current.txt +++ b/api/current.txt @@ -8559,8 +8559,9 @@ package android.content { ctor public RestrictionEntry(java.lang.String, boolean); ctor public RestrictionEntry(java.lang.String, java.lang.String[]); ctor public RestrictionEntry(java.lang.String, int); - ctor public RestrictionEntry(java.lang.String, android.content.RestrictionEntry[], boolean); ctor public RestrictionEntry(android.os.Parcel); + method public static android.content.RestrictionEntry createBundleArrayEntry(java.lang.String, android.content.RestrictionEntry[]); + method public static android.content.RestrictionEntry createBundleEntry(java.lang.String, android.content.RestrictionEntry[]); method public int describeContents(); method public java.lang.String[] getAllSelectedStrings(); method public java.lang.String[] getChoiceEntries(); diff --git a/api/system-current.txt b/api/system-current.txt index 93d7577314d26..235cf551b243c 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -8791,8 +8791,9 @@ package android.content { ctor public RestrictionEntry(java.lang.String, boolean); ctor public RestrictionEntry(java.lang.String, java.lang.String[]); ctor public RestrictionEntry(java.lang.String, int); - ctor public RestrictionEntry(java.lang.String, android.content.RestrictionEntry[], boolean); ctor public RestrictionEntry(android.os.Parcel); + method public static android.content.RestrictionEntry createBundleArrayEntry(java.lang.String, android.content.RestrictionEntry[]); + method public static android.content.RestrictionEntry createBundleEntry(java.lang.String, android.content.RestrictionEntry[]); method public int describeContents(); method public java.lang.String[] getAllSelectedStrings(); method public java.lang.String[] getChoiceEntries(); diff --git a/core/java/android/content/RestrictionEntry.java b/core/java/android/content/RestrictionEntry.java index 342ee387d469d..ab049ecbed950 100644 --- a/core/java/android/content/RestrictionEntry.java +++ b/core/java/android/content/RestrictionEntry.java @@ -200,7 +200,7 @@ public class RestrictionEntry implements Parcelable { * {@link #TYPE_BUNDLE_ARRAY bundle-array} type, otherwise the type will be set to * {@link #TYPE_BUNDLE bundle}. */ - public RestrictionEntry(String key, RestrictionEntry[] restrictionEntries, + private RestrictionEntry(String key, RestrictionEntry[] restrictionEntries, boolean isBundleArray) { mKey = key; if (isBundleArray) { @@ -219,6 +219,29 @@ public class RestrictionEntry implements Parcelable { setRestrictions(restrictionEntries); } + /** + * Creates an entry of type {@link #TYPE_BUNDLE}. + * @param key the unique key for this restriction + * @param restrictionEntries array of nested restriction entries. + * @return the newly created restriction + */ + public static RestrictionEntry createBundleEntry(String key, + RestrictionEntry[] restrictionEntries) { + return new RestrictionEntry(key, restrictionEntries, false); + } + + /** + * Creates an entry of type {@link #TYPE_BUNDLE_ARRAY}. + * @param key the unique key for this restriction + * @param restrictionEntries array of nested restriction entries. The array may only contain + * elements of type {@link #TYPE_BUNDLE bundle}. + * @return the newly created restriction + */ + public static RestrictionEntry createBundleArrayEntry(String key, + RestrictionEntry[] restrictionEntries) { + return new RestrictionEntry(key, restrictionEntries, true); + } + /** * Sets the type for this restriction. * @param type the type for this restriction.