Loading core/tests/packagemanagertests/src/android/content/pm/KernelPackageMappingTests.java +11 −6 Original line number Diff line number Diff line Loading @@ -17,14 +17,9 @@ package android.content.pm; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import android.content.Context; import android.os.FileUtils; import android.os.Process; import android.os.ServiceManager; import android.os.UserManager; import android.support.test.InstrumentationRegistry; Loading @@ -32,7 +27,6 @@ import android.support.test.runner.AndroidJUnit4; import android.util.Log; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; Loading Loading @@ -85,12 +79,23 @@ public class KernelPackageMappingTests { assertEquals("1000", getContent(getKernelPackageFile("com.android.settings", "appid"))); } @Test public void testSharedInstalledPrimary() throws Exception { assertEquals("1001", getContent(getKernelPackageFile("shared:android.uid.phone", "appid"))); } @Test public void testInstalledAll() throws Exception { assertEquals("", getContent(getKernelPackageFile("com.android.settings", "excluded_userids"))); } @Test public void testSharedInstalledAll() throws Exception { assertEquals("", getContent(getKernelPackageFile("shared:android.uid.phone", "excluded_userids"))); } @Test public void testNotInstalledSecondary() throws Exception { mSecondaryUser = getUserManager().createUser("Secondary", 0); Loading services/core/java/com/android/server/pm/Settings.java +25 −9 Original line number Diff line number Diff line Loading @@ -2634,6 +2634,10 @@ public final class Settings { writeKernelMappingLPr(ps); } for (final SharedUserSetting sus : mSharedUsers.values()) { knownSet.remove(sus.getSandboxName()); } // Remove any unclaimed mappings for (int i = 0; i < knownSet.size(); i++) { final String name = knownSet.valueAt(i); Loading @@ -2644,30 +2648,42 @@ public final class Settings { } } void writeKernelMappingLPr(SharedUserSetting sus) { if (mKernelMappingFilename == null || sus == null || sus.name == null) return; writeKernelMappingLPr(sus.getSandboxName(), sus.userId, sus.getNotInstalledUserIds()); } void writeKernelMappingLPr(PackageSetting ps) { if (mKernelMappingFilename == null || ps == null || ps.name == null) return; KernelPackageState cur = mKernelMapping.get(ps.name); writeKernelMappingLPr(ps.name, ps.appId, ps.getNotInstalledUserIds()); if (ps.sharedUser != null) { writeKernelMappingLPr(ps.sharedUser); } } void writeKernelMappingLPr(String name, int appId, int[] excludedUserIds) { KernelPackageState cur = mKernelMapping.get(name); final boolean firstTime = cur == null; int[] excludedUserIds = ps.getNotInstalledUserIds(); final boolean userIdsChanged = firstTime || !Arrays.equals(excludedUserIds, cur.excludedUserIds); // Package directory final File dir = new File(mKernelMappingFilename, ps.name); final File dir = new File(mKernelMappingFilename, name); if (firstTime) { dir.mkdir(); // Create a new mapping state cur = new KernelPackageState(); mKernelMapping.put(ps.name, cur); mKernelMapping.put(name, cur); } // If mapping is incorrect or non-existent, write the appid file if (cur.appId != ps.appId) { if (cur.appId != appId) { final File appIdFile = new File(dir, "appid"); writeIntToFile(appIdFile, ps.appId); if (DEBUG_KERNEL) Slog.d(TAG, "Mapping " + ps.name + " to " + ps.appId); writeIntToFile(appIdFile, appId); if (DEBUG_KERNEL) Slog.d(TAG, "Mapping " + name + " to " + appId); } if (userIdsChanged) { Loading @@ -2677,7 +2693,7 @@ public final class Settings { excludedUserIds[i])) { writeIntToFile(new File(dir, "excluded_userids"), excludedUserIds[i]); if (DEBUG_KERNEL) Slog.d(TAG, "Writing " + excludedUserIds[i] + " to " + ps.name + "/excluded_userids"); + name + "/excluded_userids"); } } // Build the inclusion list -- the ids to remove from the exclusion list Loading @@ -2687,7 +2703,7 @@ public final class Settings { writeIntToFile(new File(dir, "clear_userid"), cur.excludedUserIds[i]); if (DEBUG_KERNEL) Slog.d(TAG, "Writing " + cur.excludedUserIds[i] + " to " + ps.name + "/clear_userid"); + name + "/clear_userid"); } } Loading services/core/java/com/android/server/pm/SharedUserSetting.java +26 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,10 @@ import android.service.pm.PackageServiceDumpProto; import android.util.ArraySet; import android.util.proto.ProtoOutputStream; import com.android.internal.util.ArrayUtils; import libcore.util.EmptyArray; import java.util.ArrayList; import java.util.List; Loading Loading @@ -144,6 +148,28 @@ public final class SharedUserSetting extends SettingBase { } } /** Returns userIds which doesn't have any packages with this sharedUserId */ public int[] getNotInstalledUserIds() { int[] excludedUserIds = null; for (PackageSetting ps : packages) { final int[] userIds = ps.getNotInstalledUserIds(); if (excludedUserIds == null) { excludedUserIds = userIds; } else { for (int userId : excludedUserIds) { if (!ArrayUtils.contains(userIds, userId)) { excludedUserIds = ArrayUtils.removeInt(excludedUserIds, userId); } } } } return excludedUserIds == null ? EmptyArray.INT : excludedUserIds; } public String getSandboxName() { return "shared:" + name; } /** Updates all fields in this shared user setting from another. */ public SharedUserSetting updateFrom(SharedUserSetting sharedUser) { copyFrom(sharedUser); Loading Loading
core/tests/packagemanagertests/src/android/content/pm/KernelPackageMappingTests.java +11 −6 Original line number Diff line number Diff line Loading @@ -17,14 +17,9 @@ package android.content.pm; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import android.content.Context; import android.os.FileUtils; import android.os.Process; import android.os.ServiceManager; import android.os.UserManager; import android.support.test.InstrumentationRegistry; Loading @@ -32,7 +27,6 @@ import android.support.test.runner.AndroidJUnit4; import android.util.Log; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; Loading Loading @@ -85,12 +79,23 @@ public class KernelPackageMappingTests { assertEquals("1000", getContent(getKernelPackageFile("com.android.settings", "appid"))); } @Test public void testSharedInstalledPrimary() throws Exception { assertEquals("1001", getContent(getKernelPackageFile("shared:android.uid.phone", "appid"))); } @Test public void testInstalledAll() throws Exception { assertEquals("", getContent(getKernelPackageFile("com.android.settings", "excluded_userids"))); } @Test public void testSharedInstalledAll() throws Exception { assertEquals("", getContent(getKernelPackageFile("shared:android.uid.phone", "excluded_userids"))); } @Test public void testNotInstalledSecondary() throws Exception { mSecondaryUser = getUserManager().createUser("Secondary", 0); Loading
services/core/java/com/android/server/pm/Settings.java +25 −9 Original line number Diff line number Diff line Loading @@ -2634,6 +2634,10 @@ public final class Settings { writeKernelMappingLPr(ps); } for (final SharedUserSetting sus : mSharedUsers.values()) { knownSet.remove(sus.getSandboxName()); } // Remove any unclaimed mappings for (int i = 0; i < knownSet.size(); i++) { final String name = knownSet.valueAt(i); Loading @@ -2644,30 +2648,42 @@ public final class Settings { } } void writeKernelMappingLPr(SharedUserSetting sus) { if (mKernelMappingFilename == null || sus == null || sus.name == null) return; writeKernelMappingLPr(sus.getSandboxName(), sus.userId, sus.getNotInstalledUserIds()); } void writeKernelMappingLPr(PackageSetting ps) { if (mKernelMappingFilename == null || ps == null || ps.name == null) return; KernelPackageState cur = mKernelMapping.get(ps.name); writeKernelMappingLPr(ps.name, ps.appId, ps.getNotInstalledUserIds()); if (ps.sharedUser != null) { writeKernelMappingLPr(ps.sharedUser); } } void writeKernelMappingLPr(String name, int appId, int[] excludedUserIds) { KernelPackageState cur = mKernelMapping.get(name); final boolean firstTime = cur == null; int[] excludedUserIds = ps.getNotInstalledUserIds(); final boolean userIdsChanged = firstTime || !Arrays.equals(excludedUserIds, cur.excludedUserIds); // Package directory final File dir = new File(mKernelMappingFilename, ps.name); final File dir = new File(mKernelMappingFilename, name); if (firstTime) { dir.mkdir(); // Create a new mapping state cur = new KernelPackageState(); mKernelMapping.put(ps.name, cur); mKernelMapping.put(name, cur); } // If mapping is incorrect or non-existent, write the appid file if (cur.appId != ps.appId) { if (cur.appId != appId) { final File appIdFile = new File(dir, "appid"); writeIntToFile(appIdFile, ps.appId); if (DEBUG_KERNEL) Slog.d(TAG, "Mapping " + ps.name + " to " + ps.appId); writeIntToFile(appIdFile, appId); if (DEBUG_KERNEL) Slog.d(TAG, "Mapping " + name + " to " + appId); } if (userIdsChanged) { Loading @@ -2677,7 +2693,7 @@ public final class Settings { excludedUserIds[i])) { writeIntToFile(new File(dir, "excluded_userids"), excludedUserIds[i]); if (DEBUG_KERNEL) Slog.d(TAG, "Writing " + excludedUserIds[i] + " to " + ps.name + "/excluded_userids"); + name + "/excluded_userids"); } } // Build the inclusion list -- the ids to remove from the exclusion list Loading @@ -2687,7 +2703,7 @@ public final class Settings { writeIntToFile(new File(dir, "clear_userid"), cur.excludedUserIds[i]); if (DEBUG_KERNEL) Slog.d(TAG, "Writing " + cur.excludedUserIds[i] + " to " + ps.name + "/clear_userid"); + name + "/clear_userid"); } } Loading
services/core/java/com/android/server/pm/SharedUserSetting.java +26 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,10 @@ import android.service.pm.PackageServiceDumpProto; import android.util.ArraySet; import android.util.proto.ProtoOutputStream; import com.android.internal.util.ArrayUtils; import libcore.util.EmptyArray; import java.util.ArrayList; import java.util.List; Loading Loading @@ -144,6 +148,28 @@ public final class SharedUserSetting extends SettingBase { } } /** Returns userIds which doesn't have any packages with this sharedUserId */ public int[] getNotInstalledUserIds() { int[] excludedUserIds = null; for (PackageSetting ps : packages) { final int[] userIds = ps.getNotInstalledUserIds(); if (excludedUserIds == null) { excludedUserIds = userIds; } else { for (int userId : excludedUserIds) { if (!ArrayUtils.contains(userIds, userId)) { excludedUserIds = ArrayUtils.removeInt(excludedUserIds, userId); } } } } return excludedUserIds == null ? EmptyArray.INT : excludedUserIds; } public String getSandboxName() { return "shared:" + name; } /** Updates all fields in this shared user setting from another. */ public SharedUserSetting updateFrom(SharedUserSetting sharedUser) { copyFrom(sharedUser); Loading