use of android.content.ContentProviderOperation in project robolectric by robolectric.
the class ShadowContentProviderOperationTest method reflectionShouldWork.
@Test
public void reflectionShouldWork() {
final Uri uri = Uri.parse("content://authority/path");
ContentProviderOperation op = ContentProviderOperation.newInsert(uri).withValue("insertKey", "insertValue").withValueBackReference("backKey", 2).build();
// insert and values back references
assertThat(op.getUri()).isEqualTo(uri);
ShadowContentProviderOperation shadow = Shadows.shadowOf(op);
assertThat(shadow.getType()).isEqualTo(ShadowContentProviderOperation.TYPE_INSERT);
assertThat(shadow.getContentValues().getAsString("insertKey")).isEqualTo("insertValue");
assertThat(shadow.getValuesBackReferences().getAsInteger("backKey")).isEqualTo(2);
// update and selection back references
op = ContentProviderOperation.newUpdate(uri).withValue("updateKey", "updateValue").withSelection("a=? and b=?", new String[] { "abc" }).withSelectionBackReference(1, 3).build();
assertThat(op.getUri()).isEqualTo(uri);
shadow = Shadows.shadowOf(op);
assertThat(shadow.getType()).isEqualTo(ShadowContentProviderOperation.TYPE_UPDATE);
assertThat(shadow.getContentValues().getAsString("updateKey")).isEqualTo("updateValue");
assertThat(shadow.getSelection()).isEqualTo("a=? and b=?");
assertThat(shadow.getSelectionArgs()).containsExactly("abc");
assertThat(shadow.getSelectionArgsBackReferences()).isEqualTo(Collections.<Integer, Integer>singletonMap(1, 3));
// delete and expected count
op = ContentProviderOperation.newDelete(uri).withExpectedCount(1).build();
assertThat(op.getUri()).isEqualTo(uri);
shadow = Shadows.shadowOf(op);
assertThat(shadow.getType()).isEqualTo(ShadowContentProviderOperation.TYPE_DELETE);
assertThat(shadow.getExpectedCount()).isEqualTo(1);
}
use of android.content.ContentProviderOperation 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.ContentProviderOperation in project Etar-Calendar by Etar-Group.
the class EditEventHelperTest method testUpdatePastEvents.
@Smoke
@SmallTest
public void testUpdatePastEvents() {
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
ArrayList<ContentProviderOperation> expectedOps = new ArrayList<ContentProviderOperation>();
// Sep 3, 2016, 12AM UTC time
long initialBeginTime = 1472864400000L;
mValues = new ContentValues();
mModel1 = buildTestModel();
mModel1.mUri = (AUTHORITY_URI + TEST_EVENT_ID);
mActivity = buildTestContext();
mHelper = new EditEventHelper(mActivity, null);
// yyyymmddThhmmssZ
mValues.put(Events.RRULE, "FREQ=DAILY;UNTIL=20160903;WKST=SU");
mValues.put(Events.DTSTART, TEST_START);
ContentProviderOperation.Builder b = ContentProviderOperation.newUpdate(Uri.parse(mModel1.mUri)).withValues(mValues);
expectedOps.add(b.build());
mHelper.updatePastEvents(ops, mModel1, initialBeginTime);
assertEquals(expectedOps, ops);
mModel1.mAllDay = false;
// yyyymmddThhmmssZ
mValues.put(Events.RRULE, "FREQ=DAILY;UNTIL=20160903T005959Z;WKST=SU");
expectedOps.clear();
b = ContentProviderOperation.newUpdate(Uri.parse(mModel1.mUri)).withValues(mValues);
expectedOps.add(b.build());
ops.clear();
mHelper.updatePastEvents(ops, mModel1, initialBeginTime);
assertEquals(expectedOps, ops);
}
use of android.content.ContentProviderOperation in project Etar-Calendar by Etar-Group.
the class EditEventHelperTest method addExpectedMinutes.
private void addExpectedMinutes(ArrayList<ContentProviderOperation> expectedOps) {
ContentProviderOperation.Builder b;
mValues = new ContentValues();
mValues.clear();
mValues.put(Reminders.MINUTES, 5);
mValues.put(Reminders.METHOD, Reminders.METHOD_DEFAULT);
mValues.put(Reminders.EVENT_ID, TEST_EVENT_ID);
b = ContentProviderOperation.newInsert(Reminders.CONTENT_URI).withValues(mValues);
expectedOps.add(b.build());
mValues.clear();
mValues.put(Reminders.MINUTES, 10);
mValues.put(Reminders.METHOD, Reminders.METHOD_DEFAULT);
mValues.put(Reminders.EVENT_ID, TEST_EVENT_ID);
b = ContentProviderOperation.newInsert(Reminders.CONTENT_URI).withValues(mValues);
expectedOps.add(b.build());
mValues.clear();
mValues.put(Reminders.MINUTES, 15);
mValues.put(Reminders.METHOD, Reminders.METHOD_DEFAULT);
mValues.put(Reminders.EVENT_ID, TEST_EVENT_ID);
b = ContentProviderOperation.newInsert(Reminders.CONTENT_URI).withValues(mValues);
expectedOps.add(b.build());
}
use of android.content.ContentProviderOperation in project Etar-Calendar by Etar-Group.
the class EditEventHelperTest method addExpectedMinutesWithBackRef.
private void addExpectedMinutesWithBackRef(ArrayList<ContentProviderOperation> expectedOps) {
ContentProviderOperation.Builder b;
mValues = new ContentValues();
mValues.clear();
mValues.put(Reminders.MINUTES, 5);
mValues.put(Reminders.METHOD, Reminders.METHOD_DEFAULT);
b = ContentProviderOperation.newInsert(Reminders.CONTENT_URI).withValues(mValues);
b.withValueBackReference(Reminders.EVENT_ID, TEST_EVENT_INDEX_ID);
expectedOps.add(b.build());
mValues.clear();
mValues.put(Reminders.MINUTES, 10);
mValues.put(Reminders.METHOD, Reminders.METHOD_DEFAULT);
b = ContentProviderOperation.newInsert(Reminders.CONTENT_URI).withValues(mValues);
b.withValueBackReference(Reminders.EVENT_ID, TEST_EVENT_INDEX_ID);
expectedOps.add(b.build());
mValues.clear();
mValues.put(Reminders.MINUTES, 15);
mValues.put(Reminders.METHOD, Reminders.METHOD_DEFAULT);
b = ContentProviderOperation.newInsert(Reminders.CONTENT_URI).withValues(mValues);
b.withValueBackReference(Reminders.EVENT_ID, TEST_EVENT_INDEX_ID);
expectedOps.add(b.build());
}
Aggregations