From c3d3c3dfbcf96f6db92b747463ac84ee244a0c85 Mon Sep 17 00:00:00 2001 From: linyuh Date: Tue, 27 Feb 2018 13:42:59 -0800 Subject: Move DirectoryCompat from "contacts/common" to "dialer/common/cp2". Bug: 73887387 Test: Existing tests PiperOrigin-RevId: 187225355 Change-Id: I65de553078e147a46d933daf34dfd912fc8aa74c --- .../com/android/contacts/common/ContactsUtils.java | 2 +- .../contacts/common/compat/DirectoryCompat.java | 55 --------------------- .../common/list/ContactEntryListAdapter.java | 2 +- .../contacts/common/list/DirectoryListLoader.java | 2 +- .../common/list/PhoneNumberListAdapter.java | 2 +- .../dialer/app/list/RegularSearchListAdapter.java | 2 +- .../android/dialer/common/cp2/DirectoryCompat.java | 56 ++++++++++++++++++++++ .../cp2/Cp2ExtendedDirectoryPhoneLookup.java | 20 ++------ .../dialer/phonenumbercache/ContactInfoHelper.java | 2 +- .../directories/DirectoryContactViewHolder.java | 7 +-- .../directories/DirectoryContactsCursor.java | 4 +- .../directories/DirectoryContactsCursorLoader.java | 4 +- .../directories/res/values/strings.xml | 6 +++ .../com/android/incallui/CallerInfoAsyncQuery.java | 2 +- 14 files changed, 77 insertions(+), 89 deletions(-) delete mode 100644 java/com/android/contacts/common/compat/DirectoryCompat.java create mode 100644 java/com/android/dialer/common/cp2/DirectoryCompat.java diff --git a/java/com/android/contacts/common/ContactsUtils.java b/java/com/android/contacts/common/ContactsUtils.java index bc0e42300..bca8b62e0 100644 --- a/java/com/android/contacts/common/ContactsUtils.java +++ b/java/com/android/contacts/common/ContactsUtils.java @@ -18,7 +18,7 @@ package com.android.contacts.common; import android.provider.ContactsContract.Contacts; import android.support.annotation.IntDef; -import com.android.contacts.common.compat.DirectoryCompat; +import com.android.dialer.common.cp2.DirectoryCompat; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/java/com/android/contacts/common/compat/DirectoryCompat.java b/java/com/android/contacts/common/compat/DirectoryCompat.java deleted file mode 100644 index e67087659..000000000 --- a/java/com/android/contacts/common/compat/DirectoryCompat.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2015 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.contacts.common.compat; - -import android.net.Uri; -import android.os.Build.VERSION; -import android.os.Build.VERSION_CODES; -import android.provider.ContactsContract.Directory; - -public class DirectoryCompat { - - public static Uri getContentUri() { - if (VERSION.SDK_INT >= VERSION_CODES.N) { - return Directory.ENTERPRISE_CONTENT_URI; - } - return Directory.CONTENT_URI; - } - - public static boolean isInvisibleDirectory(long directoryId) { - if (VERSION.SDK_INT >= VERSION_CODES.N) { - return (directoryId == Directory.LOCAL_INVISIBLE - || directoryId == Directory.ENTERPRISE_LOCAL_INVISIBLE); - } - return directoryId == Directory.LOCAL_INVISIBLE; - } - - public static boolean isRemoteDirectoryId(long directoryId) { - if (VERSION.SDK_INT >= VERSION_CODES.N) { - return Directory.isRemoteDirectoryId(directoryId); - } - return !(directoryId == Directory.DEFAULT || directoryId == Directory.LOCAL_INVISIBLE); - } - - public static boolean isEnterpriseDirectoryId(long directoryId) { - return VERSION.SDK_INT >= VERSION_CODES.N && Directory.isEnterpriseDirectoryId(directoryId); - } - - public static boolean isOnlyEnterpriseDirectoryId(long directoryId) { - return isEnterpriseDirectoryId(directoryId) && !isRemoteDirectoryId(directoryId); - } -} diff --git a/java/com/android/contacts/common/list/ContactEntryListAdapter.java b/java/com/android/contacts/common/list/ContactEntryListAdapter.java index 117825dce..413a1deff 100644 --- a/java/com/android/contacts/common/list/ContactEntryListAdapter.java +++ b/java/com/android/contacts/common/list/ContactEntryListAdapter.java @@ -34,9 +34,9 @@ import android.widget.SectionIndexer; import android.widget.TextView; import com.android.contacts.common.ContactsUtils; import com.android.contacts.common.R; -import com.android.contacts.common.compat.DirectoryCompat; import com.android.contacts.common.util.SearchUtil; import com.android.dialer.common.LogUtil; +import com.android.dialer.common.cp2.DirectoryCompat; import com.android.dialer.compat.CompatUtils; import com.android.dialer.configprovider.ConfigProviderBindings; import com.android.dialer.contactphoto.ContactPhotoManager; diff --git a/java/com/android/contacts/common/list/DirectoryListLoader.java b/java/com/android/contacts/common/list/DirectoryListLoader.java index be62cc7a8..ce78d2cff 100644 --- a/java/com/android/contacts/common/list/DirectoryListLoader.java +++ b/java/com/android/contacts/common/list/DirectoryListLoader.java @@ -26,8 +26,8 @@ import android.os.Handler; import android.provider.ContactsContract.Directory; import android.text.TextUtils; import com.android.contacts.common.R; -import com.android.contacts.common.compat.DirectoryCompat; import com.android.dialer.common.LogUtil; +import com.android.dialer.common.cp2.DirectoryCompat; import com.android.dialer.util.PermissionsUtil; /** A specialized loader for the list of directories, see {@link Directory}. */ diff --git a/java/com/android/contacts/common/list/PhoneNumberListAdapter.java b/java/com/android/contacts/common/list/PhoneNumberListAdapter.java index 58628d2a3..3c45abf37 100644 --- a/java/com/android/contacts/common/list/PhoneNumberListAdapter.java +++ b/java/com/android/contacts/common/list/PhoneNumberListAdapter.java @@ -34,13 +34,13 @@ import android.view.ViewGroup; import com.android.contacts.common.ContactsUtils; import com.android.contacts.common.R; import com.android.contacts.common.compat.CallableCompat; -import com.android.contacts.common.compat.DirectoryCompat; import com.android.contacts.common.compat.PhoneCompat; import com.android.contacts.common.extensions.PhoneDirectoryExtenderAccessor; import com.android.contacts.common.list.ContactListItemView.CallToAction; import com.android.contacts.common.preference.ContactsPreferences; import com.android.contacts.common.util.Constants; import com.android.dialer.common.LogUtil; +import com.android.dialer.common.cp2.DirectoryCompat; import com.android.dialer.compat.CompatUtils; import com.android.dialer.configprovider.ConfigProviderBindings; import com.android.dialer.contactphoto.ContactPhotoManager.DefaultImageRequest; diff --git a/java/com/android/dialer/app/list/RegularSearchListAdapter.java b/java/com/android/dialer/app/list/RegularSearchListAdapter.java index aee68ae58..c92f48c8b 100644 --- a/java/com/android/dialer/app/list/RegularSearchListAdapter.java +++ b/java/com/android/dialer/app/list/RegularSearchListAdapter.java @@ -20,8 +20,8 @@ import android.database.Cursor; import android.net.Uri; import android.text.TextUtils; import com.android.contacts.common.ContactsUtils; -import com.android.contacts.common.compat.DirectoryCompat; import com.android.contacts.common.list.DirectoryPartition; +import com.android.dialer.common.cp2.DirectoryCompat; import com.android.dialer.phonenumbercache.CachedNumberLookupService; import com.android.dialer.phonenumbercache.CachedNumberLookupService.CachedContactInfo; import com.android.dialer.phonenumbercache.ContactInfo; diff --git a/java/com/android/dialer/common/cp2/DirectoryCompat.java b/java/com/android/dialer/common/cp2/DirectoryCompat.java new file mode 100644 index 000000000..3e33394a2 --- /dev/null +++ b/java/com/android/dialer/common/cp2/DirectoryCompat.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.dialer.common.cp2; + +import android.net.Uri; +import android.os.Build.VERSION; +import android.os.Build.VERSION_CODES; +import android.provider.ContactsContract.Directory; + +/** Compatibility utility for {@link Directory}. */ +public class DirectoryCompat { + + public static Uri getContentUri() { + if (VERSION.SDK_INT >= VERSION_CODES.N) { + return Directory.ENTERPRISE_CONTENT_URI; + } + return Directory.CONTENT_URI; + } + + public static boolean isInvisibleDirectory(long directoryId) { + if (VERSION.SDK_INT >= VERSION_CODES.N) { + return (directoryId == Directory.LOCAL_INVISIBLE + || directoryId == Directory.ENTERPRISE_LOCAL_INVISIBLE); + } + return directoryId == Directory.LOCAL_INVISIBLE; + } + + public static boolean isRemoteDirectoryId(long directoryId) { + if (VERSION.SDK_INT >= VERSION_CODES.N) { + return Directory.isRemoteDirectoryId(directoryId); + } + return directoryId != Directory.DEFAULT && directoryId != Directory.LOCAL_INVISIBLE; + } + + public static boolean isEnterpriseDirectoryId(long directoryId) { + return VERSION.SDK_INT >= VERSION_CODES.N && Directory.isEnterpriseDirectoryId(directoryId); + } + + public static boolean isOnlyEnterpriseDirectoryId(long directoryId) { + return isEnterpriseDirectoryId(directoryId) && !isRemoteDirectoryId(directoryId); + } +} diff --git a/java/com/android/dialer/phonelookup/cp2/Cp2ExtendedDirectoryPhoneLookup.java b/java/com/android/dialer/phonelookup/cp2/Cp2ExtendedDirectoryPhoneLookup.java index df164bd1b..519ec5f82 100644 --- a/java/com/android/dialer/phonelookup/cp2/Cp2ExtendedDirectoryPhoneLookup.java +++ b/java/com/android/dialer/phonelookup/cp2/Cp2ExtendedDirectoryPhoneLookup.java @@ -22,12 +22,12 @@ import android.net.Uri; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.provider.ContactsContract; -import android.provider.ContactsContract.Directory; import android.support.annotation.VisibleForTesting; import com.android.dialer.DialerPhoneNumber; import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.Annotations.BackgroundExecutor; import com.android.dialer.common.concurrent.Annotations.LightweightExecutor; +import com.android.dialer.common.cp2.DirectoryCompat; import com.android.dialer.inject.ApplicationContext; import com.android.dialer.phonelookup.PhoneLookup; import com.android.dialer.phonelookup.PhoneLookupInfo; @@ -80,7 +80,7 @@ public final class Cp2ExtendedDirectoryPhoneLookup implements PhoneLookup= VERSION_CODES.N - ? ContactsContract.Directory.ENTERPRISE_CONTENT_URI - : ContactsContract.Directory.CONTENT_URI; - } - @VisibleForTesting static Uri getContentUriForContacts(String number, long directoryId) { Uri baseUri = @@ -204,13 +197,8 @@ public final class Cp2ExtendedDirectoryPhoneLookup implements PhoneLookup= VERSION_CODES.N - ? Directory.isRemoteDirectoryId(directoryId) - || Directory.isEnterpriseDirectoryId(directoryId) - : (directoryId != Directory.DEFAULT - && directoryId != Directory.LOCAL_INVISIBLE - && directoryId != Directory.ENTERPRISE_LOCAL_INVISIBLE); + return DirectoryCompat.isRemoteDirectoryId(directoryId) + || DirectoryCompat.isEnterpriseDirectoryId(directoryId); } @Override diff --git a/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java b/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java index e99533a40..f094be8a5 100644 --- a/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java +++ b/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java @@ -35,10 +35,10 @@ import android.telephony.PhoneNumberUtils; import android.text.TextUtils; import com.android.contacts.common.ContactsUtils; import com.android.contacts.common.ContactsUtils.UserType; -import com.android.contacts.common.compat.DirectoryCompat; import com.android.contacts.common.util.Constants; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; +import com.android.dialer.common.cp2.DirectoryCompat; import com.android.dialer.logging.ContactSource; import com.android.dialer.oem.CequintCallerIdManager; import com.android.dialer.oem.CequintCallerIdManager.CequintCallerIdContact; diff --git a/java/com/android/dialer/searchfragment/directories/DirectoryContactViewHolder.java b/java/com/android/dialer/searchfragment/directories/DirectoryContactViewHolder.java index fc5bce1b2..aef1e9ece 100644 --- a/java/com/android/dialer/searchfragment/directories/DirectoryContactViewHolder.java +++ b/java/com/android/dialer/searchfragment/directories/DirectoryContactViewHolder.java @@ -29,9 +29,9 @@ import android.view.View; import android.widget.ImageView; import android.widget.QuickContactBadge; import android.widget.TextView; -import com.android.contacts.common.compat.DirectoryCompat; import com.android.dialer.callintent.CallInitiationType; import com.android.dialer.callintent.CallIntentBuilder; +import com.android.dialer.common.cp2.DirectoryCompat; import com.android.dialer.contactphoto.ContactPhotoManager; import com.android.dialer.lettertile.LetterTileDrawable; import com.android.dialer.precall.PreCall; @@ -73,14 +73,11 @@ public final class DirectoryContactViewHolder extends RecyclerView.ViewHolder String secondaryInfo = TextUtils.isEmpty(label) ? number - : context.getString( - com.android.contacts.common.R.string.call_subject_type_and_number, label, number); + : context.getString(R.string.call_subject_type_and_number, label, number); nameView.setText(QueryBoldingUtil.getNameWithQueryBolded(query, name, context)); numberView.setText(QueryBoldingUtil.getNameWithQueryBolded(query, secondaryInfo, context)); workBadge.setVisibility( - // TODO(a bug): Consider moving DirectoryCompat out of "contacts/common" and share it - // with PhoneLookups. DirectoryCompat.isOnlyEnterpriseDirectoryId(cursor.getDirectoryId()) ? View.VISIBLE : View.GONE); diff --git a/java/com/android/dialer/searchfragment/directories/DirectoryContactsCursor.java b/java/com/android/dialer/searchfragment/directories/DirectoryContactsCursor.java index 8f9ab0e60..0c1ad8318 100644 --- a/java/com/android/dialer/searchfragment/directories/DirectoryContactsCursor.java +++ b/java/com/android/dialer/searchfragment/directories/DirectoryContactsCursor.java @@ -22,8 +22,8 @@ import android.database.MatrixCursor; import android.database.MergeCursor; import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; -import com.android.contacts.common.compat.DirectoryCompat; import com.android.dialer.common.Assert; +import com.android.dialer.common.cp2.DirectoryCompat; import com.android.dialer.searchfragment.common.SearchCursor; import com.android.dialer.searchfragment.directories.DirectoriesCursorLoader.Directory; import java.util.ArrayList; @@ -101,8 +101,6 @@ public final class DirectoryContactsCursor extends MergeCursor implements Search private static MatrixCursor createHeaderCursor(Context context, String name, long id) { MatrixCursor headerCursor = new MatrixCursor(PROJECTION, 1); - // TODO(a bug): Consider moving DirectoryCompat out of "contacts/common" and share it - // with PhoneLookups. if (DirectoryCompat.isOnlyEnterpriseDirectoryId(id)) { headerCursor.addRow( new Object[] {context.getString(R.string.directory_search_label_work), id}); diff --git a/java/com/android/dialer/searchfragment/directories/DirectoryContactsCursorLoader.java b/java/com/android/dialer/searchfragment/directories/DirectoryContactsCursorLoader.java index a94878577..d719cb9d9 100644 --- a/java/com/android/dialer/searchfragment/directories/DirectoryContactsCursorLoader.java +++ b/java/com/android/dialer/searchfragment/directories/DirectoryContactsCursorLoader.java @@ -27,7 +27,7 @@ import android.provider.ContactsContract; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.support.annotation.NonNull; import android.support.annotation.VisibleForTesting; -import com.android.contacts.common.compat.DirectoryCompat; +import com.android.dialer.common.cp2.DirectoryCompat; import com.android.dialer.searchfragment.common.Projections; import com.android.dialer.searchfragment.directories.DirectoriesCursorLoader.Directory; import java.util.ArrayList; @@ -71,8 +71,6 @@ public final class DirectoryContactsCursorLoader extends CursorLoader { for (int i = 0; i < directories.size(); i++) { Directory directory = directories.get(i); - // TODO(a bug): Consider moving DirectoryCompat out of "contacts/common" and share it - // with PhoneLookups. if (!DirectoryCompat.isRemoteDirectoryId(directory.getId()) && !DirectoryCompat.isEnterpriseDirectoryId(directory.getId())) { cursors[i] = null; diff --git a/java/com/android/dialer/searchfragment/directories/res/values/strings.xml b/java/com/android/dialer/searchfragment/directories/res/values/strings.xml index beabba135..097f353ea 100644 --- a/java/com/android/dialer/searchfragment/directories/res/values/strings.xml +++ b/java/com/android/dialer/searchfragment/directories/res/values/strings.xml @@ -17,4 +17,10 @@ Directory %1$s + + + + %1$s %2$s + \ No newline at end of file diff --git a/java/com/android/incallui/CallerInfoAsyncQuery.java b/java/com/android/incallui/CallerInfoAsyncQuery.java index 52ca8cafa..335895220 100644 --- a/java/com/android/incallui/CallerInfoAsyncQuery.java +++ b/java/com/android/incallui/CallerInfoAsyncQuery.java @@ -37,7 +37,7 @@ import android.support.annotation.RequiresPermission; import android.support.annotation.WorkerThread; import android.telephony.PhoneNumberUtils; import android.text.TextUtils; -import com.android.contacts.common.compat.DirectoryCompat; +import com.android.dialer.common.cp2.DirectoryCompat; import com.android.dialer.phonenumbercache.CachedNumberLookupService; import com.android.dialer.phonenumbercache.CachedNumberLookupService.CachedContactInfo; import com.android.dialer.phonenumbercache.ContactInfoHelper; -- cgit v1.2.3