Prevent NPE in getSliceDescendants

Since acquireUnstableContentProviderClient returns a nullable value, it
is better to check for null to avoid an NPE and gracefully return an
empty collection instead.

Bug: 179684490
Test: make
Change-Id: Icb6cc66a8a347e710b8f0e34e4134000de2b2663
This commit is contained in:
Nikolas Havrikov
2021-10-25 15:10:24 +02:00
parent 5e2736ae5d
commit c0cc49a4a2

View File

@@ -41,6 +41,7 @@ import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManager.ServiceNotFoundException;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.Log;
@@ -223,10 +224,15 @@ public class SliceManager {
public @NonNull Collection<Uri> getSliceDescendants(@NonNull Uri uri) {
ContentResolver resolver = mContext.getContentResolver();
try (ContentProviderClient provider = resolver.acquireUnstableContentProviderClient(uri)) {
Bundle extras = new Bundle();
extras.putParcelable(SliceProvider.EXTRA_BIND_URI, uri);
final Bundle res = provider.call(SliceProvider.METHOD_GET_DESCENDANTS, null, extras);
return res.getParcelableArrayList(SliceProvider.EXTRA_SLICE_DESCENDANTS);
if (provider == null) {
Log.w(TAG, TextUtils.formatSimple("Unknown URI: %s", uri));
} else {
Bundle extras = new Bundle();
extras.putParcelable(SliceProvider.EXTRA_BIND_URI, uri);
final Bundle res = provider.call(
SliceProvider.METHOD_GET_DESCENDANTS, null, extras);
return res.getParcelableArrayList(SliceProvider.EXTRA_SLICE_DESCENDANTS);
}
} catch (RemoteException e) {
Log.e(TAG, "Unable to get slice descendants", e);
}