Allow shared lib and package name to match - CTS

The old package manager implementation was guarding for
shared libs to not match any package name but due to a
bug this was not enfroced and as a result we have apps
where the package and lib match, e.g. GCore. The new
static shared lib support properly enforced the rule
breaking apps. So, this CL relexes the constraint.

Test: These are the tests

bug:34598313

Change-Id: I6883e0e05ff8d239de8ff7946a6725eca3fc04f6
(cherry picked from commit 67c7138e7a74ea1556ea29b03d1abec4a141d08f)
diff --git a/hostsidetests/os/src/android/os/cts/StaticSharedLibsHostTests.java b/hostsidetests/os/src/android/os/cts/StaticSharedLibsHostTests.java
index 185363c..7452d22 100644
--- a/hostsidetests/os/src/android/os/cts/StaticSharedLibsHostTests.java
+++ b/hostsidetests/os/src/android/os/cts/StaticSharedLibsHostTests.java
@@ -39,6 +39,12 @@
     private static final String STATIC_LIB_PROVIDER4_APK = "CtsStaticSharedLibProviderApp4.apk";
     private static final String STATIC_LIB_PROVIDER4_PKG = "android.os.lib.provider";
 
+    private static final String STATIC_LIB_PROVIDER5_APK = "CtsStaticSharedLibProviderApp5.apk";
+    private static final String STATIC_LIB_PROVIDER5_PKG = "android.os.lib.provider";
+
+    private static final String STATIC_LIB_PROVIDER6_APK = "CtsStaticSharedLibProviderApp6.apk";
+    private static final String STATIC_LIB_PROVIDER6_PKG = "android.os.lib.provider";
+
     private static final String STATIC_LIB_CONSUMER1_APK = "CtsStaticSharedLibConsumerApp1.apk";
     private static final String STATIC_LIB_CONSUMER1_PKG = "android.os.lib.consumer1";
 
@@ -224,6 +230,22 @@
         }
     }
 
+    public void testLibraryAndPackageNameCanMatch() throws Exception {
+        getDevice().uninstallPackage(STATIC_LIB_PROVIDER5_PKG);
+        getDevice().uninstallPackage(STATIC_LIB_PROVIDER6_PKG);
+        try {
+            // Install a library with same name as package should work.
+            assertNull(getDevice().installPackage(mBuildHelper.getTestFile(
+                    STATIC_LIB_PROVIDER5_APK), false, false));
+            // Install a library with same name as package should work.
+            assertNull(getDevice().installPackage(mBuildHelper.getTestFile(
+                    STATIC_LIB_PROVIDER6_APK), true, false));
+        } finally {
+            getDevice().uninstallPackage(STATIC_LIB_PROVIDER5_PKG);
+            getDevice().uninstallPackage(STATIC_LIB_PROVIDER6_PKG);
+        }
+    }
+
     public void testGetSharedLibraries() throws Exception {
         getDevice().uninstallPackage(STATIC_LIB_CONSUMER1_PKG);
         getDevice().uninstallPackage(STATIC_LIB_CONSUMER2_PKG);
diff --git a/hostsidetests/os/test-apps/StaticSharedLibProviderApp5/Android.mk b/hostsidetests/os/test-apps/StaticSharedLibProviderApp5/Android.mk
new file mode 100644
index 0000000..a9df0f8
--- /dev/null
+++ b/hostsidetests/os/test-apps/StaticSharedLibProviderApp5/Android.mk
@@ -0,0 +1,33 @@
+#
+# Copyright (C) 2017 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.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := tests
+
+LOCAL_SDK_VERSION := current
+
+LOCAL_PACKAGE_NAME := CtsStaticSharedLibProviderApp5
+
+LOCAL_COMPATIBILITY_SUITE := cts
+
+LOCAL_AAPT_FLAGS := --shared-lib
+
+LOCAL_EXPORT_PACKAGE_RESOURCES := true
+
+include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/os/test-apps/StaticSharedLibProviderApp5/AndroidManifest.xml b/hostsidetests/os/test-apps/StaticSharedLibProviderApp5/AndroidManifest.xml
new file mode 100755
index 0000000..404a0fa
--- /dev/null
+++ b/hostsidetests/os/test-apps/StaticSharedLibProviderApp5/AndroidManifest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Copyright (C) 2017 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.
+ -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+        package="android.os.lib.provider"
+        android:versionCode="1"
+        android:versionName="1.0">
+    <application android:hasCode="false">
+        <static-library android:name="android.os.lib.provider_2" android:version="1"/>
+    </application>
+</manifest>
diff --git a/hostsidetests/os/test-apps/StaticSharedLibProviderApp6/Android.mk b/hostsidetests/os/test-apps/StaticSharedLibProviderApp6/Android.mk
new file mode 100644
index 0000000..3c06105
--- /dev/null
+++ b/hostsidetests/os/test-apps/StaticSharedLibProviderApp6/Android.mk
@@ -0,0 +1,33 @@
+#
+# Copyright (C) 2017 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.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := tests
+
+LOCAL_SDK_VERSION := current
+
+LOCAL_PACKAGE_NAME := CtsStaticSharedLibProviderApp6
+
+LOCAL_COMPATIBILITY_SUITE := cts
+
+LOCAL_AAPT_FLAGS := --shared-lib
+
+LOCAL_EXPORT_PACKAGE_RESOURCES := true
+
+include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/os/test-apps/StaticSharedLibProviderApp6/AndroidManifest.xml b/hostsidetests/os/test-apps/StaticSharedLibProviderApp6/AndroidManifest.xml
new file mode 100755
index 0000000..7619998f
--- /dev/null
+++ b/hostsidetests/os/test-apps/StaticSharedLibProviderApp6/AndroidManifest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Copyright (C) 2017 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.
+ -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+        package="android.os.lib.provider"
+        android:versionCode="2"
+        android:versionName="2.0">
+    <application android:hasCode="false">
+        <static-library android:name="android.os.lib.provider_2" android:version="2"/>
+    </application>
+</manifest>