blob: 3b090b5d206101fb8a25c17801322b81c7dbf28e [file] [log] [blame]
Ricky Waidffb27d2015-12-08 16:58:27 +00001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Gary Mai69c182a2016-12-05 13:07:03 -080017package com.android.contacts.compat;
Ricky Waidffb27d2015-12-08 16:58:27 +000018
19import android.net.Uri;
Wenyi Wangfe4048c2015-12-21 15:53:43 -080020import android.provider.ContactsContract;
Ricky Waidffb27d2015-12-08 16:58:27 +000021import android.provider.ContactsContract.Contacts;
22
Gary Mai0a49afa2016-12-05 15:53:58 -080023import com.android.contacts.ContactsUtils;
Ricky Waidffb27d2015-12-08 16:58:27 +000024
Wenyi Wangfe4048c2015-12-21 15:53:43 -080025/**
26 * Compatibility class for {@link ContactsContract.Contacts}
27 */
Ricky Waidffb27d2015-12-08 16:58:27 +000028public class ContactsCompat {
Wenyi Wangfe4048c2015-12-21 15:53:43 -080029 /**
30 * Not instantiable.
31 */
32 private ContactsCompat() {
33 }
Ricky Waidffb27d2015-12-08 16:58:27 +000034
35 // TODO: Use N APIs
36 private static final Uri ENTERPRISE_CONTENT_FILTER_URI =
37 Uri.withAppendedPath(Contacts.CONTENT_URI, "filter_enterprise");
38
Wenyi Wangfe4048c2015-12-21 15:53:43 -080039 // Copied from ContactsContract.Contacts#ENTERPRISE_CONTACT_ID_BASE, which is hidden.
40 private static final long ENTERPRISE_CONTACT_ID_BASE = 1000000000;
41
Ricky Waidffb27d2015-12-08 16:58:27 +000042 public static Uri getContentUri() {
Victor Changfdb995d2015-12-23 13:44:39 +080043 if (ContactsUtils.FLAG_N_FEATURE) {
Ricky Waidffb27d2015-12-08 16:58:27 +000044 return ENTERPRISE_CONTENT_FILTER_URI;
45 }
46 return Contacts.CONTENT_FILTER_URI;
47 }
Wenyi Wangfe4048c2015-12-21 15:53:43 -080048
49 /**
50 * Return {@code true} if a contact ID is from the contacts provider on the enterprise profile.
51 */
52 public static boolean isEnterpriseContactId(long contactId) {
53 if (CompatUtils.isLollipopCompatible()) {
54 return Contacts.isEnterpriseContactId(contactId);
55 } else {
56 // copied from ContactsContract.Contacts.isEnterpriseContactId
57 return (contactId >= ENTERPRISE_CONTACT_ID_BASE) &&
58 (contactId < ContactsContract.Profile.MIN_ID);
59 }
60 }
Ricky Waidffb27d2015-12-08 16:58:27 +000061}