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

Commit 704a6471 authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 1927 into donut

* changes:
  Fix build breakage
parents 0dfe16dc 6e9610e1
Loading
Loading
Loading
Loading
+15 −9
Original line number Diff line number Diff line
@@ -340,27 +340,33 @@ public class Contacts {
        }

        /**
         * Adds a person to the My Contacts group.
         * 
         * @param resolver the resolver to use
         * @param personId the person to add to the group
         * @return the URI of the group membership row
         * @throws IllegalStateException if the My Contacts group can't be found
         * @hide Used in vCard parser code.
         */
        public static Uri addToMyContactsGroup(ContentResolver resolver, long personId) {
            long groupId = 0;
        public static long tryGetMyContactsGroupId(ContentResolver resolver) {
            Cursor groupsCursor = resolver.query(Groups.CONTENT_URI, GROUPS_PROJECTION,
                    Groups.SYSTEM_ID + "='" + Groups.GROUP_MY_CONTACTS + "'", null, null);
            if (groupsCursor != null) {
                try {
                    if (groupsCursor.moveToFirst()) {
                        groupId = groupsCursor.getLong(0);
                        return groupsCursor.getLong(0);
                    }
                } finally {
                    groupsCursor.close();
                }
            }
            return 0;
        }

        /**
         * Adds a person to the My Contacts group.
         *
         * @param resolver the resolver to use
         * @param personId the person to add to the group
         * @return the URI of the group membership row
         * @throws IllegalStateException if the My Contacts group can't be found
         */
        public static Uri addToMyContactsGroup(ContentResolver resolver, long personId) {
            long groupId = tryGetMyContactsGroupId(resolver);
            if (groupId == 0) {
                throw new IllegalStateException("Failed to find the My Contacts group");
            }