blob: 14d465090a905987bbb74365972a8318035ca1d4 [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
The Android Open Source Projecta3c0aab2009-03-18 17:39:48 -070019import java.util.Date;
20
The Android Open Source Project0c908882009-03-03 19:32:16 -080021import android.app.ISearchManager;
22import android.app.SearchManager;
23import android.content.ComponentName;
24import android.content.ContentProvider;
25import android.content.ContentUris;
26import android.content.ContentValues;
27import android.content.Context;
28import android.content.Intent;
The Android Open Source Projecta3c0aab2009-03-18 17:39:48 -070029import android.content.SharedPreferences;
The Android Open Source Project0c908882009-03-03 19:32:16 -080030import android.content.UriMatcher;
The Android Open Source Projecta3c0aab2009-03-18 17:39:48 -070031import android.content.SharedPreferences.Editor;
The Android Open Source Project0c908882009-03-03 19:32:16 -080032import android.database.AbstractCursor;
33import android.database.Cursor;
34import android.database.sqlite.SQLiteOpenHelper;
35import android.database.sqlite.SQLiteDatabase;
36import android.net.Uri;
37import android.os.RemoteException;
38import android.os.ServiceManager;
39import android.os.SystemProperties;
The Android Open Source Projecta3c0aab2009-03-18 17:39:48 -070040import android.preference.PreferenceManager;
The Android Open Source Project0c908882009-03-03 19:32:16 -080041import android.provider.Browser;
42import android.util.Log;
43import android.server.search.SearchableInfo;
44import android.text.util.Regex;
45
46public class BrowserProvider extends ContentProvider {
47
48 private SQLiteOpenHelper mOpenHelper;
49 private static final String sDatabaseName = "browser.db";
50 private static final String TAG = "BrowserProvider";
51 private static final String ORDER_BY = "visits DESC, date DESC";
52
The Android Open Source Projecta3c0aab2009-03-18 17:39:48 -070053 private static final String PICASA_URL = "http://picasaweb.google.com/m/" +
54 "viewer?source=androidclient";
55
The Android Open Source Project0c908882009-03-03 19:32:16 -080056 private static final String[] TABLE_NAMES = new String[] {
57 "bookmarks", "searches"
58 };
59 private static final String[] SUGGEST_PROJECTION = new String[] {
60 "_id", "url", "title", "bookmark"
61 };
62 private static final String SUGGEST_SELECTION =
63 "url LIKE ? OR url LIKE ? OR url LIKE ? OR url LIKE ?";
64 private String[] SUGGEST_ARGS = new String[4];
65
66 // shared suggestion array index, make sure to match COLUMNS
67 private static final int SUGGEST_COLUMN_INTENT_ACTION_ID = 1;
68 private static final int SUGGEST_COLUMN_INTENT_DATA_ID = 2;
69 private static final int SUGGEST_COLUMN_TEXT_1_ID = 3;
70 private static final int SUGGEST_COLUMN_TEXT_2_ID = 4;
71 private static final int SUGGEST_COLUMN_ICON_1_ID = 5;
72 private static final int SUGGEST_COLUMN_ICON_2_ID = 6;
73 private static final int SUGGEST_COLUMN_QUERY_ID = 7;
74
75 // shared suggestion columns
76 private static final String[] COLUMNS = new String[] {
77 "_id",
78 SearchManager.SUGGEST_COLUMN_INTENT_ACTION,
79 SearchManager.SUGGEST_COLUMN_INTENT_DATA,
80 SearchManager.SUGGEST_COLUMN_TEXT_1,
81 SearchManager.SUGGEST_COLUMN_TEXT_2,
82 SearchManager.SUGGEST_COLUMN_ICON_1,
83 SearchManager.SUGGEST_COLUMN_ICON_2,
84 SearchManager.SUGGEST_COLUMN_QUERY};
85
86 private static final int MAX_SUGGESTION_SHORT_ENTRIES = 3;
87 private static final int MAX_SUGGESTION_LONG_ENTRIES = 6;
88
89 // make sure that these match the index of TABLE_NAMES
90 private static final int URI_MATCH_BOOKMARKS = 0;
91 private static final int URI_MATCH_SEARCHES = 1;
92 // (id % 10) should match the table name index
93 private static final int URI_MATCH_BOOKMARKS_ID = 10;
94 private static final int URI_MATCH_SEARCHES_ID = 11;
95 //
96 private static final int URI_MATCH_SUGGEST = 20;
97
98 private static final UriMatcher URI_MATCHER;
99
100 static {
101 URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
102 URI_MATCHER.addURI("browser", TABLE_NAMES[URI_MATCH_BOOKMARKS],
103 URI_MATCH_BOOKMARKS);
104 URI_MATCHER.addURI("browser", TABLE_NAMES[URI_MATCH_BOOKMARKS] + "/#",
105 URI_MATCH_BOOKMARKS_ID);
106 URI_MATCHER.addURI("browser", TABLE_NAMES[URI_MATCH_SEARCHES],
107 URI_MATCH_SEARCHES);
108 URI_MATCHER.addURI("browser", TABLE_NAMES[URI_MATCH_SEARCHES] + "/#",
109 URI_MATCH_SEARCHES_ID);
110 URI_MATCHER.addURI("browser", SearchManager.SUGGEST_URI_PATH_QUERY,
111 URI_MATCH_SUGGEST);
112 }
113
114 // 1 -> 2 add cache table
115 // 2 -> 3 update history table
116 // 3 -> 4 add passwords table
117 // 4 -> 5 add settings table
118 // 5 -> 6 ?
119 // 6 -> 7 ?
120 // 7 -> 8 drop proxy table
121 // 8 -> 9 drop settings table
122 // 9 -> 10 add form_urls and form_data
123 // 10 -> 11 add searches table
124 // 11 -> 12 modify cache table
125 // 12 -> 13 modify cache table
126 // 13 -> 14 correspond with Google Bookmarks schema
127 // 14 -> 15 move couple of tables to either browser private database or webview database
128 // 15 -> 17 Set it up for the SearchManager
129 // 17 -> 18 Added favicon in bookmarks table for Home shortcuts
130 // 18 -> 19 Remove labels table
131 private static final int DATABASE_VERSION = 19;
132
133 public BrowserProvider() {
134 }
135
136
137 private static CharSequence replaceSystemPropertyInString(CharSequence srcString) {
138 StringBuffer sb = new StringBuffer();
139 int lastCharLoc = 0;
140 for (int i = 0; i < srcString.length(); ++i) {
141 char c = srcString.charAt(i);
142 if (c == '{') {
143 sb.append(srcString.subSequence(lastCharLoc, i));
144 lastCharLoc = i;
145 inner:
146 for (int j = i; j < srcString.length(); ++j) {
147 char k = srcString.charAt(j);
148 if (k == '}') {
149 String propertyKeyValue = srcString.subSequence(i + 1, j).toString();
150 // See if the propertyKeyValue specifies a default value
151 int defaultOffset = propertyKeyValue.indexOf(':');
152 if (defaultOffset == -1) {
153 sb.append(SystemProperties.get(propertyKeyValue));
154 } else {
155 String propertyKey = propertyKeyValue.substring(0, defaultOffset);
156 String defaultValue =
157 propertyKeyValue.substring(defaultOffset + 1,
158 propertyKeyValue.length());
159 sb.append(SystemProperties.get(propertyKey, defaultValue));
160 }
161 lastCharLoc = j + 1;
162 i = j;
163 break inner;
164 }
165 }
166 }
167 }
168 if (srcString.length() - lastCharLoc > 0) {
169 // Put on the tail, if there is one
170 sb.append(srcString.subSequence(lastCharLoc, srcString.length()));
171 }
172 return sb;
173 }
174
175 private static class DatabaseHelper extends SQLiteOpenHelper {
176 private Context mContext;
177
178 public DatabaseHelper(Context context) {
179 super(context, sDatabaseName, null, DATABASE_VERSION);
180 mContext = context;
181 }
182
183 @Override
184 public void onCreate(SQLiteDatabase db) {
185 db.execSQL("CREATE TABLE bookmarks (" +
186 "_id INTEGER PRIMARY KEY," +
187 "title TEXT," +
188 "url TEXT," +
189 "visits INTEGER," +
190 "date LONG," +
191 "created LONG," +
192 "description TEXT," +
193 "bookmark INTEGER," +
194 "favicon BLOB DEFAULT NULL" +
195 ");");
196
197 final CharSequence[] bookmarks = mContext.getResources()
198 .getTextArray(R.array.bookmarks);
199 int size = bookmarks.length;
200 try {
201 for (int i = 0; i < size; i = i + 2) {
202 CharSequence bookmarkDestination = replaceSystemPropertyInString(bookmarks[i + 1]);
203 db.execSQL("INSERT INTO bookmarks (title, url, visits, " +
204 "date, created, bookmark)" + " VALUES('" +
205 bookmarks[i] + "', '" + bookmarkDestination +
206 "', 0, 0, 0, 1);");
207 }
208 } catch (ArrayIndexOutOfBoundsException e) {
209 }
210
211 db.execSQL("CREATE TABLE searches (" +
212 "_id INTEGER PRIMARY KEY," +
213 "search TEXT," +
214 "date LONG" +
215 ");");
216 }
217
218 @Override
219 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
220 Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
221 + newVersion + ", which will destroy all old data");
222 if (oldVersion == 18) {
223 db.execSQL("DROP TABLE IF EXISTS labels");
224 } else {
225 db.execSQL("DROP TABLE IF EXISTS bookmarks");
226 db.execSQL("DROP TABLE IF EXISTS searches");
227 onCreate(db);
228 }
229 }
230 }
231
232 @Override
233 public boolean onCreate() {
The Android Open Source Projecta3c0aab2009-03-18 17:39:48 -0700234 final Context context = getContext();
235 mOpenHelper = new DatabaseHelper(context);
236 // we added "picasa web album" into default bookmarks for version 19.
237 // To avoid erasing the bookmark table, we added it explicitly for
238 // version 18 and 19 as in the other cases, we will erase the table.
239 if (DATABASE_VERSION == 18 || DATABASE_VERSION == 19) {
240 SharedPreferences p = PreferenceManager
241 .getDefaultSharedPreferences(context);
242 boolean fix = p.getBoolean("fix_picasa", true);
243 if (fix) {
244 fixPicasaBookmark();
245 Editor ed = p.edit();
246 ed.putBoolean("fix_picasa", false);
247 ed.commit();
248 }
249 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800250 return true;
251 }
252
The Android Open Source Projecta3c0aab2009-03-18 17:39:48 -0700253 private void fixPicasaBookmark() {
254 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
255 Cursor cursor = db.rawQuery("SELECT _id FROM bookmarks WHERE " +
256 "bookmark = 1 AND url = ?", new String[] { PICASA_URL });
257 try {
258 if (!cursor.moveToFirst()) {
259 // set "created" so that it will be on the top of the list
260 db.execSQL("INSERT INTO bookmarks (title, url, visits, " +
261 "date, created, bookmark)" + " VALUES('" +
262 getContext().getString(R.string.picasa) + "', '"
263 + PICASA_URL + "', 0, 0, " + new Date().getTime()
264 + ", 1);");
265 }
266 } finally {
267 if (cursor != null) {
268 cursor.close();
269 }
270 }
271 }
272
The Android Open Source Project0c908882009-03-03 19:32:16 -0800273 /*
274 * Subclass AbstractCursor so we can combine multiple Cursors and add
275 * "Google Search".
276 * Here are the rules.
277 * 1. We only have MAX_SUGGESTION_LONG_ENTRIES in the list plus
278 * "Google Search";
279 * 2. If bookmark/history entries are less than
280 * (MAX_SUGGESTION_SHORT_ENTRIES -1), we include Google suggest.
281 */
282 private class MySuggestionCursor extends AbstractCursor {
283 private Cursor mHistoryCursor;
284 private Cursor mSuggestCursor;
285 private int mHistoryCount;
286 private int mSuggestionCount;
287 private boolean mBeyondCursor;
288 private String mString;
289
290 public MySuggestionCursor(Cursor hc, Cursor sc, String string) {
291 mHistoryCursor = hc;
292 mSuggestCursor = sc;
293 mHistoryCount = hc.getCount();
294 mSuggestionCount = sc != null ? sc.getCount() : 0;
295 if (mSuggestionCount > (MAX_SUGGESTION_LONG_ENTRIES - mHistoryCount)) {
296 mSuggestionCount = MAX_SUGGESTION_LONG_ENTRIES - mHistoryCount;
297 }
298 mString = string;
299 mBeyondCursor = false;
300 }
301
302 @Override
303 public boolean onMove(int oldPosition, int newPosition) {
304 if (mHistoryCursor == null) {
305 return false;
306 }
307 if (mHistoryCount > newPosition) {
308 mHistoryCursor.moveToPosition(newPosition);
309 mBeyondCursor = false;
310 } else if (mHistoryCount + mSuggestionCount > newPosition) {
311 mSuggestCursor.moveToPosition(newPosition - mHistoryCount);
312 mBeyondCursor = false;
313 } else {
314 mBeyondCursor = true;
315 }
316 return true;
317 }
318
319 @Override
320 public int getCount() {
321 if (mString.length() > 0) {
322 return mHistoryCount + mSuggestionCount + 1;
323 } else {
324 return mHistoryCount + mSuggestionCount;
325 }
326 }
327
328 @Override
329 public String[] getColumnNames() {
330 return COLUMNS;
331 }
332
333 @Override
334 public String getString(int columnIndex) {
335 if ((mPos != -1 && mHistoryCursor != null)) {
336 switch(columnIndex) {
337 case SUGGEST_COLUMN_INTENT_ACTION_ID:
338 if (mHistoryCount > mPos) {
339 return Intent.ACTION_VIEW;
340 } else {
341 return Intent.ACTION_SEARCH;
342 }
343
344 case SUGGEST_COLUMN_INTENT_DATA_ID:
345 if (mHistoryCount > mPos) {
346 return mHistoryCursor.getString(1);
347 } else {
348 return null;
349 }
350
351 case SUGGEST_COLUMN_TEXT_1_ID:
352 if (mHistoryCount > mPos) {
353 return mHistoryCursor.getString(1);
354 } else if (!mBeyondCursor) {
355 return mSuggestCursor.getString(1);
356 } else {
357 return mString;
358 }
359
360 case SUGGEST_COLUMN_TEXT_2_ID:
361 if (mHistoryCount > mPos) {
362 return mHistoryCursor.getString(2);
363 } else if (!mBeyondCursor) {
364 return mSuggestCursor.getString(2);
365 } else {
366 return getContext().getString(R.string.search_google);
367 }
368
369 case SUGGEST_COLUMN_ICON_1_ID:
370 if (mHistoryCount > mPos) {
371 if (mHistoryCursor.getInt(3) == 1) {
372 return new Integer(
373 R.drawable.ic_search_category_bookmark)
374 .toString();
375 } else {
376 return new Integer(
377 R.drawable.ic_search_category_history)
378 .toString();
379 }
380 } else {
381 return new Integer(
382 R.drawable.ic_search_category_suggest)
383 .toString();
384 }
385
386 case SUGGEST_COLUMN_ICON_2_ID:
387 return new String("0");
388
389 case SUGGEST_COLUMN_QUERY_ID:
390 if (mHistoryCount > mPos) {
391 return null;
392 } else if (!mBeyondCursor) {
393 return mSuggestCursor.getString(3);
394 } else {
395 return mString;
396 }
397 }
398 }
399 return null;
400 }
401
402 @Override
403 public double getDouble(int column) {
404 throw new UnsupportedOperationException();
405 }
406
407 @Override
408 public float getFloat(int column) {
409 throw new UnsupportedOperationException();
410 }
411
412 @Override
413 public int getInt(int column) {
414 throw new UnsupportedOperationException();
415 }
416
417 @Override
418 public long getLong(int column) {
419 if ((mPos != -1) && column == 0) {
420 return mPos; // use row# as the _Id
421 }
422 throw new UnsupportedOperationException();
423 }
424
425 @Override
426 public short getShort(int column) {
427 throw new UnsupportedOperationException();
428 }
429
430 @Override
431 public boolean isNull(int column) {
432 throw new UnsupportedOperationException();
433 }
434
435 // TODO Temporary change, finalize after jq's changes go in
436 public void deactivate() {
437 if (mHistoryCursor != null) {
438 mHistoryCursor.deactivate();
439 }
440 if (mSuggestCursor != null) {
441 mSuggestCursor.deactivate();
442 }
443 super.deactivate();
444 }
445
446 public boolean requery() {
447 return (mHistoryCursor != null ? mHistoryCursor.requery() : false) |
448 (mSuggestCursor != null ? mSuggestCursor.requery() : false);
449 }
450
451 // TODO Temporary change, finalize after jq's changes go in
452 public void close() {
453 super.close();
454 if (mHistoryCursor != null) {
455 mHistoryCursor.close();
456 mHistoryCursor = null;
457 }
458 if (mSuggestCursor != null) {
459 mSuggestCursor.close();
460 mSuggestCursor = null;
461 }
462 }
463 }
464
465 @Override
466 public Cursor query(Uri url, String[] projectionIn, String selection,
467 String[] selectionArgs, String sortOrder)
468 throws IllegalStateException {
469 SQLiteDatabase db = mOpenHelper.getReadableDatabase();
470
471 int match = URI_MATCHER.match(url);
472 if (match == -1) {
473 throw new IllegalArgumentException("Unknown URL");
474 }
475
476 if (match == URI_MATCH_SUGGEST) {
477 String suggestSelection;
478 String [] myArgs;
479 if (selectionArgs[0] == null || selectionArgs[0].equals("")) {
480 suggestSelection = null;
481 myArgs = null;
482 } else {
483 String like = selectionArgs[0] + "%";
484 if (selectionArgs[0].startsWith("http")) {
485 myArgs = new String[1];
486 myArgs[0] = like;
487 suggestSelection = selection;
488 } else {
489 SUGGEST_ARGS[0] = "http://" + like;
490 SUGGEST_ARGS[1] = "http://www." + like;
491 SUGGEST_ARGS[2] = "https://" + like;
492 SUGGEST_ARGS[3] = "https://www." + like;
493 myArgs = SUGGEST_ARGS;
494 suggestSelection = SUGGEST_SELECTION;
495 }
496 }
497
498 Cursor c = db.query(TABLE_NAMES[URI_MATCH_BOOKMARKS],
499 SUGGEST_PROJECTION, suggestSelection, myArgs, null, null,
500 ORDER_BY,
501 (new Integer(MAX_SUGGESTION_LONG_ENTRIES)).toString());
502
503 if (Regex.WEB_URL_PATTERN.matcher(selectionArgs[0]).matches()) {
504 return new MySuggestionCursor(c, null, "");
505 } else {
506 // get Google suggest if there is still space in the list
507 if (myArgs != null && myArgs.length > 1
508 && c.getCount() < (MAX_SUGGESTION_SHORT_ENTRIES - 1)) {
509 ISearchManager sm = ISearchManager.Stub
510 .asInterface(ServiceManager
511 .getService(Context.SEARCH_SERVICE));
512 SearchableInfo si = null;
513 try {
514 // use the global search to get Google suggest provider
515 si = sm.getSearchableInfo(new ComponentName(
516 getContext(), "com.android.browser"), true);
517
518 // similar to the getSuggestions() in SearchDialog.java
519 StringBuilder uriStr = new StringBuilder("content://");
520 uriStr.append(si.getSuggestAuthority());
521 // if content path provided, insert it now
522 final String contentPath = si.getSuggestPath();
523 if (contentPath != null) {
524 uriStr.append('/');
525 uriStr.append(contentPath);
526 }
527 // append standard suggestion query path
528 uriStr.append('/' + SearchManager.SUGGEST_URI_PATH_QUERY);
529 // inject query, either as selection args or inline
530 String[] selArgs = null;
531 if (si.getSuggestSelection() != null) {
532 selArgs = new String[] {selectionArgs[0]};
533 } else {
534 uriStr.append('/');
535 uriStr.append(Uri.encode(selectionArgs[0]));
536 }
537
538 // finally, make the query
539 Cursor sc = getContext().getContentResolver().query(
540 Uri.parse(uriStr.toString()), null,
541 si.getSuggestSelection(), selArgs, null);
542
543 return new MySuggestionCursor(c, sc, selectionArgs[0]);
544 } catch (RemoteException e) {
545 }
546 }
547 return new MySuggestionCursor(c, null, selectionArgs[0]);
548 }
549 }
550
551 String[] projection = null;
552 if (projectionIn != null && projectionIn.length > 0) {
553 projection = new String[projectionIn.length + 1];
554 System.arraycopy(projectionIn, 0, projection, 0, projectionIn.length);
555 projection[projectionIn.length] = "_id AS _id";
556 }
557
558 StringBuilder whereClause = new StringBuilder(256);
559 if (match == URI_MATCH_BOOKMARKS_ID || match == URI_MATCH_SEARCHES_ID) {
560 whereClause.append("(_id = ").append(url.getPathSegments().get(1))
561 .append(")");
562 }
563
564 // Tack on the user's selection, if present
565 if (selection != null && selection.length() > 0) {
566 if (whereClause.length() > 0) {
567 whereClause.append(" AND ");
568 }
569
570 whereClause.append('(');
571 whereClause.append(selection);
572 whereClause.append(')');
573 }
574 Cursor c = db.query(TABLE_NAMES[match % 10], projection,
575 whereClause.toString(), selectionArgs, null, null, sortOrder,
576 null);
577 c.setNotificationUri(getContext().getContentResolver(), url);
578 return c;
579 }
580
581 @Override
582 public String getType(Uri url) {
583 int match = URI_MATCHER.match(url);
584 switch (match) {
585 case URI_MATCH_BOOKMARKS:
586 return "vnd.android.cursor.dir/bookmark";
587
588 case URI_MATCH_BOOKMARKS_ID:
589 return "vnd.android.cursor.item/bookmark";
590
591 case URI_MATCH_SEARCHES:
592 return "vnd.android.cursor.dir/searches";
593
594 case URI_MATCH_SEARCHES_ID:
595 return "vnd.android.cursor.item/searches";
596
597 case URI_MATCH_SUGGEST:
598 return SearchManager.SUGGEST_MIME_TYPE;
599
600 default:
601 throw new IllegalArgumentException("Unknown URL");
602 }
603 }
604
605 @Override
606 public Uri insert(Uri url, ContentValues initialValues) {
607 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
608
609 int match = URI_MATCHER.match(url);
610 Uri uri = null;
611 switch (match) {
612 case URI_MATCH_BOOKMARKS: {
613 // Insert into the bookmarks table
614 long rowID = db.insert(TABLE_NAMES[URI_MATCH_BOOKMARKS], "url",
615 initialValues);
616 if (rowID > 0) {
617 uri = ContentUris.withAppendedId(Browser.BOOKMARKS_URI,
618 rowID);
619 }
620 break;
621 }
622
623 case URI_MATCH_SEARCHES: {
624 // Insert into the searches table
625 long rowID = db.insert(TABLE_NAMES[URI_MATCH_SEARCHES], "url",
626 initialValues);
627 if (rowID > 0) {
628 uri = ContentUris.withAppendedId(Browser.SEARCHES_URI,
629 rowID);
630 }
631 break;
632 }
633
634 default:
635 throw new IllegalArgumentException("Unknown URL");
636 }
637
638 if (uri == null) {
639 throw new IllegalArgumentException("Unknown URL");
640 }
641 getContext().getContentResolver().notifyChange(uri, null);
642 return uri;
643 }
644
645 @Override
646 public int delete(Uri url, String where, String[] whereArgs) {
647 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
648
649 int match = URI_MATCHER.match(url);
650 if (match == -1 || match == URI_MATCH_SUGGEST) {
651 throw new IllegalArgumentException("Unknown URL");
652 }
653
654 if (match == URI_MATCH_BOOKMARKS_ID || match == URI_MATCH_SEARCHES_ID) {
655 StringBuilder sb = new StringBuilder();
656 if (where != null && where.length() > 0) {
657 sb.append("( ");
658 sb.append(where);
659 sb.append(" ) AND ");
660 }
661 sb.append("_id = ");
662 sb.append(url.getPathSegments().get(1));
663 where = sb.toString();
664 }
665
666 int count = db.delete(TABLE_NAMES[match % 10], where, whereArgs);
667 getContext().getContentResolver().notifyChange(url, null);
668 return count;
669 }
670
671 @Override
672 public int update(Uri url, ContentValues values, String where,
673 String[] whereArgs) {
674 SQLiteDatabase db = mOpenHelper.getWritableDatabase();
675
676 int match = URI_MATCHER.match(url);
677 if (match == -1 || match == URI_MATCH_SUGGEST) {
678 throw new IllegalArgumentException("Unknown URL");
679 }
680
681 if (match == URI_MATCH_BOOKMARKS_ID || match == URI_MATCH_SEARCHES_ID) {
682 StringBuilder sb = new StringBuilder();
683 if (where != null && where.length() > 0) {
684 sb.append("( ");
685 sb.append(where);
686 sb.append(" ) AND ");
687 }
688 sb.append("_id = ");
689 sb.append(url.getPathSegments().get(1));
690 where = sb.toString();
691 }
692
693 int ret = db.update(TABLE_NAMES[match % 10], values, where, whereArgs);
694 getContext().getContentResolver().notifyChange(url, null);
695 return ret;
696 }
697}