Skip to content
This repository was archived by the owner on Jan 4, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2a4fff7
Resolve custom printer icon boundary exploit.
199ashish Jul 17, 2023
0038840
Add PackageInstaller SessionParams restrictions
May 26, 2020
c3017eb
Validate package names passed to the installer.
alexbuy Nov 2, 2023
e112de7
Disallow system apps to be installed/updated as instant.
alexbuy Dec 20, 2023
4a98702
Close AccountManagerService.session after timeout.
Jan 3, 2024
b3fb018
isUserInLockDown can be true when there are other strong auth require…
Jan 18, 2024
525fe1b
Fix security vulnerability that creates user with no restrictions whe…
Jan 10, 2024
bc6193c
[BACKPORT] Prioritize system toasts
Oct 16, 2023
ac7dcf0
Don't try to show the current toast again while it's showing.
jtomljanovic Nov 6, 2020
062cd07
DO NOT MERGE: ActivityManager#killBackgroundProcesses can kill caller…
Oct 26, 2022
c894a30
DO NOT MERGE: Fix ActivityManager#killBackgroundProcesses permissions
Oct 19, 2023
8d42812
Verify URI permission for channel sound update from NotificationListe…
Feb 1, 2024
02cec37
Added throttle when reporting shortcut usage
pinyaoting Nov 30, 2023
9129222
Prevend user spoofing in isRequestPinItemSupported
pinyaoting Jul 20, 2021
098bec8
Check for NLS bind permission when rebinding services
Feb 22, 2024
66f73bd
Fix error handling for non-dynamic permissions
Feb 20, 2024
9185f42
Add more checkKeyIntent checks to AccountManagerService.
Mar 26, 2024
8706bda
[DO NOT MERGE][Autofill Framework] Add in check for intent filter when
haoranzhang-beep Mar 13, 2024
0a1707a
Check hidden API exemptions
hboehm Jan 3, 2024
79f4cac
Add StatusBarNotification::getNormalizedUserId
Apr 13, 2020
73f6c1e
Add Context.createContextAsUser()
Oct 9, 2019
2eb6cfb
Explicitly take flags in createContextAsUser()
Oct 12, 2019
98bb229
Resolve message/conversation image Uris with the correct user id
Mar 22, 2024
12c3991
[RESTRICT AUTOMERGE] AccessibilityManagerService: remove uninstalled …
ameerarmaly Mar 8, 2024
d54b490
[BACKPORT] Verify UID of incoming Zygote connections.
Feb 29, 2024
72f173f
Fix security vulnerability of non-dynamic permission removal
Apr 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api/system-current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1346,8 +1346,9 @@ package android.content {

public abstract class Context {
method @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) public boolean bindServiceAsUser(@RequiresPermission android.content.Intent, android.content.ServiceConnection, int, android.os.UserHandle);
method @NonNull public android.content.Context createContextAsUser(@NonNull android.os.UserHandle, int);
method public abstract android.content.Context createCredentialProtectedStorageContext();
method public android.content.Context createPackageContextAsUser(String, int, android.os.UserHandle) throws android.content.pm.PackageManager.NameNotFoundException;
method @NonNull public android.content.Context createPackageContextAsUser(@NonNull String, int, @NonNull android.os.UserHandle) throws android.content.pm.PackageManager.NameNotFoundException;
method @Nullable public abstract java.io.File getPreloadsFileCache();
method public abstract boolean isCredentialProtectedStorage();
method public abstract void sendBroadcast(android.content.Intent, @Nullable String, @Nullable android.os.Bundle);
Expand Down
3 changes: 2 additions & 1 deletion api/test-current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,8 @@ package android.content {
}

public abstract class Context {
method public android.content.Context createPackageContextAsUser(String, int, android.os.UserHandle) throws android.content.pm.PackageManager.NameNotFoundException;
method @NonNull public android.content.Context createContextAsUser(@NonNull android.os.UserHandle, int);
method @NonNull public android.content.Context createPackageContextAsUser(@NonNull String, int, @NonNull android.os.UserHandle) throws android.content.pm.PackageManager.NameNotFoundException;
method public abstract android.view.Display getDisplay();
method public abstract int getDisplayId();
method public android.os.UserHandle getUser();
Expand Down
9 changes: 9 additions & 0 deletions core/java/android/app/ContextImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2200,6 +2200,15 @@ public Context createPackageContextAsUser(String packageName, int flags, UserHan
"Application package " + packageName + " not found");
}

@Override
public Context createContextAsUser(UserHandle user, @CreatePackageOptions int flags) {
try {
return createPackageContextAsUser(getPackageName(), flags, user);
} catch (NameNotFoundException e) {
throw new IllegalStateException("Own package not found: package=" + getPackageName());
}
}

@Override
public Context createContextForSplit(String splitName) throws NameNotFoundException {
if (!mPackageInfo.getApplicationInfo().requestsIsolatedSplitLoading()) {
Expand Down
20 changes: 19 additions & 1 deletion core/java/android/content/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -5232,15 +5232,33 @@ public abstract Context createPackageContext(String packageName,
*/
@SystemApi
@TestApi
@NonNull
public Context createPackageContextAsUser(
String packageName, @CreatePackageOptions int flags, UserHandle user)
@NonNull String packageName, @CreatePackageOptions int flags, @NonNull UserHandle user)
throws PackageManager.NameNotFoundException {
if (Build.IS_ENG) {
throw new IllegalStateException("createPackageContextAsUser not overridden!");
}
return this;
}

/**
* Similar to {@link #createPackageContext(String, int)}, but for the own package with a
* different {@link UserHandle}. For example, {@link #getContentResolver()}
* will open any {@link Uri} as the given user.
*
* @hide
*/
@SystemApi
@TestApi
@NonNull
public Context createContextAsUser(@NonNull UserHandle user, @CreatePackageOptions int flags) {
if (Build.IS_ENG) {
throw new IllegalStateException("createContextAsUser not overridden!");
}
return this;
}

/**
* Creates a context given an {@link android.content.pm.ApplicationInfo}.
*
Expand Down
6 changes: 6 additions & 0 deletions core/java/android/content/ContextWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,12 @@ public Context createPackageContextAsUser(String packageName, int flags, UserHan
return mBase.createPackageContextAsUser(packageName, flags, user);
}

/** @hide */
@Override
public Context createContextAsUser(UserHandle user, @CreatePackageOptions int flags) {
return mBase.createContextAsUser(user, flags);
}

/** @hide */
@Override
@UnsupportedAppUsage
Expand Down
12 changes: 11 additions & 1 deletion core/java/android/content/pm/PackageInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,13 @@ public static class SessionParams implements Parcelable {
/** {@hide} */
public static final int UID_UNKNOWN = -1;

/**
* This value is derived from the maximum file name length. No package above this limit
* can ever be successfully installed on the device.
* @hide
*/
public static final int MAX_PACKAGE_NAME_LENGTH = 255;

/** {@hide} */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
public int mode = MODE_INVALID;
Expand Down Expand Up @@ -1450,6 +1457,8 @@ public void setAppIcon(@Nullable Bitmap appIcon) {

/**
* Optionally set a label representing the app being installed.
*
* This value will be trimmed to the first 1000 characters.
*/
public void setAppLabel(@Nullable CharSequence appLabel) {
this.appLabel = (appLabel != null) ? appLabel.toString() : null;
Expand Down Expand Up @@ -1519,7 +1528,8 @@ public void setGrantedRuntimePermissions(String[] permissions) {
*
* <p>Initially, all restricted permissions are whitelisted but you can change
* which ones are whitelisted by calling this method or the corresponding ones
* on the {@link PackageManager}.
* on the {@link PackageManager}. Only soft or hard restricted permissions on the current
* Android version are supported and any invalid entries will be removed.
*
* @see PackageManager#addWhitelistedRestrictedPermission(String, String, int)
* @see PackageManager#removeWhitelistedRestrictedPermission(String, String, int)
Expand Down
12 changes: 10 additions & 2 deletions core/java/android/content/pm/PackageItemInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,16 @@
* in the implementation of Parcelable in subclasses.
*/
public class PackageItemInfo {
/** The maximum length of a safe label, in characters */
private static final int MAX_SAFE_LABEL_LENGTH = 1000;

/**
* The maximum length of a safe label, in characters
*
* TODO(b/157997155): It may make sense to expose this publicly so that apps can check for the
* value and truncate the strings/use a different label, without having to hardcode and make
* assumptions about the value.
* @hide
*/
public static final int MAX_SAFE_LABEL_LENGTH = 1000;

/** @hide */
public static final float DEFAULT_MAX_LABEL_SIZE_PX = 500f;
Expand Down
2 changes: 1 addition & 1 deletion core/java/android/content/pm/PackageParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1644,7 +1644,7 @@ private static ApkLite parseApkLiteInner(File apkFile, FileDescriptor fd, String
}
}

private static String validateName(String name, boolean requireSeparator,
public static String validateName(String name, boolean requireSeparator,
boolean requireFilename) {
final int N = name.length();
boolean hasSep = false;
Expand Down
37 changes: 37 additions & 0 deletions core/java/android/os/PersistableBundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,43 @@ public void saveToXml(XmlSerializer out) throws IOException, XmlPullParserExcept
XmlUtils.writeMapXml(mMap, out, this);
}

/**
* Checks whether all keys and values are within the given character limit.
* Note: Maximum character limit of String that can be saved to XML as part of bundle is 65535.
* Otherwise IOException is thrown.
* @param limit length of String keys and values in the PersistableBundle, including nested
* PersistableBundles to check against.
*
* @hide
*/
public boolean isBundleContentsWithinLengthLimit(int limit) {
unparcel();
if (mMap == null) {
return true;
}
for (int i = 0; i < mMap.size(); i++) {
if (mMap.keyAt(i) != null && mMap.keyAt(i).length() > limit) {
return false;
}
final Object value = mMap.valueAt(i);
if (value instanceof String && ((String) value).length() > limit) {
return false;
} else if (value instanceof String[]) {
String[] stringArray = (String[]) value;
for (int j = 0; j < stringArray.length; j++) {
if (stringArray[j] != null
&& stringArray[j].length() > limit) {
return false;
}
}
} else if (value instanceof PersistableBundle
&& !((PersistableBundle) value).isBundleContentsWithinLengthLimit(limit)) {
return false;
}
}
return true;
}

/** @hide */
static class MyReadMapCallback implements XmlUtils.ReadMapCallback {
@Override
Expand Down
23 changes: 19 additions & 4 deletions core/java/android/os/UserManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ public class UserManager {

private Boolean mIsManagedProfileCached;

/** Maximum length of username.
* @hide
*/
public static final int MAX_USER_NAME_LENGTH = 100;

/** Maximum length of user property String value.
* @hide
*/
public static final int MAX_ACCOUNT_STRING_LENGTH = 500;

/** Maximum length of account options String values.
* @hide
*/
public static final int MAX_ACCOUNT_OPTIONS_LENGTH = 1000;

/**
* @hide
* No user restriction.
Expand Down Expand Up @@ -2199,15 +2214,15 @@ public UserInfo createRestrictedProfile(String name) {
* time, the preferred user name and account information are used by the setup process for that
* user.
*
* @param userName Optional name to assign to the user.
* @param userName Optional name to assign to the user. Character limit is 100.
* @param accountName Optional account name that will be used by the setup wizard to initialize
* the user.
* the user. Character limit is 500.
* @param accountType Optional account type for the account to be created. This is required
* if the account name is specified.
* if the account name is specified. Character limit is 500.
* @param accountOptions Optional bundle of data to be passed in during account creation in the
* new user via {@link AccountManager#addAccount(String, String, String[],
* Bundle, android.app.Activity, android.accounts.AccountManagerCallback,
* Handler)}.
* Handler)}. Character limit is 1000.
* @return An Intent that can be launched from an Activity.
* @see #USER_CREATION_FAILED_NOT_PERMITTED
* @see #USER_CREATION_FAILED_NO_MORE_USERS
Expand Down
10 changes: 10 additions & 0 deletions core/java/android/os/ZygoteProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ private Process.ProcessStartResult zygoteSendArgsAndGetResult(
throw new ZygoteStartFailedEx("Embedded newlines not allowed");
} else if (arg.indexOf('\r') >= 0) {
throw new ZygoteStartFailedEx("Embedded carriage returns not allowed");
} else if (arg.indexOf('\u0000') >= 0) {
throw new ZygoteStartFailedEx("Embedded nulls not allowed");
}
}

Expand Down Expand Up @@ -869,6 +871,14 @@ private boolean maybeSetApiBlacklistExemptions(ZygoteState state, boolean sendIf
return true;
}

for (/* NonNull */ String s : mApiBlacklistExemptions) {
// indexOf() is intrinsified and faster than contains().
if (s.indexOf('\n') >= 0 || s.indexOf('\r') >= 0 || s.indexOf('\u0000') >= 0) {
Slog.e(LOG_TAG, "Failed to set API denylist exemptions: Bad character");
mApiBlacklistExemptions = Collections.emptyList();
return false;
}
}
try {
state.mZygoteOutputWriter.write(Integer.toString(mApiBlacklistExemptions.size() + 1));
state.mZygoteOutputWriter.newLine();
Expand Down
12 changes: 12 additions & 0 deletions core/java/android/service/notification/StatusBarNotification.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,18 @@ public int getUserId() {
return this.user.getIdentifier();
}

/**
* Like {@link #getUserId()} but handles special users.
* @hide
*/
public int getNormalizedUserId() {
int userId = getUserId();
if (userId == UserHandle.USER_ALL) {
userId = UserHandle.USER_SYSTEM;
}
return userId;
}

/** The package that the notification belongs to. */
public String getPackageName() {
return pkg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ private String checkUserCreationRequirements() {
if (cantCreateUser) {
setResult(UserManager.USER_CREATION_FAILED_NOT_PERMITTED);
return null;
} else if (!(isUserPropertyWithinLimit(mUserName, UserManager.MAX_USER_NAME_LENGTH)
&& isUserPropertyWithinLimit(mAccountName, UserManager.MAX_ACCOUNT_STRING_LENGTH)
&& isUserPropertyWithinLimit(mAccountType, UserManager.MAX_ACCOUNT_STRING_LENGTH))
|| (mAccountOptions != null && !mAccountOptions.isBundleContentsWithinLengthLimit(
UserManager.MAX_ACCOUNT_OPTIONS_LENGTH))) {
setResult(UserManager.USER_CREATION_FAILED_NOT_PERMITTED);
Log.i(TAG, "User properties must not exceed their character limits");
return null;
} else if (cantCreateAnyMoreUsers) {
setResult(UserManager.USER_CREATION_FAILED_NO_MORE_USERS);
return null;
Expand Down Expand Up @@ -137,4 +145,8 @@ public void onClick(DialogInterface dialog, int which) {
}
finish();
}

private boolean isUserPropertyWithinLimit(String property, int limit) {
return property == null || property.length() <= limit;
}
}
3 changes: 3 additions & 0 deletions core/java/com/android/internal/os/ZygoteConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ class ZygoteConnection {
throw ex;
}

if (peer.getUid() != Process.SYSTEM_UID) {
throw new ZygoteSecurityException("Only system UID is allowed to connect to Zygote.");
}
isEof = false;
}

Expand Down
4 changes: 2 additions & 2 deletions core/java/com/android/internal/widget/LockPatternUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1782,8 +1782,8 @@ public boolean isBiometricAllowedForUser(int userId) {
}

public boolean isUserInLockdown(int userId) {
return getStrongAuthForUser(userId)
== StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN;
return (getStrongAuthForUser(userId)
& StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN) != 0;
}

private ICheckCredentialProgressCallback wrapCallback(
Expand Down
42 changes: 42 additions & 0 deletions core/tests/PackageInstallerSessions/Android.bp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// Copyright 2020 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.
//

android_test {
name: "FrameworksCorePackageInstallerSessionsTests",

srcs: [
"src/**/*.kt",
],
static_libs: [
"androidx.test.rules",
"compatibility-device-util-axt",
"frameworks-base-testutils",
"platform-test-annotations",
"testng",
"truth-prebuilt",
],

libs: [
"android.test.runner",
"android.test.base",
"framework",
"framework-res",
],

platform_apis: true,
sdk_version: "test_current",
test_suites: ["device-tests"],
}
29 changes: 29 additions & 0 deletions core/tests/PackageInstallerSessions/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
* Copyright (C) 2020 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.
-->

<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.frameworks.coretests.package_installer_sessions"
>

<application>
<uses-library android:name="android.test.runner" />
</application>

<instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
android:targetPackage="com.android.frameworks.coretests.package_installer_sessions"/>
</manifest>
Loading