Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Commit

Permalink
Merge tag 'android-8.1.0_r81' into staging/lineage-15.1_merge-android…
Browse files Browse the repository at this point in the history
…-8.1.0_r81

Android 8.1.0 Release 81 (6780335)

* tag 'android-8.1.0_r81':
  Mark implicit PendingIntents as immutable
  RESTRICT AUTOMERGE Do not set referrerUri on SessionInfo for non-owners
  Add missing isShellUser check
  Remove unused intent in NiNotification
  • Loading branch information
haggertk committed Oct 11, 2020
2 parents b732512 + 7e7ea09 commit bd09980
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 18 deletions.
2 changes: 2 additions & 0 deletions core/java/android/content/pm/PackageInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,7 @@ public long getSize() {

/**
* Get the value set in {@link SessionParams#setOriginatingUri(Uri)}.
* Note: This value will only be non-null for the owner of the session.
*/
public @Nullable Uri getOriginatingUri() {
return originatingUri;
Expand All @@ -1585,6 +1586,7 @@ public int getOriginatingUid() {

/**
* Get the value set in {@link SessionParams#setReferrerUri(Uri)}
* Note: This value will only be non-null for the owner of the session.
*/
public @Nullable Uri getReferrerUri() {
return referrerUri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
Expand Down Expand Up @@ -402,13 +401,9 @@ private synchronized void setNiNotification(GpsNiNotification notif) {
mNiNotificationBuilder.setDefaults(0);
}

// if not to popup dialog immediately, pending intent will open the dialog
Intent intent = !mPopupImmediately ? getDlgIntent(notif) : new Intent();
PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, intent, 0);
mNiNotificationBuilder.setTicker(getNotifTicker(notif, mContext))
.setContentTitle(title)
.setContentText(message)
.setContentIntent(pi);
.setContentText(message);

notificationManager.notifyAsUser(null, notif.notificationId, mNiNotificationBuilder.build(),
UserHandle.ALL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,13 @@ public void dumpLeak(int garbageCount) {
.setContentText(String.format(
"SystemUI has detected %d leaked objects. Tap to send", garbageCount))
.setSmallIcon(com.android.internal.R.drawable.stat_sys_adb)
.setContentIntent(PendingIntent.getActivityAsUser(mContext, 0,
.setContentIntent(PendingIntent.getActivityAsUser(
mContext,
0,
getIntent(hprofFile, dumpFile),
PendingIntent.FLAG_UPDATE_CURRENT, null, UserHandle.CURRENT));
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE,
null,
UserHandle.CURRENT));
notiMan.notify(TAG, 0, builder.build());
} catch (IOException e) {
Log.e(TAG, "Couldn't dump heap for leak", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4331,9 +4331,18 @@ public int getPackageProcessState(String packageName, String callingPackage) {
return procState;
}

private boolean isCallerShell() {
final int callingUid = Binder.getCallingUid();
return callingUid == SHELL_UID || callingUid == ROOT_UID;
}

@Override
public boolean setProcessMemoryTrimLevel(String process, int userId, int level)
throws RemoteException {
if (!isCallerShell()) {
EventLog.writeEvent(0x534e4554, 160390416, Binder.getCallingUid(), "");
throw new SecurityException("Only shell can call it");
}
synchronized (this) {
final ProcessRecord app = findProcessLocked(process, userId, "setProcessMemoryTrimLevel");
if (app == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,20 +683,24 @@ static void prepareExternalStageCid(String stageCid, long sizeBytes) throws IOEx
public SessionInfo getSessionInfo(int sessionId) {
synchronized (mSessions) {
final PackageInstallerSession session = mSessions.get(sessionId);
return session != null ? session.generateInfo() : null;

return session != null
? session.generateInfoForCaller(true /*withIcon*/, Binder.getCallingUid())
: null;
}
}

@Override
public ParceledListSlice<SessionInfo> getAllSessions(int userId) {
mPm.enforceCrossUserPermission(Binder.getCallingUid(), userId, true, false, "getAllSessions");
final int callingUid = Binder.getCallingUid();
mPm.enforceCrossUserPermission(callingUid, userId, true, false, "getAllSessions");

final List<SessionInfo> result = new ArrayList<>();
synchronized (mSessions) {
for (int i = 0; i < mSessions.size(); i++) {
final PackageInstallerSession session = mSessions.valueAt(i);
if (session.userId == userId) {
result.add(session.generateInfo(false));
result.add(session.generateInfoForCaller(false, callingUid));
}
}
}
Expand All @@ -713,7 +717,8 @@ public ParceledListSlice<SessionInfo> getMySessions(String installerPackageName,
for (int i = 0; i < mSessions.size(); i++) {
final PackageInstallerSession session = mSessions.valueAt(i);

SessionInfo info = session.generateInfo(false);
SessionInfo info =
session.generateInfoForCaller(false /*withIcon*/, Process.SYSTEM_UID);
if (Objects.equals(info.getInstallerPackageName(), installerPackageName)
&& session.userId == userId) {
result.add(info);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,41 @@ public PackageInstallerSession(PackageInstallerService.InternalCallback callback
}
}

public SessionInfo generateInfo() {
return generateInfo(true);
/**
* Returns {@code true} if the {@link SessionInfo} object should be produced with potentially
* sensitive data scrubbed from its fields.
*
* @param callingUid the uid of the caller; the recipient of the {@link SessionInfo} that may
* need to be scrubbed
*/
private boolean shouldScrubData(int callingUid) {
return !(callingUid < Process.FIRST_APPLICATION_UID || getInstallerUid() == callingUid);
}

/**
* Generates a {@link SessionInfo} object for the provided uid. This may result in some fields
* that may contain sensitive info being filtered.
*
* @param includeIcon true if the icon should be included in the object
* @param callingUid the uid of the caller; the recipient of the {@link SessionInfo} that may
* need to be scrubbed
* @see #shouldScrubData(int)
*/
public SessionInfo generateInfoForCaller(boolean includeIcon, int callingUid) {
return generateInfoInternal(includeIcon, shouldScrubData(callingUid));
}

public SessionInfo generateInfo(boolean includeIcon) {
/**
* Generates a {@link SessionInfo} object to ensure proper hiding of sensitive fields.
*
* @param includeIcon true if the icon should be included in the object
* @see #generateInfoForCaller(boolean, int)
*/
public SessionInfo generateInfoScrubbed(boolean includeIcon) {
return generateInfoInternal(includeIcon, true /*scrubData*/);
}

private SessionInfo generateInfoInternal(boolean includeIcon, boolean scrubData) {
final SessionInfo info = new SessionInfo();
synchronized (mLock) {
info.sessionId = sessionId;
Expand All @@ -411,9 +441,13 @@ public SessionInfo generateInfo(boolean includeIcon) {
info.appLabel = params.appLabel;

info.installLocation = params.installLocation;
info.originatingUri = params.originatingUri;
if (!scrubData) {
info.originatingUri = params.originatingUri;
}
info.originatingUid = params.originatingUid;
info.referrerUri = params.referrerUri;
if (!scrubData) {
info.referrerUri = params.referrerUri;
}
info.grantedRuntimePermissions = params.grantedRuntimePermissions;
info.installFlags = params.installFlags;
}
Expand Down Expand Up @@ -1490,7 +1524,7 @@ private void dispatchSessionFinished(int returnCode, String msg, Bundle extras)
// Send broadcast to default launcher only if it's a new install
final boolean isNewInstall = extras == null || !extras.getBoolean(Intent.EXTRA_REPLACING);
if (success && isNewInstall) {
mPm.sendSessionCommitBroadcast(generateInfo(), userId);
mPm.sendSessionCommitBroadcast(generateInfoScrubbed(true /*icon*/), userId);
}

mCallback.onSessionFinished(this, success);
Expand Down

0 comments on commit bd09980

Please sign in to comment.