Merge "Prevent ClassCastException" into sc-v2-dev am: 32438ace61
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16213958 Change-Id: Ie8b3d5e0deb70ed372451e3698fac5f597abec2a
This commit is contained in:
@@ -28,6 +28,7 @@ import android.os.UserHandle
|
|||||||
import android.service.controls.Control
|
import android.service.controls.Control
|
||||||
import android.service.controls.ControlsProviderService
|
import android.service.controls.ControlsProviderService
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import java.lang.ClassCastException
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Proxy to launch in user 0
|
* Proxy to launch in user 0
|
||||||
@@ -59,20 +60,29 @@ class ControlsRequestReceiver : BroadcastReceiver() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val packageName = intent.getParcelableExtra<ComponentName>(Intent.EXTRA_COMPONENT_NAME)
|
val targetComponent = try {
|
||||||
?.packageName
|
intent.getParcelableExtra<ComponentName>(Intent.EXTRA_COMPONENT_NAME)
|
||||||
|
} catch (e: ClassCastException) {
|
||||||
|
Log.e(TAG, "Malformed intent extra ComponentName", e)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val control = try {
|
||||||
|
intent.getParcelableExtra<Control>(ControlsProviderService.EXTRA_CONTROL)
|
||||||
|
} catch (e: ClassCastException) {
|
||||||
|
Log.e(TAG, "Malformed intent extra Control", e)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val packageName = targetComponent?.packageName
|
||||||
|
|
||||||
if (packageName == null || !isPackageInForeground(context, packageName)) {
|
if (packageName == null || !isPackageInForeground(context, packageName)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val activityIntent = Intent(context, ControlsRequestDialog::class.java).apply {
|
val activityIntent = Intent(context, ControlsRequestDialog::class.java).apply {
|
||||||
Intent.EXTRA_COMPONENT_NAME.let {
|
putExtra(Intent.EXTRA_COMPONENT_NAME, targetComponent)
|
||||||
putExtra(it, intent.getParcelableExtra<ComponentName>(it))
|
putExtra(ControlsProviderService.EXTRA_CONTROL, control)
|
||||||
}
|
|
||||||
ControlsProviderService.EXTRA_CONTROL.let {
|
|
||||||
putExtra(it, intent.getParcelableExtra<Control>(it))
|
|
||||||
}
|
|
||||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
|
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
|
||||||
}
|
}
|
||||||
activityIntent.putExtra(Intent.EXTRA_USER_ID, context.userId)
|
activityIntent.putExtra(Intent.EXTRA_USER_ID, context.userId)
|
||||||
|
|||||||
@@ -154,6 +154,28 @@ class ControlsRequestReceiverTest : SysuiTestCase() {
|
|||||||
assertNull(wrapper.intent)
|
assertNull(wrapper.intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testClassCastExceptionComponentName_noCrash() {
|
||||||
|
val badIntent = Intent(ControlsProviderService.ACTION_ADD_CONTROL).apply {
|
||||||
|
putExtra(Intent.EXTRA_COMPONENT_NAME, Intent())
|
||||||
|
putExtra(ControlsProviderService.EXTRA_CONTROL, control)
|
||||||
|
}
|
||||||
|
receiver.onReceive(wrapper, badIntent)
|
||||||
|
|
||||||
|
assertNull(wrapper.intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testClassCastExceptionControl_noCrash() {
|
||||||
|
val badIntent = Intent(ControlsProviderService.ACTION_ADD_CONTROL).apply {
|
||||||
|
putExtra(Intent.EXTRA_COMPONENT_NAME, componentName)
|
||||||
|
putExtra(ControlsProviderService.EXTRA_CONTROL, Intent())
|
||||||
|
}
|
||||||
|
receiver.onReceive(wrapper, badIntent)
|
||||||
|
|
||||||
|
assertNull(wrapper.intent)
|
||||||
|
}
|
||||||
|
|
||||||
class MyWrapper(context: Context) : ContextWrapper(context) {
|
class MyWrapper(context: Context) : ContextWrapper(context) {
|
||||||
var intent: Intent? = null
|
var intent: Intent? = null
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user