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
This commit is contained in:
@@ -440,6 +440,7 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
if (mHelpUri != null && getActivity() != null) {
|
if (mHelpUri != null && getActivity() != null) {
|
||||||
HelpUtils.prepareHelpMenuItem(getActivity(), menu, mHelpUri, getClass().getName());
|
HelpUtils.prepareHelpMenuItem(getActivity(), menu, mHelpUri, getClass().getName());
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.deviceinfo;
|
package com.android.settings.deviceinfo;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.LoaderManager;
|
import android.app.LoaderManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -78,16 +79,15 @@ public class StorageDashboardFragment extends DashboardFragment
|
|||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
|
|
||||||
// Initialize the storage sizes that we can quickly calc.
|
// Initialize the storage sizes that we can quickly calc.
|
||||||
final Context context = getActivity();
|
final Activity activity = getActivity();
|
||||||
StorageManager sm = context.getSystemService(StorageManager.class);
|
StorageManager sm = activity.getSystemService(StorageManager.class);
|
||||||
mVolume = Utils.maybeInitializeVolume(sm, getArguments());
|
mVolume = Utils.maybeInitializeVolume(sm, getArguments());
|
||||||
if (mVolume == null) {
|
if (mVolume == null) {
|
||||||
getActivity().finish();
|
activity.finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mOptionMenuController = new PrivateVolumeOptionMenuController(
|
initializeOptionsMenu(activity);
|
||||||
context, mVolume, new PackageManagerWrapperImpl(context.getPackageManager()));
|
|
||||||
|
|
||||||
final long sharedDataSize = mVolume.getPath().getTotalSpace();
|
final long sharedDataSize = mVolume.getPath().getTotalSpace();
|
||||||
long totalSize = sm.getPrimaryStorageSize();
|
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
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
@@ -156,7 +165,6 @@ public class StorageDashboardFragment extends DashboardFragment
|
|||||||
new AutomaticStorageManagementSwitchPreferenceController(
|
new AutomaticStorageManagementSwitchPreferenceController(
|
||||||
context, mMetricsFeatureProvider, getFragmentManager());
|
context, mMetricsFeatureProvider, getFragmentManager());
|
||||||
getLifecycle().addObserver(asmController);
|
getLifecycle().addObserver(asmController);
|
||||||
getLifecycle().addObserver(mOptionMenuController);
|
|
||||||
controllers.add(asmController);
|
controllers.add(asmController);
|
||||||
return controllers;
|
return controllers;
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,10 @@ package com.android.settings.deviceinfo;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
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.os.storage.StorageManager;
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
|
|
||||||
@@ -55,6 +59,15 @@ public class StorageDashboardFragmentTest {
|
|||||||
assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_STORAGE);
|
assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_STORAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_initializeOptionsMenuInvalidatesExistingMenu() {
|
||||||
|
Activity activity = mock(Activity.class);
|
||||||
|
|
||||||
|
mFragment.initializeOptionsMenu(activity);
|
||||||
|
|
||||||
|
verify(activity).invalidateOptionsMenu();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSearchIndexProvider_shouldIndexResource() {
|
public void testSearchIndexProvider_shouldIndexResource() {
|
||||||
final List<SearchIndexableResource> indexRes =
|
final List<SearchIndexableResource> indexRes =
|
||||||
|
Reference in New Issue
Block a user