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