1/* 2 * Copyright (C) 2017 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 */ 17 18package com.android.settings.search; 19 20import static com.android.settings.search.IndexDatabaseHelper.Tables.TABLE_SAVED_QUERIES; 21 22import android.content.Context; 23import android.database.sqlite.SQLiteDatabase; 24import android.database.sqlite.SQLiteException; 25import android.util.Log; 26 27import com.android.settings.utils.AsyncLoader; 28 29public class SavedQueryRemover extends AsyncLoader<Void> { 30 31 private static final String LOG_TAG = "SavedQueryRemover"; 32 33 public SavedQueryRemover(Context context) { 34 super(context); 35 } 36 37 @Override 38 public Void loadInBackground() { 39 final SQLiteDatabase database = getWritableDatabase(); 40 try { 41 // First, delete all saved queries that are the same 42 database.delete(TABLE_SAVED_QUERIES, 43 null /* where */, 44 null /* whereArgs */); 45 } catch (Exception e) { 46 Log.d(LOG_TAG, "Cannot update saved Search queries", e); 47 } 48 return null; 49 } 50 51 @Override 52 protected void onDiscardResult(Void result) { 53 54 } 55 56 private SQLiteDatabase getWritableDatabase() { 57 try { 58 return IndexDatabaseHelper.getInstance(getContext()).getWritableDatabase(); 59 } catch (SQLiteException e) { 60 Log.e(LOG_TAG, "Cannot open writable database", e); 61 return null; 62 } 63 } 64} 65