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

Commit 98edc951 authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Load resources for the correct user

For apps that are only installed on secondary users, the SystemUI is
unable to see them by default. Added some methods to explicitly pass the
userId of the user the resources are requested for by the StatusBarIcon

Bug: 7214384

Also fix binding to remote views

Bug: 7192802

Change-Id: I5d6c5f624aa37fb231f3467f9764c8d99077a91d
parent b1c4ab5c
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -1740,6 +1740,11 @@ public final class ActivityThread {

    public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo,
            int flags) {
        return getPackageInfo(packageName, compatInfo, flags, UserHandle.myUserId());
    }

    public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo,
            int flags, int userId) {
        synchronized (mPackages) {
            WeakReference<LoadedApk> ref;
            if ((flags&Context.CONTEXT_INCLUDE_CODE) != 0) {
@@ -1768,7 +1773,7 @@ public final class ActivityThread {
        ApplicationInfo ai = null;
        try {
            ai = getPackageManager().getApplicationInfo(packageName,
                    PackageManager.GET_SHARED_LIBRARY_FILES, UserHandle.myUserId());
                    PackageManager.GET_SHARED_LIBRARY_FILES, userId);
        } catch (RemoteException e) {
            // Ignore
        }
+15 −0
Original line number Diff line number Diff line
@@ -759,6 +759,21 @@ final class ApplicationPackageManager extends PackageManager {
            getApplicationInfo(appPackageName, 0));
    }

    /** @hide */
    @Override
    public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
            throws NameNotFoundException {
        try {
            ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, 0, userId);
            if (ai != null) {
                return getResourcesForApplication(ai);
            }
        } catch (RemoteException e) {
            throw new RuntimeException("Package manager has died", e);
        }
        throw new NameNotFoundException("Package " + appPackageName + " doesn't exist");
    }

    int mCachedSafeMode = -1;
    @Override public boolean isSafeMode() {
        try {
+2 −1
Original line number Diff line number Diff line
@@ -1707,7 +1707,8 @@ class ContextImpl extends Context {
        }

        LoadedApk pi =
            mMainThread.getPackageInfo(packageName, mResources.getCompatibilityInfo(), flags);
            mMainThread.getPackageInfo(packageName, mResources.getCompatibilityInfo(), flags,
                    user.getIdentifier());
        if (pi != null) {
            ContextImpl c = new ContextImpl();
            c.mRestricted = (flags & CONTEXT_RESTRICTED) == CONTEXT_RESTRICTED;
+4 −0
Original line number Diff line number Diff line
@@ -2341,6 +2341,10 @@ public abstract class PackageManager {
    public abstract Resources getResourcesForApplication(String appPackageName)
            throws NameNotFoundException;

    /** @hide */
    public abstract Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
            throws NameNotFoundException;

    /**
     * Retrieve overall information about an application package defined
     * in a package archive file
+10 −4
Original line number Diff line number Diff line
@@ -18,18 +18,21 @@ package com.android.internal.statusbar;

import android.os.Parcel;
import android.os.Parcelable;
import android.os.UserHandle;

public class StatusBarIcon implements Parcelable {
    public String iconPackage;
    public UserHandle user;
    public int iconId;
    public int iconLevel;
    public boolean visible = true;
    public int number;
    public CharSequence contentDescription;

    public StatusBarIcon(String iconPackage, int iconId, int iconLevel, int number,
    public StatusBarIcon(String iconPackage, UserHandle user, int iconId, int iconLevel, int number,
            CharSequence contentDescription) {
        this.iconPackage = iconPackage;
        this.user = user;
        this.iconId = iconId;
        this.iconLevel = iconLevel;
        this.number = number;
@@ -38,15 +41,16 @@ public class StatusBarIcon implements Parcelable {

    @Override
    public String toString() {
        return "StatusBarIcon(pkg=" + this.iconPackage + " id=0x" + Integer.toHexString(this.iconId)
        return "StatusBarIcon(pkg=" + this.iconPackage + "user=" + user.getIdentifier()
                + " id=0x" + Integer.toHexString(this.iconId)
                + " level=" + this.iconLevel + " visible=" + visible
                + " num=" + this.number + " )";
    }

    @Override
    public StatusBarIcon clone() {
        StatusBarIcon that = new StatusBarIcon(this.iconPackage, this.iconId, this.iconLevel,
                this.number, this.contentDescription);
        StatusBarIcon that = new StatusBarIcon(this.iconPackage, this.user, this.iconId,
                this.iconLevel, this.number, this.contentDescription);
        that.visible = this.visible;
        return that;
    }
@@ -60,6 +64,7 @@ public class StatusBarIcon implements Parcelable {

    public void readFromParcel(Parcel in) {
        this.iconPackage = in.readString();
        this.user = (UserHandle) in.readParcelable(null);
        this.iconId = in.readInt();
        this.iconLevel = in.readInt();
        this.visible = in.readInt() != 0;
@@ -69,6 +74,7 @@ public class StatusBarIcon implements Parcelable {

    public void writeToParcel(Parcel out, int flags) {
        out.writeString(this.iconPackage);
        out.writeParcelable(this.user, 0);
        out.writeInt(this.iconId);
        out.writeInt(this.iconLevel);
        out.writeInt(this.visible ? 1 : 0);
Loading