Fix NotificationListenerService fail to mirror work notification
1. Instead of getting application info in runtime, just retrieve the one in the context to avoid cross user operation. 2. Functions in PackageManager that retrieve badged icon now return badged icon if the targer user is managed profile instead of checking whether target user is a managed profile of the user in mContext. 3. Relax the restriction of getUserInfo, if the caller is asking a user in the same profile group or having the manage user permission, we let it go. Bug: 26469166 Change-Id: Ia1ffc5743f7d94bd489cdb7571eaed51499ebdd9
This commit is contained in:
@@ -1147,7 +1147,7 @@ public class ApplicationPackageManager extends PackageManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Drawable getManagedProfileIconForDensity(UserHandle user, int drawableId, int density) {
|
private Drawable getManagedProfileIconForDensity(UserHandle user, int drawableId, int density) {
|
||||||
UserInfo userInfo = getUserIfProfile(user.getIdentifier());
|
UserInfo userInfo = getUserInfo(user.getIdentifier());
|
||||||
if (userInfo != null && userInfo.isManagedProfile()) {
|
if (userInfo != null && userInfo.isManagedProfile()) {
|
||||||
return getDrawableForDensity(drawableId, density);
|
return getDrawableForDensity(drawableId, density);
|
||||||
}
|
}
|
||||||
@@ -1156,7 +1156,7 @@ public class ApplicationPackageManager extends PackageManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) {
|
public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) {
|
||||||
UserInfo userInfo = getUserIfProfile(user.getIdentifier());
|
UserInfo userInfo = getUserInfo(user.getIdentifier());
|
||||||
if (userInfo != null && userInfo.isManagedProfile()) {
|
if (userInfo != null && userInfo.isManagedProfile()) {
|
||||||
return Resources.getSystem().getString(
|
return Resources.getSystem().getString(
|
||||||
com.android.internal.R.string.managed_profile_label_badge, label);
|
com.android.internal.R.string.managed_profile_label_badge, label);
|
||||||
@@ -2252,21 +2252,15 @@ public class ApplicationPackageManager extends PackageManager {
|
|||||||
|
|
||||||
private int getBadgeResIdForUser(int userHandle) {
|
private int getBadgeResIdForUser(int userHandle) {
|
||||||
// Return the framework-provided badge.
|
// Return the framework-provided badge.
|
||||||
UserInfo userInfo = getUserIfProfile(userHandle);
|
UserInfo userInfo = getUserInfo(userHandle);
|
||||||
if (userInfo != null && userInfo.isManagedProfile()) {
|
if (userInfo != null && userInfo.isManagedProfile()) {
|
||||||
return com.android.internal.R.drawable.ic_corp_icon_badge;
|
return com.android.internal.R.drawable.ic_corp_icon_badge;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private UserInfo getUserIfProfile(int userHandle) {
|
private UserInfo getUserInfo(int userHandle) {
|
||||||
List<UserInfo> userProfiles = getUserManager().getProfiles(mContext.getUserId());
|
return getUserManager().getUserInfo(userHandle);
|
||||||
for (UserInfo user : userProfiles) {
|
|
||||||
if (user.id == userHandle) {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@hide} */
|
/** {@hide} */
|
||||||
|
|||||||
@@ -3173,16 +3173,9 @@ public class Notification implements Parcelable
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void bindHeaderAppName(RemoteViews contentView) {
|
private void bindHeaderAppName(RemoteViews contentView) {
|
||||||
PackageManager packageManager = mContext.getPackageManager();
|
CharSequence appName = mContext.getPackageManager()
|
||||||
ApplicationInfo info = null;
|
.getApplicationLabel(mContext.getApplicationInfo());
|
||||||
try {
|
|
||||||
info = packageManager.getApplicationInfo(mContext.getApplicationInfo().packageName,
|
|
||||||
0);
|
|
||||||
} catch (final NameNotFoundException e) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
CharSequence appName = info != null ? packageManager.getApplicationLabel(info)
|
|
||||||
: null;
|
|
||||||
if (TextUtils.isEmpty(appName)) {
|
if (TextUtils.isEmpty(appName)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4387,10 +4387,8 @@ public abstract class PackageManager {
|
|||||||
int badgeDensity);
|
int badgeDensity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the target user is a managed profile of the calling user or if the
|
* If the target user is a managed profile, then this returns a badged copy of the given icon
|
||||||
* target user is the caller and is itself a managed profile, then this
|
* to be able to distinguish it from the original icon. For badging an arbitrary drawable use
|
||||||
* returns a badged copy of the given icon to be able to distinguish it from
|
|
||||||
* the original icon. For badging an arbitrary drawable use
|
|
||||||
* {@link #getUserBadgedDrawableForDensity(
|
* {@link #getUserBadgedDrawableForDensity(
|
||||||
* android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}.
|
* android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}.
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -972,7 +972,8 @@ public class UserManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the UserInfo object describing a specific user.
|
* Returns the UserInfo object describing a specific user.
|
||||||
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
|
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission or the caller is
|
||||||
|
* in the same profile group of target user.
|
||||||
* @param userHandle the user handle of the user whose information is being requested.
|
* @param userHandle the user handle of the user whose information is being requested.
|
||||||
* @return the UserInfo object for a specific user.
|
* @return the UserInfo object for a specific user.
|
||||||
* @hide
|
* @hide
|
||||||
|
|||||||
@@ -641,7 +641,12 @@ public class UserManagerService extends IUserManager.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserInfo getUserInfo(int userId) {
|
public UserInfo getUserInfo(int userId) {
|
||||||
checkManageUsersPermission("query user");
|
if (!hasManageUsersPermission()
|
||||||
|
&& !isSameProfileGroupLP(UserHandle.getCallingUserId(), userId)) {
|
||||||
|
throw new SecurityException(
|
||||||
|
"You need MANAGE_USERS permission to: query users outside profile group");
|
||||||
|
}
|
||||||
|
|
||||||
synchronized (mUsersLock) {
|
synchronized (mUsersLock) {
|
||||||
return getUserInfoLU(userId);
|
return getUserInfoLU(userId);
|
||||||
}
|
}
|
||||||
@@ -1196,17 +1201,27 @@ public class UserManagerService extends IUserManager.Stub {
|
|||||||
*
|
*
|
||||||
* @param message used as message if SecurityException is thrown
|
* @param message used as message if SecurityException is thrown
|
||||||
* @throws SecurityException if the caller is not system or root
|
* @throws SecurityException if the caller is not system or root
|
||||||
|
* @see #hasManageUsersPermission()
|
||||||
*/
|
*/
|
||||||
private static final void checkManageUsersPermission(String message) {
|
private static final void checkManageUsersPermission(String message) {
|
||||||
final int uid = Binder.getCallingUid();
|
if (!hasManageUsersPermission()) {
|
||||||
if (!UserHandle.isSameApp(uid, Process.SYSTEM_UID) && uid != Process.ROOT_UID
|
|
||||||
&& ActivityManager.checkComponentPermission(
|
|
||||||
android.Manifest.permission.MANAGE_USERS,
|
|
||||||
uid, -1, true) != PackageManager.PERMISSION_GRANTED) {
|
|
||||||
throw new SecurityException("You need MANAGE_USERS permission to: " + message);
|
throw new SecurityException("You need MANAGE_USERS permission to: " + message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return whether the calling UID is system UID or root's UID or the calling app has the
|
||||||
|
* {@link android.Manifest.permission#MANAGE_USERS MANAGE_USERS}.
|
||||||
|
*/
|
||||||
|
private static final boolean hasManageUsersPermission() {
|
||||||
|
final int callingUid = Binder.getCallingUid();
|
||||||
|
return UserHandle.isSameApp(callingUid, Process.SYSTEM_UID)
|
||||||
|
|| callingUid == Process.ROOT_UID
|
||||||
|
|| ActivityManager.checkComponentPermission(
|
||||||
|
android.Manifest.permission.MANAGE_USERS,
|
||||||
|
callingUid, -1, true) == PackageManager.PERMISSION_GRANTED;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enforces that only the system UID or root's UID (on any user) can make certain calls to the
|
* Enforces that only the system UID or root's UID (on any user) can make certain calls to the
|
||||||
* UserManager.
|
* UserManager.
|
||||||
|
|||||||
Reference in New Issue
Block a user