mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 11:12:15 -05:00
Fix update and insert for new api content provider
This commit is contained in:
parent
cff35ca842
commit
8c496d3393
@ -27,6 +27,7 @@ import android.database.sqlite.SQLiteDatabase;
|
|||||||
import android.database.sqlite.SQLiteQueryBuilder;
|
import android.database.sqlite.SQLiteQueryBuilder;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.BaseColumns;
|
import android.provider.BaseColumns;
|
||||||
|
import android.support.v4.database.DatabaseUtilsCompat;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
@ -860,11 +861,11 @@ public class KeychainProvider extends ContentProvider {
|
|||||||
selectionArgs);
|
selectionArgs);
|
||||||
break;
|
break;
|
||||||
case API_APPS_BY_PACKAGE_NAME:
|
case API_APPS_BY_PACKAGE_NAME:
|
||||||
count = db.delete(Tables.API_APPS, buildDefaultApiAppsSelection(uri, true, selection),
|
count = db.delete(Tables.API_APPS, buildDefaultApiAppsSelection(uri, selection),
|
||||||
selectionArgs);
|
selectionArgs);
|
||||||
break;
|
break;
|
||||||
case API_ACCOUNTS_BY_ACCOUNT_NAME:
|
case API_ACCOUNTS_BY_ACCOUNT_NAME:
|
||||||
count = db.delete(Tables.API_ACCOUNTS, buildDefaultApiAccountsSelection(uri, true, selection),
|
count = db.delete(Tables.API_ACCOUNTS, buildDefaultApiAccountsSelection(uri, selection),
|
||||||
selectionArgs);
|
selectionArgs);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -931,11 +932,11 @@ public class KeychainProvider extends ContentProvider {
|
|||||||
break;
|
break;
|
||||||
case API_APPS_BY_PACKAGE_NAME:
|
case API_APPS_BY_PACKAGE_NAME:
|
||||||
count = db.update(Tables.API_APPS, values,
|
count = db.update(Tables.API_APPS, values,
|
||||||
buildDefaultApiAppsSelection(uri, true, selection), selectionArgs);
|
buildDefaultApiAppsSelection(uri, selection), selectionArgs);
|
||||||
break;
|
break;
|
||||||
case API_ACCOUNTS_BY_ACCOUNT_NAME:
|
case API_ACCOUNTS_BY_ACCOUNT_NAME:
|
||||||
count = db.update(Tables.API_ACCOUNTS, values,
|
count = db.update(Tables.API_ACCOUNTS, values,
|
||||||
buildDefaultApiAccountsSelection(uri, true, selection), selectionArgs);
|
buildDefaultApiAccountsSelection(uri, selection), selectionArgs);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new UnsupportedOperationException("Unknown uri: " + uri);
|
throw new UnsupportedOperationException("Unknown uri: " + uri);
|
||||||
@ -1034,34 +1035,29 @@ public class KeychainProvider extends ContentProvider {
|
|||||||
* @param selection
|
* @param selection
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private String buildDefaultApiAppsSelection(Uri uri, boolean packageSelection, String selection) {
|
private String buildDefaultApiAppsSelection(Uri uri, String selection) {
|
||||||
String lastPathSegment = uri.getLastPathSegment();
|
String packageName = DatabaseUtils.sqlEscapeString(uri.getLastPathSegment());
|
||||||
|
|
||||||
String andSelection = "";
|
String andSelection = "";
|
||||||
if (!TextUtils.isEmpty(selection)) {
|
if (!TextUtils.isEmpty(selection)) {
|
||||||
andSelection = " AND (" + selection + ")";
|
andSelection = " AND (" + selection + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packageSelection) {
|
return ApiApps.PACKAGE_NAME + "=" + packageName + andSelection;
|
||||||
return ApiApps.PACKAGE_NAME + "=" + lastPathSegment + andSelection;
|
|
||||||
} else {
|
|
||||||
return BaseColumns._ID + "=" + lastPathSegment + andSelection;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String buildDefaultApiAccountsSelection(Uri uri, boolean packageSelection, String selection) {
|
private String buildDefaultApiAccountsSelection(Uri uri, String selection) {
|
||||||
String lastPathSegment = uri.getLastPathSegment();
|
String packageName = DatabaseUtils.sqlEscapeString(uri.getPathSegments().get(2));
|
||||||
|
String accountName = DatabaseUtils.sqlEscapeString(uri.getLastPathSegment());
|
||||||
|
|
||||||
String andSelection = "";
|
String andSelection = "";
|
||||||
if (!TextUtils.isEmpty(selection)) {
|
if (!TextUtils.isEmpty(selection)) {
|
||||||
andSelection = " AND (" + selection + ")";
|
andSelection = " AND (" + selection + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packageSelection) {
|
return ApiAccounts.PACKAGE_NAME_FK + "=" + packageName + " AND "
|
||||||
return ApiAccounts.PACKAGE_NAME_FK + "=" + lastPathSegment + andSelection;
|
+ ApiAccounts.ACCOUNT_NAME + "=" + accountName
|
||||||
} else {
|
+ andSelection;
|
||||||
return BaseColumns._ID + "=" + lastPathSegment + andSelection;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
|
Loading…
Reference in New Issue
Block a user