From d3427ae78f0a6cf9f702cbcfce4abc0c72823582 Mon Sep 17 00:00:00 2001 From: Tony Wickham Date: Fri, 21 Apr 2017 11:47:18 -0700 Subject: [PATCH] Address API Review comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - throw NullPointerException if the package name is null; there’s already a method with the specified null behavior. - Return value of this method should be @NonNull - return an empty list. Document this. Test: Unit test on AppWidgetServiceImplTest $ runtest --path=services/tests/servicestests/src/com/android/server/appwidget/AppWidgetServiceImplTest.java Bug: 37544056 Change-Id: I047a8e7c4e519ef7c5deddaca0d1ad931dc91343 --- .../android/appwidget/AppWidgetManager.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/core/java/android/appwidget/AppWidgetManager.java b/core/java/android/appwidget/AppWidgetManager.java index 9f35e85b0665c..6327f34ebd5eb 100644 --- a/core/java/android/appwidget/AppWidgetManager.java +++ b/core/java/android/appwidget/AppWidgetManager.java @@ -712,12 +712,13 @@ public class AppWidgetManager { * * @param profile The profile for which to get providers. Passing null is equivalent * to querying for only the calling user. - * @return The installed providers. + * @return The installed providers, or an empty list if none are found for the given user. * * @see android.os.Process#myUserHandle() * @see android.os.UserManager#getUserProfiles() */ - public List getInstalledProvidersForProfile(@Nullable UserHandle profile) { + public @NonNull List getInstalledProvidersForProfile( + @Nullable UserHandle profile) { if (mService == null) { return Collections.emptyList(); } @@ -735,13 +736,20 @@ public class AppWidgetManager { * equivalent to {@link #getInstalledProvidersForProfile(UserHandle)}. * @param profile The profile for which to get providers. Passing null is equivalent * to querying for only the calling user. - * @return The installed providers. + * @return The installed providers, or an empty list if none are found for the given + * package and user. + * @throws NullPointerException if the provided package name is null * * @see android.os.Process#myUserHandle() * @see android.os.UserManager#getUserProfiles() */ - public List getInstalledProvidersForPackage(@Nullable String packageName, - @Nullable UserHandle profile) { + public @NonNull List getInstalledProvidersForPackage( + @NonNull String packageName, @Nullable UserHandle profile) { + if (packageName == null) { + throw new NullPointerException("A non-null package must be passed to this method. " + + "If you want all widgets regardless of package, see " + + "getInstalledProvidersForProfile(UserHandle)"); + } if (mService == null) { return Collections.emptyList(); }