Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 369f96dd authored by yuemingw's avatar yuemingw
Browse files

Add API to view calendar events cross profile.

Bug: 118456236
Test: .manual by TestDPC
cts test will be added later
Change-Id: I0d36586ea6017dea446abd8e609c2712ba88e93c
parent 5e34c414
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -35929,9 +35929,11 @@ package android.provider {
  }
  public final class CalendarContract {
    method public static boolean startViewCalendarEventInManagedProfile(android.content.Context, long, long, long, boolean, int);
    field public static final java.lang.String ACCOUNT_TYPE_LOCAL = "LOCAL";
    field public static final java.lang.String ACTION_EVENT_REMINDER = "android.intent.action.EVENT_REMINDER";
    field public static final java.lang.String ACTION_HANDLE_CUSTOM_EVENT = "android.provider.calendar.action.HANDLE_CUSTOM_EVENT";
    field public static final java.lang.String ACTION_VIEW_WORK_CALENDAR_EVENT = "android.provider.calendar.action.VIEW_WORK_CALENDAR_EVENT";
    field public static final java.lang.String AUTHORITY = "com.android.calendar";
    field public static final java.lang.String CALLER_IS_SYNCADAPTER = "caller_is_syncadapter";
    field public static final android.net.Uri CONTENT_URI;
@@ -35939,6 +35941,7 @@ package android.provider {
    field public static final java.lang.String EXTRA_EVENT_ALL_DAY = "allDay";
    field public static final java.lang.String EXTRA_EVENT_BEGIN_TIME = "beginTime";
    field public static final java.lang.String EXTRA_EVENT_END_TIME = "endTime";
    field public static final java.lang.String EXTRA_EVENT_ID = "id";
  }
  public static final class CalendarContract.Attendees implements android.provider.BaseColumns android.provider.CalendarContract.AttendeesColumns android.provider.CalendarContract.EventsColumns {
+30 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManager.UserOperationException;
import android.os.UserManager.UserOperationResult;
import android.provider.CalendarContract;
import android.provider.ContactsContract.Directory;
import android.provider.Settings;
import android.security.AttestedKeyPair;
@@ -10308,4 +10309,33 @@ public class DevicePolicyManager {
        }
        return false;
    }

    /**
     * Starts an activity to view calendar events in the managed profile.
     *
     * @param eventId the id of the event to be viewed.
     * @param start the start time of the event.
     * @param end the end time of the event.
     * @param allDay if the event is an all-day event.
     * @param flags flags to be set for the intent
     * @return {@code true} if the activity is started successfully. {@code false} otherwise.
     *
     * @see CalendarContract#startViewCalenderEventInManagedProfile(Context, String, long, long,
     * long, boolean, int)
     *
     * @hide
     */
    public boolean startViewCalendarEventInManagedProfile(long eventId, long start, long end,
            boolean allDay, int flags) {
        throwIfParentInstance("startViewCalendarEventInManagedProfile");
        if (mService != null) {
            try {
                return mService.startViewCalendarEventInManagedProfile(mContext.getPackageName(),
                        eventId, start, end, allDay, flags);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }
        return false;
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -431,4 +431,6 @@ interface IDevicePolicyManager {

    boolean isManagedKiosk();
    boolean isUnattendedManagedKiosk();

    boolean startViewCalendarEventInManagedProfile(String packageName, long eventId, long start, long end, boolean allDay, int flags);
}
+66 −14
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.provider;

import android.annotation.NonNull;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.UnsupportedAppUsage;
@@ -41,6 +42,8 @@ import android.text.format.DateUtils;
import android.text.format.Time;
import android.util.Log;

import com.android.internal.util.Preconditions;

/**
 * <p>
 * The contract between the calendar provider and applications. Contains
@@ -128,6 +131,13 @@ public final class CalendarContract {
    public static final String ACTION_HANDLE_CUSTOM_EVENT =
        "android.provider.calendar.action.HANDLE_CUSTOM_EVENT";

    /**
     * Action used to help apps show calendar events in the managed profile.
     */
    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
    public static final String ACTION_VIEW_WORK_CALENDAR_EVENT =
            "android.provider.calendar.action.VIEW_WORK_CALENDAR_EVENT";

    /**
     * Intent Extras key: {@link EventsColumns#CUSTOM_APP_URI} for the event in
     * the {@link #ACTION_HANDLE_CUSTOM_EVENT} intent
@@ -152,6 +162,11 @@ public final class CalendarContract {
     */
    public static final String EXTRA_EVENT_ALL_DAY = "allDay";

    /**
     * Intent Extras key: The id of an event.
     */
    public static final String EXTRA_EVENT_ID = "id";

    /**
     * This authority is used for writing to or querying from the calendar
     * provider. Note: This is set at first run and cannot be changed without
@@ -194,6 +209,43 @@ public final class CalendarContract {
     */
    private CalendarContract() {}

    /**
     * Starts an activity to view calendar events in the managed profile.
     *
     * When this API is called, the system will attempt to start an activity
     * in the managed profile with an intent targeting the same caller package.
     * The intent will have its action set to
     * {@link CalendarContract#ACTION_VIEW_WORK_CALENDAR_EVENT} and contain extras
     * corresponding to the API's arguments. A calendar app intending to support
     * cross profile events viewing should handle this intent, parse the arguments
     * and show the appropriate UI.
     *
     * @param context the context.
     * @param eventId the id of the event to be viewed. Will be put into {@link #EXTRA_EVENT_ID}
     *                field of the intent.
     * @param start the start time of the event. Will be put into {@link #EXTRA_EVENT_BEGIN_TIME}
     *              field of the intent.
     * @param end the end time of the event. Will be put into {@link #EXTRA_EVENT_END_TIME} field
     *            of the intent.
     * @param allDay if the event is an all-day event. Will be put into
     *               {@link #EXTRA_EVENT_ALL_DAY} field of the intent.
     * @param flags flags to be set on the intent via {@link Intent#setFlags}
     * @return {@code true} if the activity is started successfully. {@code false} otherwise.
     *
     * @see #EXTRA_EVENT_ID
     * @see #EXTRA_EVENT_BEGIN_TIME
     * @see #EXTRA_EVENT_END_TIME
     * @see #EXTRA_EVENT_ALL_DAY
     */
    public static boolean startViewCalendarEventInManagedProfile(@NonNull Context context,
            long eventId, long start, long end, boolean allDay, int flags) {
        Preconditions.checkNotNull(context, "Context is null");
        final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(
                Context.DEVICE_POLICY_SERVICE);
        return dpm.startViewCalendarEventInManagedProfile(eventId, start,
                end, allDay, flags);
    }

    /**
     * Generic columns for use by sync adapters. The specific functions of these
     * columns are private to the sync adapter. Other clients of the API should
@@ -695,7 +747,7 @@ public final class CalendarContract {
        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/calendars");

        /**
         * The content:// style URL for querying Calendars table in the work profile. Appending a
         * The content:// style URL for querying Calendars table in the managed profile. Appending a
         * calendar id using {@link ContentUris#withAppendedId(Uri, long)} will
         * specify a single calendar.
         *
@@ -715,9 +767,9 @@ public final class CalendarContract {
         * projection of the query to this uri that are not contained in the above list.
         *
         * <p>This uri will return an empty cursor if the calling user is not a parent profile
         * of a work profile, or cross profile calendar is disabled in Settings, or this uri is
         * queried from a package that is not whitelisted by profile owner of the work profile via
         * {@link DevicePolicyManager#addCrossProfileCalendarPackage(ComponentName, String)}.
         * of a managed profile, or cross profile calendar is disabled in Settings, or this uri is
         * queried from a package that is not whitelisted by profile owner of the managed profile
         * via {@link DevicePolicyManager#addCrossProfileCalendarPackage(ComponentName, String)}.
         *
         * @see DevicePolicyManager#getCrossProfileCalendarPackages(ComponentName)
         * @see Settings.Secure#CROSS_PROFILE_CALENDAR_ENABLED
@@ -1673,7 +1725,7 @@ public final class CalendarContract {
                Uri.parse("content://" + AUTHORITY + "/events");

        /**
         * The content:// style URL for querying Events table in the work profile. Appending an
         * The content:// style URL for querying Events table in the managed profile. Appending an
         * event id using {@link ContentUris#withAppendedId(Uri, long)} will
         * specify a single event.
         *
@@ -1706,9 +1758,9 @@ public final class CalendarContract {
         * projection of the query to this uri that are not contained in the above list.
         *
         * <p>This uri will return an empty cursor if the calling user is not a parent profile
         * of a work profile, or cross profile calendar is disabled in Settings, or this uri is
         * queried from a package that is not whitelisted by profile owner of the work profile via
         * {@link DevicePolicyManager#addCrossProfileCalendarPackage(ComponentName, String)}.
         * of a managed profile, or cross profile calendar is disabled in Settings, or this uri is
         * queried from a package that is not whitelisted by profile owner of the managed profile
         * via {@link DevicePolicyManager#addCrossProfileCalendarPackage(ComponentName, String)}.
         *
         * @see DevicePolicyManager#getCrossProfileCalendarPackages(ComponentName)
         * @see Settings.Secure#CROSS_PROFILE_CALENDAR_ENABLED
@@ -1896,7 +1948,7 @@ public final class CalendarContract {
            Uri.parse("content://" + AUTHORITY + "/instances/searchbyday");

        /**
         * The content:// style URL for querying an instance range in the work profile.
         * The content:// style URL for querying an instance range in the managed profile.
         * It supports similar semantics as {@link #CONTENT_URI}.
         *
         * <p>The following columns plus the columns that are whitelisted by
@@ -1916,9 +1968,9 @@ public final class CalendarContract {
         * projection of the query to this uri that are not contained in the above list.
         *
         * <p>This uri will return an empty cursor if the calling user is not a parent profile
         * of a work profile, or cross profile calendar for the work profile is disabled in
         * of a managed profile, or cross profile calendar for the managed profile is disabled in
         * Settings, or this uri is queried from a package that is not whitelisted by
         * profile owner of the work profile via
         * profile owner of the managed profile via
         * {@link DevicePolicyManager#addCrossProfileCalendarPackage(ComponentName, String)}.
         *
         * @see DevicePolicyManager#getCrossProfileCalendarPackages(ComponentName)
@@ -1929,7 +1981,7 @@ public final class CalendarContract {

        /**
         * The content:// style URL for querying an instance range by Julian
         * Day in the work profile. It supports similar semantics as {@link #CONTENT_BY_DAY_URI}
         * Day in the managed profile. It supports similar semantics as {@link #CONTENT_BY_DAY_URI}
         * and performs similar checks as {@link #ENTERPRISE_CONTENT_URI}.
         */
        public static final Uri ENTERPRISE_CONTENT_BY_DAY_URI =
@@ -1937,7 +1989,7 @@ public final class CalendarContract {

        /**
         * The content:// style URL for querying an instance range with a search
         * term in the work profile. It supports similar semantics as {@link #CONTENT_SEARCH_URI}
         * term in the managed profile. It supports similar semantics as {@link #CONTENT_SEARCH_URI}
         * and performs similar checks as {@link #ENTERPRISE_CONTENT_URI}.
         */
        public static final Uri ENTERPRISE_CONTENT_SEARCH_URI =
@@ -1945,7 +1997,7 @@ public final class CalendarContract {

        /**
         * The content:// style URL for querying an instance range with a search
         * term in the work profile. It supports similar semantics as
         * term in the managed profile. It supports similar semantics as
         * {@link #CONTENT_SEARCH_BY_DAY_URI} and performs similar checks as
         * {@link #ENTERPRISE_CONTENT_URI}.
         */
+6 −0
Original line number Diff line number Diff line
@@ -136,4 +136,10 @@ abstract class BaseIDevicePolicyManager extends IDevicePolicyManager.Stub {
    public boolean isUnattendedManagedKiosk() {
        return false;
    }

    @Override
    public boolean startViewCalendarEventInManagedProfile(String packageName, long eventId,
            long start, long end, boolean allDay, int flags) {
        return false;
    }
}
Loading