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

Commit e6740f74 authored by Daniel Nishi's avatar Daniel Nishi
Browse files

Fix a bug where options menu was not showing.

There were two issues that stopped the options menu from
showing properly. First, the SettingsPreferenceFragment did
not call its super class, causing the Lifecycle methods to
never be called. Second, the options menu was not being
invalidated which also stopped the Lifecycle methods from
being called.

Change-Id: I29f2fc105c7ecae7adaccb2e4643e48646398d8d
Fixes: 37255835
Test: Robotest
parent 190b560c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -440,6 +440,7 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
        if (mHelpUri != null && getActivity() != null) {
            HelpUtils.prepareHelpMenuItem(getActivity(), menu, mHelpUri, getClass().getName());
        }
+14 −6
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.settings.deviceinfo;

import android.app.Activity;
import android.app.LoaderManager;
import android.content.Context;
import android.content.Intent;
@@ -78,16 +79,15 @@ public class StorageDashboardFragment extends DashboardFragment
        super.onCreate(icicle);

        // Initialize the storage sizes that we can quickly calc.
        final Context context = getActivity();
        StorageManager sm = context.getSystemService(StorageManager.class);
        final Activity activity = getActivity();
        StorageManager sm = activity.getSystemService(StorageManager.class);
        mVolume = Utils.maybeInitializeVolume(sm, getArguments());
        if (mVolume == null) {
            getActivity().finish();
            activity.finish();
            return;
        }

        mOptionMenuController = new PrivateVolumeOptionMenuController(
                context, mVolume, new PackageManagerWrapperImpl(context.getPackageManager()));
        initializeOptionsMenu(activity);

        final long sharedDataSize = mVolume.getPath().getTotalSpace();
        long totalSize = sm.getPrimaryStorageSize();
@@ -114,6 +114,15 @@ public class StorageDashboardFragment extends DashboardFragment
        }
    }

    @VisibleForTesting
    void initializeOptionsMenu(Activity activity) {
        mOptionMenuController = new PrivateVolumeOptionMenuController(
                activity, mVolume, new PackageManagerWrapperImpl(activity.getPackageManager()));
        getLifecycle().addObserver(mOptionMenuController);
        setHasOptionsMenu(true);
        activity.invalidateOptionsMenu();
    }

    @Override
    public void onResume() {
        super.onResume();
@@ -156,7 +165,6 @@ public class StorageDashboardFragment extends DashboardFragment
                new AutomaticStorageManagementSwitchPreferenceController(
                        context, mMetricsFeatureProvider, getFragmentManager());
        getLifecycle().addObserver(asmController);
        getLifecycle().addObserver(mOptionMenuController);
        controllers.add(asmController);
        return controllers;
    }
+13 −0
Original line number Diff line number Diff line
@@ -18,6 +18,10 @@ package com.android.settings.deviceinfo;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

import android.app.Activity;
import android.os.storage.StorageManager;
import android.provider.SearchIndexableResource;

@@ -55,6 +59,15 @@ public class StorageDashboardFragmentTest {
        assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_STORAGE);
    }

    @Test
    public void test_initializeOptionsMenuInvalidatesExistingMenu() {
        Activity activity = mock(Activity.class);

        mFragment.initializeOptionsMenu(activity);

        verify(activity).invalidateOptionsMenu();
    }

    @Test
    public void testSearchIndexProvider_shouldIndexResource() {
        final List<SearchIndexableResource> indexRes =