blob: cdab3a35e551eec1533213256e3c96c60f7d8212 [file] [log] [blame]
The Android Open Source Project0c908882009-03-03 19:32:16 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.browser;
18
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -070019import com.google.android.providers.GoogleSettings.Partner;
The Android Open Source Projecta3c0aab2009-03-18 17:39:48 -070020
The Android Open Source Project0c908882009-03-03 19:32:16 -080021import android.app.SearchManager;
Christopher Tate9c0dd8c2009-07-10 17:51:48 -070022import android.backup.BackupManager;
The Android Open Source Project0c908882009-03-03 19:32:16 -080023import android.content.ComponentName;
24import android.content.ContentProvider;
Christopher Tatef0c36f72009-07-28 15:24:05 -070025import android.content.ContentResolver;
The Android Open Source Project0c908882009-03-03 19:32:16 -080026import android.content.ContentUris;
27import android.content.ContentValues;
28import android.content.Context;
29import android.content.Intent;
The Android Open Source Projecta3c0aab2009-03-18 17:39:48 -070030import android.content.SharedPreferences;
The Android Open Source Project0c908882009-03-03 19:32:16 -080031import android.content.UriMatcher;
The Android Open Source Projecta3c0aab2009-03-18 17:39:48 -070032import android.content.SharedPreferences.Editor;
Satish Sampath565505b2009-05-29 15:37:27 +010033import android.content.pm.PackageManager;
34import android.content.pm.ResolveInfo;
The Android Open Source Project0c908882009-03-03 19:32:16 -080035import android.database.AbstractCursor;
Leon Scroggins62b71f72009-06-12 17:51:22 -040036import android.database.ContentObserver;
The Android Open Source Project0c908882009-03-03 19:32:16 -080037import android.database.Cursor;
The Android Open Source Project0c908882009-03-03 19:32:16 -080038import android.database.sqlite.SQLiteDatabase;
Bjorn Bringertbcd20b32009-04-29 21:52:09 +010039import android.database.sqlite.SQLiteOpenHelper;
The Android Open Source Project0c908882009-03-03 19:32:16 -080040import android.net.Uri;
Leon Scroggins62b71f72009-06-12 17:51:22 -040041import android.os.Handler;
The Android Open Source Projecta3c0aab2009-03-18 17:39:48 -070042import android.preference.PreferenceManager;
The Android Open Source Project0c908882009-03-03 19:32:16 -080043import android.provider.Browser;
Leon Scroggins62b71f72009-06-12 17:51:22 -040044import android.provider.Settings;
Christopher Tatef0c36f72009-07-28 15:24:05 -070045import android.provider.Browser.BookmarkColumns;
The Android Open Source Project0c908882009-03-03 19:32:16 -080046import android.server.search.SearchableInfo;
Mike LeBeau21beb132009-05-13 14:57:50 -070047import android.text.TextUtils;
The Android Open Source Project0c908882009-03-03 19:32:16 -080048import android.text.util.Regex;
Bjorn Bringertbcd20b32009-04-29 21:52:09 +010049import android.util.Log;
Mike LeBeauc42f81b2009-05-14 15:04:19 -070050import android.util.TypedValue;
Bjorn Bringertbcd20b32009-04-29 21:52:09 +010051
52import java.util.Date;
Mike LeBeauc42f81b2009-05-14 15:04:19 -070053import java.util.regex.Matcher;
54import java.util.regex.Pattern;
The Android Open Source Project0c908882009-03-03 19:32:16 -080055
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -070056
The Android Open Source Project0c908882009-03-03 19:32:16 -080057public class BrowserProvider extends ContentProvider {
58
59 private SQLiteOpenHelper mOpenHelper;
Christopher Tate9c0dd8c2009-07-10 17:51:48 -070060 private BackupManager mBackupManager;
The Android Open Source Project0c908882009-03-03 19:32:16 -080061 private static final String sDatabaseName = "browser.db";
62 private static final String TAG = "BrowserProvider";
63 private static final String ORDER_BY = "visits DESC, date DESC";
64
The Android Open Source Projecta3c0aab2009-03-18 17:39:48 -070065 private static final String PICASA_URL = "http://picasaweb.google.com/m/" +
66 "viewer?source=androidclient";
67
The Android Open Source Project0c908882009-03-03 19:32:16 -080068 private static final String[] TABLE_NAMES = new String[] {
69 "bookmarks", "searches"
70 };
71 private static final String[] SUGGEST_PROJECTION = new String[] {
72 "_id", "url", "title", "bookmark"
73 };
Satish Sampath565505b2009-05-29 15:37:27 +010074 private static final String SUGGEST_SELECTION =
Leon Scrogginsbd359cc2009-05-26 15:57:35 -040075 "url LIKE ? OR url LIKE ? OR url LIKE ? OR url LIKE ?"
76 + " OR title LIKE ?";
77 private String[] SUGGEST_ARGS = new String[5];
The Android Open Source Project0c908882009-03-03 19:32:16 -080078
79 // shared suggestion array index, make sure to match COLUMNS
80 private static final int SUGGEST_COLUMN_INTENT_ACTION_ID = 1;
81 private static final int SUGGEST_COLUMN_INTENT_DATA_ID = 2;
82 private static final int SUGGEST_COLUMN_TEXT_1_ID = 3;
83 private static final int SUGGEST_COLUMN_TEXT_2_ID = 4;
84 private static final int SUGGEST_COLUMN_ICON_1_ID = 5;
85 private static final int SUGGEST_COLUMN_ICON_2_ID = 6;
86 private static final int SUGGEST_COLUMN_QUERY_ID = 7;
Mike LeBeau1ef26a32009-05-13 20:11:00 -070087 private static final int SUGGEST_COLUMN_FORMAT = 8;
The Android Open Source Project0c908882009-03-03 19:32:16 -080088
89 // shared suggestion columns
90 private static final String[] COLUMNS = new String[] {
91 "_id",
92 SearchManager.SUGGEST_COLUMN_INTENT_ACTION,
93 SearchManager.SUGGEST_COLUMN_INTENT_DATA,
94 SearchManager.SUGGEST_COLUMN_TEXT_1,
95 SearchManager.SUGGEST_COLUMN_TEXT_2,
96 SearchManager.SUGGEST_COLUMN_ICON_1,
97 SearchManager.SUGGEST_COLUMN_ICON_2,
Mike LeBeau1ef26a32009-05-13 20:11:00 -070098 SearchManager.SUGGEST_COLUMN_QUERY,
99 SearchManager.SUGGEST_COLUMN_FORMAT};
The Android Open Source Project0c908882009-03-03 19:32:16 -0800100
101 private static final int MAX_SUGGESTION_SHORT_ENTRIES = 3;
102 private static final int MAX_SUGGESTION_LONG_ENTRIES = 6;
Leon Scroggins31887fd2009-05-18 16:58:08 -0400103 private static final String MAX_SUGGESTION_LONG_ENTRIES_STRING =
104 Integer.valueOf(MAX_SUGGESTION_LONG_ENTRIES).toString();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800105
106 // make sure that these match the index of TABLE_NAMES
107 private static final int URI_MATCH_BOOKMARKS = 0;
108 private static final int URI_MATCH_SEARCHES = 1;
109 // (id % 10) should match the table name index
110 private static final int URI_MATCH_BOOKMARKS_ID = 10;
111 private static final int URI_MATCH_SEARCHES_ID = 11;
112 //
113 private static final int URI_MATCH_SUGGEST = 20;
Bjorn Bringert346dafb2009-04-29 21:41:47 +0100114 private static final int URI_MATCH_BOOKMARKS_SUGGEST = 21;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800115
116 private static final UriMatcher URI_MATCHER;
117
118 static {
119 URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
120 URI_MATCHER.addURI("browser", TABLE_NAMES[URI_MATCH_BOOKMARKS],
121 URI_MATCH_BOOKMARKS);
122 URI_MATCHER.addURI("browser", TABLE_NAMES[URI_MATCH_BOOKMARKS] + "/#",
123 URI_MATCH_BOOKMARKS_ID);
124 URI_MATCHER.addURI("browser", TABLE_NAMES[URI_MATCH_SEARCHES],
125 URI_MATCH_SEARCHES);
126 URI_MATCHER.addURI("browser", TABLE_NAMES[URI_MATCH_SEARCHES] + "/#",
127 URI_MATCH_SEARCHES_ID);
128 URI_MATCHER.addURI("browser", SearchManager.SUGGEST_URI_PATH_QUERY,
129 URI_MATCH_SUGGEST);
Bjorn Bringert346dafb2009-04-29 21:41:47 +0100130 URI_MATCHER.addURI("browser",
131 TABLE_NAMES[URI_MATCH_BOOKMARKS] + "/" + SearchManager.SUGGEST_URI_PATH_QUERY,
132 URI_MATCH_BOOKMARKS_SUGGEST);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800133 }
134
135 // 1 -> 2 add cache table
136 // 2 -> 3 update history table
137 // 3 -> 4 add passwords table
138 // 4 -> 5 add settings table
139 // 5 -> 6 ?
140 // 6 -> 7 ?
141 // 7 -> 8 drop proxy table
142 // 8 -> 9 drop settings table
143 // 9 -> 10 add form_urls and form_data
144 // 10 -> 11 add searches table
145 // 11 -> 12 modify cache table
146 // 12 -> 13 modify cache table
147 // 13 -> 14 correspond with Google Bookmarks schema
148 // 14 -> 15 move couple of tables to either browser private database or webview database
149 // 15 -> 17 Set it up for the SearchManager
150 // 17 -> 18 Added favicon in bookmarks table for Home shortcuts
151 // 18 -> 19 Remove labels table
Leon Scrogginsb6b7f9e2009-06-18 12:05:28 -0400152 // 19 -> 20 Added thumbnail
153 private static final int DATABASE_VERSION = 20;
Satish Sampath565505b2009-05-29 15:37:27 +0100154
Mike LeBeauc42f81b2009-05-14 15:04:19 -0700155 // Regular expression which matches http://, followed by some stuff, followed by
156 // optionally a trailing slash, all matched as separate groups.
157 private static final Pattern STRIP_URL_PATTERN = Pattern.compile("^(http://)(.*?)(/$)?");
Satish Sampath565505b2009-05-29 15:37:27 +0100158
Bjorn Bringertd8b0ad22009-06-22 10:36:29 +0100159 private SearchManager mSearchManager;
160
Satish Sampath60d24e22009-07-09 16:46:08 +0100161 // The ID of the ColorStateList to be applied to urls of website suggestions, as derived from
Mike LeBeauc42f81b2009-05-14 15:04:19 -0700162 // the current theme. This is not set until/unless beautifyUrl is called, at which point
163 // this variable caches the color value.
Satish Sampath60d24e22009-07-09 16:46:08 +0100164 private static String mSearchUrlColorId;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800165
166 public BrowserProvider() {
167 }
Satish Sampath565505b2009-05-29 15:37:27 +0100168
The Android Open Source Project0c908882009-03-03 19:32:16 -0800169
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700170 private static CharSequence replaceSystemPropertyInString(Context context, CharSequence srcString) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800171 StringBuffer sb = new StringBuffer();
172 int lastCharLoc = 0;
Satish Sampath565505b2009-05-29 15:37:27 +0100173
Ramanan Rajeswaran378e5722009-07-01 08:46:58 -0700174 final String client_id = Partner.getString(context.getContentResolver(),
175 Partner.CLIENT_ID, "android-google");
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700176
The Android Open Source Project0c908882009-03-03 19:32:16 -0800177 for (int i = 0; i < srcString.length(); ++i) {
178 char c = srcString.charAt(i);
179 if (c == '{') {
180 sb.append(srcString.subSequence(lastCharLoc, i));
181 lastCharLoc = i;
182 inner:
183 for (int j = i; j < srcString.length(); ++j) {
184 char k = srcString.charAt(j);
185 if (k == '}') {
186 String propertyKeyValue = srcString.subSequence(i + 1, j).toString();
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700187 if (propertyKeyValue.equals("CLIENT_ID")) {
188 sb.append(client_id);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800189 } else {
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700190 sb.append("unknown");
The Android Open Source Project0c908882009-03-03 19:32:16 -0800191 }
192 lastCharLoc = j + 1;
193 i = j;
194 break inner;
195 }
196 }
197 }
198 }
199 if (srcString.length() - lastCharLoc > 0) {
200 // Put on the tail, if there is one
201 sb.append(srcString.subSequence(lastCharLoc, srcString.length()));
202 }
203 return sb;
204 }
205
206 private static class DatabaseHelper extends SQLiteOpenHelper {
207 private Context mContext;
208
209 public DatabaseHelper(Context context) {
210 super(context, sDatabaseName, null, DATABASE_VERSION);
211 mContext = context;
212 }
213
214 @Override
215 public void onCreate(SQLiteDatabase db) {
216 db.execSQL("CREATE TABLE bookmarks (" +
217 "_id INTEGER PRIMARY KEY," +
218 "title TEXT," +
219 "url TEXT," +
220 "visits INTEGER," +
221 "date LONG," +
222 "created LONG," +
223 "description TEXT," +
224 "bookmark INTEGER," +
Leon Scrogginsb6b7f9e2009-06-18 12:05:28 -0400225 "favicon BLOB DEFAULT NULL," +
226 "thumbnail BLOB DEFAULT NULL" +
The Android Open Source Project0c908882009-03-03 19:32:16 -0800227 ");");
228
229 final CharSequence[] bookmarks = mContext.getResources()
230 .getTextArray(R.array.bookmarks);
231 int size = bookmarks.length;
232 try {
233 for (int i = 0; i < size; i = i + 2) {
Ramanan Rajeswarandd4f4292009-03-24 20:41:19 -0700234 CharSequence bookmarkDestination = replaceSystemPropertyInString(mContext, bookmarks[i + 1]);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800235 db.execSQL("INSERT INTO bookmarks (title, url, visits, " +
236 "date, created, bookmark)" + " VALUES('" +
Satish Sampath565505b2009-05-29 15:37:27 +0100237 bookmarks[i] + "', '" + bookmarkDestination +
The Android Open Source Project0c908882009-03-03 19:32:16 -0800238 "', 0, 0, 0, 1);");
239 }
240 } catch (ArrayIndexOutOfBoundsException e) {
241 }
242
243 db.execSQL("CREATE TABLE searches (" +
244 "_id INTEGER PRIMARY KEY," +
245 "search TEXT," +
246 "date LONG" +
247 ");");
248 }
249
250 @Override
251 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
252 Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
Leon Scrogginsb6b7f9e2009-06-18 12:05:28 -0400253 + newVersion);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800254 if (oldVersion == 18) {
255 db.execSQL("DROP TABLE IF EXISTS labels");
Leon Scrogginsb6b7f9e2009-06-18 12:05:28 -0400256 }
257 if (oldVersion <= 19) {
258 db.execSQL("ALTER TABLE bookmarks ADD COLUMN thumbnail BLOB DEFAULT NULL;");
The Android Open Source Project0c908882009-03-03 19:32:16 -0800259 } else {
260 db.execSQL("DROP TABLE IF EXISTS bookmarks");
261 db.execSQL("DROP TABLE IF EXISTS searches");
262 onCreate(db);
263 }
264 }
265 }
266
267 @Override
268 public boolean onCreate() {
The Android Open Source Projecta3c0aab2009-03-18 17:39:48 -0700269 final Context context = getContext();
270 mOpenHelper = new DatabaseHelper(context);
Christopher Tate9c0dd8c2009-07-10 17:51:48 -0700271 mBackupManager = new BackupManager(context);
Satish Sampath565505b2009-05-29 15:37:27 +0100272 // we added "picasa web album" into default bookmarks for version 19.
The Android Open Source Projecta3c0aab2009-03-18 17:39:48 -0700273 // To avoid erasing the bookmark table, we added it explicitly for
274 // version 18 and 19 as in the other cases, we will erase the table.
275 if (DATABASE_VERSION == 18 || DATABASE_VERSION == 19) {
276 SharedPreferences p = PreferenceManager
277 .getDefaultSharedPreferences(context);
278 boolean fix = p.getBoolean("fix_picasa", true);
279 if (fix) {
280 fixPicasaBookmark();
281 Editor ed = p.edit();
282 ed.putBoolean("fix_picasa", false);
283 ed.commit();
284 }
285 }
Bjorn Bringertd8b0ad22009-06-22 10:36:29 +0100286 mSearchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
Leon Scroggins62b71f72009-06-12 17:51:22 -0400287 mShowWebSuggestionsSettingChangeObserver
288 = new ShowWebSuggestionsSettingChangeObserver();
289 context.getContentResolver().registerContentObserver(
290 Settings.System.getUriFor(
291 Settings.System.SHOW_WEB_SUGGESTIONS),
292 true, mShowWebSuggestionsSettingChangeObserver);
293 updateShowWebSuggestions();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800294 return true;
295 }
296
Leon Scroggins62b71f72009-06-12 17:51:22 -0400297 /**
298 * This Observer will ensure that if the user changes the system
299 * setting of whether to display web suggestions, we will
300 * change accordingly.
301 */
302 /* package */ class ShowWebSuggestionsSettingChangeObserver
303 extends ContentObserver {
304 public ShowWebSuggestionsSettingChangeObserver() {
305 super(new Handler());
306 }
307
308 @Override
309 public void onChange(boolean selfChange) {
310 updateShowWebSuggestions();
311 }
312 }
313
314 private ShowWebSuggestionsSettingChangeObserver
315 mShowWebSuggestionsSettingChangeObserver;
316
317 // If non-null, then the system is set to show web suggestions,
318 // and this is the SearchableInfo to use to get them.
319 private SearchableInfo mSearchableInfo;
320
321 /**
322 * Check the system settings to see whether web suggestions are
323 * allowed. If so, store the SearchableInfo to grab suggestions
324 * while the user is typing.
325 */
326 private void updateShowWebSuggestions() {
327 mSearchableInfo = null;
328 Context context = getContext();
329 if (Settings.System.getInt(context.getContentResolver(),
330 Settings.System.SHOW_WEB_SUGGESTIONS,
331 1 /* default on */) == 1) {
332 Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
333 intent.addCategory(Intent.CATEGORY_DEFAULT);
334 ResolveInfo info = context.getPackageManager().resolveActivity(
335 intent, PackageManager.MATCH_DEFAULT_ONLY);
336 if (info != null) {
337 ComponentName googleSearchComponent =
338 new ComponentName(info.activityInfo.packageName,
339 info.activityInfo.name);
Bjorn Bringertd8b0ad22009-06-22 10:36:29 +0100340 mSearchableInfo = mSearchManager.getSearchableInfo(
Leon Scroggins62b71f72009-06-12 17:51:22 -0400341 googleSearchComponent, false);
342 }
343 }
344 }
345
The Android Open Source Projecta3c0aab2009-03-18 17:39:48 -0700346 private void fixPicasaBookmark() {
347 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
348 Cursor cursor = db.rawQuery("SELECT _id FROM bookmarks WHERE " +
349 "bookmark = 1 AND url = ?", new String[] { PICASA_URL });
350 try {
351 if (!cursor.moveToFirst()) {
352 // set "created" so that it will be on the top of the list
353 db.execSQL("INSERT INTO bookmarks (title, url, visits, " +
354 "date, created, bookmark)" + " VALUES('" +
355 getContext().getString(R.string.picasa) + "', '"
356 + PICASA_URL + "', 0, 0, " + new Date().getTime()
357 + ", 1);");
358 }
359 } finally {
360 if (cursor != null) {
361 cursor.close();
362 }
363 }
364 }
365
The Android Open Source Project0c908882009-03-03 19:32:16 -0800366 /*
367 * Subclass AbstractCursor so we can combine multiple Cursors and add
368 * "Google Search".
369 * Here are the rules.
Satish Sampath565505b2009-05-29 15:37:27 +0100370 * 1. We only have MAX_SUGGESTION_LONG_ENTRIES in the list plus
The Android Open Source Project0c908882009-03-03 19:32:16 -0800371 * "Google Search";
Satish Sampath565505b2009-05-29 15:37:27 +0100372 * 2. If bookmark/history entries are less than
The Android Open Source Project0c908882009-03-03 19:32:16 -0800373 * (MAX_SUGGESTION_SHORT_ENTRIES -1), we include Google suggest.
374 */
375 private class MySuggestionCursor extends AbstractCursor {
376 private Cursor mHistoryCursor;
377 private Cursor mSuggestCursor;
378 private int mHistoryCount;
379 private int mSuggestionCount;
380 private boolean mBeyondCursor;
381 private String mString;
Satish Sampath565505b2009-05-29 15:37:27 +0100382 private int mSuggestText1Id;
383 private int mSuggestText2Id;
384 private int mSuggestQueryId;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800385
386 public MySuggestionCursor(Cursor hc, Cursor sc, String string) {
387 mHistoryCursor = hc;
388 mSuggestCursor = sc;
389 mHistoryCount = hc.getCount();
390 mSuggestionCount = sc != null ? sc.getCount() : 0;
391 if (mSuggestionCount > (MAX_SUGGESTION_LONG_ENTRIES - mHistoryCount)) {
392 mSuggestionCount = MAX_SUGGESTION_LONG_ENTRIES - mHistoryCount;
393 }
394 mString = string;
395 mBeyondCursor = false;
Satish Sampath565505b2009-05-29 15:37:27 +0100396
397 // Some web suggest providers only give suggestions and have no description string for
398 // items. The order of the result columns may be different as well. So retrieve the
399 // column indices for the fields we need now and check before using below.
400 if (mSuggestCursor == null) {
401 mSuggestText1Id = -1;
402 mSuggestText2Id = -1;
403 mSuggestQueryId = -1;
404 } else {
405 mSuggestText1Id = mSuggestCursor.getColumnIndex(
406 SearchManager.SUGGEST_COLUMN_TEXT_1);
407 mSuggestText2Id = mSuggestCursor.getColumnIndex(
408 SearchManager.SUGGEST_COLUMN_TEXT_2);
409 mSuggestQueryId = mSuggestCursor.getColumnIndex(
410 SearchManager.SUGGEST_COLUMN_QUERY);
411 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800412 }
413
414 @Override
415 public boolean onMove(int oldPosition, int newPosition) {
416 if (mHistoryCursor == null) {
417 return false;
418 }
419 if (mHistoryCount > newPosition) {
420 mHistoryCursor.moveToPosition(newPosition);
421 mBeyondCursor = false;
422 } else if (mHistoryCount + mSuggestionCount > newPosition) {
423 mSuggestCursor.moveToPosition(newPosition - mHistoryCount);
424 mBeyondCursor = false;
425 } else {
426 mBeyondCursor = true;
427 }
428 return true;
429 }
430
431 @Override
432 public int getCount() {
433 if (mString.length() > 0) {
434 return mHistoryCount + mSuggestionCount + 1;
435 } else {
436 return mHistoryCount + mSuggestionCount;
437 }
438 }
439
440 @Override
441 public String[] getColumnNames() {
442 return COLUMNS;
443 }
Satish Sampath565505b2009-05-29 15:37:27 +0100444
The Android Open Source Project0c908882009-03-03 19:32:16 -0800445 @Override
446 public String getString(int columnIndex) {
447 if ((mPos != -1 && mHistoryCursor != null)) {
448 switch(columnIndex) {
449 case SUGGEST_COLUMN_INTENT_ACTION_ID:
450 if (mHistoryCount > mPos) {
451 return Intent.ACTION_VIEW;
452 } else {
453 return Intent.ACTION_SEARCH;
454 }
455
456 case SUGGEST_COLUMN_INTENT_DATA_ID:
457 if (mHistoryCount > mPos) {
458 return mHistoryCursor.getString(1);
459 } else {
460 return null;
461 }
462
463 case SUGGEST_COLUMN_TEXT_1_ID:
464 if (mHistoryCount > mPos) {
Mike LeBeau1ef26a32009-05-13 20:11:00 -0700465 return getHistoryTitle();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800466 } else if (!mBeyondCursor) {
Satish Sampath565505b2009-05-29 15:37:27 +0100467 if (mSuggestText1Id == -1) return null;
468 return mSuggestCursor.getString(mSuggestText1Id);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800469 } else {
470 return mString;
471 }
472
473 case SUGGEST_COLUMN_TEXT_2_ID:
474 if (mHistoryCount > mPos) {
Mike LeBeau1ef26a32009-05-13 20:11:00 -0700475 return getHistorySubtitle();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800476 } else if (!mBeyondCursor) {
Satish Sampath565505b2009-05-29 15:37:27 +0100477 if (mSuggestText2Id == -1) return null;
478 return mSuggestCursor.getString(mSuggestText2Id);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800479 } else {
Mike LeBeau1ef26a32009-05-13 20:11:00 -0700480 return getContext().getString(R.string.search_the_web);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800481 }
482
483 case SUGGEST_COLUMN_ICON_1_ID:
484 if (mHistoryCount > mPos) {
485 if (mHistoryCursor.getInt(3) == 1) {
Leon Scroggins31887fd2009-05-18 16:58:08 -0400486 return Integer.valueOf(
The Android Open Source Project0c908882009-03-03 19:32:16 -0800487 R.drawable.ic_search_category_bookmark)
488 .toString();
489 } else {
Leon Scroggins31887fd2009-05-18 16:58:08 -0400490 return Integer.valueOf(
The Android Open Source Project0c908882009-03-03 19:32:16 -0800491 R.drawable.ic_search_category_history)
492 .toString();
493 }
494 } else {
Leon Scroggins31887fd2009-05-18 16:58:08 -0400495 return Integer.valueOf(
The Android Open Source Project0c908882009-03-03 19:32:16 -0800496 R.drawable.ic_search_category_suggest)
497 .toString();
498 }
499
500 case SUGGEST_COLUMN_ICON_2_ID:
Leon Scroggins31887fd2009-05-18 16:58:08 -0400501 return "0";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800502
503 case SUGGEST_COLUMN_QUERY_ID:
504 if (mHistoryCount > mPos) {
Mike LeBeau2af73052009-06-23 17:36:59 -0700505 // Return the url in the intent query column. This is ignored
506 // within the browser because our searchable is set to
507 // android:searchMode="queryRewriteFromData", but it is used by
508 // global search for query rewriting.
509 return mHistoryCursor.getString(1);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800510 } else if (!mBeyondCursor) {
Satish Sampath565505b2009-05-29 15:37:27 +0100511 if (mSuggestQueryId == -1) return null;
512 return mSuggestCursor.getString(mSuggestQueryId);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800513 } else {
514 return mString;
515 }
Satish Sampath565505b2009-05-29 15:37:27 +0100516
Mike LeBeau1ef26a32009-05-13 20:11:00 -0700517 case SUGGEST_COLUMN_FORMAT:
518 return "html";
The Android Open Source Project0c908882009-03-03 19:32:16 -0800519 }
520 }
521 return null;
522 }
523
524 @Override
525 public double getDouble(int column) {
526 throw new UnsupportedOperationException();
527 }
528
529 @Override
530 public float getFloat(int column) {
531 throw new UnsupportedOperationException();
532 }
533
534 @Override
535 public int getInt(int column) {
536 throw new UnsupportedOperationException();
537 }
538
539 @Override
540 public long getLong(int column) {
541 if ((mPos != -1) && column == 0) {
542 return mPos; // use row# as the _Id
543 }
544 throw new UnsupportedOperationException();
545 }
546
547 @Override
548 public short getShort(int column) {
549 throw new UnsupportedOperationException();
550 }
551
552 @Override
553 public boolean isNull(int column) {
554 throw new UnsupportedOperationException();
555 }
556
557 // TODO Temporary change, finalize after jq's changes go in
558 public void deactivate() {
559 if (mHistoryCursor != null) {
560 mHistoryCursor.deactivate();
561 }
562 if (mSuggestCursor != null) {
563 mSuggestCursor.deactivate();
564 }
565 super.deactivate();
566 }
567
568 public boolean requery() {
569 return (mHistoryCursor != null ? mHistoryCursor.requery() : false) |
570 (mSuggestCursor != null ? mSuggestCursor.requery() : false);
571 }
572
573 // TODO Temporary change, finalize after jq's changes go in
574 public void close() {
575 super.close();
576 if (mHistoryCursor != null) {
577 mHistoryCursor.close();
578 mHistoryCursor = null;
579 }
580 if (mSuggestCursor != null) {
581 mSuggestCursor.close();
582 mSuggestCursor = null;
583 }
584 }
Satish Sampath565505b2009-05-29 15:37:27 +0100585
Mike LeBeau21beb132009-05-13 14:57:50 -0700586 /**
587 * Provides the title (text line 1) for a browser suggestion, which should be the
588 * webpage title. If the webpage title is empty, returns the stripped url instead.
Satish Sampath565505b2009-05-29 15:37:27 +0100589 *
Mike LeBeau21beb132009-05-13 14:57:50 -0700590 * @return the title string to use
591 */
Mike LeBeau1ef26a32009-05-13 20:11:00 -0700592 private String getHistoryTitle() {
593 String title = mHistoryCursor.getString(2 /* webpage title */);
Mike LeBeau21beb132009-05-13 14:57:50 -0700594 if (TextUtils.isEmpty(title) || TextUtils.getTrimmedLength(title) == 0) {
Mike LeBeau1ef26a32009-05-13 20:11:00 -0700595 title = beautifyUrl(mHistoryCursor.getString(1 /* url */));
Mike LeBeau21beb132009-05-13 14:57:50 -0700596 }
597 return title;
598 }
Satish Sampath565505b2009-05-29 15:37:27 +0100599
Mike LeBeau21beb132009-05-13 14:57:50 -0700600 /**
601 * Provides the subtitle (text line 2) for a browser suggestion, which should be the
602 * webpage url. If the webpage title is empty, then the url should go in the title
603 * instead, and the subtitle should be empty, so this would return null.
Satish Sampath565505b2009-05-29 15:37:27 +0100604 *
Mike LeBeau21beb132009-05-13 14:57:50 -0700605 * @return the subtitle string to use, or null if none
606 */
Mike LeBeau1ef26a32009-05-13 20:11:00 -0700607 private String getHistorySubtitle() {
608 String title = mHistoryCursor.getString(2 /* webpage title */);
Mike LeBeau21beb132009-05-13 14:57:50 -0700609 if (TextUtils.isEmpty(title) || TextUtils.getTrimmedLength(title) == 0) {
610 return null;
611 } else {
Mike LeBeau1ef26a32009-05-13 20:11:00 -0700612 return beautifyUrl(mHistoryCursor.getString(1 /* url */));
Mike LeBeau21beb132009-05-13 14:57:50 -0700613 }
614 }
Satish Sampath565505b2009-05-29 15:37:27 +0100615
Mike LeBeau21beb132009-05-13 14:57:50 -0700616 /**
Mike LeBeauc42f81b2009-05-14 15:04:19 -0700617 * Strips "http://" from the beginning of a url and "/" from the end,
618 * and adds html formatting to make it green.
Mike LeBeau21beb132009-05-13 14:57:50 -0700619 */
Mike LeBeau1ef26a32009-05-13 20:11:00 -0700620 private String beautifyUrl(String url) {
Satish Sampath60d24e22009-07-09 16:46:08 +0100621 if (mSearchUrlColorId == null) {
Mike LeBeauc42f81b2009-05-14 15:04:19 -0700622 // Get the color used for this purpose from the current theme.
623 TypedValue colorValue = new TypedValue();
624 getContext().getTheme().resolveAttribute(
625 com.android.internal.R.attr.textColorSearchUrl, colorValue, true);
Satish Sampath60d24e22009-07-09 16:46:08 +0100626 mSearchUrlColorId = Integer.toString(colorValue.resourceId);
Mike LeBeau21beb132009-05-13 14:57:50 -0700627 }
Satish Sampath565505b2009-05-29 15:37:27 +0100628
Satish Sampath60d24e22009-07-09 16:46:08 +0100629 return "<font color=\"@" + mSearchUrlColorId + "\">" + stripUrl(url) + "</font>";
Mike LeBeau21beb132009-05-13 14:57:50 -0700630 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800631 }
632
633 @Override
634 public Cursor query(Uri url, String[] projectionIn, String selection,
Satish Sampath565505b2009-05-29 15:37:27 +0100635 String[] selectionArgs, String sortOrder)
The Android Open Source Project0c908882009-03-03 19:32:16 -0800636 throws IllegalStateException {
637 SQLiteDatabase db = mOpenHelper.getReadableDatabase();
638
639 int match = URI_MATCHER.match(url);
640 if (match == -1) {
641 throw new IllegalArgumentException("Unknown URL");
642 }
643
Bjorn Bringert346dafb2009-04-29 21:41:47 +0100644 if (match == URI_MATCH_SUGGEST || match == URI_MATCH_BOOKMARKS_SUGGEST) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800645 String suggestSelection;
646 String [] myArgs;
647 if (selectionArgs[0] == null || selectionArgs[0].equals("")) {
648 suggestSelection = null;
649 myArgs = null;
650 } else {
651 String like = selectionArgs[0] + "%";
Leon Scrogginsfaa15db2009-04-03 10:16:06 -0700652 if (selectionArgs[0].startsWith("http")
653 || selectionArgs[0].startsWith("file")) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800654 myArgs = new String[1];
655 myArgs[0] = like;
656 suggestSelection = selection;
657 } else {
658 SUGGEST_ARGS[0] = "http://" + like;
659 SUGGEST_ARGS[1] = "http://www." + like;
660 SUGGEST_ARGS[2] = "https://" + like;
661 SUGGEST_ARGS[3] = "https://www." + like;
Leon Scrogginsbd359cc2009-05-26 15:57:35 -0400662 // To match against titles.
663 SUGGEST_ARGS[4] = like;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800664 myArgs = SUGGEST_ARGS;
665 suggestSelection = SUGGEST_SELECTION;
666 }
667 }
668
669 Cursor c = db.query(TABLE_NAMES[URI_MATCH_BOOKMARKS],
670 SUGGEST_PROJECTION, suggestSelection, myArgs, null, null,
Leon Scroggins31887fd2009-05-18 16:58:08 -0400671 ORDER_BY, MAX_SUGGESTION_LONG_ENTRIES_STRING);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800672
Bjorn Bringert346dafb2009-04-29 21:41:47 +0100673 if (match == URI_MATCH_BOOKMARKS_SUGGEST
674 || Regex.WEB_URL_PATTERN.matcher(selectionArgs[0]).matches()) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800675 return new MySuggestionCursor(c, null, "");
676 } else {
677 // get Google suggest if there is still space in the list
678 if (myArgs != null && myArgs.length > 1
Leon Scroggins62b71f72009-06-12 17:51:22 -0400679 && mSearchableInfo != null
The Android Open Source Project0c908882009-03-03 19:32:16 -0800680 && c.getCount() < (MAX_SUGGESTION_SHORT_ENTRIES - 1)) {
Bjorn Bringertd8b0ad22009-06-22 10:36:29 +0100681 Cursor sc = mSearchManager.getSuggestions(mSearchableInfo, selectionArgs[0]);
Leon Scroggins62b71f72009-06-12 17:51:22 -0400682 return new MySuggestionCursor(c, sc, selectionArgs[0]);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800683 }
684 return new MySuggestionCursor(c, null, selectionArgs[0]);
685 }
686 }
687
688 String[] projection = null;
689 if (projectionIn != null && projectionIn.length > 0) {
690 projection = new String[projectionIn.length + 1];
691 System.arraycopy(projectionIn, 0, projection, 0, projectionIn.length);
692 projection[projectionIn.length] = "_id AS _id";
693 }
694
695 StringBuilder whereClause = new StringBuilder(256);
696 if (match == URI_MATCH_BOOKMARKS_ID || match == URI_MATCH_SEARCHES_ID) {
697 whereClause.append("(_id = ").append(url.getPathSegments().get(1))
698 .append(")");
699 }
700
701 // Tack on the user's selection, if present
702 if (selection != null && selection.length() > 0) {
703 if (whereClause.length() > 0) {
704 whereClause.append(" AND ");
705 }
706
707 whereClause.append('(');
708 whereClause.append(selection);
709 whereClause.append(')');
710 }
711 Cursor c = db.query(TABLE_NAMES[match % 10], projection,
712 whereClause.toString(), selectionArgs, null, null, sortOrder,
713 null);
714 c.setNotificationUri(getContext().getContentResolver(), url);
715 return c;
716 }
717
718 @Override
719 public String getType(Uri url) {
720 int match = URI_MATCHER.match(url);
721 switch (match) {
722 case URI_MATCH_BOOKMARKS:
723 return "vnd.android.cursor.dir/bookmark";
724
725 case URI_MATCH_BOOKMARKS_ID:
726 return "vnd.android.cursor.item/bookmark";
727
728 case URI_MATCH_SEARCHES:
729 return "vnd.android.cursor.dir/searches";
730
731 case URI_MATCH_SEARCHES_ID:
732 return "vnd.android.cursor.item/searches";
733
734 case URI_MATCH_SUGGEST:
735 return SearchManager.SUGGEST_MIME_TYPE;
736
737 default:
738 throw new IllegalArgumentException("Unknown URL");
739 }
740 }
741
742 @Override
743 public Uri insert(Uri url, ContentValues initialValues) {
Christopher Tate9c0dd8c2009-07-10 17:51:48 -0700744 boolean isBookmarkTable = false;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800745 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
746
747 int match = URI_MATCHER.match(url);
748 Uri uri = null;
749 switch (match) {
750 case URI_MATCH_BOOKMARKS: {
751 // Insert into the bookmarks table
752 long rowID = db.insert(TABLE_NAMES[URI_MATCH_BOOKMARKS], "url",
753 initialValues);
754 if (rowID > 0) {
755 uri = ContentUris.withAppendedId(Browser.BOOKMARKS_URI,
756 rowID);
757 }
Christopher Tate9c0dd8c2009-07-10 17:51:48 -0700758 isBookmarkTable = true;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800759 break;
760 }
761
762 case URI_MATCH_SEARCHES: {
763 // Insert into the searches table
764 long rowID = db.insert(TABLE_NAMES[URI_MATCH_SEARCHES], "url",
765 initialValues);
766 if (rowID > 0) {
767 uri = ContentUris.withAppendedId(Browser.SEARCHES_URI,
768 rowID);
769 }
770 break;
771 }
772
773 default:
774 throw new IllegalArgumentException("Unknown URL");
775 }
776
777 if (uri == null) {
778 throw new IllegalArgumentException("Unknown URL");
779 }
780 getContext().getContentResolver().notifyChange(uri, null);
Christopher Tate9c0dd8c2009-07-10 17:51:48 -0700781
Christopher Tatef0c36f72009-07-28 15:24:05 -0700782 // Back up the new bookmark set if we just inserted one.
783 // A row created when bookmarks are added from scratch will have
784 // bookmark=1 in the initial value set.
785 if (isBookmarkTable
786 && initialValues.containsKey(BookmarkColumns.BOOKMARK)
787 && initialValues.getAsInteger(BookmarkColumns.BOOKMARK) != 0) {
Christopher Tate9c0dd8c2009-07-10 17:51:48 -0700788 mBackupManager.dataChanged();
789 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800790 return uri;
791 }
792
793 @Override
794 public int delete(Uri url, String where, String[] whereArgs) {
795 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
796
797 int match = URI_MATCHER.match(url);
798 if (match == -1 || match == URI_MATCH_SUGGEST) {
799 throw new IllegalArgumentException("Unknown URL");
800 }
801
Christopher Tatef0c36f72009-07-28 15:24:05 -0700802 // need to know whether it's the bookmarks table for a couple of reasons
Christopher Tate9c0dd8c2009-07-10 17:51:48 -0700803 boolean isBookmarkTable = (match == URI_MATCH_BOOKMARKS_ID);
Christopher Tatef0c36f72009-07-28 15:24:05 -0700804 String id = null;
Christopher Tate9c0dd8c2009-07-10 17:51:48 -0700805
806 if (isBookmarkTable || match == URI_MATCH_SEARCHES_ID) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800807 StringBuilder sb = new StringBuilder();
808 if (where != null && where.length() > 0) {
809 sb.append("( ");
810 sb.append(where);
811 sb.append(" ) AND ");
812 }
Christopher Tatef0c36f72009-07-28 15:24:05 -0700813 id = url.getPathSegments().get(1);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800814 sb.append("_id = ");
Christopher Tatef0c36f72009-07-28 15:24:05 -0700815 sb.append(id);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800816 where = sb.toString();
817 }
818
Christopher Tatef0c36f72009-07-28 15:24:05 -0700819 ContentResolver cr = getContext().getContentResolver();
Christopher Tate9c0dd8c2009-07-10 17:51:48 -0700820
Christopher Tatef0c36f72009-07-28 15:24:05 -0700821 // we'lll need to back up the bookmark set if we are about to delete one
Christopher Tate9c0dd8c2009-07-10 17:51:48 -0700822 if (isBookmarkTable) {
Christopher Tatef0c36f72009-07-28 15:24:05 -0700823 Cursor cursor = cr.query(Browser.BOOKMARKS_URI,
824 new String[] { BookmarkColumns.BOOKMARK },
825 "_id = " + id, null, null);
826 if (cursor.moveToNext()) {
827 if (cursor.getInt(0) != 0) {
828 // yep, this record is a bookmark
829 mBackupManager.dataChanged();
830 }
831 }
832 cursor.close();
Christopher Tate9c0dd8c2009-07-10 17:51:48 -0700833 }
Christopher Tatef0c36f72009-07-28 15:24:05 -0700834
835 int count = db.delete(TABLE_NAMES[match % 10], where, whereArgs);
836 cr.notifyChange(url, null);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800837 return count;
838 }
839
840 @Override
841 public int update(Uri url, ContentValues values, String where,
842 String[] whereArgs) {
843 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
844
845 int match = URI_MATCHER.match(url);
846 if (match == -1 || match == URI_MATCH_SUGGEST) {
847 throw new IllegalArgumentException("Unknown URL");
848 }
849
Christopher Tatef0c36f72009-07-28 15:24:05 -0700850 String id = null;
Christopher Tate9c0dd8c2009-07-10 17:51:48 -0700851 boolean isBookmarkTable = (match == URI_MATCH_BOOKMARKS_ID);
Christopher Tatef0c36f72009-07-28 15:24:05 -0700852 boolean changingBookmarks = false;
Christopher Tate9c0dd8c2009-07-10 17:51:48 -0700853
854 if (isBookmarkTable || match == URI_MATCH_SEARCHES_ID) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800855 StringBuilder sb = new StringBuilder();
856 if (where != null && where.length() > 0) {
857 sb.append("( ");
858 sb.append(where);
859 sb.append(" ) AND ");
860 }
Christopher Tatef0c36f72009-07-28 15:24:05 -0700861 id = url.getPathSegments().get(1);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800862 sb.append("_id = ");
Christopher Tatef0c36f72009-07-28 15:24:05 -0700863 sb.append(id);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800864 where = sb.toString();
865 }
866
Christopher Tatef0c36f72009-07-28 15:24:05 -0700867 ContentResolver cr = getContext().getContentResolver();
Christopher Tate9c0dd8c2009-07-10 17:51:48 -0700868
Christopher Tatef0c36f72009-07-28 15:24:05 -0700869 // Not all bookmark-table updates should be backed up. Look to see
870 // whether we changed the title, url, or "is a bookmark" state, and
871 // request a backup if so.
Christopher Tate9c0dd8c2009-07-10 17:51:48 -0700872 if (isBookmarkTable) {
Christopher Tatef0c36f72009-07-28 15:24:05 -0700873 // Alterations to the bookmark field inherently change the bookmark
874 // set, so we don't need to query the record; we know a priori that
875 // we will need to back up this change.
876 if (values.containsKey(BookmarkColumns.BOOKMARK)) {
877 changingBookmarks = true;
878 }
879 // changing the title or URL of a bookmark record requires a backup,
880 // but we don't know wether such an update is on a bookmark without
881 // querying the record
882 if (!changingBookmarks &&
883 (values.containsKey(BookmarkColumns.TITLE)
884 || values.containsKey(BookmarkColumns.URL))) {
885 // when isBookmarkTable is true, the 'id' var was assigned above
886 Cursor cursor = cr.query(Browser.BOOKMARKS_URI,
887 new String[] { BookmarkColumns.BOOKMARK },
888 "_id = " + id, null, null);
889 if (cursor.moveToNext()) {
890 changingBookmarks = (cursor.getInt(0) != 0);
891 }
892 cursor.close();
893 }
894
895 // if this *is* a bookmark row we're altering, we need to back it up.
896 if (changingBookmarks) {
897 mBackupManager.dataChanged();
898 }
Christopher Tate9c0dd8c2009-07-10 17:51:48 -0700899 }
Christopher Tatef0c36f72009-07-28 15:24:05 -0700900
901 int ret = db.update(TABLE_NAMES[match % 10], values, where, whereArgs);
902 cr.notifyChange(url, null);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800903 return ret;
904 }
Satish Sampath565505b2009-05-29 15:37:27 +0100905
Mike LeBeauc42f81b2009-05-14 15:04:19 -0700906 /**
907 * Strips the provided url of preceding "http://" and any trailing "/". Does not
908 * strip "https://". If the provided string cannot be stripped, the original string
909 * is returned.
Satish Sampath565505b2009-05-29 15:37:27 +0100910 *
Mike LeBeauc42f81b2009-05-14 15:04:19 -0700911 * TODO: Put this in TextUtils to be used by other packages doing something similar.
Satish Sampath565505b2009-05-29 15:37:27 +0100912 *
Mike LeBeauc42f81b2009-05-14 15:04:19 -0700913 * @param url a url to strip, like "http://www.google.com/"
914 * @return a stripped url like "www.google.com", or the original string if it could
915 * not be stripped
916 */
917 private static String stripUrl(String url) {
918 if (url == null) return null;
919 Matcher m = STRIP_URL_PATTERN.matcher(url);
920 if (m.matches() && m.groupCount() == 3) {
921 return m.group(2);
922 } else {
923 return url;
924 }
925 }
926
The Android Open Source Project0c908882009-03-03 19:32:16 -0800927}