use of android.content.OperationApplicationException in project VirtualAPK by didi.
the class RemoteContentProvider method applyBatch.
@NonNull
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
try {
Field uriField = ContentProviderOperation.class.getDeclaredField("mUri");
uriField.setAccessible(true);
for (ContentProviderOperation operation : operations) {
Uri pluginUri = Uri.parse(operation.getUri().getQueryParameter(KEY_URI));
uriField.set(operation, pluginUri);
}
} catch (Exception e) {
return new ContentProviderResult[0];
}
if (operations.size() > 0) {
ContentProvider provider = getContentProvider(operations.get(0).getUri());
if (provider != null) {
return provider.applyBatch(operations);
}
}
return new ContentProviderResult[0];
}
use of android.content.OperationApplicationException in project network-monitor by caarmen.
the class DBImport method execute.
/**
* Replace the database of our app with the contents of the database found at the given uri.
*/
@Override
public void execute(ProgressListener listener) {
try {
if (mUri.getScheme().equals("file")) {
File db = new File(mUri.getEncodedPath());
importDB(db, listener);
} else {
InputStream is = mContext.getContentResolver().openInputStream(mUri);
File tempDb = new File(mContext.getCacheDir(), "temp" + System.currentTimeMillis() + ".db");
FileOutputStream os = new FileOutputStream(tempDb);
if (IoUtil.copy(is, os) > 0) {
importDB(tempDb, listener);
// noinspection ResultOfMethodCallIgnored
tempDb.delete();
}
}
} catch (RemoteException | OperationApplicationException | SQLException | IOException e) {
Log.w(TAG, "Error importing the db: " + e.getMessage(), e);
}
}
use of android.content.OperationApplicationException in project iosched by google.
the class SessionCalendarService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
if (!permissionsAlreadyGranted()) {
LOGW(TAG, "Calendar permission not granted.");
return;
}
final String action = intent.getAction();
LOGD(TAG, "Received intent: " + action);
final ContentResolver resolver = getContentResolver();
if (ACTION_UPDATE_ALL_SESSIONS_CALENDAR.equals(action) && SettingsUtils.shouldSyncCalendar(this)) {
try {
getContentResolver().applyBatch(CalendarContract.AUTHORITY, processAllSessionsCalendar(resolver, getCalendarId(intent)));
sendBroadcast(new Intent(SessionCalendarService.ACTION_UPDATE_ALL_SESSIONS_CALENDAR_COMPLETED));
} catch (RemoteException | OperationApplicationException e) {
LOGE(TAG, "Error adding all sessions to Google Calendar", e);
}
} else if (ACTION_CLEAR_ALL_SESSIONS_CALENDAR.equals(action)) {
try {
getContentResolver().applyBatch(CalendarContract.AUTHORITY, processClearAllSessions(getCalendarId(intent)));
} catch (RemoteException | OperationApplicationException e) {
LOGE(TAG, "Error clearing all sessions from Google Calendar", e);
}
}
}
use of android.content.OperationApplicationException in project iosched by google.
the class PostSignInUpgradeService method onHandleIntent.
@Override
protected void onHandleIntent(@Nullable Intent intent) {
if (intent == null) {
return;
}
String accountName = intent.getStringExtra(KEY_ACCOUNT_NAME);
if (accountName == null) {
return;
}
// TODO: It would be better if the default value for the account in
// the non-signed in case was not "null". When that is modified update this.
String previousAccountName = null;
// The task is to upgrade all user data that was associated with a non-logged in user
// and update it to the signed in user.
ArrayList<ContentProviderOperation> ops = new ArrayList<>(3);
// noinspection ConstantConditions
ops.add(ContentProviderOperation.newUpdate(ScheduleContractHelper.addOverrideAccountUpdateAllowed(MySchedule.buildMyScheduleUri(previousAccountName))).withValue(MySchedule.MY_SCHEDULE_ACCOUNT_NAME, accountName).build());
// noinspection ConstantConditions
ops.add(ContentProviderOperation.newUpdate(ScheduleContractHelper.addOverrideAccountUpdateAllowed(MyFeedbackSubmitted.buildMyFeedbackSubmittedUri(previousAccountName))).withValue(MyFeedbackSubmitted.MY_FEEDBACK_SUBMITTED_ACCOUNT_NAME, accountName).build());
// Delete any reservations (should be none)
// noinspection ConstantConditions
ops.add(ContentProviderOperation.newDelete(MyReservations.buildMyReservationUri(previousAccountName)).withSelection(MyReservations.MY_RESERVATION_ACCOUNT_NAME, null).build());
try {
ContentProviderResult[] results = getContentResolver().applyBatch(ScheduleContract.CONTENT_AUTHORITY, ops);
if (LogUtils.LOGGING_ENABLED) {
for (ContentProviderResult res : results) {
LOGV(TAG, "Result of update: uri: " + res.uri + " count: " + res.count);
}
}
} catch (RemoteException | OperationApplicationException e) {
LOGE(TAG, "Unexpected exception upgrading the user data to signed in user", e);
} finally {
// Note: Once we are done with the upgrade we trigger a manual sync for user data
SyncHelper.requestManualSync(true);
}
}
use of android.content.OperationApplicationException in project iosched by google.
the class ConferenceDataHandler method applyConferenceData.
/**
* Parses the conference data in the given objects and imports the data into the
* content provider. The format of the data is documented at https://code.google.com/p/iosched.
*
* @param dataBodies The collection of JSON objects to parse and import.
* @param dataTimestamp The timestamp of the data. This should be in RFC1123 format.
* @param downloadsAllowed Whether or not we are supposed to download data from the internet if
* needed.
* @throws IOException If there is a problem parsing the data.
*/
public void applyConferenceData(String[] dataBodies, String dataTimestamp, boolean downloadsAllowed) throws IOException {
LOGD(TAG, "Applying data from " + dataBodies.length + " files, timestamp " + dataTimestamp);
// create handlers for each data type
mHandlerForKey.put(DATA_KEY_ROOMS, mRoomsHandler = new RoomsHandler(mContext));
mHandlerForKey.put(DATA_KEY_BLOCKS, mBlocksHandler = new BlocksHandler(mContext));
mHandlerForKey.put(DATA_KEY_TAGS, mTagsHandler = new TagsHandler(mContext));
mHandlerForKey.put(DATA_KEY_SPEAKERS, mSpeakersHandler = new SpeakersHandler(mContext));
mHandlerForKey.put(DATA_KEY_SESSIONS, mSessionsHandler = new SessionsHandler(mContext));
mHandlerForKey.put(DATA_KEY_SEARCH_SUGGESTIONS, mSearchSuggestHandler = new SearchSuggestHandler(mContext));
mHandlerForKey.put(DATA_KEY_MAP, mMapPropertyHandler = new MapPropertyHandler(mContext));
mHandlerForKey.put(DATA_KEY_HASHTAGS, mHashtagsHandler = new HashtagsHandler(mContext));
mHandlerForKey.put(DATA_KEY_VIDEOS, mVideosHandler = new VideosHandler(mContext));
mHandlerForKey.put(DATA_KEY_CARDS, mCardHandler = new CardHandler(mContext));
// process the jsons. This will call each of the handlers when appropriate to deal
// with the objects we see in the data.
LOGD(TAG, "Processing " + dataBodies.length + " JSON objects.");
for (int i = 0; i < dataBodies.length; i++) {
LOGD(TAG, "Processing json object #" + (i + 1) + " of " + dataBodies.length);
processDataBody(dataBodies[i]);
}
// the sessions handler needs to know the tag and speaker maps to process sessions
mSessionsHandler.setTagMap(mTagsHandler.getTagMap());
mSessionsHandler.setSpeakerMap(mSpeakersHandler.getSpeakerMap());
// produce the necessary content provider operations
ArrayList<ContentProviderOperation> batch = new ArrayList<>();
for (String key : DATA_KEYS_IN_ORDER) {
LOGI(TAG, "Building content provider operations for: " + key);
mHandlerForKey.get(key).makeContentProviderOperations(batch);
LOGI(TAG, "Content provider operations so far: " + batch.size());
}
LOGD(TAG, "Total content provider operations: " + batch.size());
// download or process local map tile overlay files (SVG files)
LOGD(TAG, "Processing map overlay files");
processMapOverlayFiles(mMapPropertyHandler.getTileOverlays(), downloadsAllowed);
// finally, push the changes into the Content Provider
LOGI(TAG, "Applying " + batch.size() + " content provider operations.");
try {
int operations = batch.size();
if (operations > 0) {
mContext.getContentResolver().applyBatch(ScheduleContract.CONTENT_AUTHORITY, batch);
}
LOGD(TAG, "Successfully applied " + operations + " content provider operations.");
mContentProviderOperationsDone += operations;
} catch (RemoteException ex) {
LOGE(TAG, "RemoteException while applying content provider operations.");
throw new RuntimeException("Error executing content provider batch operation", ex);
} catch (OperationApplicationException ex) {
LOGE(TAG, "OperationApplicationException while applying content provider operations.");
throw new RuntimeException("Error executing content provider batch operation", ex);
}
// notify all top-level paths
LOGD(TAG, "Notifying changes on all top-level paths on Content Resolver.");
ContentResolver resolver = mContext.getContentResolver();
for (String path : ScheduleContract.TOP_LEVEL_PATHS) {
Uri uri = ScheduleContract.BASE_CONTENT_URI.buildUpon().appendPath(path).build();
resolver.notifyChange(uri, null);
}
// update our data timestamp
setDataTimestamp(dataTimestamp);
LOGD(TAG, "Done applying conference data.");
}
Aggregations