Log.d("ZXGLOG","entryValues = " +entryValues[i]+"/i = " + i);//selectedItem = 0,固定为0
log的结果
// D/ZXGLOG: entryValues = yahoo_es/i = 0
// D/ZXGLOG: entryValues = google/i = 1
// D/ZXGLOG: entryValues = ask_es/i = 2
// D/ZXGLOG: entryValues = bing_es_ES/i = 3
// D/ZXGLOG: entryValues = terra_es/i = 4
// D/ZXGLOG: entryValues = hispavista/i = 5
2,BrowserSettings.java
getSearchEngineName()
entryValues[i] = searchEngines.get(i).getName(); //浏览器引擎赋值的地方
3,searchEngines从这里来:(BrowserSettings.java)
List searchEngines = searchEngineManager.getAvailables();//engine comes frome here
4,通过系统服务得到 searchEngineManager (BrowserSettings.java)
SearchEngineManager searchEngineManager =
(SearchEngineManager) mContext.getSystemService(Context.SEARCH_ENGINE_SERVICE);
5,通过 getAvailables() ,跳转到SearchEngineManager .java的方法 getAvailables()
public List getAvailables() {
try {
return mService.getAvailables();
} catch (RemoteException e) {
Slog.e(TAG, "getSearchEngineInfos() failed: " + e);
return null;
}
}
可以看出是从 mService.getAvailables();这里来的
6,mService,(SearchEngineManager .java)
mService = ISearchEngineManagerService.Stub.asInterface(//AIDL : get service by AIDL
ServiceManager.getService(Context.SEARCH_ENGINE_SERVICE));
7,看到ISearchEngineManagerService,前面开头为I,是AIDL通讯的方式,
全路径为:
Z:\zhouxingui\mt6737_hltx_20170725\frameworks\base\core\java\com\mediatek\search\ISearchEngineManagerService.aidl
会有一个类SearchEngineManagerService.java来对应的。(这里要补充AIDL的知识)
通过 ctrl + shift + N :SearchEngineManagerService.java找到这个类
8,getAvailables() , 这是SearchEngineManagerService.java(对应的ISearchEngineManagerService.aidl的方法):
public synchronized List getAvailables() {
Log.i(TAG, "get avilable search engines");
if (mSearchEngines == null) {
initSearchEngines();
}
return mSearchEngines;
}
log信息,4次:
get avilable search engines
get avilable search engines
get avilable search engines
get avilable search engines
9,先执行 initSearchEngines();(SearchEngineManagerService.java)
目的是给private List mSearchEngines;赋值
源码如下:
private void initSearchEngines() throws IllegalArgumentException {
IRegionalPhoneSearchEngineExt regionalPhoneSearchEngineExt = MPlugin.createInstance(
IRegionalPhoneSearchEngineExt.class.getName(), mContext);
if (regionalPhoneSearchEngineExt != null) {
mSearchEngines = regionalPhoneSearchEngineExt.initSearchEngineInfosFromRpm(mContext);
if (mSearchEngines != null) {
mDefaultSearchEngine = mSearchEngines.get(0);
Log.d(TAG, "initSearchEngineInfosFromRpm( Search engine init");
return;
}
}
mSearchEngines = new ArrayList();
Resources res = mContext.getResources();
String[] searchEngines =
res.getStringArray(com.mediatek.internal.R.array.new_search_engines);
if (null == searchEngines || 1 >= searchEngines.length) {
// todo: throws an exception in this case.
throw new IllegalArgumentException("No data found for ");
}
String sp = searchEngines[0];
for (int i = 1; i < searchEngines.length; i++) {
String configInfo = searchEngines[i];
SearchEngine info = SearchEngine.parseFrom(configInfo, sp);
mSearchEngines.add(info);
Log.d(TAG, "mSearchEngines.add(info);engine init");
}
// keep old setting.
if (mDefaultSearchEngine != null) {
mDefaultSearchEngine = getBestMatch(mDefaultSearchEngine.getName(),
mDefaultSearchEngine.getFaviconUri());
}
if (mDefaultSearchEngine == null) {
mDefaultSearchEngine = mSearchEngines.get(0);
}
// tell search widget that search engine changed.
broadcastSearchEngineChangedInternal(mContext);
}
再看:initSearchEngines()方法
有两处可能给private List mSearchEngines 的赋值的地方:
mSearchEngines = regionalPhoneSearchEngineExt.initSearchEngineInfosFromRpm(mContext);
和
mSearchEngines.add(info);
\frameworks\base\services\core\java\com\mediatek\search\SearchEngineManagerService.java
framework层,所以要全编译,调试打印log,查看哪个执行了
Log.d(TAG, "initSearchEngineInfosFromRpm( Search engine init");查看是否为空
日志:信息,可以看出执行了mSearchEngines.add(info);engine init,也就是for循环
D/SearchEngineManagerService: initSearchEngineInfosFromRpm( Search engine init
01-01 07:00:52.483 819-2815/system_process D/SearchEngineManagerService: mSearchEngines.add(info);engine init
01-01 07:00:52.487 819-2815/system_process D/SearchEngineManagerService: mSearchEngines.add(info);engine init
01-01 07:00:52.489 819-2815/system_process D/SearchEngineManagerService: mSearchEngines.add(info);engine init
01-01 07:00:52.490 819-2815/system_process D/SearchEngineManagerService: mSearchEngines.add(info);engine init
01-01 07:00:52.491 819-2815/system_process D/SearchEngineManagerService: mSearchEngines.add(info);engine init
01-01 07:00:52.497 819-2815/system_process D/SearchEngineManagerService: mSearchEngines.add(info);engine init
可以看出执行了mSearchEngines.add(info);engine init,也就是for循环
for (int i = 1; i < searchEngines.length; i++) {
String configInfo = searchEngines[i];
SearchEngine info = SearchEngine.parseFrom(configInfo, sp);
mSearchEngines.add(info);
Log.d(TAG, "mSearchEngines.add(info);engine init");
}
10,结论:mSearchEngines.add(info);是给private List mSearchEngines 的赋值的地方,
部分代码:
Resources res = mContext.getResources();
//get search_engines list
String[] searchEngines =
res.getStringArray(com.mediatek.internal.R.array.new_search_engines);
if (null == searchEngines || 1 >= searchEngines.length) {
// todo: throws an exception in this case.
throw new IllegalArgumentException("No data found for ");
}
String sp = searchEngines[0];
for (int i = 1; i < searchEngines.length; i++) {
String configInfo = searchEngines[i];
SearchEngine info = SearchEngine.parseFrom(configInfo, sp);
mSearchEngines.add(info);
Log.d(TAG, "mSearchEngines.add(info);engine init");
}
可以看出SearchEngine info = SearchEngine.parseFrom(configInfo, sp);
而configInfo = searchEngines[i];
sp = searchEngines[0];
其中,searchEngines =
res.getStringArray(com.mediatek.internal.R.array.new_search_engines);
可以得出:searchEngines来自R.array.new_search_engines
全局搜索得到
打印log刚好对应 new_search_engines的值
return entryValues[selectedItem];
for (int i = 0; i
Log.d("ZXGLOG","entryValues = " +entryValues[i]+"/i = " + i);//selectedItem = 0,固定为0
log的结果
// D/ZXGLOG: entryValues = yahoo_es/i = 0
// D/ZXGLOG: entryValues = google/i = 1
// D/ZXGLOG: entryValues = ask_es/i = 2
// D/ZXGLOG: entryValues = bing_es_ES/i = 3
// D/ZXGLOG: entryValues = terra_es/i = 4
// D/ZXGLOG: entryValues = hispavista/i = 5
new_search_engines.xml(ES下的)
全路径名:
vendor/mediatek/proprietary/frameworks/base/res/res/values-es-rES/donottranslate-new-search_engines.xml
- --
- yahoo_es--Yahoo! Espa༚--es.yahoo.com--search_engine_yahoo--https://es.search.yahoo.com/search?ei={inputEncoding}&.tsrc=mtkandroid&p={searchTerms}--UTF-8--http://sugg.es.search.yahoo.com/gossip-es/?output=fxjson&command={searchTerms}
- google--Google--google.com--search_engine_google--http://www.google.com/m?hl={language}&ie={inputEncoding}&source=android-browser&q={searchTerms}--UTF-8--http://www.google.com/complete/search?hl={language}&json=true&q={searchTerms}
- ask_es--Ask.com Espa༚--es.ask.com--search_engine_ask--http://es.ask.com/web?q={searchTerms}--UTF-8--http://ss.es.ask.com/query?q={searchTerms}&li=ff
- bing_es_ES--Bing--bing.com--search_engine_bing--http://www.bing.com/search?setmkt=es-ES&q={searchTerms}--UTF-8--http://api.bing.com/osjson.aspx?query={searchTerms}&language={language}
- terra_es--Terra--terra.es--search_engine_terra--http://buscador.terra.es/Default.aspx?query={searchTerms}&source=Search--ISO-8859-1--nil
- hispavista--hispavista--hispavista.com--search_engine_hispavista--http://buscar.hispavista.com/?cadena={searchTerms}--iso-8859-1--nil
在西班牙语环境下刚好对应!!!!!!
需求,第一个默认搜索引擎为yahoo
所以
更改new_search_engines.中item的顺序,将google改到第一位,其他代码都不动,重新刷机运行!!看结果搞定!!!!!
参考博客:
安卓5.1浏览器设置默认搜索引擎为百度
https://blog.csdn.net/hexiaoshuai1992/article/details/49680177