summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2019-05-08 03:11:24 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2019-05-08 03:11:24 +0000
commitf013f1c6428ebb1702543a184d6f6d356321d9ef (patch)
tree2250d0ca95b1f4d9737844a407824a5914a4296f
parentf74d87f641d8d9029798512ac4f39833aee707b0 (diff)
parent9437165cf6415d07d3933bb9638ec43fa55a565b (diff)
downloadplatform_packages_providers_CalendarProvider-android10-security-release.tar.gz
platform_packages_providers_CalendarProvider-android10-security-release.tar.bz2
platform_packages_providers_CalendarProvider-android10-security-release.zip
Change-Id: I9800c12096612e870f1a60fd55cfe999001604c7
-rw-r--r--src/com/android/providers/calendar/CalendarProvider2.java10
-rw-r--r--tests/src/com/android/providers/calendar/CalendarProvider2Test.java17
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);
}