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 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 sqlbrite by square.
the class BriteDatabase method insert.
/**
* Insert a row into the specified {@code table} and notify any subscribed queries.
*
* @see SQLiteDatabase#insertWithOnConflict(String, String, ContentValues, int)
*/
@WorkerThread
public long insert(@NonNull String table, @NonNull ContentValues values, @ConflictAlgorithm int conflictAlgorithm) {
SQLiteDatabase db = getWritableDatabase();
if (logging) {
log("INSERT\n table: %s\n values: %s\n conflictAlgorithm: %s", table, values, conflictString(conflictAlgorithm));
}
long rowId = db.insertWithOnConflict(table, null, values, conflictAlgorithm);
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 query.
/**
* Runs the provided SQL and returns a {@link Cursor} over the result set.
*
* @see SQLiteDatabase#rawQuery(String, String[])
*/
@CheckResult
@WorkerThread
public Cursor query(@NonNull String sql, @NonNull String... args) {
long startNanos = nanoTime();
Cursor cursor = getReadableDatabase().rawQuery(sql, args);
long tookMillis = NANOSECONDS.toMillis(nanoTime() - startNanos);
if (logging) {
log("QUERY (%sms)\n sql: %s\n args: %s", tookMillis, indentSql(sql), Arrays.toString(args));
}
return cursor;
}
use of android.support.annotation.WorkerThread in project Shuttle by timusus.
the class PlaylistUtils method makePlaylistName.
@WorkerThread
public static String makePlaylistName(Context context) {
String template = context.getString(R.string.new_playlist_name_template);
int num = 1;
Query query = new Query.Builder().uri(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI).projection(new String[] { MediaStore.Audio.Playlists.NAME }).sort(MediaStore.Audio.Playlists.NAME).build();
Cursor cursor = SqlUtils.createQuery(context, query);
if (cursor == null) {
return null;
}
String suggestedName = String.format(template, num++);
// Need to loop until we've made 1 full pass through without finding a match.
// Looping more than once shouldn't happen very often, but will happen
// if you have playlists named "New Playlist 1"/10/2/3/4/5/6/7/8/9, where
// making only one pass would result in "New Playlist 10" being erroneously
// picked for the new name.
boolean done = false;
while (!done) {
done = true;
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
String playlistName = cursor.getString(0);
if (playlistName.compareToIgnoreCase(suggestedName) == 0) {
suggestedName = String.format(template, num++);
done = false;
}
cursor.moveToNext();
}
}
cursor.close();
return suggestedName;
}
Aggregations