use of android.support.annotation.WorkerThread in project nextcloud-notes by stefan-niedermann.
the class NoteSQLiteOpenHelper method getFavoritesCount.
@NonNull
@WorkerThread
public Map<String, Integer> getFavoritesCount() {
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.query(table_notes, new String[] { key_favorite, "COUNT(*)" }, key_status + " != ?", new String[] { DBStatus.LOCAL_DELETED.getTitle() }, key_favorite, null, key_favorite);
Map<String, Integer> favorites = new HashMap<>(cursor.getCount());
while (cursor.moveToNext()) {
favorites.put(cursor.getString(0), cursor.getInt(1));
}
cursor.close();
return favorites;
}
use of android.support.annotation.WorkerThread in project XposedInstaller by rovo89.
the class FrameworkZips method analyze.
@WorkerThread
private static LocalFrameworkZip analyze(File file) {
String filename = file.getName();
ZipFile zipFile = null;
try {
zipFile = new ZipFile(file);
ZipCheckResult zcr = InstallZipUtil.checkZip(zipFile);
if (!zcr.isValidZip()) {
return null;
}
LocalFrameworkZip zip = new LocalFrameworkZip();
ZipEntry entry;
if ((entry = zipFile.getEntry("system/xposed.prop")) != null) {
XposedProp prop = InstallZipUtil.parseXposedProp(zipFile.getInputStream(entry));
if (prop == null || !prop.isCompatible()) {
Log.w(XposedApp.TAG, "ZIP file is not compatible: " + file);
return null;
}
zip.title = "Version " + prop.getVersion();
} else if (filename.startsWith("xposed-uninstaller-")) {
// TODO provide more information inside uninstaller ZIPs
zip.type = Type.UNINSTALLER;
zip.title = "Uninstaller";
int start = "xposed-uninstaller-".length();
int end = filename.lastIndexOf('-');
if (start < end) {
zip.title += " (" + filename.substring(start, end) + ")";
}
} else {
return null;
}
zip.path = file;
return zip;
} catch (IOException e) {
Log.e(XposedApp.TAG, "Errors while checking " + file, e);
return null;
} finally {
if (zipFile != null) {
InstallZipUtil.closeSilently(zipFile);
}
}
}
use of android.support.annotation.WorkerThread in project XposedInstaller by rovo89.
the class FrameworkZips method refreshLocal.
@WorkerThread
private static void refreshLocal() {
// noinspection unchecked
Map<String, List<LocalFrameworkZip>>[] zipsArray = new Map[TYPE_COUNT];
for (int i = 0; i < TYPE_COUNT; i++) {
zipsArray[i] = new TreeMap<>();
}
for (File dir : DownloadsUtil.getDownloadDirs(DownloadsUtil.DOWNLOAD_FRAMEWORK)) {
if (!dir.isDirectory()) {
continue;
}
for (String filename : dir.list()) {
if (!filename.endsWith(".zip")) {
continue;
}
LocalFrameworkZip zip = analyze(new File(dir, filename));
if (zip != null) {
Map<String, List<LocalFrameworkZip>> zips = zipsArray[zip.type.ordinal()];
List<LocalFrameworkZip> list = zips.get(zip.title);
if (list == null) {
list = new ArrayList<>(1);
zips.put(zip.title, list);
}
list.add(zip);
}
}
}
synchronized (FrameworkZips.class) {
sLocal = zipsArray;
}
}
use of android.support.annotation.WorkerThread in project sqlbrite by square.
the class BriteDatabase method insert.
/**
* Insert a row into the specified {@code table} and notify any subscribed queries.
*
* @see SupportSQLiteDatabase#insert(String, int, ContentValues)
*/
@WorkerThread
public long insert(@NonNull String table, @ConflictAlgorithm int conflictAlgorithm, @NonNull ContentValues values) {
SupportSQLiteDatabase db = getWritableDatabase();
if (logging) {
log("INSERT\n table: %s\n values: %s\n conflictAlgorithm: %s", table, values, conflictString(conflictAlgorithm));
}
long rowId = db.insert(table, conflictAlgorithm, values);
if (logging)
log("INSERT id: %s", rowId);
if (rowId != -1) {
// Only send a table trigger if the insert was successful.
sendTableTrigger(Collections.singleton(table));
}
return rowId;
}
use of android.support.annotation.WorkerThread in project sqlbrite by square.
the class BriteDatabase method update.
/**
* Update rows in the specified {@code table} and notify any subscribed queries. This method
* will not trigger a notification if no rows were updated.
*
* @see SupportSQLiteDatabase#update(String, int, ContentValues, String, Object[])
*/
@WorkerThread
public int update(@NonNull String table, @ConflictAlgorithm int conflictAlgorithm, @NonNull ContentValues values, @Nullable String whereClause, @Nullable String... whereArgs) {
SupportSQLiteDatabase db = getWritableDatabase();
if (logging) {
log("UPDATE\n table: %s\n values: %s\n whereClause: %s\n whereArgs: %s\n conflictAlgorithm: %s", table, values, whereClause, Arrays.toString(whereArgs), conflictString(conflictAlgorithm));
}
int rows = db.update(table, conflictAlgorithm, values, whereClause, whereArgs);
if (logging)
log("UPDATE affected %s %s", rows, rows != 1 ? "rows" : "row");
if (rows > 0) {
// Only send a table trigger if rows were affected.
sendTableTrigger(Collections.singleton(table));
}
return rows;
}
Aggregations