Fix bug #15469483 Search menu should not be present when Settings is launched as a Shortcut

- create the Search menu only for non shortcut launch

Change-Id: I8f83fb6c199509f2b2215a20b19f92e3d736b733
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index e602fa6..6ba79cc 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -133,6 +133,7 @@
     private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
     private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
     private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
+    private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
 
     /**
      * When starting this activity, the invoking Intent can contain this extra
@@ -306,7 +307,9 @@
     private SwitchBar mSwitchBar;
 
     private Button mNextButton;
+
     private boolean mDisplayHomeAsUpEnabled;
+    private boolean mDisplaySearch;
 
     private boolean mIsShowingDashboard;
 
@@ -401,6 +404,10 @@
 
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
+        if (!mDisplaySearch) {
+            return false;
+        }
+
         MenuInflater inflater = getMenuInflater();
         inflater.inflate(R.menu.options_menu, menu);
 
@@ -454,6 +461,7 @@
         getFragmentManager().addOnBackStackChangedListener(this);
 
         mDisplayHomeAsUpEnabled = true;
+        mDisplaySearch = true;
 
         // Getting Intent properties can only be done after the super.onCreate(...)
         final String initialFragmentName = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
@@ -483,12 +491,14 @@
             }
 
             mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
+            mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
         } else {
             if (!mIsShowingDashboard) {
                 final ComponentName cn = getIntent().getComponent();
-                // No UP is we are launched thru a Settings shortcut
+                // No UP nor Search is shown we are launched thru a Settings "shortcut"
                 if (!cn.getClassName().equals(SubSettings.class.getName())) {
                     mDisplayHomeAsUpEnabled = false;
+                    mDisplaySearch = false;
                 }
                 final String initialTitle = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
                 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
@@ -610,17 +620,20 @@
         }
 
         outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
+        outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
 
-        // The option menus are created if the ActionBar is visible and they are also created
-        // asynchronously. If you launch Settings with an Intent action like
-        // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
-        // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
-        // menu item and search view are null.
-        boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
-        outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
+        if (mDisplaySearch) {
+            // The option menus are created if the ActionBar is visible and they are also created
+            // asynchronously. If you launch Settings with an Intent action like
+            // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
+            // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
+            // menu item and search view are null.
+            boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
+            outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
 
-        String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
-        outState.putString(SAVE_KEY_SEARCH_QUERY, query);
+            String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
+            outState.putString(SAVE_KEY_SEARCH_QUERY, query);
+        }
     }
 
     @Override
@@ -641,7 +654,7 @@
 
         mDynamicIndexableContentMonitor.register(this);
 
-        if(!TextUtils.isEmpty(mSearchQuery)) {
+        if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
             onQueryTextSubmit(mSearchQuery);
         }
     }