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

Commit 9dd0ba0e authored by yuemingw's avatar yuemingw Committed by Yueming Wang
Browse files

Add a hidden API for Cross Profile Calendar Settings UI.

Settings wants to know if there is currently any package that is allowed
for cross profile calendar by PO.
The UI is added in work account settings, which actually runs
in primary user, and we can't call the public
getCrossProfileCalendarPakcages(work_user_admin) from primary user.
So we need to add this hidden API.

Bug: b/117976974
Test: make ROBOTEST_FILTER=CrossProfileCalendarPreferenceControllerTest -j40 RunSettingsRoboTests
Change-Id: I3df29a25a7826639828041b47dcfb7dcf086c411
parent 9f6fb2a3
Loading
Loading
Loading
Loading
+30 −1
Original line number Diff line number Diff line
@@ -10092,11 +10092,40 @@ public class DevicePolicyManager {
        if (mService != null) {
            try {
                return mService.isPackageAllowedToAccessCalendarForUser(packageName,
                        mContext.getUserId());
                        myUserId());
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }
        return false;
    }

    /**
     * Gets a set of package names that are whitelisted to access cross profile calendar APIs.
     *
     * <p>To query for a specific user, use
     * {@link Context#createPackageContextAsUser(String, int, UserHandle)} to create a context for
     * that user, and get a {@link DevicePolicyManager} from this context.
     *
     * @return the set of names of packages that were previously whitelisted via
     * {@link #addCrossProfileCalendarPackage(ComponentName, String)}, or an
     * empty set if none have been whitelisted.
     *
     * @see #addCrossProfileCalendarPackage(ComponentName, String)
     * @see #removeCrossProfileCalendarPackage(ComponentName, String)
     * @see #getCrossProfileCalendarPackages(ComponentName)
     * @hide
     */
    public @NonNull Set<String>  getCrossProfileCalendarPackages() {
        throwIfParentInstance("getCrossProfileCalendarPackages");
        if (mService != null) {
            try {
                return new ArraySet<>(mService.getCrossProfileCalendarPackagesForUser(
                        myUserId()));
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }
        return Collections.emptySet();
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -427,4 +427,5 @@ interface IDevicePolicyManager {
    boolean removeCrossProfileCalendarPackage(in ComponentName admin, String packageName);
    List<String> getCrossProfileCalendarPackages(in ComponentName admin);
    boolean isPackageAllowedToAccessCalendarForUser(String packageName, int userHandle);
    List<String> getCrossProfileCalendarPackagesForUser(int userHandle);
}
+5 −0
Original line number Diff line number Diff line
@@ -120,4 +120,9 @@ abstract class BaseIDevicePolicyManager extends IDevicePolicyManager.Stub {
            int userHandle) {
        return false;
    }

    @Override
    public List<String> getCrossProfileCalendarPackagesForUser(int userHandle) {
        return Collections.emptyList();
    }
}
+16 −1
Original line number Diff line number Diff line
@@ -13426,10 +13426,25 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        enforceCrossUsersPermission(userHandle);
        synchronized (getLockObject()) {
            final ActiveAdmin admin = getProfileOwnerAdminLocked(userHandle);
            if (admin != null && admin.mCrossProfileCalendarPackages != null) {
            if (admin != null) {
                return admin.mCrossProfileCalendarPackages.contains(packageName);
            }
        }
        return false;
    }
    @Override
    public List<String> getCrossProfileCalendarPackagesForUser(int userHandle) {
        if (!mHasFeature) {
            return Collections.emptyList();
        }
        enforceCrossUsersPermission(userHandle);
        synchronized (getLockObject()) {
            final ActiveAdmin admin = getProfileOwnerAdminLocked(userHandle);
            if (admin != null) {
                return new ArrayList<String>(admin.mCrossProfileCalendarPackages);
            }
        }
        return Collections.emptyList();
    }
}