Merge "Use app info to load app data instead of component info" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
40e35dfad3
@@ -26,9 +26,10 @@ import android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AWARE
|
|||||||
import android.content.pm.PackageManager.MATCH_DIRECT_BOOT_UNAWARE
|
import android.content.pm.PackageManager.MATCH_DIRECT_BOOT_UNAWARE
|
||||||
import android.content.pm.ResolveInfo
|
import android.content.pm.ResolveInfo
|
||||||
import android.content.pm.ServiceInfo
|
import android.content.pm.ServiceInfo
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
import android.os.UserHandle
|
import android.os.UserHandle
|
||||||
import android.service.controls.ControlsProviderService
|
import android.service.controls.ControlsProviderService
|
||||||
import androidx.annotation.VisibleForTesting
|
import android.util.IconDrawableFactory
|
||||||
import androidx.annotation.WorkerThread
|
import androidx.annotation.WorkerThread
|
||||||
import com.android.settingslib.applications.DefaultAppInfo
|
import com.android.settingslib.applications.DefaultAppInfo
|
||||||
import com.android.systemui.R
|
import com.android.systemui.R
|
||||||
@@ -47,7 +48,7 @@ open class ControlsServiceInfo(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
val metadata = serviceInfo.metaData
|
val metadata = serviceInfo.metaData
|
||||||
?.getString(ControlsProviderService.META_DATA_PANEL_ACTIVITY) ?: ""
|
?.getString(ControlsProviderService.META_DATA_PANEL_ACTIVITY) ?: ""
|
||||||
val unflatenned = ComponentName.unflattenFromString(metadata)
|
val unflatenned = ComponentName.unflattenFromString(metadata)
|
||||||
if (unflatenned != null && unflatenned.packageName == componentName.packageName) {
|
if (unflatenned != null && unflatenned.packageName == componentName.packageName) {
|
||||||
_panelActivity = unflatenned
|
_panelActivity = unflatenned
|
||||||
@@ -71,21 +72,21 @@ open class ControlsServiceInfo(
|
|||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
fun resolvePanelActivity(
|
fun resolvePanelActivity(
|
||||||
allowAllApps: Boolean = false
|
allowAllApps: Boolean = false
|
||||||
) {
|
) {
|
||||||
if (resolved) return
|
if (resolved) return
|
||||||
resolved = true
|
resolved = true
|
||||||
val validPackages = context.resources
|
val validPackages = context.resources
|
||||||
.getStringArray(R.array.config_controlsPreferredPackages)
|
.getStringArray(R.array.config_controlsPreferredPackages)
|
||||||
if (componentName.packageName !in validPackages && !allowAllApps) return
|
if (componentName.packageName !in validPackages && !allowAllApps) return
|
||||||
panelActivity = _panelActivity?.let {
|
panelActivity = _panelActivity?.let {
|
||||||
val resolveInfos = mPm.queryIntentActivitiesAsUser(
|
val resolveInfos = mPm.queryIntentActivitiesAsUser(
|
||||||
Intent().setComponent(it),
|
Intent().setComponent(it),
|
||||||
PackageManager.ResolveInfoFlags.of(
|
PackageManager.ResolveInfoFlags.of(
|
||||||
MATCH_DIRECT_BOOT_AWARE.toLong() or
|
MATCH_DIRECT_BOOT_AWARE.toLong() or
|
||||||
MATCH_DIRECT_BOOT_UNAWARE.toLong()
|
MATCH_DIRECT_BOOT_UNAWARE.toLong()
|
||||||
),
|
),
|
||||||
UserHandle.of(userId)
|
UserHandle.of(userId)
|
||||||
)
|
)
|
||||||
if (resolveInfos.isNotEmpty() && verifyResolveInfo(resolveInfos[0])) {
|
if (resolveInfos.isNotEmpty() && verifyResolveInfo(resolveInfos[0])) {
|
||||||
it
|
it
|
||||||
@@ -118,6 +119,27 @@ open class ControlsServiceInfo(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
|
override fun loadLabel(): CharSequence {
|
||||||
|
return componentName?.let {
|
||||||
|
val appInfo = mPm.getApplicationInfoAsUser(componentName.packageName, 0, userId)
|
||||||
|
appInfo.loadLabel(mPm)
|
||||||
|
}
|
||||||
|
?: packageItemInfo?.loadLabel(mPm)
|
||||||
|
?: throw IllegalArgumentException("Package info is missing")
|
||||||
|
}
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
|
override fun loadIcon(): Drawable {
|
||||||
|
val packageName =
|
||||||
|
componentName?.packageName
|
||||||
|
?: packageItemInfo?.packageName
|
||||||
|
?: throw IllegalArgumentException("Package info is missing")
|
||||||
|
val factory = IconDrawableFactory.newInstance(context)
|
||||||
|
val appInfo = mPm.getApplicationInfoAsUser(packageName, 0, userId)
|
||||||
|
return factory.getBadgedIcon(appInfo)
|
||||||
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
return other is ControlsServiceInfo &&
|
return other is ControlsServiceInfo &&
|
||||||
userId == other.userId &&
|
userId == other.userId &&
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import android.content.Context
|
|||||||
import android.content.pm.ApplicationInfo
|
import android.content.pm.ApplicationInfo
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.content.pm.ServiceInfo
|
import android.content.pm.ServiceInfo
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
import android.os.UserHandle
|
import android.os.UserHandle
|
||||||
import android.service.controls.ControlsProviderService
|
import android.service.controls.ControlsProviderService
|
||||||
import android.testing.AndroidTestingRunner
|
import android.testing.AndroidTestingRunner
|
||||||
@@ -69,6 +70,7 @@ import org.junit.Test
|
|||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
import org.mockito.Mockito.clearInvocations
|
import org.mockito.Mockito.clearInvocations
|
||||||
|
import org.mockito.Mockito.doReturn
|
||||||
import org.mockito.Mockito.never
|
import org.mockito.Mockito.never
|
||||||
import org.mockito.Mockito.spy
|
import org.mockito.Mockito.spy
|
||||||
import org.mockito.Mockito.verify
|
import org.mockito.Mockito.verify
|
||||||
@@ -516,9 +518,9 @@ class ControlsUiControllerImplTest : SysuiTestCase() {
|
|||||||
name = componentName.className
|
name = componentName.className
|
||||||
}
|
}
|
||||||
return spy(ControlsServiceInfo(mContext, serviceInfo)).apply {
|
return spy(ControlsServiceInfo(mContext, serviceInfo)).apply {
|
||||||
`when`(loadLabel()).thenReturn(label)
|
doReturn(label).whenever(this).loadLabel()
|
||||||
`when`(loadIcon()).thenReturn(mock())
|
doReturn(mock<Drawable>()).whenever(this).loadIcon()
|
||||||
`when`(panelActivity).thenReturn(panelComponentName)
|
doReturn(panelComponentName).whenever(this).panelActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user