package com.android.browser;
+import com.android.browser.search.SearchEngine;
+
import android.app.SearchManager;
-import android.app.SearchableInfo;
-import android.backup.BackupManager;
-import android.content.ComponentName;
+import android.app.backup.BackupManager;
import android.content.ContentProvider;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
-import android.content.UriMatcher;
import android.content.SharedPreferences.Editor;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
+import android.content.UriMatcher;
import android.database.AbstractCursor;
-import android.database.ContentObserver;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.net.Uri;
-import android.os.AsyncTask;
-import android.os.Handler;
+import android.os.Process;
import android.preference.PreferenceManager;
import android.provider.Browser;
-import android.provider.Settings;
import android.provider.Browser.BookmarkColumns;
import android.speech.RecognizerResultsIntent;
import android.text.TextUtils;
import android.util.Log;
import android.util.Patterns;
-import android.util.TypedValue;
-import android.webkit.GeolocationPermissions;
-
import java.io.File;
import java.io.FilenameFilter;
"viewer?source=androidclient";
private static final String[] TABLE_NAMES = new String[] {
- "bookmarks", "searches", "geolocation"
+ "bookmarks", "searches"
};
private static final String[] SUGGEST_PROJECTION = new String[] {
"_id", "url", "title", "bookmark", "user_entered"
// make sure that these match the index of TABLE_NAMES
private static final int URI_MATCH_BOOKMARKS = 0;
private static final int URI_MATCH_SEARCHES = 1;
- private static final int URI_MATCH_GEOLOCATION = 2;
// (id % 10) should match the table name index
private static final int URI_MATCH_BOOKMARKS_ID = 10;
private static final int URI_MATCH_SEARCHES_ID = 11;
URI_MATCHER.addURI("browser",
TABLE_NAMES[URI_MATCH_BOOKMARKS] + "/" + SearchManager.SUGGEST_URI_PATH_QUERY,
URI_MATCH_BOOKMARKS_SUGGEST);
- URI_MATCHER.addURI("browser", TABLE_NAMES[URI_MATCH_GEOLOCATION],
- URI_MATCH_GEOLOCATION);
}
// 1 -> 2 add cache table
// optionally a trailing slash, all matched as separate groups.
private static final Pattern STRIP_URL_PATTERN = Pattern.compile("^(http://)(.*?)(/$)?");
- private SearchManager mSearchManager;
+ private BrowserSettings mSettings;
public BrowserProvider() {
}
}
private void removeGears() {
- AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
- public Void doInBackground(Void... unused) {
+ new Thread() {
+ @Override
+ public void run() {
+ Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
String browserDataDirString = mContext.getApplicationInfo().dataDir;
final String appPluginsDirString = "app_plugins";
final String gearsPrefix = "gears";
File appPluginsDir = new File(browserDataDirString + File.separator
+ appPluginsDirString);
if (!appPluginsDir.exists()) {
- return null;
+ return;
}
// Delete the Gears plugin files
File[] gearsFiles = appPluginsDir.listFiles(new FilenameFilter() {
File gearsDataDir = new File(browserDataDirString + File.separator
+ gearsPrefix);
if (!gearsDataDir.exists()) {
- return null;
+ return;
}
deleteDirectory(gearsDataDir);
- return null;
}
private void deleteDirectory(File currentDir) {
}
currentDir.delete();
}
- };
-
- task.execute();
+ }.start();
}
}
ed.commit();
}
}
- mSearchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
- mShowWebSuggestionsSettingChangeObserver
- = new ShowWebSuggestionsSettingChangeObserver();
- context.getContentResolver().registerContentObserver(
- Settings.System.getUriFor(
- Settings.System.SHOW_WEB_SUGGESTIONS),
- true, mShowWebSuggestionsSettingChangeObserver);
- updateShowWebSuggestions();
+ mSettings = BrowserSettings.getInstance();
return true;
}
- /**
- * This Observer will ensure that if the user changes the system
- * setting of whether to display web suggestions, we will
- * change accordingly.
- */
- /* package */ class ShowWebSuggestionsSettingChangeObserver
- extends ContentObserver {
- public ShowWebSuggestionsSettingChangeObserver() {
- super(new Handler());
- }
-
- @Override
- public void onChange(boolean selfChange) {
- updateShowWebSuggestions();
- }
- }
-
- private ShowWebSuggestionsSettingChangeObserver
- mShowWebSuggestionsSettingChangeObserver;
-
- // If non-null, then the system is set to show web suggestions,
- // and this is the SearchableInfo to use to get them.
- private SearchableInfo mSearchableInfo;
-
- /**
- * Check the system settings to see whether web suggestions are
- * allowed. If so, store the SearchableInfo to grab suggestions
- * while the user is typing.
- */
- private void updateShowWebSuggestions() {
- mSearchableInfo = null;
- Context context = getContext();
- if (Settings.System.getInt(context.getContentResolver(),
- Settings.System.SHOW_WEB_SUGGESTIONS,
- 1 /* default on */) == 1) {
- ComponentName webSearchComponent = mSearchManager.getWebSearchActivity();
- if (webSearchComponent != null) {
- mSearchableInfo = mSearchManager.getSearchableInfo(webSearchComponent);
- }
- }
- }
-
private void fixPicasaBookmark() {
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
Cursor cursor = db.rawQuery("SELECT _id FROM bookmarks WHERE " +
if (match == -1) {
throw new IllegalArgumentException("Unknown URL");
}
- if (match == URI_MATCH_GEOLOCATION) {
- throw new UnsupportedOperationException("query() not supported for geolocation");
- }
if (match == URI_MATCH_SUGGEST && mResultsCursor != null) {
Cursor results = mResultsCursor;
mResultsCursor = null;
|| Patterns.WEB_URL.matcher(selectionArgs[0]).matches()) {
return new MySuggestionCursor(c, null, "");
} else {
- // get Google suggest if there is still space in the list
+ // get search suggestions if there is still space in the list
if (myArgs != null && myArgs.length > 1
- && mSearchableInfo != null
+ && mSettings.getShowSearchSuggestions()
&& c.getCount() < (MAX_SUGGESTION_SHORT_ENTRIES - 1)) {
- Cursor sc = mSearchManager.getSuggestions(mSearchableInfo, selectionArgs[0]);
- return new MySuggestionCursor(c, sc, selectionArgs[0]);
+ SearchEngine searchEngine = mSettings.getSearchEngine();
+ if (searchEngine != null && searchEngine.supportsSuggestions()) {
+ Cursor sc = searchEngine.getSuggestions(getContext(), selectionArgs[0]);
+ return new MySuggestionCursor(c, sc, selectionArgs[0]);
+ }
}
return new MySuggestionCursor(c, null, selectionArgs[0]);
}
case URI_MATCH_SUGGEST:
return SearchManager.SUGGEST_MIME_TYPE;
- case URI_MATCH_GEOLOCATION:
- return "vnd.android.cursor.dir/geolocation";
-
default:
throw new IllegalArgumentException("Unknown URL");
}
break;
}
- case URI_MATCH_GEOLOCATION:
- String origin = initialValues.getAsString(Browser.GeolocationColumns.ORIGIN);
- if (TextUtils.isEmpty(origin)) {
- throw new IllegalArgumentException("Empty origin");
- }
- GeolocationPermissions.getInstance().allow(origin);
- // TODO: Should we have one URI per permission?
- uri = Browser.GEOLOCATION_URI;
- break;
-
default:
throw new IllegalArgumentException("Unknown URL");
}
throw new IllegalArgumentException("Unknown URL");
}
- if (match == URI_MATCH_GEOLOCATION) {
- return deleteGeolocation(url, where, whereArgs);
- }
-
// need to know whether it's the bookmarks table for a couple of reasons
boolean isBookmarkTable = (match == URI_MATCH_BOOKMARKS_ID);
String id = null;
return count;
}
- private int deleteGeolocation(Uri uri, String where, String[] whereArgs) {
- if (whereArgs.length != 1) {
- throw new IllegalArgumentException("Bad where arguments");
- }
- String origin = whereArgs[0];
- if (TextUtils.isEmpty(origin)) {
- throw new IllegalArgumentException("Empty origin");
- }
- GeolocationPermissions.getInstance().clear(origin);
- getContext().getContentResolver().notifyChange(Browser.GEOLOCATION_URI, null);
- return 1; // We always return 1, to avoid having to check whether anything was actually removed
- }
-
@Override
public int update(Uri url, ContentValues values, String where,
String[] whereArgs) {