Cleanup in response to CR comments
This commit is contained in:
		
							parent
							
								
									bb88be9403
								
							
						
					
					
						commit
						203bcda695
					
				@ -7,15 +7,12 @@ import android.database.Cursor;
 | 
				
			|||||||
import android.net.Uri;
 | 
					import android.net.Uri;
 | 
				
			||||||
import android.support.annotation.NonNull;
 | 
					import android.support.annotation.NonNull;
 | 
				
			||||||
import android.support.annotation.Nullable;
 | 
					import android.support.annotation.Nullable;
 | 
				
			||||||
import android.util.Log;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.fdroid.fdroid.data.Schema.AppPrefsTable;
 | 
					import org.fdroid.fdroid.data.Schema.AppPrefsTable;
 | 
				
			||||||
import org.fdroid.fdroid.data.Schema.AppPrefsTable.Cols;
 | 
					import org.fdroid.fdroid.data.Schema.AppPrefsTable.Cols;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class AppPrefsProvider extends FDroidProvider {
 | 
					public class AppPrefsProvider extends FDroidProvider {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static final String TAG = "AppPrefsProvider";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public static final class Helper {
 | 
					    public static final class Helper {
 | 
				
			||||||
        private Helper() { }
 | 
					        private Helper() { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -48,12 +45,12 @@ public class AppPrefsProvider extends FDroidProvider {
 | 
				
			|||||||
            try {
 | 
					            try {
 | 
				
			||||||
                if (cursor.getCount() == 0) {
 | 
					                if (cursor.getCount() == 0) {
 | 
				
			||||||
                    return null;
 | 
					                    return null;
 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                    cursor.moveToFirst();
 | 
					 | 
				
			||||||
                    return new AppPrefs(
 | 
					 | 
				
			||||||
                            cursor.getInt(cursor.getColumnIndexOrThrow(Cols.IGNORE_THIS_UPDATE)),
 | 
					 | 
				
			||||||
                            cursor.getInt(cursor.getColumnIndexOrThrow(Cols.IGNORE_ALL_UPDATES)) > 0);
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                cursor.moveToFirst();
 | 
				
			||||||
 | 
					                return new AppPrefs(
 | 
				
			||||||
 | 
					                        cursor.getInt(cursor.getColumnIndexOrThrow(Cols.IGNORE_THIS_UPDATE)),
 | 
				
			||||||
 | 
					                        cursor.getInt(cursor.getColumnIndexOrThrow(Cols.IGNORE_ALL_UPDATES)) > 0);
 | 
				
			||||||
            } finally {
 | 
					            } finally {
 | 
				
			||||||
                cursor.close();
 | 
					                cursor.close();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@ -118,18 +115,13 @@ public class AppPrefsProvider extends FDroidProvider {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public Cursor query(Uri uri, String[] projection, String customSelection, String[] selectionArgs, String sortOrder) {
 | 
					    public Cursor query(Uri uri, String[] projection, String customSelection, String[] selectionArgs, String sortOrder) {
 | 
				
			||||||
        QuerySelection selection = new QuerySelection(customSelection, selectionArgs);
 | 
					        if (MATCHER.match(uri) != CODE_SINGLE) {
 | 
				
			||||||
 | 
					            throw new UnsupportedOperationException("Invalid URI for app content provider: " + uri);
 | 
				
			||||||
        switch (MATCHER.match(uri)) {
 | 
					 | 
				
			||||||
            case CODE_SINGLE:
 | 
					 | 
				
			||||||
                selection = selection.add(querySingle(uri.getLastPathSegment()));
 | 
					 | 
				
			||||||
                break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            default:
 | 
					 | 
				
			||||||
                Log.e(TAG, "Invalid URI for app content provider: " + uri);
 | 
					 | 
				
			||||||
                throw new UnsupportedOperationException("Invalid URI for app content provider: " + uri);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        QuerySelection selection = new QuerySelection(customSelection, selectionArgs)
 | 
				
			||||||
 | 
					                .add(querySingle(uri.getLastPathSegment()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Query query = new Query();
 | 
					        Query query = new Query();
 | 
				
			||||||
        query.addSelection(selection);
 | 
					        query.addSelection(selection);
 | 
				
			||||||
        query.addFields(projection);
 | 
					        query.addFields(projection);
 | 
				
			||||||
@ -142,10 +134,7 @@ public class AppPrefsProvider extends FDroidProvider {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public int delete(Uri uri, String where, String[] whereArgs) {
 | 
					    public int delete(Uri uri, String where, String[] whereArgs) {
 | 
				
			||||||
        switch (MATCHER.match(uri)) {
 | 
					        throw new UnsupportedOperationException("Delete not supported for " + uri + ".");
 | 
				
			||||||
            default:
 | 
					 | 
				
			||||||
                throw new UnsupportedOperationException("Delete not supported for " + uri + ".");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
@ -157,17 +146,13 @@ public class AppPrefsProvider extends FDroidProvider {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
 | 
					    public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
 | 
				
			||||||
        switch (MATCHER.match(uri)) {
 | 
					        if (MATCHER.match(uri) != CODE_SINGLE) {
 | 
				
			||||||
            case CODE_SINGLE:
 | 
					            throw new UnsupportedOperationException("Update not supported for " + uri + ".");
 | 
				
			||||||
                QuerySelection query = new QuerySelection(where, whereArgs)
 | 
					 | 
				
			||||||
                        .add(querySingle(uri.getLastPathSegment()));
 | 
					 | 
				
			||||||
                int count = db().update(getTableName(), values, query.getSelection(), query.getArgs());
 | 
					 | 
				
			||||||
                getContext().getContentResolver().notifyChange(AppProvider.getCanUpdateUri(), null);
 | 
					 | 
				
			||||||
                return count;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            default:
 | 
					 | 
				
			||||||
                throw new UnsupportedOperationException("Update not supported for " + uri + ".");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        QuerySelection query = new QuerySelection(where, whereArgs).add(querySingle(uri.getLastPathSegment()));
 | 
				
			||||||
 | 
					        int count = db().update(getTableName(), values, query.getSelection(), query.getArgs());
 | 
				
			||||||
 | 
					        getContext().getContentResolver().notifyChange(AppProvider.getCanUpdateUri(), null);
 | 
				
			||||||
 | 
					        return count;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -330,27 +330,28 @@ class DBHelper extends SQLiteOpenHelper {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void addAppPrefsTable(SQLiteDatabase db, int oldVersion) {
 | 
					    private void addAppPrefsTable(SQLiteDatabase db, int oldVersion) {
 | 
				
			||||||
        if (oldVersion < 60) {
 | 
					        if (oldVersion >= 60) {
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
            Utils.debugLog(TAG, "Creating app preferences table");
 | 
					 | 
				
			||||||
            db.execSQL(CREATE_TABLE_APP_PREFS);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            Utils.debugLog(TAG, "Migrating app preferences to separate table");
 | 
					 | 
				
			||||||
            db.execSQL(
 | 
					 | 
				
			||||||
                    "INSERT INTO " + AppPrefsTable.NAME + " ("
 | 
					 | 
				
			||||||
                    + AppPrefsTable.Cols.PACKAGE_NAME + ", "
 | 
					 | 
				
			||||||
                    + AppPrefsTable.Cols.IGNORE_THIS_UPDATE + ", "
 | 
					 | 
				
			||||||
                    + AppPrefsTable.Cols.IGNORE_ALL_UPDATES
 | 
					 | 
				
			||||||
                    + ") SELECT "
 | 
					 | 
				
			||||||
                    + AppTable.Cols.PACKAGE_NAME + ", "
 | 
					 | 
				
			||||||
                    + "ignoreThisUpdate, "
 | 
					 | 
				
			||||||
                    + "ignoreAllUpdates "
 | 
					 | 
				
			||||||
                    + "FROM " + AppTable.NAME + " "
 | 
					 | 
				
			||||||
                    + "WHERE ignoreThisUpdate > 0 OR ignoreAllUpdates > 0"
 | 
					 | 
				
			||||||
            );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            resetTransient(db);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Utils.debugLog(TAG, "Creating app preferences table");
 | 
				
			||||||
 | 
					        db.execSQL(CREATE_TABLE_APP_PREFS);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Utils.debugLog(TAG, "Migrating app preferences to separate table");
 | 
				
			||||||
 | 
					        db.execSQL(
 | 
				
			||||||
 | 
					                "INSERT INTO " + AppPrefsTable.NAME + " ("
 | 
				
			||||||
 | 
					                + AppPrefsTable.Cols.PACKAGE_NAME + ", "
 | 
				
			||||||
 | 
					                + AppPrefsTable.Cols.IGNORE_THIS_UPDATE + ", "
 | 
				
			||||||
 | 
					                + AppPrefsTable.Cols.IGNORE_ALL_UPDATES
 | 
				
			||||||
 | 
					                + ") SELECT "
 | 
				
			||||||
 | 
					                + AppTable.Cols.PACKAGE_NAME + ", "
 | 
				
			||||||
 | 
					                + "ignoreThisUpdate, "
 | 
				
			||||||
 | 
					                + "ignoreAllUpdates "
 | 
				
			||||||
 | 
					                + "FROM " + AppTable.NAME + " "
 | 
				
			||||||
 | 
					                + "WHERE ignoreThisUpdate > 0 OR ignoreAllUpdates > 0"
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        resetTransient(db);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user