Update PackageSettingBase.usesStaticLibraries correctly.
Change-Id: Ie18f3a621a2a24ee385593454f45d4713ca8bd1f
Fixes: 36844859
Test: manual &&
android.os.cts.StaticSharedLibsHostTests - Same pass/failures before and after this change &&
runtest -c com.android.server.pm.PackageManagerSettingsTests#testInsertPackageSetting \
frameworks-services
diff --git a/services/core/java/com/android/server/pm/Settings.java b/services/core/java/com/android/server/pm/Settings.java
index 44bcff2..24cbdbf 100644
--- a/services/core/java/com/android/server/pm/Settings.java
+++ b/services/core/java/com/android/server/pm/Settings.java
@@ -987,11 +987,11 @@
// Update static shared library dependencies if needed
if (pkg.usesStaticLibraries != null && pkg.usesStaticLibrariesVersions != null
&& pkg.usesStaticLibraries.size() == pkg.usesStaticLibrariesVersions.length) {
- String[] usesStaticLibraries = new String[pkg.usesStaticLibraries.size()];
- pkg.usesStaticLibraries.toArray(usesStaticLibraries);
+ p.usesStaticLibraries = new String[pkg.usesStaticLibraries.size()];
+ pkg.usesStaticLibraries.toArray(p.usesStaticLibraries);
p.usesStaticLibrariesVersions = pkg.usesStaticLibrariesVersions;
} else {
- pkg.usesStaticLibraries = null;
+ p.usesStaticLibraries = null;
p.usesStaticLibrariesVersions = null;
}
addPackageSettingLPw(p, p.sharedUser);
diff --git a/services/tests/servicestests/src/com/android/server/pm/PackageManagerSettingsTests.java b/services/tests/servicestests/src/com/android/server/pm/PackageManagerSettingsTests.java
index 5e4ba7be..25ba66e 100644
--- a/services/tests/servicestests/src/com/android/server/pm/PackageManagerSettingsTests.java
+++ b/services/tests/servicestests/src/com/android/server/pm/PackageManagerSettingsTests.java
@@ -25,9 +25,12 @@
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import android.annotation.NonNull;
@@ -37,6 +40,7 @@
import android.content.pm.UserInfo;
import android.os.UserHandle;
import android.os.UserManagerInternal;
+import android.security.keystore.ArrayUtils;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
@@ -57,6 +61,7 @@
import java.io.IOException;
import java.security.PublicKey;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
@RunWith(AndroidJUnit4.class)
@@ -527,6 +532,41 @@
false /*notLaunched*/, false /*stopped*/, true /*installed*/);
}
+ @Test
+ public void testInsertPackageSetting() {
+ final PackageSetting ps = createPackageSetting(0 /*sharedUserId*/, 0 /*pkgFlags*/);
+ final PackageParser.Package pkg = new PackageParser.Package(PACKAGE_NAME);
+ pkg.applicationInfo.setCodePath(ps.codePathString);
+ pkg.applicationInfo.setResourcePath(ps.resourcePathString);
+ final Settings settings =
+ new Settings(InstrumentationRegistry.getContext().getFilesDir(), new Object());
+ pkg.usesStaticLibraries = new ArrayList<>(
+ Arrays.asList("foo.bar1", "foo.bar2", "foo.bar3"));
+ pkg.usesStaticLibrariesVersions = new int[] {2, 4, 6};
+ settings.insertPackageSettingLPw(ps, pkg);
+ assertEquals(pkg, ps.pkg);
+ assertArrayEquals(pkg.usesStaticLibraries.toArray(new String[0]), ps.usesStaticLibraries);
+ assertArrayEquals(pkg.usesStaticLibrariesVersions, ps.usesStaticLibrariesVersions);
+
+ pkg.usesStaticLibraries = null;
+ pkg.usesStaticLibrariesVersions = null;
+ settings.insertPackageSettingLPw(ps, pkg);
+ assertEquals(pkg, ps.pkg);
+ assertNull("Actual: " + Arrays.toString(ps.usesStaticLibraries), ps.usesStaticLibraries);
+ assertNull("Actual: " + Arrays.toString(ps.usesStaticLibrariesVersions),
+ ps.usesStaticLibrariesVersions);
+ }
+
+ private <T> void assertArrayEquals(T[] a, T[] b) {
+ assertTrue("Expected: " + Arrays.toString(a) + ", actual: " + Arrays.toString(b),
+ Arrays.equals(a, b));
+ }
+
+ private void assertArrayEquals(int[] a, int[] b) {
+ assertTrue("Expected: " + Arrays.toString(a) + ", actual: " + Arrays.toString(b),
+ Arrays.equals(a, b));
+ }
+
private void verifyUserState(PackageUserState userState, PackageUserState oldUserState,
boolean userStateChanged) {
verifyUserState(userState, oldUserState, userStateChanged, false /*notLaunched*/,