Allow google dialer code to be compiled against M and N SDKs for enterprise features
Following dialer's practice, use src-N and pre-N to separate implementation
in different build sdk
BUG=26312016
Change-Id: Ia9bd420cb2a96b1c31aa3ce2a61fd772b8811f2e
diff --git a/src-N/com/android/contacts/common/compat/DirectorySdkCompat.java b/src-N/com/android/contacts/common/compat/DirectorySdkCompat.java
index 4e6b9d9..9b065d0 100644
--- a/src-N/com/android/contacts/common/compat/DirectorySdkCompat.java
+++ b/src-N/com/android/contacts/common/compat/DirectorySdkCompat.java
@@ -16,13 +16,23 @@
package com.android.contacts.common.compat;
+import android.net.Uri;
+import android.provider.ContactsContract;
import android.provider.ContactsContract.Directory;
public class DirectorySdkCompat {
private static final String TAG = "DirectorySdkCompat";
+ public static final Uri ENTERPRISE_CONTENT_URI = Directory.ENTERPRISE_CONTENT_URI;
+ public static final long ENTERPRISE_LOCAL_DEFAULT = Directory.ENTERPRISE_DEFAULT;
+ public static final long ENTERPRISE_LOCAL_INVISIBLE = Directory.ENTERPRISE_LOCAL_INVISIBLE;
+
public static boolean isRemoteDirectory(long directoryId) {
return Directory.isRemoteDirectory(directoryId);
}
+
+ public static boolean isEnterpriseDirectoryId(long directoryId) {
+ return Directory.isEnterpriseDirectoryId(directoryId);
+ }
}
diff --git a/src-N/com/android/contacts/common/compat/SdkSelectionUtils.java b/src-N/com/android/contacts/common/compat/SdkSelectionUtils.java
new file mode 100644
index 0000000..609dfb5
--- /dev/null
+++ b/src-N/com/android/contacts/common/compat/SdkSelectionUtils.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2016 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;
+
+/**
+ * Provides information for the SDK the app is built against.
+ * Specifically, information that change when the TARGET_N_SDK build flag is set in the makefile.
+ * This is not related to the targetSdkVersion value in AndroidManifest.xml.
+ *
+ * Usage case will be branching test code in src/, instead of swapping between src-N and src-pre-N.
+ */
+public class SdkSelectionUtils {
+
+ /**
+ * Whether the app is build against N SDK.
+ *
+ * Since Build.VERSION.SDK_INT remains 23 on N SDK for now, this is currently the only way to
+ * check if we are building with N SDK or other.
+ */
+ public static final boolean TARGET_N_SDK = true;
+}
+
diff --git a/src-pre-N/com/android/contacts/common/compat/DirectorySdkCompat.java b/src-pre-N/com/android/contacts/common/compat/DirectorySdkCompat.java
index bf512fa..daf7b47 100644
--- a/src-pre-N/com/android/contacts/common/compat/DirectorySdkCompat.java
+++ b/src-pre-N/com/android/contacts/common/compat/DirectorySdkCompat.java
@@ -16,14 +16,27 @@
package com.android.contacts.common.compat;
+import android.net.Uri;
+import android.provider.ContactsContract;
+import android.provider.ContactsContract.Directory;
import android.util.Log;
public class DirectorySdkCompat {
private static final String TAG = "DirectorySdkCompat";
+ public static final Uri ENTERPRISE_CONTENT_URI =
+ Uri.withAppendedPath(ContactsContract.AUTHORITY_URI, "directories_enterprise");
+ public static final long ENTERPRISE_LOCAL_DEFAULT = 1000000000L + Directory.DEFAULT;
+ public static final long ENTERPRISE_LOCAL_INVISIBLE = 1000000000L + Directory.LOCAL_INVISIBLE;
+
public static boolean isRemoteDirectory(long directoryId) {
Log.wtf(TAG, "Not Implemented");
return false;
}
+
+ public static boolean isEnterpriseDirectoryId(long directoryId) {
+ Log.wtf(TAG, "Not Implemented");
+ return false;
+ }
}
diff --git a/src-pre-N/com/android/contacts/common/compat/SdkSelectionUtils.java b/src-pre-N/com/android/contacts/common/compat/SdkSelectionUtils.java
new file mode 100644
index 0000000..98d004a
--- /dev/null
+++ b/src-pre-N/com/android/contacts/common/compat/SdkSelectionUtils.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2016 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;
+
+/**
+ * Provides information for the SDK the app is built against.
+ * Specifically, information that change when the TARGET_N_SDK build flag is set in the makefile.
+ * This is not related to the targetSdkVersion value in AndroidManifest.xml.
+ *
+ * Usage case will be branching test code in src/, instead of using src-N/ and src-pre-N/
+ */
+public class SdkSelectionUtils {
+
+ /**
+ * Whether the app is build against N SDK.
+ *
+ * Since Build.VERSION.SDK_INT remains 23 on N SDK for now, this is currently the only way to
+ * check if we are building with N SDK or other.
+ */
+ public static final boolean TARGET_N_SDK = false;
+}
+
diff --git a/src/com/android/contacts/common/ContactsUtils.java b/src/com/android/contacts/common/ContactsUtils.java
index 2ef68d4..0eafb72 100644
--- a/src/com/android/contacts/common/ContactsUtils.java
+++ b/src/com/android/contacts/common/ContactsUtils.java
@@ -30,6 +30,7 @@
import com.android.contacts.common.model.account.AccountWithDataSet;
import com.android.contacts.common.model.dataitem.ImDataItem;
import com.android.contacts.common.testing.NeededForTesting;
+import com.android.contacts.common.compat.SdkSelectionUtils;
import com.android.contacts.common.model.AccountTypeManager;
import java.util.List;
@@ -46,10 +47,9 @@
private static int sThumbnailSize = -1;
- public static final boolean FLAG_N_FEATURE =
- false // Enforce Pre-N behavior in release build
- && (Build.VERSION.SDK_INT > Build.VERSION_CODES.M
- || Build.VERSION.CODENAME.startsWith("N"));
+ public static final boolean FLAG_N_FEATURE = SdkSelectionUtils.TARGET_N_SDK // build-time flag
+ && (Build.VERSION.SDK_INT > Build.VERSION_CODES.M // runtime flag
+ || Build.VERSION.CODENAME.startsWith("N")); // TODO: remove startsWith("N")
// TODO find a proper place for the canonical version of these
public interface ProviderNames {
diff --git a/src/com/android/contacts/common/compat/CallableCompat.java b/src/com/android/contacts/common/compat/CallableCompat.java
index 2979f63..d25d4be 100644
--- a/src/com/android/contacts/common/compat/CallableCompat.java
+++ b/src/com/android/contacts/common/compat/CallableCompat.java
@@ -28,8 +28,7 @@
Uri.withAppendedPath(Callable.CONTENT_URI, "filter_enterprise");
public static Uri getContentFilterUri() {
- // TODO: Use N APIs
- if (ContactsUtils.FLAG_N_FEATURE && android.os.Build.VERSION.CODENAME.startsWith("N")) {
+ if (ContactsUtils.FLAG_N_FEATURE) {
return ENTERPRISE_CONTENT_FILTER_URI;
}
return Callable.CONTENT_FILTER_URI;
diff --git a/src/com/android/contacts/common/compat/ContactsCompat.java b/src/com/android/contacts/common/compat/ContactsCompat.java
index 5b50385..5a5e46a 100644
--- a/src/com/android/contacts/common/compat/ContactsCompat.java
+++ b/src/com/android/contacts/common/compat/ContactsCompat.java
@@ -40,8 +40,7 @@
private static final long ENTERPRISE_CONTACT_ID_BASE = 1000000000;
public static Uri getContentUri() {
- // TODO: Use N APIs
- if (ContactsUtils.FLAG_N_FEATURE && android.os.Build.VERSION.CODENAME.startsWith("N")) {
+ if (ContactsUtils.FLAG_N_FEATURE) {
return ENTERPRISE_CONTENT_FILTER_URI;
}
return Contacts.CONTENT_FILTER_URI;
diff --git a/src/com/android/contacts/common/compat/DirectoryCompat.java b/src/com/android/contacts/common/compat/DirectoryCompat.java
index 5f6d8bf..f100938 100644
--- a/src/com/android/contacts/common/compat/DirectoryCompat.java
+++ b/src/com/android/contacts/common/compat/DirectoryCompat.java
@@ -24,30 +24,31 @@
public class DirectoryCompat {
- // TODO: Use N APIs
- private static final Uri ENTERPRISE_CONTENT_URI =
- Uri.withAppendedPath(ContactsContract.AUTHORITY_URI, "directories_enterprise");
- // TODO: Use N APIs
- private static final long ENTERPRISE_LOCAL_INVISIBLE = 1000000000L + Directory.LOCAL_INVISIBLE;
-
public static Uri getContentUri() {
- // TODO: Use N APIs
- if (ContactsUtils.FLAG_N_FEATURE && android.os.Build.VERSION.CODENAME.startsWith("N")) {
- return ENTERPRISE_CONTENT_URI;
+ if (ContactsUtils.FLAG_N_FEATURE) {
+ return DirectorySdkCompat.ENTERPRISE_CONTENT_URI;
}
return Directory.CONTENT_URI;
}
public static boolean isInvisibleDirectory(long directoryId) {
- return (directoryId == Directory.LOCAL_INVISIBLE
- || directoryId == ENTERPRISE_LOCAL_INVISIBLE);
+ if (ContactsUtils.FLAG_N_FEATURE) {
+ return (directoryId == Directory.LOCAL_INVISIBLE
+ || directoryId == DirectorySdkCompat.ENTERPRISE_LOCAL_INVISIBLE);
+ }
+ return directoryId == Directory.LOCAL_INVISIBLE;
}
public static boolean isRemoteDirectory(long directoryId) {
- // TODO: Use N APIs
- if (ContactsUtils.FLAG_N_FEATURE && android.os.Build.VERSION.CODENAME.startsWith("N")) {
+ if (ContactsUtils.FLAG_N_FEATURE) {
return DirectorySdkCompat.isRemoteDirectory(directoryId);
}
return !(directoryId == Directory.DEFAULT || directoryId == Directory.LOCAL_INVISIBLE);
}
+
+ public static boolean isEnterpriseDirectoryId(long directoryId) {
+ return ContactsUtils.FLAG_N_FEATURE
+ ? DirectorySdkCompat.isEnterpriseDirectoryId(directoryId)
+ : false;
+ }
}
diff --git a/src/com/android/contacts/common/compat/PhoneCompat.java b/src/com/android/contacts/common/compat/PhoneCompat.java
index 24600f5..5277761 100644
--- a/src/com/android/contacts/common/compat/PhoneCompat.java
+++ b/src/com/android/contacts/common/compat/PhoneCompat.java
@@ -28,8 +28,7 @@
Uri.withAppendedPath(Phone.CONTENT_URI, "filter_enterprise");
public static Uri getContentFilterUri() {
- // TODO: Use N APIs
- if (ContactsUtils.FLAG_N_FEATURE && android.os.Build.VERSION.CODENAME.startsWith("N")) {
+ if (ContactsUtils.FLAG_N_FEATURE) {
return ENTERPRISE_CONTENT_FILTER_URI;
}
return Phone.CONTENT_FILTER_URI;
diff --git a/tests/src-N/com/android/contacts/common/compat/SdkSelectionUtilsTest.java b/tests/src-N/com/android/contacts/common/compat/SdkSelectionUtilsTest.java
new file mode 100644
index 0000000..20c96b7
--- /dev/null
+++ b/tests/src-N/com/android/contacts/common/compat/SdkSelectionUtilsTest.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2016 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.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+// @formatter:off
+/**
+ * Run test with
+ * adb shell am instrument -e class com.android.dialer.SdkSelectionUtilsTest -w com.google.android.dialer.tests/android.test.InstrumentationTestRunner
+ */
+// @formatter:on
+@SmallTest
+public class SdkSelectionUtilsTest extends AndroidTestCase {
+
+ public void testTargetNSdk_True() {
+ assertTrue(SdkSelectionUtils.TARGET_N_SDK);
+ }
+}
diff --git a/tests/src-pre-N/com/android/contacts/common/compat/SdkSelectionUtilsTest.java b/tests/src-pre-N/com/android/contacts/common/compat/SdkSelectionUtilsTest.java
new file mode 100644
index 0000000..e7e3f67
--- /dev/null
+++ b/tests/src-pre-N/com/android/contacts/common/compat/SdkSelectionUtilsTest.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2016 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.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+// @formatter:off
+/**
+ * Run test with
+ * adb shell am instrument -e class com.android.dialer.SdkSelectionUtilsTest -w com.google.android.dialer.tests/android.test.InstrumentationTestRunner
+ */
+// @formatter:on
+@SmallTest
+public class SdkSelectionUtilsTest extends AndroidTestCase {
+
+ public void testTargetNSdk_False() {
+ assertFalse(SdkSelectionUtils.TARGET_N_SDK);
+ }
+}