use of android.content.OperationApplicationException in project Meltdown by phubbard.
the class MeltdownApp method doCPtest.
public void doCPtest() {
ContentResolver cr = getContentResolver();
List<Integer> items = fetchUnreadItemsIDs();
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
// Get data in max-fever-size chunks
final int PER_FETCH = 50;
final int num_fetches = (int) Math.ceil(items.size() / PER_FETCH) + 1;
for (int idx = 0; idx < num_fetches; idx++) {
int left_index = idx * PER_FETCH;
int right_index = Math.min((idx + 1) * PER_FETCH, items.size());
Log.d(TAG, "On run " + idx + " pulling from " + left_index + " to " + (right_index - 1) + " of " + items.size());
List<Integer> ids = items.subList(left_index, right_index);
String payload = xcvr.fetchListOfItems(ids);
for (int j = 0; j < ids.size(); j++) {
JSONArray jitems;
RssItem this_item;
try {
JSONObject jdata = new JSONObject(payload);
jitems = jdata.getJSONArray("items");
this_item = new RssItem(jitems.getJSONObject(j));
ops.add(ContentProviderOperation.newInsert(ItemProvider.URI).withYieldAllowed(true).withValues(this_item.getCV()).build());
} catch (JSONException je) {
Log.e(TAG, "JSON error in CP import logic: ", je);
} finally {
}
}
}
try {
cr.applyBatch(ItemProvider.AUTHORITY, ops);
} catch (RemoteException e) {
Log.e(TAG, "Remote exception in bulk save", e);
e.printStackTrace();
} catch (OperationApplicationException e) {
Log.e(TAG, "OAE exception in bulk save", e);
e.printStackTrace();
}
cr.notifyChange(ItemProvider.URI, null, false);
}
use of android.content.OperationApplicationException in project android_frameworks_base by ResurrectionRemix.
the class TvInputManagerService method registerBroadcastReceivers.
private void registerBroadcastReceivers() {
PackageMonitor monitor = new PackageMonitor() {
private void buildTvInputList(String[] packages) {
synchronized (mLock) {
if (mCurrentUserId == getChangingUserId()) {
buildTvInputListLocked(mCurrentUserId, packages);
buildTvContentRatingSystemListLocked(mCurrentUserId);
}
}
}
@Override
public void onPackageUpdateFinished(String packageName, int uid) {
if (DEBUG)
Slog.d(TAG, "onPackageUpdateFinished(packageName=" + packageName + ")");
// This callback is invoked when the TV input is reinstalled.
// In this case, isReplacing() always returns true.
buildTvInputList(new String[] { packageName });
}
@Override
public void onPackagesAvailable(String[] packages) {
if (DEBUG) {
Slog.d(TAG, "onPackagesAvailable(packages=" + Arrays.toString(packages) + ")");
}
// available.
if (isReplacing()) {
buildTvInputList(packages);
}
}
@Override
public void onPackagesUnavailable(String[] packages) {
// unavailable.
if (DEBUG) {
Slog.d(TAG, "onPackagesUnavailable(packages=" + Arrays.toString(packages) + ")");
}
if (isReplacing()) {
buildTvInputList(packages);
}
}
@Override
public void onSomePackagesChanged() {
// the TV inputs.
if (DEBUG)
Slog.d(TAG, "onSomePackagesChanged()");
if (isReplacing()) {
if (DEBUG)
Slog.d(TAG, "Skipped building TV input list due to replacing");
// methods instead.
return;
}
buildTvInputList(null);
}
@Override
public boolean onPackageChanged(String packageName, int uid, String[] components) {
// the update can be handled in {@link #onSomePackagesChanged}.
return true;
}
@Override
public void onPackageRemoved(String packageName, int uid) {
synchronized (mLock) {
UserState userState = getOrCreateUserStateLocked(getChangingUserId());
if (!userState.packageSet.contains(packageName)) {
// Not a TV input package.
return;
}
}
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
String selection = TvContract.BaseTvColumns.COLUMN_PACKAGE_NAME + "=?";
String[] selectionArgs = { packageName };
operations.add(ContentProviderOperation.newDelete(TvContract.Channels.CONTENT_URI).withSelection(selection, selectionArgs).build());
operations.add(ContentProviderOperation.newDelete(TvContract.Programs.CONTENT_URI).withSelection(selection, selectionArgs).build());
operations.add(ContentProviderOperation.newDelete(TvContract.WatchedPrograms.CONTENT_URI).withSelection(selection, selectionArgs).build());
ContentProviderResult[] results = null;
try {
ContentResolver cr = getContentResolverForUser(getChangingUserId());
results = cr.applyBatch(TvContract.AUTHORITY, operations);
} catch (RemoteException | OperationApplicationException e) {
Slog.e(TAG, "error in applyBatch", e);
}
if (DEBUG) {
Slog.d(TAG, "onPackageRemoved(packageName=" + packageName + ", uid=" + uid + ")");
Slog.d(TAG, "results=" + results);
}
}
};
monitor.register(mContext, null, UserHandle.ALL, true);
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_USER_SWITCHED);
intentFilter.addAction(Intent.ACTION_USER_REMOVED);
mContext.registerReceiverAsUser(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (Intent.ACTION_USER_SWITCHED.equals(action)) {
switchUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
} else if (Intent.ACTION_USER_REMOVED.equals(action)) {
removeUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
}
}
}, UserHandle.ALL, intentFilter, null, null);
}
use of android.content.OperationApplicationException in project android by nextcloud.
the class FileDataStorageManager method saveShares.
public void saveShares(Collection<OCShare> shares) {
cleanShares();
if (shares != null) {
ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(shares.size());
// prepare operations to insert or update files to save in the given folder
for (OCShare share : shares) {
ContentValues cv = new ContentValues();
cv.put(ProviderTableMeta.OCSHARES_FILE_SOURCE, share.getFileSource());
cv.put(ProviderTableMeta.OCSHARES_ITEM_SOURCE, share.getItemSource());
cv.put(ProviderTableMeta.OCSHARES_SHARE_TYPE, share.getShareType().getValue());
cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH, share.getShareWith());
cv.put(ProviderTableMeta.OCSHARES_PATH, share.getPath());
cv.put(ProviderTableMeta.OCSHARES_PERMISSIONS, share.getPermissions());
cv.put(ProviderTableMeta.OCSHARES_SHARED_DATE, share.getSharedDate());
cv.put(ProviderTableMeta.OCSHARES_EXPIRATION_DATE, share.getExpirationDate());
cv.put(ProviderTableMeta.OCSHARES_TOKEN, share.getToken());
cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME, share.getSharedWithDisplayName());
cv.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, share.isFolder() ? 1 : 0);
cv.put(ProviderTableMeta.OCSHARES_USER_ID, share.getUserId());
cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getRemoteId());
cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name);
if (shareExistsForRemoteId(share.getRemoteId())) {
// updating an existing file
operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI_SHARE).withValues(cv).withSelection(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + "=?", new String[] { String.valueOf(share.getRemoteId()) }).build());
} else {
// adding a new file
operations.add(ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI_SHARE).withValues(cv).build());
}
}
// apply operations in batch
if (operations.size() > 0) {
@SuppressWarnings("unused") ContentProviderResult[] results = null;
Log_OC.d(TAG, String.format(Locale.ENGLISH, SENDING_TO_FILECONTENTPROVIDER_MSG, operations.size()));
try {
if (getContentResolver() != null) {
results = getContentResolver().applyBatch(MainApp.getAuthority(), operations);
} else {
results = getContentProviderClient().applyBatch(operations);
}
} catch (OperationApplicationException | RemoteException e) {
Log_OC.e(TAG, EXCEPTION_MSG + e.getMessage(), e);
}
}
}
}
use of android.content.OperationApplicationException in project GankTouTiao by heqiangflytosky.
the class SQLiteContentProvider method applyBatch.
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
int ypCount = 0;
int opCount = 0;
boolean callerIsSyncAdapter = false;
mDb = mOpenHelper.getWritableDatabase();
mDb.beginTransaction();
try {
mApplyingBatch.set(true);
final int numOperations = operations.size();
final ContentProviderResult[] results = new ContentProviderResult[numOperations];
for (int i = 0; i < numOperations; i++) {
if (++opCount >= MAX_OPERATIONS_PER_YIELD_POINT) {
throw new OperationApplicationException("Too many content provider operations between yield points. " + "The maximum number of operations per yield point is " + MAX_OPERATIONS_PER_YIELD_POINT, ypCount);
}
final ContentProviderOperation operation = operations.get(i);
if (!callerIsSyncAdapter && isCallerSyncAdapter(operation.getUri())) {
callerIsSyncAdapter = true;
}
if (i > 0 && operation.isYieldAllowed()) {
opCount = 0;
if (mDb.yieldIfContendedSafely(SLEEP_AFTER_YIELD_DELAY)) {
ypCount++;
}
}
results[i] = operation.apply(this, results, i);
}
mDb.setTransactionSuccessful();
return results;
} finally {
mApplyingBatch.set(false);
mDb.endTransaction();
onEndTransaction(callerIsSyncAdapter);
}
}
use of android.content.OperationApplicationException in project android_packages_apps_Gallery2 by LineageOS.
the class SQLiteContentProvider method applyBatch.
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
int ypCount = 0;
int opCount = 0;
boolean callerIsSyncAdapter = false;
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
db.beginTransaction();
try {
mApplyingBatch.set(true);
final int numOperations = operations.size();
final ContentProviderResult[] results = new ContentProviderResult[numOperations];
for (int i = 0; i < numOperations; i++) {
if (++opCount >= MAX_OPERATIONS_PER_YIELD_POINT) {
throw new OperationApplicationException("Too many content provider operations between yield points. " + "The maximum number of operations per yield point is " + MAX_OPERATIONS_PER_YIELD_POINT, ypCount);
}
final ContentProviderOperation operation = operations.get(i);
if (!callerIsSyncAdapter && isCallerSyncAdapter(operation.getUri())) {
callerIsSyncAdapter = true;
}
if (i > 0 && operation.isYieldAllowed()) {
opCount = 0;
if (db.yieldIfContendedSafely(SLEEP_AFTER_YIELD_DELAY)) {
ypCount++;
}
}
results[i] = operation.apply(this, results, i);
}
db.setTransactionSuccessful();
return results;
} finally {
mApplyingBatch.set(false);
db.endTransaction();
onEndTransaction(callerIsSyncAdapter);
}
}
Aggregations