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

Commit 59710528 authored by Takamasa Kuramitsu's avatar Takamasa Kuramitsu
Browse files

Fix crash when opening inspector screen of broken folder

Files app crashes when opening inspector screen of the invalid folder,
such as top folder of the document root doesn't exist.

This CL disable the inspector menu of such invalid folder by checking
the query result of current directly.

Bug: 112321403
Test: Manual
Test: Run instrumentation tests from com.android.documentsui.tests
Change-Id: I6ebce6970bdf62707ceb359e81d5bd5f889184e4
parent b7ebcec0
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -383,6 +383,13 @@ public abstract class BaseActivity
                && !root.isRecents();
    }

    /**
     * Returns true if a directory can be inspected.
     */
    protected boolean canInspectDirectory() {
        return false;
    }

    // TODO: make navigator listen to state
    @Override
    public final void updateNavigator() {
+4 −0
Original line number Diff line number Diff line
@@ -381,5 +381,9 @@ public abstract class MenuManager {
        public boolean canCreateDirectory() {
            return mActivity.canCreateDirectory();
        }

        public boolean canInspectDirectory() {
            return mActivity.canInspectDirectory();
        }
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -1117,6 +1117,10 @@ public class DirectoryFragment extends Fragment implements SwipeRefreshLayout.On
            if (!mModel.isLoading()) {
                mActivity.notifyDirectoryLoaded(
                        mModel.doc != null ? mModel.doc.derivedUri : null);
                if (mModel.doc == null) {
                    // Invalid model, then update options menu to disable some items.
                    mActivity.invalidateOptionsMenu();
                }
            }
        }
    }
+5 −0
Original line number Diff line number Diff line
@@ -398,6 +398,11 @@ public class FilesActivity extends BaseActivity implements ActionHandler.Addons
        mInjector.focusManager.focusDocument(doc.documentId);
    }

    @Override
    protected boolean canInspectDirectory() {
        return getCurrentDirectory() != null && mInjector.getModel().doc != null;
    }

    @CallSuper
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
+1 −3
Original line number Diff line number Diff line
@@ -270,9 +270,7 @@ public final class MenuManager extends com.android.documentsui.MenuManager {
    protected void updateInspect(MenuItem inspect) {
        boolean visible = mFeatures.isInspectorEnabled();
        inspect.setVisible(visible);
        // use a null check w/ peek instead of isEmpty since
        // DocumentStack accepts null values (not sure why).
        inspect.setEnabled(visible && mState.stack.peek() != null);
        inspect.setEnabled(visible && mDirDetails.canInspectDirectory());
    }

    @Override
Loading