diff options
author | Yasmin <yasmo@google.com> | 2019-05-07 06:27:23 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-05-07 06:27:23 -0700 |
commit | aae64670394e9c9fb29a3a2410a804e7226745c0 (patch) | |
tree | 2250d0ca95b1f4d9737844a407824a5914a4296f | |
parent | 1f7e26dc41b0837a7c8de8595afc7c8d845dfead (diff) | |
parent | 9437165cf6415d07d3933bb9638ec43fa55a565b (diff) | |
download | CalendarProvider-aae64670394e9c9fb29a3a2410a804e7226745c0.tar.gz |
Throw exception when work profile doesn't exist or disabled or calendar app is not whitelisted or setting for calendar integration is disabled.
am: 9437165cf6
Change-Id: I82ec5dff1e5dd766ca6fe3f1b76d036518526f47
-rw-r--r-- | src/com/android/providers/calendar/CalendarProvider2.java | 10 | ||||
-rw-r--r-- | tests/src/com/android/providers/calendar/CalendarProvider2Test.java | 17 |
2 files changed, 17 insertions, 10 deletions
diff --git a/src/com/android/providers/calendar/CalendarProvider2.java b/src/com/android/providers/calendar/CalendarProvider2.java index e6cf42b..4a6bd22 100644 --- a/src/com/android/providers/calendar/CalendarProvider2.java +++ b/src/com/android/providers/calendar/CalendarProvider2.java @@ -929,6 +929,12 @@ public class CalendarProvider2 extends SQLiteContentProvider implements OnAccoun : selection + " AND (" + SELECTION_PRIMARY_CALENDAR + ")"; } + /* + * Throw UnsupportedOperationException if + * <p>1. Work profile doesn't exits or disabled. + * <p>2. Calling package is not allowed to access cross profile calendar. + * <p>3. CROSS_PROFILE_CALENDAR_ENABLED is turned off in Settings. + */ private Cursor queryWorkProfileProvider(Uri localUri, String[] projection, String selection, String[] selectionArgs, String sortOrder, List<String> additionalPathSegments) { @@ -936,10 +942,10 @@ public class CalendarProvider2 extends SQLiteContentProvider implements OnAccoun // allowed columns. projection = mCrossProfileCalendarHelper.getCalibratedProjection( projection, localUri); - // Return empty cursor if cross profile calendar is currently not available. + // Throw exception if cross profile calendar is currently not available. final int workProfileUserId = getWorkProfileUserId(); if (!canAccessCrossProfileCalendar(workProfileUserId)) { - return createEmptyCursor(projection); + throw new UnsupportedOperationException("Can't access cross profile for " + localUri); } Uri remoteUri = maybeAddUserId( diff --git a/tests/src/com/android/providers/calendar/CalendarProvider2Test.java b/tests/src/com/android/providers/calendar/CalendarProvider2Test.java index f420622..e0a4edf 100644 --- a/tests/src/com/android/providers/calendar/CalendarProvider2Test.java +++ b/tests/src/com/android/providers/calendar/CalendarProvider2Test.java @@ -3600,14 +3600,15 @@ public class CalendarProvider2Test extends AndroidTestCase { // Assume cross profile uri access is not allowed by policy or disabled in settings. MockCrossProfileCalendarHelper.setPackageAllowedToAccessCalendar(false); - // Test empty cursor is returned if cross profile calendar is disabled in settings. - final Cursor cursor = mResolver.query( - Calendars.ENTERPRISE_CONTENT_URI, - new String[]{}, null, null, null); - assertTrue(cursor != null); - assertTrue(cursor.getCount() == 0); - cursor.close(); - + // Throw exception if cross profile calendar is disabled in settings. + try { + final Cursor cursor = mResolver.query( + Calendars.ENTERPRISE_CONTENT_URI, + new String[]{}, null, null, null); + fail("Unsupported operation exception should have been raised."); + } catch (UnsupportedOperationException e) { + // Exception expected. + } cleanupEnterpriseTestForCalendars(1); } |