Merge "Fix side channel leakage from the api of overrideLabelAndIcon" into sc-dev
This commit is contained in:
@@ -23607,11 +23607,6 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
throw new IllegalArgumentException("Must specify a component");
|
throw new IllegalArgumentException("Must specify a component");
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean componentExists = mComponentResolver.componentExists(componentName);
|
|
||||||
if (!componentExists) {
|
|
||||||
throw new IllegalArgumentException("Component " + componentName + " not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
int callingUid = Binder.getCallingUid();
|
int callingUid = Binder.getCallingUid();
|
||||||
|
|
||||||
String componentPkgName = componentName.getPackageName();
|
String componentPkgName = componentName.getPackageName();
|
||||||
@@ -23643,6 +23638,10 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
"Changing the label is not allowed for " + componentName);
|
"Changing the label is not allowed for " + componentName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!mComponentResolver.componentExists(componentName)) {
|
||||||
|
throw new IllegalArgumentException("Component " + componentName + " not found");
|
||||||
|
}
|
||||||
|
|
||||||
if (!pkgSetting.overrideNonLocalizedLabelAndIcon(componentName, nonLocalizedLabel,
|
if (!pkgSetting.overrideNonLocalizedLabelAndIcon(componentName, nonLocalizedLabel,
|
||||||
icon, userId)) {
|
icon, userId)) {
|
||||||
// Nothing changed
|
// Nothing changed
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.server.pm.test.override
|
package com.android.server.pm.test.override
|
||||||
|
|
||||||
|
import android.app.PropertyInvalidatedCache
|
||||||
import android.content.ComponentName
|
import android.content.ComponentName
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
@@ -26,8 +27,10 @@ import android.util.ArrayMap
|
|||||||
import com.android.server.pm.AppsFilter
|
import com.android.server.pm.AppsFilter
|
||||||
import com.android.server.pm.ComponentResolver
|
import com.android.server.pm.ComponentResolver
|
||||||
import com.android.server.pm.PackageManagerService
|
import com.android.server.pm.PackageManagerService
|
||||||
|
import com.android.server.pm.PackageManagerTracedLock
|
||||||
import com.android.server.pm.PackageSetting
|
import com.android.server.pm.PackageSetting
|
||||||
import com.android.server.pm.Settings
|
import com.android.server.pm.Settings
|
||||||
|
import com.android.server.pm.UserManagerInternal
|
||||||
import com.android.server.pm.UserManagerService
|
import com.android.server.pm.UserManagerService
|
||||||
import com.android.server.pm.parsing.pkg.AndroidPackage
|
import com.android.server.pm.parsing.pkg.AndroidPackage
|
||||||
import com.android.server.pm.parsing.pkg.PackageImpl
|
import com.android.server.pm.parsing.pkg.PackageImpl
|
||||||
@@ -42,6 +45,7 @@ import com.android.server.wm.ActivityTaskManagerInternal
|
|||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
|
import org.junit.BeforeClass
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.junit.runners.Parameterized
|
import org.junit.runners.Parameterized
|
||||||
@@ -63,6 +67,7 @@ class PackageManagerComponentLabelIconOverrideTest {
|
|||||||
private const val VALID_PKG = "com.android.server.pm.test.override"
|
private const val VALID_PKG = "com.android.server.pm.test.override"
|
||||||
private const val SHARED_PKG = "com.android.server.pm.test.override.shared"
|
private const val SHARED_PKG = "com.android.server.pm.test.override.shared"
|
||||||
private const val INVALID_PKG = "com.android.server.pm.test.override.invalid"
|
private const val INVALID_PKG = "com.android.server.pm.test.override.invalid"
|
||||||
|
private const val NON_EXISTENT_PKG = "com.android.server.pm.test.override.nonexistent"
|
||||||
|
|
||||||
private const val SEND_PENDING_BROADCAST = 1 // PackageManagerService.SEND_PENDING_BROADCAST
|
private const val SEND_PENDING_BROADCAST = 1 // PackageManagerService.SEND_PENDING_BROADCAST
|
||||||
|
|
||||||
@@ -94,7 +99,8 @@ class PackageManagerComponentLabelIconOverrideTest {
|
|||||||
// Start with an array of the simplest known inputs and expected outputs
|
// Start with an array of the simplest known inputs and expected outputs
|
||||||
Params(VALID_PKG, AppType.SYSTEM_APP, Result.Changed),
|
Params(VALID_PKG, AppType.SYSTEM_APP, Result.Changed),
|
||||||
Params(SHARED_PKG, AppType.SYSTEM_APP, Result.Changed),
|
Params(SHARED_PKG, AppType.SYSTEM_APP, Result.Changed),
|
||||||
Params(INVALID_PKG, AppType.SYSTEM_APP, SecurityException::class.java)
|
Params(INVALID_PKG, AppType.SYSTEM_APP, SecurityException::class.java),
|
||||||
|
Params(NON_EXISTENT_PKG, AppType.SYSTEM_APP, SecurityException::class.java)
|
||||||
)
|
)
|
||||||
.flatMap { param ->
|
.flatMap { param ->
|
||||||
mutableListOf(param).apply {
|
mutableListOf(param).apply {
|
||||||
@@ -120,6 +126,13 @@ class PackageManagerComponentLabelIconOverrideTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
@JvmStatic
|
||||||
|
fun disablePropertyInvalidatedCache() {
|
||||||
|
// Disable binder caches in this process.
|
||||||
|
PropertyInvalidatedCache.disableForTestMode()
|
||||||
|
}
|
||||||
|
|
||||||
data class Params(
|
data class Params(
|
||||||
val pkgName: String,
|
val pkgName: String,
|
||||||
private val appType: AppType,
|
private val appType: AppType,
|
||||||
@@ -210,8 +223,10 @@ class PackageManagerComponentLabelIconOverrideTest {
|
|||||||
fun verifyExpectedResult() {
|
fun verifyExpectedResult() {
|
||||||
if (params.componentName != null) {
|
if (params.componentName != null) {
|
||||||
val activityInfo = service.getActivityInfo(params.componentName, 0, userId)
|
val activityInfo = service.getActivityInfo(params.componentName, 0, userId)
|
||||||
assertThat(activityInfo.nonLocalizedLabel).isEqualTo(params.expectedLabel)
|
if (activityInfo != null) {
|
||||||
assertThat(activityInfo.icon).isEqualTo(params.expectedIcon)
|
assertThat(activityInfo.nonLocalizedLabel).isEqualTo(params.expectedLabel)
|
||||||
|
assertThat(activityInfo.icon).isEqualTo(params.expectedIcon)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,34 +309,41 @@ class PackageManagerComponentLabelIconOverrideTest {
|
|||||||
SHARED_PKG to makePkg(SHARED_PKG) { uid = Binder.getCallingUid() },
|
SHARED_PKG to makePkg(SHARED_PKG) { uid = Binder.getCallingUid() },
|
||||||
INVALID_PKG to makePkg(INVALID_PKG) { uid = Binder.getCallingUid() + 1 }
|
INVALID_PKG to makePkg(INVALID_PKG) { uid = Binder.getCallingUid() + 1 }
|
||||||
)
|
)
|
||||||
val mockedPkgSettings = mapOf(
|
val mockedPkgSettings = mutableMapOf(
|
||||||
VALID_PKG to makePkgSetting(VALID_PKG),
|
VALID_PKG to makePkgSetting(VALID_PKG),
|
||||||
SHARED_PKG to makePkgSetting(SHARED_PKG),
|
SHARED_PKG to makePkgSetting(SHARED_PKG),
|
||||||
INVALID_PKG to makePkgSetting(INVALID_PKG)
|
INVALID_PKG to makePkgSetting(INVALID_PKG)
|
||||||
)
|
)
|
||||||
// Add pkgSetting under test so its attributes override the defaults added above
|
|
||||||
.plus(params.pkgName to mockPkgSetting)
|
|
||||||
|
|
||||||
val mockActivity: ParsedActivity = mock {
|
var mockActivity: ParsedActivity? = null
|
||||||
whenever(this.packageName) { params.pkgName }
|
if (mockedPkgSettings.containsKey(params.pkgName)) {
|
||||||
whenever(this.nonLocalizedLabel) { DEFAULT_LABEL }
|
// Add pkgSetting under test so its attributes override the defaults added above
|
||||||
whenever(this.icon) { DEFAULT_ICON }
|
mockedPkgSettings.put(params.pkgName, mockPkgSetting)
|
||||||
whenever(this.componentName) { params.componentName }
|
|
||||||
whenever(this.name) { params.componentName?.className }
|
mockActivity = mock<ParsedActivity> {
|
||||||
whenever(this.isEnabled) { true }
|
whenever(this.packageName) { params.pkgName }
|
||||||
whenever(this.isDirectBootAware) { params.isSystem }
|
whenever(this.nonLocalizedLabel) { DEFAULT_LABEL }
|
||||||
|
whenever(this.icon) { DEFAULT_ICON }
|
||||||
|
whenever(this.componentName) { params.componentName }
|
||||||
|
whenever(this.name) { params.componentName?.className }
|
||||||
|
whenever(this.isEnabled) { true }
|
||||||
|
whenever(this.isDirectBootAware) { params.isSystem }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val mockSettings = Settings(mockedPkgSettings)
|
val mockSettings = Settings(mockedPkgSettings)
|
||||||
val mockComponentResolver: ComponentResolver = mockThrowOnUnmocked {
|
val mockComponentResolver: ComponentResolver = mockThrowOnUnmocked {
|
||||||
params.componentName?.let {
|
params.componentName?.let {
|
||||||
whenever(this.componentExists(same(it))) { true }
|
whenever(this.componentExists(same(it))) { mockActivity != null }
|
||||||
whenever(this.getActivity(same(it))) { mockActivity }
|
whenever(this.getActivity(same(it))) { mockActivity }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val mockUserManagerService: UserManagerService = mockThrowOnUnmocked {
|
val mockUserManagerService: UserManagerService = mockThrowOnUnmocked {
|
||||||
val matcher: (Int) -> Boolean = { it == userId || it == userIdDifferent }
|
val matcher: (Int) -> Boolean = { it == userId || it == userIdDifferent }
|
||||||
whenever(this.exists(intThat(matcher))) { true }
|
whenever(this.exists(intThat(matcher))) { true }
|
||||||
|
}
|
||||||
|
val mockUserManagerInternal: UserManagerInternal = mockThrowOnUnmocked {
|
||||||
|
val matcher: (Int) -> Boolean = { it == userId || it == userIdDifferent }
|
||||||
whenever(this.isUserUnlockingOrUnlocked(intThat(matcher))) { true }
|
whenever(this.isUserUnlockingOrUnlocked(intThat(matcher))) { true }
|
||||||
}
|
}
|
||||||
val mockActivityTaskManager: ActivityTaskManagerInternal = mockThrowOnUnmocked {
|
val mockActivityTaskManager: ActivityTaskManagerInternal = mockThrowOnUnmocked {
|
||||||
@@ -340,18 +362,19 @@ class PackageManagerComponentLabelIconOverrideTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
val mockInjector: PackageManagerService.Injector = mock {
|
val mockInjector: PackageManagerService.Injector = mock {
|
||||||
whenever(this.lock) { Object() }
|
whenever(this.lock) { PackageManagerTracedLock() }
|
||||||
whenever(this.componentResolver) { mockComponentResolver }
|
whenever(this.componentResolver) { mockComponentResolver }
|
||||||
whenever(this.userManagerService) { mockUserManagerService }
|
whenever(this.userManagerService) { mockUserManagerService }
|
||||||
|
whenever(this.getUserManagerInternal()) { mockUserManagerInternal }
|
||||||
whenever(this.settings) { mockSettings }
|
whenever(this.settings) { mockSettings }
|
||||||
whenever(this.getLocalService(ActivityTaskManagerInternal::class.java)) {
|
whenever(this.getLocalService(ActivityTaskManagerInternal::class.java)) {
|
||||||
mockActivityTaskManager
|
mockActivityTaskManager
|
||||||
}
|
}
|
||||||
whenever(this.appsFilter) { mockAppsFilter }
|
whenever(this.appsFilter) { mockAppsFilter }
|
||||||
whenever(this.context) { mockContext }
|
whenever(this.context) { mockContext }
|
||||||
|
whenever(this.getHandler()) { testHandler }
|
||||||
}
|
}
|
||||||
val testParams = PackageManagerService.TestParams().apply {
|
val testParams = PackageManagerService.TestParams().apply {
|
||||||
this.handler = testHandler
|
|
||||||
this.pendingPackageBroadcasts = mockPendingBroadcasts
|
this.pendingPackageBroadcasts = mockPendingBroadcasts
|
||||||
this.resolveComponentName = ComponentName("android", ".Test")
|
this.resolveComponentName = ComponentName("android", ".Test")
|
||||||
this.packages = ArrayMap<String, AndroidPackage>().apply { putAll(mockedPkgs) }
|
this.packages = ArrayMap<String, AndroidPackage>().apply { putAll(mockedPkgs) }
|
||||||
|
|||||||
Reference in New Issue
Block a user