Ricky Wai | dffb27d | 2015-12-08 16:58:27 +0000 | [diff] [blame] | 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 | |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 17 | package com.android.contacts.compat; |
Ricky Wai | dffb27d | 2015-12-08 16:58:27 +0000 | [diff] [blame] | 18 | |
| 19 | import android.net.Uri; |
Wenyi Wang | fe4048c | 2015-12-21 15:53:43 -0800 | [diff] [blame] | 20 | import android.provider.ContactsContract; |
Ricky Wai | dffb27d | 2015-12-08 16:58:27 +0000 | [diff] [blame] | 21 | import android.provider.ContactsContract.Contacts; |
| 22 | |
Gary Mai | 0a49afa | 2016-12-05 15:53:58 -0800 | [diff] [blame] | 23 | import com.android.contacts.ContactsUtils; |
Ricky Wai | dffb27d | 2015-12-08 16:58:27 +0000 | [diff] [blame] | 24 | |
Wenyi Wang | fe4048c | 2015-12-21 15:53:43 -0800 | [diff] [blame] | 25 | /** |
| 26 | * Compatibility class for {@link ContactsContract.Contacts} |
| 27 | */ |
Ricky Wai | dffb27d | 2015-12-08 16:58:27 +0000 | [diff] [blame] | 28 | public class ContactsCompat { |
Wenyi Wang | fe4048c | 2015-12-21 15:53:43 -0800 | [diff] [blame] | 29 | /** |
| 30 | * Not instantiable. |
| 31 | */ |
| 32 | private ContactsCompat() { |
| 33 | } |
Ricky Wai | dffb27d | 2015-12-08 16:58:27 +0000 | [diff] [blame] | 34 | |
| 35 | // TODO: Use N APIs |
| 36 | private static final Uri ENTERPRISE_CONTENT_FILTER_URI = |
| 37 | Uri.withAppendedPath(Contacts.CONTENT_URI, "filter_enterprise"); |
| 38 | |
Wenyi Wang | fe4048c | 2015-12-21 15:53:43 -0800 | [diff] [blame] | 39 | // Copied from ContactsContract.Contacts#ENTERPRISE_CONTACT_ID_BASE, which is hidden. |
| 40 | private static final long ENTERPRISE_CONTACT_ID_BASE = 1000000000; |
| 41 | |
Ricky Wai | dffb27d | 2015-12-08 16:58:27 +0000 | [diff] [blame] | 42 | public static Uri getContentUri() { |
Victor Chang | fdb995d | 2015-12-23 13:44:39 +0800 | [diff] [blame] | 43 | if (ContactsUtils.FLAG_N_FEATURE) { |
Ricky Wai | dffb27d | 2015-12-08 16:58:27 +0000 | [diff] [blame] | 44 | return ENTERPRISE_CONTENT_FILTER_URI; |
| 45 | } |
| 46 | return Contacts.CONTENT_FILTER_URI; |
| 47 | } |
Wenyi Wang | fe4048c | 2015-12-21 15:53:43 -0800 | [diff] [blame] | 48 | |
| 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 Wai | dffb27d | 2015-12-08 16:58:27 +0000 | [diff] [blame] | 61 | } |