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

Commit 0fb46683 authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 3880 into donut

* changes:
  Run search dialog in the system process.
parents 6d78dd8e 8d17f3f2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ LOCAL_SRC_FILES += \
	core/java/android/app/IIntentSender.aidl \
	core/java/android/app/INotificationManager.aidl \
	core/java/android/app/ISearchManager.aidl \
	core/java/android/app/ISearchManagerCallback.aidl \
	core/java/android/app/IServiceConnection.aidl \
	core/java/android/app/IStatusBar.aidl \
	core/java/android/app/IThumbnailReceiver.aidl \
+33 −19
Original line number Diff line number Diff line
@@ -628,6 +628,8 @@ public class Activity extends ContextThemeWrapper
    boolean mStartedActivity;
    /*package*/ int mConfigChangeFlags;
    /*package*/ Configuration mCurrentConfig;
    private SearchManager mSearchManager;
    private Bundle mSearchDialogState = null;

    private Window mWindow;

@@ -788,6 +790,9 @@ public class Activity extends ContextThemeWrapper
    protected void onCreate(Bundle savedInstanceState) {
        mVisibleFromClient = mWindow.getWindowStyle().getBoolean(
                com.android.internal.R.styleable.Window_windowNoDisplay, true);
        // uses super.getSystemService() since this.getSystemService() looks at the
        // mSearchManager field.
        mSearchManager = (SearchManager) super.getSystemService(Context.SEARCH_SERVICE);
        mCalled = true;
    }

@@ -805,9 +810,10 @@ public class Activity extends ContextThemeWrapper
        
        // Also restore the state of a search dialog (if any)
        // TODO more generic than just this manager
        SearchManager searchManager = 
            (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        searchManager.restoreSearchDialog(savedInstanceState, SAVED_SEARCH_DIALOG_KEY);
        Bundle searchState = savedInstanceState.getBundle(SAVED_SEARCH_DIALOG_KEY);
        if (searchState != null) {
            mSearchManager.restoreSearchDialog(searchState);
        }
    }

    /**
@@ -1013,9 +1019,11 @@ public class Activity extends ContextThemeWrapper

        // Also save the state of a search dialog (if any)
        // TODO more generic than just this manager
        SearchManager searchManager = 
            (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        searchManager.saveSearchDialog(outState, SAVED_SEARCH_DIALOG_KEY);
        // onPause() should always be called before this method, so mSearchManagerState
        // should be up to date.
        if (mSearchDialogState != null) {
            outState.putBundle(SAVED_SEARCH_DIALOG_KEY, mSearchDialogState);
        }
    }

    /**
@@ -1287,12 +1295,6 @@ public class Activity extends ContextThemeWrapper
            }
        }

        // also dismiss search dialog if showing
        // TODO more generic than just this manager
        SearchManager searchManager = 
            (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        searchManager.stopSearch();

        // close any cursors we are managing.
        int numCursors = mManagedCursors.size();
        for (int i = 0; i < numCursors; i++) {
@@ -1301,6 +1303,10 @@ public class Activity extends ContextThemeWrapper
                c.mCursor.close();
            }
        }

        // Clear any search state saved in performPause(). If the state may be needed in the
        // future, it will have been saved by performSaveInstanceState()
        mSearchDialogState = null;
    }

    /**
@@ -1324,9 +1330,7 @@ public class Activity extends ContextThemeWrapper
        
        // also update search dialog if showing
        // TODO more generic than just this manager
        SearchManager searchManager = 
            (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        searchManager.onConfigurationChanged(newConfig);
        mSearchManager.onConfigurationChanged(newConfig);
        
        if (mWindow != null) {
            // Pass the configuration changed event to the window
@@ -2543,10 +2547,7 @@ public class Activity extends ContextThemeWrapper
     */
    public void startSearch(String initialQuery, boolean selectInitialQuery, 
            Bundle appSearchData, boolean globalSearch) {
        // activate the search manager and start it up!
        SearchManager searchManager = (SearchManager)
                        getSystemService(Context.SEARCH_SERVICE);
        searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
        mSearchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
                        appSearchData, globalSearch); 
    }

@@ -3265,6 +3266,8 @@ public class Activity extends ContextThemeWrapper

        if (WINDOW_SERVICE.equals(name)) {
            return mWindowManager;
        } else if (SEARCH_SERVICE.equals(name)) {
            return mSearchManager;
        }
        return super.getSystemService(name);
    }
@@ -3563,10 +3566,21 @@ public class Activity extends ContextThemeWrapper
                "Activity " + mComponent.toShortString() +
                " did not call through to super.onPostResume()");
        }

        // restore search dialog, if any
        if (mSearchDialogState != null) {
            mSearchManager.restoreSearchDialog(mSearchDialogState);
        }
        mSearchDialogState = null;
    }

    final void performPause() {
        onPause();

        // save search dialog state if the search dialog is open,
        // and then dismiss the search dialog
        mSearchDialogState = mSearchManager.saveSearchDialog();
        mSearchManager.stopSearch();
    }
    
    final void performUserLeaving() {
+14 −0
Original line number Diff line number Diff line
@@ -16,7 +16,10 @@

package android.app;

import android.app.ISearchManagerCallback;
import android.content.ComponentName;
import android.content.res.Configuration;
import android.os.Bundle;
import android.server.search.SearchableInfo;

/** @hide */
@@ -26,4 +29,15 @@ interface ISearchManager {
   List<SearchableInfo> getSearchablesForWebSearch();
   SearchableInfo getDefaultSearchableForWebSearch();
   void setDefaultWebSearch(in ComponentName component);
   void startSearch(in String initialQuery,
            boolean selectInitialQuery,
            in ComponentName launchActivity,
            in Bundle appSearchData,
            boolean globalSearch,
            ISearchManagerCallback searchManagerCallback);
    void stopSearch();
    boolean isVisible();
    Bundle onSaveInstanceState();
    void onRestoreInstanceState(in Bundle savedInstanceState);
    void onConfigurationChanged(in Configuration newConfig);
}
+23 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2009, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.app;

/** @hide */
oneway interface ISearchManagerCallback {
    void onDismiss();
    void onCancel();
}
+20 −35
Original line number Diff line number Diff line
@@ -76,8 +76,8 @@ import java.util.WeakHashMap;
import java.util.concurrent.atomic.AtomicLong;

/**
 * In-application-process implementation of Search Bar.  This is still controlled by the 
 * SearchManager, but it runs in the current activity's process to keep things lighter weight.
 * System search dialog. This is controlled by the 
 * SearchManagerService and runs in the system process.
 * 
 * @hide
 */
@@ -179,17 +179,17 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Window theWindow = getWindow();
        theWindow.setGravity(Gravity.TOP|Gravity.FILL_HORIZONTAL);

        setContentView(com.android.internal.R.layout.search_bar);

        theWindow.setLayout(ViewGroup.LayoutParams.FILL_PARENT,
        Window theWindow = getWindow();
        WindowManager.LayoutParams lp = theWindow.getAttributes();
        lp.type = WindowManager.LayoutParams.TYPE_SEARCH_BAR;
        lp.width = ViewGroup.LayoutParams.FILL_PARENT;
        // taking up the whole window (even when transparent) is less than ideal,
        // but necessary to show the popup window until the window manager supports
        // having windows anchored by their parent but not clipped by them.
                ViewGroup.LayoutParams.FILL_PARENT);
        WindowManager.LayoutParams lp = theWindow.getAttributes();
        lp.height = ViewGroup.LayoutParams.FILL_PARENT;
        lp.gravity = Gravity.TOP | Gravity.FILL_HORIZONTAL;
        lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
        theWindow.setAttributes(lp);

@@ -234,10 +234,12 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
        
        // Save voice intent for later queries/launching
        mVoiceWebSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
        mVoiceWebSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mVoiceWebSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
        
        mVoiceAppSearchIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        mVoiceAppSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        
        mLocationManager =
                (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
@@ -278,11 +280,6 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
     */
    public boolean show(String initialQuery, boolean selectInitialQuery,
            ComponentName componentName, Bundle appSearchData, boolean globalSearch) {
        if (isShowing()) {
            // race condition - already showing but not handling events yet.
            // in this case, just discard the "show" request
            return true;
        }

        // Reset any stored values from last time dialog was shown.
        mStoredComponentName = null;
@@ -442,11 +439,6 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
        
        stopLocationUpdates();
        
        // TODO: Removing the listeners means that they never get called, since 
        // Dialog.dismissDialog() calls onStop() before sendDismissMessage().
        setOnCancelListener(null);
        setOnDismissListener(null);
        
        // stop receiving broadcasts (throws exception if none registered)
        try {
            getContext().unregisterReceiver(mBroadcastReceiver);
@@ -654,15 +646,15 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
        
        mSearchAutoComplete.setDropDownAnimationStyle(0); // no animation
        mSearchAutoComplete.setThreshold(mSearchable.getSuggestThreshold());
        // we dismiss the entire dialog instead
        mSearchAutoComplete.setDropDownDismissedOnCompletion(false);

        if (mGlobalSearchMode) {
            mSearchAutoComplete.setDropDownAlwaysVisible(true);  // fill space until results come in
            mSearchAutoComplete.setDropDownDismissedOnCompletion(false);
            mSearchAutoComplete.setDropDownBackgroundResource(
                    com.android.internal.R.drawable.search_dropdown_background);
        } else {
            mSearchAutoComplete.setDropDownAlwaysVisible(false);
            mSearchAutoComplete.setDropDownDismissedOnCompletion(true);
            mSearchAutoComplete.setDropDownBackgroundResource(
                    com.android.internal.R.drawable.search_dropdown_background_apps);
        }
@@ -1317,7 +1309,8 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
    }

    /**
     * Launches an intent. Also dismisses the search dialog if not in global search mode.
     * Launches an intent and dismisses the search dialog (unless the intent
     * is one of the special intents that modifies the state of the search dialog).
     */
    private void launchIntent(Intent intent) {
        if (intent == null) {
@@ -1326,9 +1319,7 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
        if (handleSpecialIntent(intent)){
            return;
        }
        if (!mGlobalSearchMode) {
        dismiss();
        }
        getContext().startActivity(intent);
    }
    
@@ -1511,6 +1502,7 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
            int actionKey, String actionMsg) {
        // Now build the Intent
        Intent intent = new Intent(action);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (data != null) {
            intent.setData(data);
        }
@@ -1596,13 +1588,6 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
            return TextUtils.getTrimmedLength(getText()) == 0;
        }

        /**
         * Clears the entered text.
         */
        private void clear() {
            setText("");
        }
        
        /**
         * We override this method to avoid replacing the query box text
         * when a suggestion is clicked.
Loading