Change landing page from PrivacyDialog
The landing page is now the permissions page for that app Fixes: 179699198 Test: atest com.android.systemui.privacy Change-Id: If7d3f982b45cce5198a8061094bc0a0a0b151fe4
This commit is contained in:
@@ -41,13 +41,12 @@ import java.util.concurrent.atomic.AtomicBoolean
|
||||
* @param context A context to create the dialog
|
||||
* @param list list of elements to show in the dialog. The elements will show in the same order they
|
||||
* appear in the list
|
||||
* @param activityStarter a callback to start an activity for a given permission group name (as
|
||||
* given by [PrivacyType.permGroupName])
|
||||
* @param activityStarter a callback to start an activity for a given package name and user id
|
||||
*/
|
||||
class PrivacyDialog(
|
||||
context: Context,
|
||||
private val list: List<PrivacyElement>,
|
||||
activityStarter: (String) -> Unit
|
||||
activityStarter: (String, Int) -> Unit
|
||||
) : SystemUIDialog(context, R.style.ScreenRecord) {
|
||||
|
||||
private val dismissListeners = mutableListOf<WeakReference<OnDialogDismissed>>()
|
||||
@@ -129,7 +128,7 @@ class PrivacyDialog(
|
||||
} ?: firstLine
|
||||
newView.requireViewById<TextView>(R.id.text).text = finalText
|
||||
newView.apply {
|
||||
tag = element.type.permGroupName
|
||||
setTag(element)
|
||||
setOnClickListener(clickListener)
|
||||
}
|
||||
return newView
|
||||
@@ -152,12 +151,17 @@ class PrivacyDialog(
|
||||
}
|
||||
|
||||
private val clickListener = View.OnClickListener { v ->
|
||||
v.tag?.let { activityStarter(it as String) }
|
||||
v.tag?.let {
|
||||
val element = it as PrivacyElement
|
||||
activityStarter(element.packageName, element.userId)
|
||||
}
|
||||
}
|
||||
|
||||
/** */
|
||||
data class PrivacyElement(
|
||||
val type: PrivacyType,
|
||||
val packageName: String,
|
||||
val userId: Int,
|
||||
val applicationName: CharSequence,
|
||||
val attribution: CharSequence?,
|
||||
val lastActiveTimestamp: Long,
|
||||
@@ -169,6 +173,8 @@ class PrivacyDialog(
|
||||
|
||||
init {
|
||||
builder.append("type=${type.logName}")
|
||||
builder.append(", packageName=$packageName")
|
||||
builder.append(", userId=$userId")
|
||||
builder.append(", appName=$applicationName")
|
||||
if (attribution != null) {
|
||||
builder.append(", attribution=$attribution")
|
||||
|
||||
@@ -43,7 +43,7 @@ private val defaultDialogProvider = object : PrivacyDialogController.DialogProvi
|
||||
override fun makeDialog(
|
||||
context: Context,
|
||||
list: List<PrivacyDialog.PrivacyElement>,
|
||||
starter: (String) -> Unit
|
||||
starter: (String, Int) -> Unit
|
||||
): PrivacyDialog {
|
||||
return PrivacyDialog(context, list, starter)
|
||||
}
|
||||
@@ -107,10 +107,11 @@ class PrivacyDialogController(
|
||||
}
|
||||
|
||||
@MainThread
|
||||
private fun startActivity(permGroupName: String) {
|
||||
val intent = Intent(Intent.ACTION_MANAGE_PERMISSION_APPS)
|
||||
intent.putExtra(Intent.EXTRA_PERMISSION_GROUP_NAME, permGroupName)
|
||||
privacyLogger.logStartSettingsActivityFromDialog(permGroupName)
|
||||
private fun startActivity(packageName: String, userId: Int) {
|
||||
val intent = Intent(Intent.ACTION_MANAGE_APP_PERMISSIONS)
|
||||
intent.putExtra(Intent.EXTRA_PACKAGE_NAME, packageName)
|
||||
intent.putExtra(Intent.EXTRA_USER, UserHandle.of(userId))
|
||||
privacyLogger.logStartSettingsActivityFromDialog(packageName, userId)
|
||||
if (!keyguardStateController.isUnlocked) {
|
||||
// If we are locked, hide the dialog so the user can unlock
|
||||
dialog?.hide()
|
||||
@@ -159,6 +160,8 @@ class PrivacyDialogController(
|
||||
}
|
||||
PrivacyDialog.PrivacyElement(
|
||||
t,
|
||||
it.packageName,
|
||||
UserHandle.getUserId(it.uid),
|
||||
appName,
|
||||
it.attribution,
|
||||
it.lastAccess,
|
||||
@@ -257,7 +260,7 @@ class PrivacyDialogController(
|
||||
fun makeDialog(
|
||||
context: Context,
|
||||
list: List<PrivacyDialog.PrivacyElement>,
|
||||
starter: (String) -> Unit
|
||||
starter: (String, Int) -> Unit
|
||||
): PrivacyDialog
|
||||
}
|
||||
}
|
||||
@@ -121,11 +121,12 @@ class PrivacyLogger @Inject constructor(
|
||||
})
|
||||
}
|
||||
|
||||
fun logStartSettingsActivityFromDialog(permGroupName: String) {
|
||||
fun logStartSettingsActivityFromDialog(packageName: String, userId: Int) {
|
||||
log(LogLevel.INFO, {
|
||||
str1 = permGroupName
|
||||
str1 = packageName
|
||||
int1 = userId
|
||||
}, {
|
||||
"Start settings activity from dialog for perm group: $str1"
|
||||
"Start settings activity from dialog for packageName=$str1, userId=$int1 "
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -100,12 +100,12 @@ class PrivacyDialogControllerTest : SysuiTestCase() {
|
||||
|
||||
private val dialogProvider = object : PrivacyDialogController.DialogProvider {
|
||||
var list: List<PrivacyDialog.PrivacyElement>? = null
|
||||
var starter: ((String) -> Unit)? = null
|
||||
var starter: ((String, Int) -> Unit)? = null
|
||||
|
||||
override fun makeDialog(
|
||||
context: Context,
|
||||
list: List<PrivacyDialog.PrivacyElement>,
|
||||
starter: (String) -> Unit
|
||||
starter: (String, Int) -> Unit
|
||||
): PrivacyDialog {
|
||||
this.list = list
|
||||
this.starter = starter
|
||||
@@ -210,7 +210,7 @@ class PrivacyDialogControllerTest : SysuiTestCase() {
|
||||
fun testSingleElementInList() {
|
||||
val usage = createMockPermGroupUsage(
|
||||
packageName = TEST_PACKAGE_NAME,
|
||||
uid = generateUidForUser(0),
|
||||
uid = generateUidForUser(USER_ID),
|
||||
permGroupName = PERM_CAMERA,
|
||||
lastAccess = 5L,
|
||||
isActive = true,
|
||||
@@ -224,6 +224,8 @@ class PrivacyDialogControllerTest : SysuiTestCase() {
|
||||
|
||||
val expected = PrivacyDialog.PrivacyElement(
|
||||
type = PrivacyType.TYPE_CAMERA,
|
||||
packageName = TEST_PACKAGE_NAME,
|
||||
userId = USER_ID,
|
||||
applicationName = TEST_PACKAGE_NAME,
|
||||
attribution = TEST_ATTRIBUTION,
|
||||
lastActiveTimestamp = 5L,
|
||||
@@ -459,13 +461,28 @@ class PrivacyDialogControllerTest : SysuiTestCase() {
|
||||
controller.showDialog(context)
|
||||
exhaustExecutors()
|
||||
|
||||
dialogProvider.starter?.invoke(PERM_MICROPHONE)
|
||||
dialogProvider.starter?.invoke(TEST_PACKAGE_NAME, USER_ID)
|
||||
verify(activityStarter)
|
||||
.startActivity(capture(intentCaptor), eq(true), any<ActivityStarter.Callback>())
|
||||
|
||||
assertThat(intentCaptor.value.action).isEqualTo(Intent.ACTION_MANAGE_PERMISSION_APPS)
|
||||
assertThat(intentCaptor.value.getStringExtra(Intent.EXTRA_PERMISSION_GROUP_NAME))
|
||||
.isEqualTo(PERM_MICROPHONE)
|
||||
assertThat(intentCaptor.value.action).isEqualTo(Intent.ACTION_MANAGE_APP_PERMISSIONS)
|
||||
assertThat(intentCaptor.value.getStringExtra(Intent.EXTRA_PACKAGE_NAME))
|
||||
.isEqualTo(TEST_PACKAGE_NAME)
|
||||
assertThat(intentCaptor.value.getParcelableExtra(Intent.EXTRA_USER) as? UserHandle)
|
||||
.isEqualTo(UserHandle.of(USER_ID))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStartActivityCorrectIntent_enterpriseUser() {
|
||||
controller.showDialog(context)
|
||||
exhaustExecutors()
|
||||
|
||||
dialogProvider.starter?.invoke(TEST_PACKAGE_NAME, ENT_USER_ID)
|
||||
verify(activityStarter)
|
||||
.startActivity(capture(intentCaptor), eq(true), any<ActivityStarter.Callback>())
|
||||
|
||||
assertThat(intentCaptor.value.getParcelableExtra(Intent.EXTRA_USER) as? UserHandle)
|
||||
.isEqualTo(UserHandle.of(ENT_USER_ID))
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -473,7 +490,7 @@ class PrivacyDialogControllerTest : SysuiTestCase() {
|
||||
controller.showDialog(context)
|
||||
exhaustExecutors()
|
||||
|
||||
dialogProvider.starter?.invoke(PERM_MICROPHONE)
|
||||
dialogProvider.starter?.invoke(TEST_PACKAGE_NAME, USER_ID)
|
||||
verify(activityStarter).startActivity(any(), eq(true), capture(activityStartedCaptor))
|
||||
|
||||
activityStartedCaptor.value.onActivityStarted(ActivityManager.START_DELIVERED_TO_TOP)
|
||||
@@ -486,7 +503,7 @@ class PrivacyDialogControllerTest : SysuiTestCase() {
|
||||
controller.showDialog(context)
|
||||
exhaustExecutors()
|
||||
|
||||
dialogProvider.starter?.invoke(PERM_MICROPHONE)
|
||||
dialogProvider.starter?.invoke(TEST_PACKAGE_NAME, USER_ID)
|
||||
verify(activityStarter).startActivity(any(), eq(true), capture(activityStartedCaptor))
|
||||
|
||||
activityStartedCaptor.value.onActivityStarted(ActivityManager.START_ABORTED)
|
||||
|
||||
@@ -40,8 +40,13 @@ import org.mockito.MockitoAnnotations
|
||||
@TestableLooper.RunWithLooper(setAsMainLooper = true)
|
||||
class PrivacyDialogTest : SysuiTestCase() {
|
||||
|
||||
companion object {
|
||||
private const val TEST_PACKAGE_NAME = "test_pkg"
|
||||
private const val TEST_USER_ID = 0
|
||||
}
|
||||
|
||||
@Mock
|
||||
private lateinit var starter: (String) -> Unit
|
||||
private lateinit var starter: (String, Int) -> Unit
|
||||
|
||||
private lateinit var dialog: PrivacyDialog
|
||||
|
||||
@@ -58,10 +63,12 @@ class PrivacyDialogTest : SysuiTestCase() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStarterCalledWithCorrectPermGroupName() {
|
||||
fun testStarterCalledWithCorrectParams() {
|
||||
val list = listOf(
|
||||
PrivacyDialog.PrivacyElement(
|
||||
PrivacyType.TYPE_MICROPHONE,
|
||||
TEST_PACKAGE_NAME,
|
||||
TEST_USER_ID,
|
||||
"App",
|
||||
null,
|
||||
0L,
|
||||
@@ -73,7 +80,7 @@ class PrivacyDialogTest : SysuiTestCase() {
|
||||
dialog = PrivacyDialog(context, list, starter)
|
||||
dialog.show()
|
||||
dialog.requireViewById<View>(R.id.privacy_item).callOnClick()
|
||||
verify(starter).invoke(PrivacyType.TYPE_MICROPHONE.permGroupName)
|
||||
verify(starter).invoke(TEST_PACKAGE_NAME, TEST_USER_ID)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -104,6 +111,8 @@ class PrivacyDialogTest : SysuiTestCase() {
|
||||
val list = listOf(
|
||||
PrivacyDialog.PrivacyElement(
|
||||
PrivacyType.TYPE_CAMERA,
|
||||
TEST_PACKAGE_NAME,
|
||||
TEST_USER_ID,
|
||||
"App",
|
||||
null,
|
||||
0L,
|
||||
@@ -113,6 +122,8 @@ class PrivacyDialogTest : SysuiTestCase() {
|
||||
),
|
||||
PrivacyDialog.PrivacyElement(
|
||||
PrivacyType.TYPE_MICROPHONE,
|
||||
TEST_PACKAGE_NAME,
|
||||
TEST_USER_ID,
|
||||
"App",
|
||||
null,
|
||||
0L,
|
||||
@@ -130,6 +141,8 @@ class PrivacyDialogTest : SysuiTestCase() {
|
||||
fun testUsingText() {
|
||||
val element = PrivacyDialog.PrivacyElement(
|
||||
PrivacyType.TYPE_CAMERA,
|
||||
TEST_PACKAGE_NAME,
|
||||
TEST_USER_ID,
|
||||
"App",
|
||||
null,
|
||||
0L,
|
||||
@@ -154,6 +167,8 @@ class PrivacyDialogTest : SysuiTestCase() {
|
||||
fun testRecentText() {
|
||||
val element = PrivacyDialog.PrivacyElement(
|
||||
PrivacyType.TYPE_MICROPHONE,
|
||||
TEST_PACKAGE_NAME,
|
||||
TEST_USER_ID,
|
||||
"App",
|
||||
null,
|
||||
0L,
|
||||
@@ -178,6 +193,8 @@ class PrivacyDialogTest : SysuiTestCase() {
|
||||
fun testEnterprise() {
|
||||
val element = PrivacyDialog.PrivacyElement(
|
||||
PrivacyType.TYPE_MICROPHONE,
|
||||
TEST_PACKAGE_NAME,
|
||||
TEST_USER_ID,
|
||||
"App",
|
||||
null,
|
||||
0L,
|
||||
@@ -198,6 +215,8 @@ class PrivacyDialogTest : SysuiTestCase() {
|
||||
fun testPhoneCall() {
|
||||
val element = PrivacyDialog.PrivacyElement(
|
||||
PrivacyType.TYPE_MICROPHONE,
|
||||
TEST_PACKAGE_NAME,
|
||||
TEST_USER_ID,
|
||||
"App",
|
||||
null,
|
||||
0L,
|
||||
@@ -218,6 +237,8 @@ class PrivacyDialogTest : SysuiTestCase() {
|
||||
fun testAttribution() {
|
||||
val element = PrivacyDialog.PrivacyElement(
|
||||
PrivacyType.TYPE_MICROPHONE,
|
||||
TEST_PACKAGE_NAME,
|
||||
TEST_USER_ID,
|
||||
"App",
|
||||
"attribution",
|
||||
0L,
|
||||
|
||||
Reference in New Issue
Block a user