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

Commit b0761d3b authored by Ben Lin's avatar Ben Lin
Browse files

Fix NPE caused by not getting a Root DocumentInfo back from task.

We do a force callback on GetRootsDocumentInfoTask, so if the doc we get
back is null, we need to safe-guard against it. It's not very common
that we get no DocumentInfo back (we have a timeout, and most
well-behaving Providers should give us a DocumentInfo), but it is
possible that Provider took too long to respond.

Bug: 35399529
Change-Id: Ic2153c78019c835ea509397d9b208913eb28f7a0
parent c046d558
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import com.android.documentsui.ActionHandler;
import com.android.documentsui.BaseActivity;
import com.android.documentsui.DocumentsApplication;
import com.android.documentsui.DragAndDropHelper;
import com.android.documentsui.DragShadowBuilder;
import com.android.documentsui.Injector;
import com.android.documentsui.Injector.Injected;
import com.android.documentsui.ItemDragListener;
@@ -378,13 +379,24 @@ public class RootsFragment extends Fragment implements ItemDragListener.DragHost

        final RootItem rootItem = (RootItem) item;
        getRootDocument(rootItem, (DocumentInfo doc) -> {
            rootItem.docInfo = doc;
            getBaseActivity().getShadowBuilder().setAppearDroppable(
                    doc.isCreateSupported() && DragAndDropHelper.canCopyTo(localState, doc));
            v.updateDragShadow(getBaseActivity().getShadowBuilder());
            updateDropShadow(v, localState, rootItem, doc);
        });
    }

    private void updateDropShadow(
            View v, Object localState, RootItem rootItem, DocumentInfo rootDoc) {
        final DragShadowBuilder shadowBuilder = getBaseActivity().getShadowBuilder();
        if (rootDoc == null) {
            Log.e(TAG, "Root DocumentInfo is null. Defaulting to appear not droppable.");
            shadowBuilder.setAppearDroppable(false);
        } else {
            rootItem.docInfo = rootDoc;
            shadowBuilder.setAppearDroppable(rootDoc.isCreateSupported()
                    && DragAndDropHelper.canCopyTo(localState, rootDoc));
        }
        v.updateDragShadow(shadowBuilder);
    }

    // In RootsFragment we always reset the drag shadow as it exits a RootItemView.
    @Override
    public void onDragExited(View v, Object localState) {