Loading core/java/android/content/pm/PackageInstaller.java +1 −8 Original line number Diff line number Diff line Loading @@ -349,14 +349,7 @@ public class PackageInstaller { */ public int createSession(@NonNull SessionParams params) throws IOException { try { final String installerPackage; if (params.installerPackageName == null) { installerPackage = mInstallerPackageName; } else { installerPackage = params.installerPackageName; } return mInstaller.createSession(params, installerPackage, mUserId); return mInstaller.createSession(params, mInstallerPackageName, mUserId); } catch (RuntimeException e) { ExceptionUtils.maybeUnwrapIOException(e); throw e; Loading core/proto/android/service/package.proto +9 −0 Original line number Diff line number Diff line Loading @@ -114,6 +114,13 @@ message PackageProto { optional int32 distraction_flags = 10; } message InstallSourceProto { option (android.msg_privacy).dest = DEST_AUTOMATIC; // The package that requested the installation of this one. optional string initiating_package_name = 1; } // Name of package. e.g. "com.android.providers.telephony". optional string name = 1; // UID for this package as assigned by Android OS. Loading @@ -133,4 +140,6 @@ message PackageProto { repeated SplitProto splits = 8; // Per-user package info. repeated UserInfoProto users = 9; // Where the request to install this package came from, optional InstallSourceProto install_source = 10; } services/core/java/com/android/server/pm/InstallSource.java 0 → 100644 +59 −0 Original line number Diff line number Diff line /* * Copyright 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.pm; import android.annotation.Nullable; import com.android.internal.util.IndentingPrintWriter; /** * Immutable class holding information about where the request to install or update an app * came from. */ final class InstallSource { private static final InstallSource EMPTY = new InstallSource(null); /** * The package that requested the installation, if known. */ @Nullable final String initiatingPackageName; static InstallSource create(@Nullable String initiatingPackageName) { return initiatingPackageName == null ? EMPTY : new InstallSource(initiatingPackageName.intern()); } private InstallSource(@Nullable String initiatingPackageName) { this.initiatingPackageName = initiatingPackageName; } void dump(IndentingPrintWriter pw) { pw.printPair("installInitiatingPackageName", initiatingPackageName); } /** * Return an InstallSource the same as this one except it does not refer to the specified * installer package name. */ InstallSource removeInstallerPackage(String packageName) { if (packageName != null && packageName.equals(initiatingPackageName)) { return create(null); } return this; } } services/core/java/com/android/server/pm/PackageInstallerService.java +16 −6 Original line number Diff line number Diff line Loading @@ -482,15 +482,24 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements throw new SecurityException("User restriction prevents installing"); } String requestedInstallerPackageName = params.installerPackageName != null ? params.installerPackageName : installerPackageName; if ((callingUid == Process.SHELL_UID) || (callingUid == Process.ROOT_UID)) { params.installFlags |= PackageManager.INSTALL_FROM_ADB; } else { if (callingUid != Process.SYSTEM_UID) { // The supplied installerPackageName must always belong to the calling app. mAppOps.checkPackage(callingUid, installerPackageName); } // Only apps with INSTALL_PACKAGES are allowed to set an installer that is not the // caller. if (mContext.checkCallingOrSelfPermission(Manifest.permission.INSTALL_PACKAGES) != PackageManager.PERMISSION_GRANTED) { mAppOps.checkPackage(callingUid, installerPackageName); if (!requestedInstallerPackageName.equals(installerPackageName)) { if (mContext.checkCallingOrSelfPermission(Manifest.permission.INSTALL_PACKAGES) != PackageManager.PERMISSION_GRANTED) { mAppOps.checkPackage(callingUid, requestedInstallerPackageName); } } params.installFlags &= ~PackageManager.INSTALL_FROM_ADB; Loading Loading @@ -614,11 +623,12 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements stageCid = buildExternalStageCid(sessionId); } } InstallSource installSource = InstallSource.create(installerPackageName); session = new PackageInstallerSession(mInternalCallback, mContext, mPm, this, mInstallThread.getLooper(), mStagingManager, sessionId, userId, installerPackageName, callingUid, params, createdMillis, stageDir, stageCid, false, false, false, null, SessionInfo.INVALID_ID, false, false, false, SessionInfo.STAGED_SESSION_NO_ERROR, ""); requestedInstallerPackageName, callingUid, installSource, params, createdMillis, stageDir, stageCid, false, false, false, null, SessionInfo.INVALID_ID, false, false, false, SessionInfo.STAGED_SESSION_NO_ERROR, ""); synchronized (mSessions) { mSessions.put(sessionId, session); Loading services/core/java/com/android/server/pm/PackageInstallerSession.java +20 −12 Original line number Diff line number Diff line Loading @@ -146,6 +146,8 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { private static final String ATTR_USER_ID = "userId"; private static final String ATTR_INSTALLER_PACKAGE_NAME = "installerPackageName"; private static final String ATTR_INSTALLER_UID = "installerUid"; private static final String ATTR_INITIATING_PACKAGE_NAME = "installInitiatingPackageName"; private static final String ATTR_CREATED_MILLIS = "createdMillis"; private static final String ATTR_UPDATED_MILLIS = "updatedMillis"; private static final String ATTR_SESSION_STAGE_DIR = "sessionStageDir"; Loading Loading @@ -218,6 +220,10 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { @GuardedBy("mLock") private int mInstallerUid; /** Where this install request came from */ @GuardedBy("mLock") private InstallSource mInstallSource; @GuardedBy("mLock") private float mClientProgress = 0; @GuardedBy("mLock") Loading Loading @@ -413,7 +419,8 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { Context context, PackageManagerService pm, PackageSessionProvider sessionProvider, Looper looper, StagingManager stagingManager, int sessionId, int userId, String installerPackageName, int installerUid, SessionParams params, long createdMillis, String installerPackageName, int installerUid, @NonNull InstallSource installSource, SessionParams params, long createdMillis, File stageDir, String stageCid, boolean prepared, boolean committed, boolean sealed, @Nullable int[] childSessionIds, int parentSessionId, boolean isReady, boolean isFailed, boolean isApplied, int stagedSessionErrorCode, Loading @@ -430,6 +437,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { mOriginalInstallerUid = installerUid; mInstallerPackageName = installerPackageName; mInstallerUid = installerUid; mInstallSource = Preconditions.checkNotNull(installSource); this.params = params; this.createdMillis = createdMillis; this.updatedMillis = createdMillis; Loading Loading @@ -1225,6 +1233,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { mInstallerPackageName = packageName; mInstallerUid = newOwnerAppInfo.uid; mInstallSource = InstallSource.create(packageName); } // Persist the fact that we've sealed ourselves to prevent Loading Loading @@ -1443,7 +1452,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { mRelinquished = true; return new PackageManagerService.ActiveInstallSession(mPackageName, stageDir, localObserver, params, mInstallerPackageName, mInstallerUid, user, localObserver, params, mInstallerPackageName, mInstallerUid, mInstallSource, user, mSigningDetails); } Loading Loading @@ -2336,6 +2345,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { pw.printPair("mOriginalInstallerUid", mOriginalInstallerUid); pw.printPair("mInstallerPackageName", mInstallerPackageName); pw.printPair("mInstallerUid", mInstallerUid); mInstallSource.dump(pw); pw.printPair("createdMillis", createdMillis); pw.printPair("updatedMillis", updatedMillis); pw.printPair("stageDir", stageDir); Loading Loading @@ -2416,6 +2426,8 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { writeStringAttribute(out, ATTR_INSTALLER_PACKAGE_NAME, mInstallerPackageName); writeIntAttribute(out, ATTR_INSTALLER_UID, mInstallerUid); writeStringAttribute(out, ATTR_INITIATING_PACKAGE_NAME, mInstallSource.initiatingPackageName); writeLongAttribute(out, ATTR_CREATED_MILLIS, createdMillis); writeLongAttribute(out, ATTR_UPDATED_MILLIS, updatedMillis); if (stageDir != null) { Loading Loading @@ -2521,6 +2533,8 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { final String installerPackageName = readStringAttribute(in, ATTR_INSTALLER_PACKAGE_NAME); final int installerUid = readIntAttribute(in, ATTR_INSTALLER_UID, pm.getPackageUid( installerPackageName, PackageManager.MATCH_UNINSTALLED_PACKAGES, userId)); final String installInitiatingPackageName = readStringAttribute(in, ATTR_INITIATING_PACKAGE_NAME); final long createdMillis = readLongAttribute(in, ATTR_CREATED_MILLIS); long updatedMillis = readLongAttribute(in, ATTR_UPDATED_MILLIS); final String stageDirRaw = readStringAttribute(in, ATTR_SESSION_STAGE_DIR); Loading Loading @@ -2612,17 +2626,11 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { childSessionIdsArray = EMPTY_CHILD_SESSION_ARRAY; } InstallSource installSource = InstallSource.create(installInitiatingPackageName); return new PackageInstallerSession(callback, context, pm, sessionProvider, installerThread, stagingManager, sessionId, userId, installerPackageName, installerUid, params, createdMillis, stageDir, stageCid, prepared, committed, sealed, childSessionIdsArray, parentSessionId, isReady, isFailed, isApplied, stagedSessionErrorCode, stagedSessionErrorMessage); } /** * Reads the session ID from a child session tag stored in the provided {@link XmlPullParser} */ static int readChildSessionIdFromXml(@NonNull XmlPullParser in) { return readIntAttribute(in, ATTR_SESSION_ID, SessionInfo.INVALID_ID); installerUid, installSource, params, createdMillis, stageDir, stageCid, prepared, committed, sealed, childSessionIdsArray, parentSessionId, isReady, isFailed, isApplied, stagedSessionErrorCode, stagedSessionErrorMessage); } } Loading
core/java/android/content/pm/PackageInstaller.java +1 −8 Original line number Diff line number Diff line Loading @@ -349,14 +349,7 @@ public class PackageInstaller { */ public int createSession(@NonNull SessionParams params) throws IOException { try { final String installerPackage; if (params.installerPackageName == null) { installerPackage = mInstallerPackageName; } else { installerPackage = params.installerPackageName; } return mInstaller.createSession(params, installerPackage, mUserId); return mInstaller.createSession(params, mInstallerPackageName, mUserId); } catch (RuntimeException e) { ExceptionUtils.maybeUnwrapIOException(e); throw e; Loading
core/proto/android/service/package.proto +9 −0 Original line number Diff line number Diff line Loading @@ -114,6 +114,13 @@ message PackageProto { optional int32 distraction_flags = 10; } message InstallSourceProto { option (android.msg_privacy).dest = DEST_AUTOMATIC; // The package that requested the installation of this one. optional string initiating_package_name = 1; } // Name of package. e.g. "com.android.providers.telephony". optional string name = 1; // UID for this package as assigned by Android OS. Loading @@ -133,4 +140,6 @@ message PackageProto { repeated SplitProto splits = 8; // Per-user package info. repeated UserInfoProto users = 9; // Where the request to install this package came from, optional InstallSourceProto install_source = 10; }
services/core/java/com/android/server/pm/InstallSource.java 0 → 100644 +59 −0 Original line number Diff line number Diff line /* * Copyright 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.pm; import android.annotation.Nullable; import com.android.internal.util.IndentingPrintWriter; /** * Immutable class holding information about where the request to install or update an app * came from. */ final class InstallSource { private static final InstallSource EMPTY = new InstallSource(null); /** * The package that requested the installation, if known. */ @Nullable final String initiatingPackageName; static InstallSource create(@Nullable String initiatingPackageName) { return initiatingPackageName == null ? EMPTY : new InstallSource(initiatingPackageName.intern()); } private InstallSource(@Nullable String initiatingPackageName) { this.initiatingPackageName = initiatingPackageName; } void dump(IndentingPrintWriter pw) { pw.printPair("installInitiatingPackageName", initiatingPackageName); } /** * Return an InstallSource the same as this one except it does not refer to the specified * installer package name. */ InstallSource removeInstallerPackage(String packageName) { if (packageName != null && packageName.equals(initiatingPackageName)) { return create(null); } return this; } }
services/core/java/com/android/server/pm/PackageInstallerService.java +16 −6 Original line number Diff line number Diff line Loading @@ -482,15 +482,24 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements throw new SecurityException("User restriction prevents installing"); } String requestedInstallerPackageName = params.installerPackageName != null ? params.installerPackageName : installerPackageName; if ((callingUid == Process.SHELL_UID) || (callingUid == Process.ROOT_UID)) { params.installFlags |= PackageManager.INSTALL_FROM_ADB; } else { if (callingUid != Process.SYSTEM_UID) { // The supplied installerPackageName must always belong to the calling app. mAppOps.checkPackage(callingUid, installerPackageName); } // Only apps with INSTALL_PACKAGES are allowed to set an installer that is not the // caller. if (mContext.checkCallingOrSelfPermission(Manifest.permission.INSTALL_PACKAGES) != PackageManager.PERMISSION_GRANTED) { mAppOps.checkPackage(callingUid, installerPackageName); if (!requestedInstallerPackageName.equals(installerPackageName)) { if (mContext.checkCallingOrSelfPermission(Manifest.permission.INSTALL_PACKAGES) != PackageManager.PERMISSION_GRANTED) { mAppOps.checkPackage(callingUid, requestedInstallerPackageName); } } params.installFlags &= ~PackageManager.INSTALL_FROM_ADB; Loading Loading @@ -614,11 +623,12 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements stageCid = buildExternalStageCid(sessionId); } } InstallSource installSource = InstallSource.create(installerPackageName); session = new PackageInstallerSession(mInternalCallback, mContext, mPm, this, mInstallThread.getLooper(), mStagingManager, sessionId, userId, installerPackageName, callingUid, params, createdMillis, stageDir, stageCid, false, false, false, null, SessionInfo.INVALID_ID, false, false, false, SessionInfo.STAGED_SESSION_NO_ERROR, ""); requestedInstallerPackageName, callingUid, installSource, params, createdMillis, stageDir, stageCid, false, false, false, null, SessionInfo.INVALID_ID, false, false, false, SessionInfo.STAGED_SESSION_NO_ERROR, ""); synchronized (mSessions) { mSessions.put(sessionId, session); Loading
services/core/java/com/android/server/pm/PackageInstallerSession.java +20 −12 Original line number Diff line number Diff line Loading @@ -146,6 +146,8 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { private static final String ATTR_USER_ID = "userId"; private static final String ATTR_INSTALLER_PACKAGE_NAME = "installerPackageName"; private static final String ATTR_INSTALLER_UID = "installerUid"; private static final String ATTR_INITIATING_PACKAGE_NAME = "installInitiatingPackageName"; private static final String ATTR_CREATED_MILLIS = "createdMillis"; private static final String ATTR_UPDATED_MILLIS = "updatedMillis"; private static final String ATTR_SESSION_STAGE_DIR = "sessionStageDir"; Loading Loading @@ -218,6 +220,10 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { @GuardedBy("mLock") private int mInstallerUid; /** Where this install request came from */ @GuardedBy("mLock") private InstallSource mInstallSource; @GuardedBy("mLock") private float mClientProgress = 0; @GuardedBy("mLock") Loading Loading @@ -413,7 +419,8 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { Context context, PackageManagerService pm, PackageSessionProvider sessionProvider, Looper looper, StagingManager stagingManager, int sessionId, int userId, String installerPackageName, int installerUid, SessionParams params, long createdMillis, String installerPackageName, int installerUid, @NonNull InstallSource installSource, SessionParams params, long createdMillis, File stageDir, String stageCid, boolean prepared, boolean committed, boolean sealed, @Nullable int[] childSessionIds, int parentSessionId, boolean isReady, boolean isFailed, boolean isApplied, int stagedSessionErrorCode, Loading @@ -430,6 +437,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { mOriginalInstallerUid = installerUid; mInstallerPackageName = installerPackageName; mInstallerUid = installerUid; mInstallSource = Preconditions.checkNotNull(installSource); this.params = params; this.createdMillis = createdMillis; this.updatedMillis = createdMillis; Loading Loading @@ -1225,6 +1233,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { mInstallerPackageName = packageName; mInstallerUid = newOwnerAppInfo.uid; mInstallSource = InstallSource.create(packageName); } // Persist the fact that we've sealed ourselves to prevent Loading Loading @@ -1443,7 +1452,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { mRelinquished = true; return new PackageManagerService.ActiveInstallSession(mPackageName, stageDir, localObserver, params, mInstallerPackageName, mInstallerUid, user, localObserver, params, mInstallerPackageName, mInstallerUid, mInstallSource, user, mSigningDetails); } Loading Loading @@ -2336,6 +2345,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { pw.printPair("mOriginalInstallerUid", mOriginalInstallerUid); pw.printPair("mInstallerPackageName", mInstallerPackageName); pw.printPair("mInstallerUid", mInstallerUid); mInstallSource.dump(pw); pw.printPair("createdMillis", createdMillis); pw.printPair("updatedMillis", updatedMillis); pw.printPair("stageDir", stageDir); Loading Loading @@ -2416,6 +2426,8 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { writeStringAttribute(out, ATTR_INSTALLER_PACKAGE_NAME, mInstallerPackageName); writeIntAttribute(out, ATTR_INSTALLER_UID, mInstallerUid); writeStringAttribute(out, ATTR_INITIATING_PACKAGE_NAME, mInstallSource.initiatingPackageName); writeLongAttribute(out, ATTR_CREATED_MILLIS, createdMillis); writeLongAttribute(out, ATTR_UPDATED_MILLIS, updatedMillis); if (stageDir != null) { Loading Loading @@ -2521,6 +2533,8 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { final String installerPackageName = readStringAttribute(in, ATTR_INSTALLER_PACKAGE_NAME); final int installerUid = readIntAttribute(in, ATTR_INSTALLER_UID, pm.getPackageUid( installerPackageName, PackageManager.MATCH_UNINSTALLED_PACKAGES, userId)); final String installInitiatingPackageName = readStringAttribute(in, ATTR_INITIATING_PACKAGE_NAME); final long createdMillis = readLongAttribute(in, ATTR_CREATED_MILLIS); long updatedMillis = readLongAttribute(in, ATTR_UPDATED_MILLIS); final String stageDirRaw = readStringAttribute(in, ATTR_SESSION_STAGE_DIR); Loading Loading @@ -2612,17 +2626,11 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { childSessionIdsArray = EMPTY_CHILD_SESSION_ARRAY; } InstallSource installSource = InstallSource.create(installInitiatingPackageName); return new PackageInstallerSession(callback, context, pm, sessionProvider, installerThread, stagingManager, sessionId, userId, installerPackageName, installerUid, params, createdMillis, stageDir, stageCid, prepared, committed, sealed, childSessionIdsArray, parentSessionId, isReady, isFailed, isApplied, stagedSessionErrorCode, stagedSessionErrorMessage); } /** * Reads the session ID from a child session tag stored in the provided {@link XmlPullParser} */ static int readChildSessionIdFromXml(@NonNull XmlPullParser in) { return readIntAttribute(in, ATTR_SESSION_ID, SessionInfo.INVALID_ID); installerUid, installSource, params, createdMillis, stageDir, stageCid, prepared, committed, sealed, childSessionIdsArray, parentSessionId, isReady, isFailed, isApplied, stagedSessionErrorCode, stagedSessionErrorMessage); } }