Skip to content

Conversation

@PavloNetrebchuk
Copy link
Contributor

@PavloNetrebchuk PavloNetrebchuk commented Dec 5, 2025

Fix Google Calendar Integration

Problem

Calendar events were not appearing in Google Calendar. 441

Root Cause

The code was attempting to use CALLER_IS_SYNCADAPTER=true URI parameter, which is only available to actual sync adapters, not regular Android applications. This caused calendar and event operations to fail silently.

Why Regular Apps Can't Use CALLER_IS_SYNCADAPTER

The CALLER_IS_SYNCADAPTER parameter is a security and permission mechanism in Android's Calendar Provider:

  1. Security Model: Sync adapters are system-level components that must be declared in AndroidManifest.xml with specific permissions and metadata. They are granted elevated privileges to modify calendar data across accounts.

  2. Permission Requirements: To use CALLER_IS_SYNCADAPTER, an app must:

    • Be declared as a sync adapter in the manifest
    • Have a corresponding AccountAuthenticator
    • Be registered with the system's sync framework
    • Have the android.permission.WRITE_SYNC_SETTINGS permission
  3. Regular App Limitations: Regular applications (like our OpenEdX app) cannot:

    • Create calendars in Google accounts using sync adapter URIs
    • Use sync adapter URIs for event operations
    • Delete Google calendars (only Google's sync adapter can do this)
  4. What Happens When Used Incorrectly: When a regular app tries to use CALLER_IS_SYNCADAPTER=true:

    • The Calendar Provider ignores the parameter or rejects the operation
    • Operations fail silently without throwing exceptions
    • No calendar/events are created, but no error is reported

Solution

1. Fixed Calendar Creation

  • Before: Attempted to create calendars using sync adapter URI (failed silently)
  • After:
    • First tries to find an existing Google Calendar (primary or any writable)
    • If found, uses that calendar ID so events sync to Google Calendar
    • If no Google Calendar exists, creates a local calendar
    • Uses standard CalendarContract.Calendars.CONTENT_URI instead of sync adapter URI

2. Fixed Event Operations

  • Before: Attempted to use sync adapter URI for adding/deleting events
  • After: Uses standard CalendarContract.Events.CONTENT_URI
    • Events automatically sync to Google Calendar if the calendar is a Google Calendar
    • Works correctly for both Google and local calendars

3. Fixed Calendar Deletion

  • Before: Only deleted calendar, leaving events behind
  • After:
    • First deletes all events in the calendar
    • For Google Calendars: Only deletes events (cannot delete the calendar itself)
    • For local calendars: Deletes both events and the calendar
    • Uses proper ContentUris.withAppendedId() for URI construction

Limitation ⚠️

Because the application lacks permissions to create calendars and can only insert events into the user’s default calendar, it is not possible to customize calendar properties such as name or color.


Creating google calendar:

Screen.Recording.2025-12-05.at.13.56.40.mov

Creating local calendar:

Screen.Recording.2025-12-15.at.15.30.07.mov

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Dec 5, 2025
@openedx-webhooks
Copy link

Thanks for the pull request, @PavloNetrebchuk!

This repository is currently maintained by @openedx/openedx-mobile-maintainers.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

Copy link
Contributor

@volodymyr-chekyrta volodymyr-chekyrta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@PavloNetrebchuk PavloNetrebchuk force-pushed the feat/google_calendar_sync branch 5 times, most recently from 7cbdfc6 to 2cbb408 Compare December 8, 2025 16:43
@PavloNetrebchuk PavloNetrebchuk force-pushed the feat/google_calendar_sync branch from 2cbb408 to 0baa9e5 Compare December 8, 2025 16:47
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Ready for Review in Contributions Dec 11, 2025
Copy link
Contributor

@IvanStepanok IvanStepanok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@volodymyr-chekyrta volodymyr-chekyrta merged commit a0c0c92 into openedx:develop Dec 18, 2025
6 checks passed
@github-project-automation github-project-automation bot moved this from Ready for Review to Done in Contributions Dec 18, 2025
@volodymyr-chekyrta volodymyr-chekyrta deleted the feat/google_calendar_sync branch December 18, 2025 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open-source-contribution PR author is not from Axim or 2U

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Course Shared Calendar Events Not Visible in Google Calendar by Default

4 participants