Search in sources :

Example 16 with WorkerThread

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;
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) ZipFile(java.util.zip.ZipFile) File(java.io.File) WorkerThread(android.support.annotation.WorkerThread)

Example 17 with WorkerThread

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);
        }
    }
}
Also used : XposedProp(de.robv.android.xposed.installer.util.InstallZipUtil.XposedProp) ZipFile(java.util.zip.ZipFile) ZipCheckResult(de.robv.android.xposed.installer.util.InstallZipUtil.ZipCheckResult) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) WorkerThread(android.support.annotation.WorkerThread)

Example 18 with WorkerThread

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;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) WorkerThread(android.support.annotation.WorkerThread)

Example 19 with WorkerThread

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;
}
Also used : Cursor(android.database.Cursor) WorkerThread(android.support.annotation.WorkerThread) CheckResult(android.support.annotation.CheckResult)

Example 20 with WorkerThread

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;
}
Also used : Query(com.simplecity.amp_library.model.Query) SpannableStringBuilder(android.text.SpannableStringBuilder) Cursor(android.database.Cursor) WorkerThread(android.support.annotation.WorkerThread)

Aggregations

WorkerThread (android.support.annotation.WorkerThread)52 NonNull (android.support.annotation.NonNull)21 Cursor (android.database.Cursor)17 StorIOException (com.pushtorefresh.storio.StorIOException)15 File (java.io.File)11 ArrayList (java.util.ArrayList)11 Uri (android.net.Uri)8 ContentValues (android.content.ContentValues)6 Nullable (android.support.annotation.Nullable)6 StorIOSQLite (com.pushtorefresh.storio.sqlite.StorIOSQLite)6 HashMap (java.util.HashMap)6 HistoryItem (acr.browser.lightning.database.HistoryItem)5 IOException (java.io.IOException)5 FileInputStream (java.io.FileInputStream)4 Intent (android.content.Intent)3 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 FileNotFoundException (java.io.FileNotFoundException)3 InputStream (java.io.InputStream)3 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)3 ContentUris (android.content.ContentUris)2