Merge "Only show "reset app preference" actionbar menu in app info"
diff --git a/src/com/android/settings/applications/ManageApplications.java b/src/com/android/settings/applications/ManageApplications.java
index f24c3f7..5d61fe5 100644
--- a/src/com/android/settings/applications/ManageApplications.java
+++ b/src/com/android/settings/applications/ManageApplications.java
@@ -625,7 +625,6 @@
         if (mOptionsMenu == null) {
             return;
         }
-        final Context context = getActivity();
         mOptionsMenu.findItem(R.id.advanced).setVisible(false);
 
         mOptionsMenu.findItem(R.id.sort_order_alpha).setVisible(mListType == LIST_TYPE_STORAGE
@@ -637,6 +636,8 @@
                 && mListType != LIST_TYPE_HIGH_POWER);
         mOptionsMenu.findItem(R.id.hide_system).setVisible(mShowSystem
                 && mListType != LIST_TYPE_HIGH_POWER);
+
+        mOptionsMenu.findItem(R.id.reset_app_preferences).setVisible(mListType == LIST_TYPE_MAIN);
     }
 
     @Override
diff --git a/tests/robotests/src/com/android/settings/applications/ManageApplicationsTest.java b/tests/robotests/src/com/android/settings/applications/ManageApplicationsTest.java
index 871b5a0..ee184fd 100644
--- a/tests/robotests/src/com/android/settings/applications/ManageApplicationsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/ManageApplicationsTest.java
@@ -20,26 +20,33 @@
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
 import android.os.Looper;
+import android.view.Menu;
+import android.view.MenuItem;
 import android.widget.TextView;
+
 import com.android.settings.R;
 import com.android.settings.Settings;
 import com.android.settings.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.core.lifecycle.Lifecycle;
-import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor;
 import com.android.settings.testutils.shadow.SettingsShadowResources;
 import com.android.settings.testutils.shadow.SettingsShadowResources.SettingsShadowTheme;
+import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor;
 import com.android.settings.testutils.shadow.ShadowEventLogWriter;
 import com.android.settingslib.applications.ApplicationsState;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.annotation.Config;
+import org.robolectric.fakes.RoboMenuItem;
 import org.robolectric.util.ReflectionHelpers;
 
+import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -59,16 +66,20 @@
         })
 public class ManageApplicationsTest {
 
-    @Mock private ApplicationsState mState;
-    @Mock private ApplicationsState.Session mSession;
-
+    @Mock
+    private ApplicationsState mState;
+    @Mock
+    private ApplicationsState.Session mSession;
+    @Mock
+    private Menu mMenu;
+    private MenuItem mAppReset;
     private Looper mBgLooper;
     private ManageApplications mFragment;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-
+        mAppReset = new RoboMenuItem(R.id.reset_app_preferences);
         ReflectionHelpers.setStaticField(ApplicationsState.class, "sInstance", mState);
         when(mState.newSession(any())).thenReturn(mSession);
         mBgLooper = Looper.myLooper();
@@ -94,10 +105,41 @@
         ManageApplications fragment = mock(ManageApplications.class);
         when(fragment.getActivity()).thenReturn(mock(Activity.class));
         final ManageApplications.ApplicationsAdapter adapter =
-            new ManageApplications.ApplicationsAdapter(mState, fragment, 0);
+                new ManageApplications.ApplicationsAdapter(mState, fragment, 0);
 
         adapter.updateDisableView(view, info);
 
         verify(view).setText(R.string.disabled);
     }
+
+    @Test
+    public void updateMenu_mainListType_showAppReset() {
+        setUpOptionMenus();
+        ReflectionHelpers.setField(mFragment, "mListType", ManageApplications.LIST_TYPE_MAIN);
+        ReflectionHelpers.setField(mFragment, "mOptionsMenu", mMenu);
+
+        mFragment.updateOptionsMenu();
+        assertThat(mMenu.findItem(R.id.reset_app_preferences).isVisible()).isTrue();
+    }
+
+    @Test
+    public void updateMenu_batteryListType_hideAppReset() {
+        setUpOptionMenus();
+        ReflectionHelpers.setField(mFragment, "mListType", ManageApplications.LIST_TYPE_HIGH_POWER);
+        ReflectionHelpers.setField(mFragment, "mOptionsMenu", mMenu);
+
+        mFragment.updateOptionsMenu();
+        assertThat(mMenu.findItem(R.id.reset_app_preferences).isVisible()).isFalse();
+    }
+
+    private void setUpOptionMenus() {
+        when(mMenu.findItem(anyInt())).thenAnswer(invocation -> {
+            final Object[] args = invocation.getArguments();
+            final int id = (int) args[0];
+            if (id == mAppReset.getItemId()) {
+                return mAppReset;
+            }
+            return new RoboMenuItem(id);
+        });
+    }
 }