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

Commit 40c85052 authored by Garfield Tan's avatar Garfield Tan
Browse files

Remove State#restored.

The stack itself is the best indicator of if it has been initialized or
not. With a small refactor we can encapsulate the stack modification in
initialization phase to ActionHandlers only.

Hopefully it won't cause other issues in other corner cases.

Credits to Sony Mobile devs on their bug report.

Bug: 34593795
Change-Id: I4c8e5f9816ede8bb335151626c2aedd2bed521cc
(cherry picked from commit 23618f30215a4bfecaa10795e2ba413702c12bbf)
parent 317d65f8
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -363,6 +363,12 @@ public abstract class BaseActivity
     */
    @Override
    public final void refreshCurrentRootAndDirectory(int anim) {
        // The following call will crash if it's called before onCreateOptionMenu() is called in
        // which we install menu item to search view manager, and there is a search query we need to
        // restore. This happens when we're still initializing our UI so we shouldn't cancel the
        // search which will be restored later in onCreateOptionMenu(). Try finding a way to guard
        // refreshCurrentRootAndDirectory() from being called while we're restoring the state of UI
        // from the saved state passed in onCreate().
        mSearchManager.cancelSearch();

        refreshDirectory(anim);
+4 −0
Original line number Diff line number Diff line
@@ -90,6 +90,10 @@ public class DocumentStack implements Durable, Parcelable {
        mRoot = src.mRoot;
    }

    public boolean isInitialized() {
        return mRoot != null;
    }

    public @Nullable RootInfo getRoot() {
        return mRoot;
    }
+0 −3
Original line number Diff line number Diff line
@@ -79,7 +79,6 @@ public class State implements android.os.Parcelable {
    public boolean localOnly;
    public boolean showDeviceStorageOption;
    public boolean showAdvanced;
    public boolean restored;
    /*
     * Indicates handler was an external app, like photos.
     */
@@ -131,7 +130,6 @@ public class State implements android.os.Parcelable {
        out.writeInt(localOnly ? 1 : 0);
        out.writeInt(showDeviceStorageOption ? 1 : 0);
        out.writeInt(showAdvanced ? 1 : 0);
        out.writeInt(restored ? 1 : 0);
        out.writeInt(external ? 1 : 0);
        DurableUtils.writeToParcel(out, stack);
        out.writeMap(dirConfigs);
@@ -155,7 +153,6 @@ public class State implements android.os.Parcelable {
            state.localOnly = in.readInt() != 0;
            state.showDeviceStorageOption = in.readInt() != 0;
            state.showAdvanced = in.readInt() != 0;
            state.restored = in.readInt() != 0;
            state.external = in.readInt() != 0;
            DurableUtils.readFromParcel(in, state.stack);
            in.readMap(state.dirConfigs, loader);
+9 −6
Original line number Diff line number Diff line
@@ -341,12 +341,14 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa
    public void initLocation(Intent intent) {
        assert(intent != null);

        if (mState.restored) {
        // stack is initialized if it's restored from bundle, which means we're restoring a
        // previously stored state.
        if (mState.stack.isInitialized()) {
            if (DEBUG) Log.d(TAG, "Stack already resolved for uri: " + intent.getData());
            return;
        }

        if (launchToStackLocation(mState.stack)) {
        if (launchToStackLocation(intent)) {
            if (DEBUG) Log.d(TAG, "Launched to location from stack.");
            return;
        }
@@ -370,9 +372,8 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa
        loadHomeDir();
    }

    // If a non-empty stack is present in our state, it was read (presumably)
    // from EXTRA_STACK intent extra. In this case, we'll skip other means of
    // loading or restoring the stack (like URI).
    // If EXTRA_STACK is not null in intent, we'll skip other means of loading
    // or restoring the stack (like URI).
    //
    // When restoring from a stack, if a URI is present, it should only ever be:
    // -- a launch URI: Launch URIs support sensible activity management,
@@ -381,11 +382,13 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa
    //
    // Any other URI is *sorta* unexpected...except when browsing an archive
    // in downloads.
    private boolean launchToStackLocation(DocumentStack stack) {
    private boolean launchToStackLocation(Intent intent) {
        DocumentStack stack = intent.getParcelableExtra(Shared.EXTRA_STACK);
        if (stack == null || stack.getRoot() == null) {
            return false;
        }

        mState.stack.reset(stack);
        if (mState.stack.isEmpty()) {
            mActivity.onRootPicked(mState.stack.getRoot());
        } else {
+0 −5
Original line number Diff line number Diff line
@@ -177,11 +177,6 @@ public class FilesActivity extends BaseActivity implements ActionHandler.Addons

        // Options specific to the DocumentsActivity.
        assert(!intent.hasExtra(Intent.EXTRA_LOCAL_ONLY));

        final DocumentStack stack = intent.getParcelableExtra(Shared.EXTRA_STACK);
        if (stack != null) {
            state.stack.reset(stack);
        }
    }

    @Override
Loading