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

Commit d2d6014f authored by krosaen's avatar krosaen Committed by Karl Rosaen
Browse files

NEW API for SearchManager and Activity to 'triggerSearch'.

This is pretty much the same thing as startSearch, except it also launches the
query.  We enforce that this can only be done for the package of the app that is
associated with the search mananger (e.g you can't trigger a contacts search
from anywhere).
parent 1a8c1599
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
@@ -16991,6 +16991,23 @@
<parameter name="get" type="boolean">
</parameter>
</method>
<method name="triggerSearch"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="query" type="java.lang.String">
</parameter>
<parameter name="appSearchData" type="android.os.Bundle">
</parameter>
<parameter name="globalSearch" type="boolean">
</parameter>
</method>
<method name="unregisterForContextMenu"
 return="void"
 abstract="false"
@@ -23213,6 +23230,25 @@
 visibility="public"
>
</method>
<method name="triggerSearch"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="query" type="java.lang.String">
</parameter>
<parameter name="launchActivity" type="android.content.ComponentName">
</parameter>
<parameter name="appSearchData" type="android.os.Bundle">
</parameter>
<parameter name="globalSearch" type="boolean">
</parameter>
</method>
<field name="ACTION_KEY"
 type="java.lang.String"
 transient="false"
+20 −1
Original line number Diff line number Diff line
@@ -2535,6 +2535,25 @@ public class Activity extends ContextThemeWrapper
                        appSearchData, globalSearch); 
    }

    /**
     * Similar to {@link #startSearch}, but actually fires off the search query after invoking
     * the search dialog.  Made available for testing purposes.
     *
     * @param query The query to trigger.  If empty, the request will be ignored.
     * @param appSearchData An application can insert application-specific
     * context here, in order to improve quality or specificity of its own
     * searches.  This data will be returned with SEARCH intent(s).  Null if
     * no extra data is required.
     * @param globalSearch If false, this will only launch the search that has been specifically
     * defined by the application (which is usually defined as a local search).  If no default
     * search is defined in the current application or activity, no search will be launched.
     * If true, this will always launch a platform-global (e.g. web-based) search instead.
     */
    public void triggerSearch(String query, Bundle appSearchData, boolean globalSearch) {
        ensureSearchManager();
        mSearchManager.triggerSearch(query, getComponentName(), appSearchData, globalSearch);
    }

    /**
     * Request that key events come to this activity. Use this if your
     * activity has no views with focus, but the activity still wants
@@ -3256,7 +3275,7 @@ public class Activity extends ContextThemeWrapper
                throw new IllegalArgumentException("no ident");
            }
        }
        mSearchManager.setIdent(ident);
        mSearchManager.setIdent(ident, getComponentName());
    }
    
    @Override
+11 −0
Original line number Diff line number Diff line
@@ -36,6 +36,17 @@ interface ISearchManager {
            boolean globalSearch,
            ISearchManagerCallback searchManagerCallback,
            int ident);

    void triggerSearch(in String query,
            in ComponentName launchActivity,
            in Bundle appSearchData,
            ISearchManagerCallback searchManagerCallback,
            boolean globalSearch,
            int ident);

    void stopSearch();


    boolean isVisible();

}
+1 −1
Original line number Diff line number Diff line
@@ -1120,7 +1120,7 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
    /**
     * Launch a search for the text in the query text field.
     */
    protected void launchQuerySearch()  {
    public void launchQuerySearch()  {
        launchQuerySearch(KeyEvent.KEYCODE_UNKNOWN, null);
    }

+60 −2
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.os.ServiceManager;
import android.server.search.SearchableInfo;
import android.util.Log;
import android.view.KeyEvent;
import android.text.TextUtils;

import java.util.List;

@@ -1622,8 +1623,18 @@ public class SearchManager

    private final Context mContext;

    /**
     * compact representation of the activity associated with this search manager so
     * we can say who we are when starting search.  the search managerservice, in turn,
     * uses this to properly handle the back stack.
     */
    private int mIdent;

    /**
     * The package associated with this seach manager.
     */
    private String mAssociatedPackage;
    
    // package private since they are used by the inner class SearchManagerCallback
    /* package */ final Handler mHandler;
    /* package */ OnDismissListener mDismissListener = null;
@@ -1642,11 +1653,15 @@ public class SearchManager
        return mIdent != 0;
    }
    
    /*package*/ void setIdent(int ident) {
    /*package*/ void setIdent(int ident, ComponentName component) {
        if (mIdent != 0) {
            throw new IllegalStateException("mIdent already set");
        }
        if (component == null) {
            throw new IllegalArgumentException("component must be non-null");
        }
        mIdent = ident;
        mAssociatedPackage = component.getPackageName();
    }
    
    /**
@@ -1696,12 +1711,55 @@ public class SearchManager
                            boolean globalSearch) {
        if (mIdent == 0) throw new IllegalArgumentException(
                "Called from outside of an Activity context");
        if (!globalSearch && !mAssociatedPackage.equals(launchActivity.getPackageName())) {
            Log.w(TAG, "invoking app search on a different package " +
                    "not associated with this search manager");
        }
        try {
            // activate the search manager and start it up!
            mService.startSearch(initialQuery, selectInitialQuery, launchActivity, appSearchData,
                    globalSearch, mSearchManagerCallback, mIdent);
        } catch (RemoteException ex) {
            Log.e(TAG, "startSearch() failed: " + ex);
            Log.e(TAG, "startSearch() failed.", ex);
        }
    }

    /**
     * Similar to {@link #startSearch} but actually fires off the search query after invoking
     * the search dialog.  Made available for testing purposes.
     *
     * @param query The query to trigger.  If empty, request will be ignored.
     * @param launchActivity The ComponentName of the activity that has launched this search.
     * @param appSearchData An application can insert application-specific
     * context here, in order to improve quality or specificity of its own
     * searches.  This data will be returned with SEARCH intent(s).  Null if
     * no extra data is required.
     * @param globalSearch If false, this will only launch the search that has been specifically
     * defined by the application (which is usually defined as a local search).  If no default
     * search is defined in the current application or activity, no search will be launched.
     * If true, this will always launch a platform-global (e.g. web-based) search instead.
     *
     * @see #startSearch
     */
    public void triggerSearch(String query,
                              ComponentName launchActivity,
                              Bundle appSearchData,
                              boolean globalSearch) {
        if (mIdent == 0) throw new IllegalArgumentException(
                "Called from outside of an Activity context");
        if (!mAssociatedPackage.equals(launchActivity.getPackageName())) {
            throw new IllegalArgumentException("invoking app search on a different package " +
                    "not associated with this search manager");
        }
        if (query == null || TextUtils.getTrimmedLength(query) == 0) {
            Log.w(TAG, "triggerSearch called with empty query, ignoring.");
            return;
        }
        try {
            mService.triggerSearch(query, launchActivity, appSearchData, mSearchManagerCallback,
                    globalSearch, mIdent);
        } catch (RemoteException ex) {
            Log.e(TAG, "triggerSearch() failed.", ex);
        }
    }

Loading