• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package com.android.contacts.compat;
18 
19 import android.net.Uri;
20 import android.provider.ContactsContract;
21 import android.provider.ContactsContract.Contacts;
22 
23 import com.android.contacts.ContactsUtils;
24 
25 /**
26  * Compatibility class for {@link ContactsContract.Contacts}
27  */
28 public class ContactsCompat {
29     /**
30      * Not instantiable.
31      */
ContactsCompat()32     private ContactsCompat() {
33     }
34 
35     // TODO: Use N APIs
36     private static final Uri ENTERPRISE_CONTENT_FILTER_URI =
37             Uri.withAppendedPath(Contacts.CONTENT_URI, "filter_enterprise");
38 
39     // Copied from ContactsContract.Contacts#ENTERPRISE_CONTACT_ID_BASE, which is hidden.
40     private static final long ENTERPRISE_CONTACT_ID_BASE = 1000000000;
41 
getContentUri()42     public static Uri getContentUri() {
43         if (ContactsUtils.FLAG_N_FEATURE) {
44             return ENTERPRISE_CONTENT_FILTER_URI;
45         }
46         return Contacts.CONTENT_FILTER_URI;
47     }
48 
49     /**
50      * Return {@code true} if a contact ID is from the contacts provider on the enterprise profile.
51      */
isEnterpriseContactId(long contactId)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     }
61 }
62