Files
app_Settings/src/com/android/settings/search/SavedQueryRemover.java
Jaekyun Seok 47f6e54895 Move codes generating html file from xml files to SettingsLib (1/2)
LicenseHtmlGeneratorFromXml, LicenseHtmlLoader and indirecly AsyncLoader
shoud be commonly used by Settings and TvSettings.

So this CL will move them to SettingsLib.

Test: building succeeded and tested on sailfish.
  make ROBOTEST_FILTER=SettingsLicenseActivityTest RunSettingsRoboTests

Change-Id: I12e9169b1d3d313a6c5da0d575a6526327268381
2017-12-07 06:41:30 +09:00

65 lines
1.9 KiB
Java

/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.settings.search;
import static com.android.settings.search.IndexDatabaseHelper.Tables.TABLE_SAVED_QUERIES;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.util.Log;
import com.android.settingslib.utils.AsyncLoader;
public class SavedQueryRemover extends AsyncLoader<Void> {
private static final String LOG_TAG = "SavedQueryRemover";
public SavedQueryRemover(Context context) {
super(context);
}
@Override
public Void loadInBackground() {
final SQLiteDatabase database = getWritableDatabase();
try {
// First, delete all saved queries that are the same
database.delete(TABLE_SAVED_QUERIES,
null /* where */,
null /* whereArgs */);
} catch (Exception e) {
Log.d(LOG_TAG, "Cannot update saved Search queries", e);
}
return null;
}
@Override
protected void onDiscardResult(Void result) {
}
private SQLiteDatabase getWritableDatabase() {
try {
return IndexDatabaseHelper.getInstance(getContext()).getWritableDatabase();
} catch (SQLiteException e) {
Log.e(LOG_TAG, "Cannot open writable database", e);
return null;
}
}
}