Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 12783cb4 authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

Push sharedUserIds info to config/sdcardfs.

Bug: 117573457
Test: manual
Test: atest core/tests/packagemanagertests/src/android/content/pm/KernelPackageMappingTests.java
Change-Id: I652a0e7dab75d68247d2270edbddcc1b7ea18229
parent 5b3a6a81
Loading
Loading
Loading
Loading
+11 −6
Original line number Original line Diff line number Diff line
@@ -17,14 +17,9 @@
package android.content.pm;
package android.content.pm;


import static org.junit.Assert.assertEquals;
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.content.Context;
import android.os.FileUtils;
import android.os.FileUtils;
import android.os.Process;
import android.os.ServiceManager;
import android.os.ServiceManager;
import android.os.UserManager;
import android.os.UserManager;
import android.support.test.InstrumentationRegistry;
import android.support.test.InstrumentationRegistry;
@@ -32,7 +27,6 @@ import android.support.test.runner.AndroidJUnit4;
import android.util.Log;
import android.util.Log;


import org.junit.After;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.RunWith;


@@ -85,12 +79,23 @@ public class KernelPackageMappingTests {
        assertEquals("1000", getContent(getKernelPackageFile("com.android.settings", "appid")));
        assertEquals("1000", getContent(getKernelPackageFile("com.android.settings", "appid")));
    }
    }


    @Test
    public void testSharedInstalledPrimary() throws Exception {
        assertEquals("1001", getContent(getKernelPackageFile("shared:android.uid.phone", "appid")));
    }

    @Test
    @Test
    public void testInstalledAll() throws Exception {
    public void testInstalledAll() throws Exception {
        assertEquals("", getContent(getKernelPackageFile("com.android.settings",
        assertEquals("", getContent(getKernelPackageFile("com.android.settings",
                "excluded_userids")));
                "excluded_userids")));
    }
    }


    @Test
    public void testSharedInstalledAll() throws Exception {
        assertEquals("", getContent(getKernelPackageFile("shared:android.uid.phone",
                "excluded_userids")));
    }

    @Test
    @Test
    public void testNotInstalledSecondary() throws Exception {
    public void testNotInstalledSecondary() throws Exception {
        mSecondaryUser = getUserManager().createUser("Secondary", 0);
        mSecondaryUser = getUserManager().createUser("Secondary", 0);
+25 −9
Original line number Original line Diff line number Diff line
@@ -2634,6 +2634,10 @@ public final class Settings {
            writeKernelMappingLPr(ps);
            writeKernelMappingLPr(ps);
        }
        }


        for (final SharedUserSetting sus : mSharedUsers.values()) {
            knownSet.remove(sus.getSandboxName());
        }

        // Remove any unclaimed mappings
        // Remove any unclaimed mappings
        for (int i = 0; i < knownSet.size(); i++) {
        for (int i = 0; i < knownSet.size(); i++) {
            final String name = knownSet.valueAt(i);
            final String name = knownSet.valueAt(i);
@@ -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) {
    void writeKernelMappingLPr(PackageSetting ps) {
        if (mKernelMappingFilename == null || ps == null || ps.name == null) return;
        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;
        final boolean firstTime = cur == null;
        int[] excludedUserIds = ps.getNotInstalledUserIds();
        final boolean userIdsChanged = firstTime
        final boolean userIdsChanged = firstTime
                || !Arrays.equals(excludedUserIds, cur.excludedUserIds);
                || !Arrays.equals(excludedUserIds, cur.excludedUserIds);


        // Package directory
        // Package directory
        final File dir = new File(mKernelMappingFilename, ps.name);
        final File dir = new File(mKernelMappingFilename, name);


        if (firstTime) {
        if (firstTime) {
            dir.mkdir();
            dir.mkdir();
            // Create a new mapping state
            // Create a new mapping state
            cur = new KernelPackageState();
            cur = new KernelPackageState();
            mKernelMapping.put(ps.name, cur);
            mKernelMapping.put(name, cur);
        }
        }


        // If mapping is incorrect or non-existent, write the appid file
        // 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");
            final File appIdFile = new File(dir, "appid");
            writeIntToFile(appIdFile, ps.appId);
            writeIntToFile(appIdFile, appId);
            if (DEBUG_KERNEL) Slog.d(TAG, "Mapping " + ps.name + " to " + ps.appId);
            if (DEBUG_KERNEL) Slog.d(TAG, "Mapping " + name + " to " + appId);
        }
        }


        if (userIdsChanged) {
        if (userIdsChanged) {
@@ -2677,7 +2693,7 @@ public final class Settings {
                        excludedUserIds[i])) {
                        excludedUserIds[i])) {
                    writeIntToFile(new File(dir, "excluded_userids"), excludedUserIds[i]);
                    writeIntToFile(new File(dir, "excluded_userids"), excludedUserIds[i]);
                    if (DEBUG_KERNEL) Slog.d(TAG, "Writing " + excludedUserIds[i] + " to "
                    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
            // Build the inclusion list -- the ids to remove from the exclusion list
@@ -2687,7 +2703,7 @@ public final class Settings {
                        writeIntToFile(new File(dir, "clear_userid"),
                        writeIntToFile(new File(dir, "clear_userid"),
                                cur.excludedUserIds[i]);
                                cur.excludedUserIds[i]);
                        if (DEBUG_KERNEL) Slog.d(TAG, "Writing " + cur.excludedUserIds[i] + " to "
                        if (DEBUG_KERNEL) Slog.d(TAG, "Writing " + cur.excludedUserIds[i] + " to "
                                + ps.name + "/clear_userid");
                                + name + "/clear_userid");


                    }
                    }
                }
                }
+26 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,10 @@ import android.service.pm.PackageServiceDumpProto;
import android.util.ArraySet;
import android.util.ArraySet;
import android.util.proto.ProtoOutputStream;
import android.util.proto.ProtoOutputStream;


import com.android.internal.util.ArrayUtils;

import libcore.util.EmptyArray;

import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;


@@ -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. */
    /** Updates all fields in this shared user setting from another. */
    public SharedUserSetting updateFrom(SharedUserSetting sharedUser) {
    public SharedUserSetting updateFrom(SharedUserSetting sharedUser) {
        copyFrom(sharedUser);
        copyFrom(sharedUser);