Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c0cc49a4 authored by Nikolas Havrikov's avatar Nikolas Havrikov
Browse files

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
parent 5e2736ae
Loading
Loading
Loading
Loading
+10 −4
Original line number Original line Diff line number Diff line
@@ -41,6 +41,7 @@ import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManager;
import android.os.ServiceManager.ServiceNotFoundException;
import android.os.ServiceManager.ServiceNotFoundException;
import android.os.UserHandle;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.ArraySet;
import android.util.Log;
import android.util.Log;


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