1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.privacy 18 19 import android.app.ActivityManager 20 import android.content.Context 21 import android.content.Intent 22 import android.content.pm.ApplicationInfo 23 import android.content.pm.PackageManager 24 import android.content.pm.UserInfo 25 import android.os.Process.SYSTEM_UID 26 import android.os.UserHandle 27 import android.permission.PermGroupUsage 28 import android.permission.PermissionManager 29 import android.testing.AndroidTestingRunner 30 import androidx.test.filters.SmallTest 31 import com.android.internal.logging.UiEventLogger 32 import com.android.systemui.SysuiTestCase 33 import com.android.systemui.appops.AppOpsController 34 import com.android.systemui.plugins.ActivityStarter 35 import com.android.systemui.privacy.logging.PrivacyLogger 36 import com.android.systemui.settings.UserTracker 37 import com.android.systemui.statusbar.policy.KeyguardStateController 38 import com.android.systemui.util.concurrency.FakeExecutor 39 import com.android.systemui.util.mockito.capture 40 import com.android.systemui.util.mockito.eq 41 import com.android.systemui.util.time.FakeSystemClock 42 import com.google.common.truth.Truth.assertThat 43 import org.junit.After 44 import org.junit.Before 45 import org.junit.Test 46 import org.junit.runner.RunWith 47 import org.mockito.ArgumentCaptor 48 import org.mockito.ArgumentMatchers.any 49 import org.mockito.ArgumentMatchers.anyBoolean 50 import org.mockito.ArgumentMatchers.anyInt 51 import org.mockito.ArgumentMatchers.anyString 52 import org.mockito.Captor 53 import org.mockito.Mock 54 import org.mockito.Mockito.`when` 55 import org.mockito.Mockito.atLeastOnce 56 import org.mockito.Mockito.mock 57 import org.mockito.Mockito.never 58 import org.mockito.Mockito.times 59 import org.mockito.Mockito.verify 60 import org.mockito.MockitoAnnotations 61 62 @SmallTest 63 @RunWith(AndroidTestingRunner::class) 64 class PrivacyDialogControllerTest : SysuiTestCase() { 65 66 companion object { 67 private const val USER_ID = 0 68 private const val ENT_USER_ID = 10 69 70 private const val TEST_PACKAGE_NAME = "test package name" 71 private const val TEST_ATTRIBUTION = "test attribution" 72 73 private const val PERM_CAMERA = android.Manifest.permission_group.CAMERA 74 private const val PERM_MICROPHONE = android.Manifest.permission_group.MICROPHONE 75 private const val PERM_LOCATION = android.Manifest.permission_group.LOCATION 76 } 77 78 @Mock 79 private lateinit var dialog: PrivacyDialog 80 @Mock 81 private lateinit var permissionManager: PermissionManager 82 @Mock 83 private lateinit var packageManager: PackageManager 84 @Mock 85 private lateinit var privacyItemController: PrivacyItemController 86 @Mock 87 private lateinit var userTracker: UserTracker 88 @Mock 89 private lateinit var activityStarter: ActivityStarter 90 @Mock 91 private lateinit var privacyLogger: PrivacyLogger 92 @Mock 93 private lateinit var keyguardStateController: KeyguardStateController 94 @Mock 95 private lateinit var appOpsController: AppOpsController 96 @Captor 97 private lateinit var dialogDismissedCaptor: ArgumentCaptor<PrivacyDialog.OnDialogDismissed> 98 @Captor 99 private lateinit var activityStartedCaptor: ArgumentCaptor<ActivityStarter.Callback> 100 @Captor 101 private lateinit var intentCaptor: ArgumentCaptor<Intent> 102 @Mock 103 private lateinit var uiEventLogger: UiEventLogger 104 105 private val backgroundExecutor = FakeExecutor(FakeSystemClock()) 106 private val uiExecutor = FakeExecutor(FakeSystemClock()) 107 private lateinit var controller: PrivacyDialogController 108 private var nextUid: Int = 0 109 110 private val dialogProvider = object : PrivacyDialogController.DialogProvider { 111 var list: List<PrivacyDialog.PrivacyElement>? = null 112 var starter: ((String, Int) -> Unit)? = null 113 114 override fun makeDialog( 115 context: Context, 116 list: List<PrivacyDialog.PrivacyElement>, 117 starter: (String, Int) -> Unit 118 ): PrivacyDialog { 119 this.list = list 120 this.starter = starter 121 return dialog 122 } 123 } 124 125 @Before 126 fun setUp() { 127 MockitoAnnotations.initMocks(this) 128 129 nextUid = 0 130 131 setUpDefaultMockResponses() 132 133 controller = PrivacyDialogController( 134 permissionManager, 135 packageManager, 136 privacyItemController, 137 userTracker, 138 activityStarter, 139 backgroundExecutor, 140 uiExecutor, 141 privacyLogger, 142 keyguardStateController, 143 appOpsController, 144 uiEventLogger, 145 dialogProvider 146 ) 147 } 148 149 @After 150 fun tearDown() { 151 FakeExecutor.exhaustExecutors(uiExecutor, backgroundExecutor) 152 dialogProvider.list = null 153 dialogProvider.starter = null 154 } 155 156 @Test 157 fun testMicMutedParameter() { 158 `when`(appOpsController.isMicMuted).thenReturn(true) 159 controller.showDialog(context) 160 backgroundExecutor.runAllReady() 161 162 verify(permissionManager).getIndicatorAppOpUsageData(true) 163 } 164 165 @Test 166 fun testPermissionManagerOnlyCalledInBackgroundThread() { 167 controller.showDialog(context) 168 verify(permissionManager, never()).getIndicatorAppOpUsageData(anyBoolean()) 169 backgroundExecutor.runAllReady() 170 verify(permissionManager).getIndicatorAppOpUsageData(anyBoolean()) 171 } 172 173 @Test 174 fun testPackageManagerOnlyCalledInBackgroundThread() { 175 val usage = createMockPermGroupUsage() 176 `when`(usage.isPhoneCall).thenReturn(false) 177 `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn(listOf(usage)) 178 179 controller.showDialog(context) 180 verify(packageManager, never()).getApplicationInfoAsUser(anyString(), anyInt(), anyInt()) 181 backgroundExecutor.runAllReady() 182 verify(packageManager, atLeastOnce()) 183 .getApplicationInfoAsUser(anyString(), anyInt(), anyInt()) 184 } 185 186 @Test 187 fun testShowDialogShowsDialog() { 188 val usage = createMockPermGroupUsage() 189 `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn(listOf(usage)) 190 191 controller.showDialog(context) 192 exhaustExecutors() 193 194 verify(dialog).show() 195 } 196 197 @Test 198 fun testDontShowEmptyDialog() { 199 controller.showDialog(context) 200 exhaustExecutors() 201 202 verify(dialog, never()).show() 203 } 204 205 @Test 206 fun testHideDialogDismissesDialogIfShown() { 207 val usage = createMockPermGroupUsage() 208 `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn(listOf(usage)) 209 controller.showDialog(context) 210 exhaustExecutors() 211 212 controller.dismissDialog() 213 verify(dialog).dismiss() 214 } 215 216 @Test 217 fun testHideDialogNoopIfNotShown() { 218 controller.dismissDialog() 219 verify(dialog, never()).dismiss() 220 } 221 222 @Test 223 fun testHideDialogNoopAfterDismissed() { 224 val usage = createMockPermGroupUsage() 225 `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn(listOf(usage)) 226 controller.showDialog(context) 227 exhaustExecutors() 228 229 verify(dialog).addOnDismissListener(capture(dialogDismissedCaptor)) 230 231 dialogDismissedCaptor.value.onDialogDismissed() 232 controller.dismissDialog() 233 verify(dialog, never()).dismiss() 234 } 235 236 @Test 237 fun testShowForAllUsers() { 238 val usage = createMockPermGroupUsage() 239 `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn(listOf(usage)) 240 controller.showDialog(context) 241 242 exhaustExecutors() 243 verify(dialog).setShowForAllUsers(true) 244 } 245 246 @Test 247 fun testSingleElementInList() { 248 val usage = createMockPermGroupUsage( 249 packageName = TEST_PACKAGE_NAME, 250 uid = generateUidForUser(USER_ID), 251 permGroupName = PERM_CAMERA, 252 lastAccess = 5L, 253 isActive = true, 254 isPhoneCall = false, 255 attribution = TEST_ATTRIBUTION 256 ) 257 `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn(listOf(usage)) 258 259 controller.showDialog(context) 260 exhaustExecutors() 261 262 val expected = PrivacyDialog.PrivacyElement( 263 type = PrivacyType.TYPE_CAMERA, 264 packageName = TEST_PACKAGE_NAME, 265 userId = USER_ID, 266 applicationName = TEST_PACKAGE_NAME, 267 attribution = TEST_ATTRIBUTION, 268 lastActiveTimestamp = 5L, 269 active = true, 270 phoneCall = false, 271 enterprise = false 272 ) 273 assertThat(dialogProvider.list).containsExactly(expected) 274 } 275 276 @Test 277 fun testTwoElementsDifferentType_sorted() { 278 val usage_camera = createMockPermGroupUsage( 279 packageName = "${TEST_PACKAGE_NAME}_camera", 280 permGroupName = PERM_CAMERA 281 ) 282 val usage_microphone = createMockPermGroupUsage( 283 packageName = "${TEST_PACKAGE_NAME}_microphone", 284 permGroupName = PERM_MICROPHONE 285 ) 286 `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn( 287 listOf(usage_microphone, usage_camera) 288 ) 289 290 controller.showDialog(context) 291 exhaustExecutors() 292 293 dialogProvider.list?.let { list -> 294 assertThat(list).hasSize(2) 295 assertThat(list.get(0).type.compareTo(list.get(1).type)).isLessThan(0) 296 } 297 } 298 299 @Test 300 fun testTwoElementsSameType_oneActive() { 301 val usage_active = createMockPermGroupUsage( 302 packageName = "${TEST_PACKAGE_NAME}_active", 303 isActive = true 304 ) 305 val usage_recent = createMockPermGroupUsage( 306 packageName = "${TEST_PACKAGE_NAME}_recent", 307 isActive = false 308 ) 309 `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn( 310 listOf(usage_recent, usage_active) 311 ) 312 313 controller.showDialog(context) 314 exhaustExecutors() 315 316 assertThat(dialogProvider.list).hasSize(1) 317 assertThat(dialogProvider.list?.get(0)?.active).isTrue() 318 } 319 320 @Test 321 fun testTwoElementsSameType_twoActive() { 322 val usage_active = createMockPermGroupUsage( 323 packageName = "${TEST_PACKAGE_NAME}_active", 324 isActive = true, 325 lastAccess = 0L 326 ) 327 val usage_active_moreRecent = createMockPermGroupUsage( 328 packageName = "${TEST_PACKAGE_NAME}_active_recent", 329 isActive = true, 330 lastAccess = 1L 331 ) 332 `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn( 333 listOf(usage_active, usage_active_moreRecent) 334 ) 335 controller.showDialog(context) 336 exhaustExecutors() 337 assertThat(dialogProvider.list).hasSize(2) 338 assertThat(dialogProvider.list?.get(0)?.lastActiveTimestamp).isEqualTo(1L) 339 assertThat(dialogProvider.list?.get(1)?.lastActiveTimestamp).isEqualTo(0L) 340 } 341 342 @Test 343 fun testManyElementsSameType_bothRecent() { 344 val usage_recent = createMockPermGroupUsage( 345 packageName = "${TEST_PACKAGE_NAME}_recent", 346 isActive = false, 347 lastAccess = 0L 348 ) 349 val usage_moreRecent = createMockPermGroupUsage( 350 packageName = "${TEST_PACKAGE_NAME}_moreRecent", 351 isActive = false, 352 lastAccess = 1L 353 ) 354 val usage_mostRecent = createMockPermGroupUsage( 355 packageName = "${TEST_PACKAGE_NAME}_mostRecent", 356 isActive = false, 357 lastAccess = 2L 358 ) 359 `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn( 360 listOf(usage_recent, usage_mostRecent, usage_moreRecent) 361 ) 362 363 controller.showDialog(context) 364 exhaustExecutors() 365 366 assertThat(dialogProvider.list).hasSize(1) 367 assertThat(dialogProvider.list?.get(0)?.lastActiveTimestamp).isEqualTo(2L) 368 } 369 370 @Test 371 fun testMicAndCameraDisabled() { 372 val usage_camera = createMockPermGroupUsage( 373 permGroupName = PERM_CAMERA 374 ) 375 val usage_microphone = createMockPermGroupUsage( 376 permGroupName = PERM_MICROPHONE 377 ) 378 val usage_location = createMockPermGroupUsage( 379 permGroupName = PERM_LOCATION 380 ) 381 382 `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn( 383 listOf(usage_camera, usage_location, usage_microphone) 384 ) 385 `when`(privacyItemController.micCameraAvailable).thenReturn(false) 386 387 controller.showDialog(context) 388 exhaustExecutors() 389 390 assertThat(dialogProvider.list).hasSize(1) 391 assertThat(dialogProvider.list?.get(0)?.type).isEqualTo(PrivacyType.TYPE_LOCATION) 392 } 393 394 @Test 395 fun testLocationDisabled() { 396 val usage_camera = createMockPermGroupUsage( 397 permGroupName = PERM_CAMERA 398 ) 399 val usage_microphone = createMockPermGroupUsage( 400 permGroupName = PERM_MICROPHONE 401 ) 402 val usage_location = createMockPermGroupUsage( 403 permGroupName = PERM_LOCATION 404 ) 405 406 `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn( 407 listOf(usage_camera, usage_location, usage_microphone) 408 ) 409 `when`(privacyItemController.locationAvailable).thenReturn(false) 410 411 controller.showDialog(context) 412 exhaustExecutors() 413 414 assertThat(dialogProvider.list).hasSize(2) 415 dialogProvider.list?.forEach { 416 assertThat(it.type).isNotEqualTo(PrivacyType.TYPE_LOCATION) 417 } 418 } 419 420 @Test 421 fun testAllIndicatorsAvailable() { 422 val usage_camera = createMockPermGroupUsage( 423 permGroupName = PERM_CAMERA 424 ) 425 val usage_microphone = createMockPermGroupUsage( 426 permGroupName = PERM_MICROPHONE 427 ) 428 val usage_location = createMockPermGroupUsage( 429 permGroupName = PERM_LOCATION 430 ) 431 432 `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn( 433 listOf(usage_camera, usage_location, usage_microphone) 434 ) 435 `when`(privacyItemController.micCameraAvailable).thenReturn(true) 436 `when`(privacyItemController.locationAvailable).thenReturn(true) 437 438 controller.showDialog(context) 439 exhaustExecutors() 440 441 assertThat(dialogProvider.list).hasSize(3) 442 } 443 444 @Test 445 fun testNoIndicatorsAvailable() { 446 val usage_camera = createMockPermGroupUsage( 447 permGroupName = PERM_CAMERA 448 ) 449 val usage_microphone = createMockPermGroupUsage( 450 permGroupName = PERM_MICROPHONE 451 ) 452 val usage_location = createMockPermGroupUsage( 453 permGroupName = PERM_LOCATION 454 ) 455 456 `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn( 457 listOf(usage_camera, usage_location, usage_microphone) 458 ) 459 `when`(privacyItemController.micCameraAvailable).thenReturn(false) 460 `when`(privacyItemController.locationAvailable).thenReturn(false) 461 462 controller.showDialog(context) 463 exhaustExecutors() 464 465 verify(dialog, never()).show() 466 } 467 468 @Test 469 fun testEnterpriseUser() { 470 val usage_enterprise = createMockPermGroupUsage( 471 uid = generateUidForUser(ENT_USER_ID) 472 ) 473 `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())) 474 .thenReturn(listOf(usage_enterprise)) 475 476 controller.showDialog(context) 477 exhaustExecutors() 478 479 assertThat(dialogProvider.list?.single()?.enterprise).isTrue() 480 } 481 482 @Test 483 fun testNotCurrentUser() { 484 val usage_other = createMockPermGroupUsage( 485 uid = generateUidForUser(ENT_USER_ID + 1) 486 ) 487 `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())) 488 .thenReturn(listOf(usage_other)) 489 490 controller.showDialog(context) 491 exhaustExecutors() 492 493 verify(dialog, never()).show() 494 } 495 496 @Test 497 fun testStartActivityCorrectIntent() { 498 val usage = createMockPermGroupUsage() 499 `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn(listOf(usage)) 500 controller.showDialog(context) 501 exhaustExecutors() 502 503 dialogProvider.starter?.invoke(TEST_PACKAGE_NAME, USER_ID) 504 verify(activityStarter) 505 .startActivity(capture(intentCaptor), eq(true), any<ActivityStarter.Callback>()) 506 507 assertThat(intentCaptor.value.action).isEqualTo(Intent.ACTION_MANAGE_APP_PERMISSIONS) 508 assertThat(intentCaptor.value.getStringExtra(Intent.EXTRA_PACKAGE_NAME)) 509 .isEqualTo(TEST_PACKAGE_NAME) 510 assertThat(intentCaptor.value.getParcelableExtra(Intent.EXTRA_USER) as? UserHandle) 511 .isEqualTo(UserHandle.of(USER_ID)) 512 } 513 514 @Test 515 fun testStartActivityCorrectIntent_enterpriseUser() { 516 val usage = createMockPermGroupUsage() 517 `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn(listOf(usage)) 518 controller.showDialog(context) 519 exhaustExecutors() 520 521 dialogProvider.starter?.invoke(TEST_PACKAGE_NAME, ENT_USER_ID) 522 verify(activityStarter) 523 .startActivity(capture(intentCaptor), eq(true), any<ActivityStarter.Callback>()) 524 525 assertThat(intentCaptor.value.getParcelableExtra(Intent.EXTRA_USER) as? UserHandle) 526 .isEqualTo(UserHandle.of(ENT_USER_ID)) 527 } 528 529 @Test 530 fun testStartActivitySuccess() { 531 val usage = createMockPermGroupUsage() 532 `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn(listOf(usage)) 533 controller.showDialog(context) 534 exhaustExecutors() 535 536 dialogProvider.starter?.invoke(TEST_PACKAGE_NAME, USER_ID) 537 verify(activityStarter).startActivity(any(), eq(true), capture(activityStartedCaptor)) 538 539 activityStartedCaptor.value.onActivityStarted(ActivityManager.START_DELIVERED_TO_TOP) 540 541 verify(dialog).dismiss() 542 } 543 544 @Test 545 fun testStartActivityFailure() { 546 val usage = createMockPermGroupUsage() 547 `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn(listOf(usage)) 548 controller.showDialog(context) 549 exhaustExecutors() 550 551 dialogProvider.starter?.invoke(TEST_PACKAGE_NAME, USER_ID) 552 verify(activityStarter).startActivity(any(), eq(true), capture(activityStartedCaptor)) 553 554 activityStartedCaptor.value.onActivityStarted(ActivityManager.START_ABORTED) 555 556 verify(dialog, never()).dismiss() 557 } 558 559 @Test 560 fun testCallOnSecondaryUser() { 561 // Calls happen in 562 val usage = createMockPermGroupUsage(uid = SYSTEM_UID, isPhoneCall = true) 563 `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn(listOf(usage)) 564 `when`(userTracker.userProfiles).thenReturn(listOf( 565 UserInfo(ENT_USER_ID, "", 0) 566 )) 567 568 controller.showDialog(context) 569 exhaustExecutors() 570 571 verify(dialog).show() 572 } 573 574 @Test 575 fun testStartActivityLogs() { 576 val usage = createMockPermGroupUsage() 577 `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn(listOf(usage)) 578 controller.showDialog(context) 579 exhaustExecutors() 580 581 dialogProvider.starter?.invoke(TEST_PACKAGE_NAME, USER_ID) 582 verify(uiEventLogger).log(PrivacyDialogEvent.PRIVACY_DIALOG_ITEM_CLICKED_TO_APP_SETTINGS, 583 USER_ID, TEST_PACKAGE_NAME) 584 } 585 586 @Test 587 fun testDismissedDialogLogs() { 588 val usage = createMockPermGroupUsage() 589 `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn(listOf(usage)) 590 controller.showDialog(context) 591 exhaustExecutors() 592 593 verify(dialog).addOnDismissListener(capture(dialogDismissedCaptor)) 594 595 dialogDismissedCaptor.value.onDialogDismissed() 596 597 controller.dismissDialog() 598 599 verify(uiEventLogger, times(1)).log(PrivacyDialogEvent.PRIVACY_DIALOG_DISMISSED) 600 } 601 602 private fun exhaustExecutors() { 603 FakeExecutor.exhaustExecutors(backgroundExecutor, uiExecutor) 604 } 605 606 private fun setUpDefaultMockResponses() { 607 `when`(permissionManager.getIndicatorAppOpUsageData(anyBoolean())).thenReturn(emptyList()) 608 `when`(appOpsController.isMicMuted).thenReturn(false) 609 610 `when`(packageManager.getApplicationInfoAsUser(anyString(), anyInt(), anyInt())) 611 .thenAnswer { 612 FakeApplicationInfo(it.getArgument(0)) 613 } 614 615 `when`(privacyItemController.locationAvailable).thenReturn(true) 616 `when`(privacyItemController.micCameraAvailable).thenReturn(true) 617 618 `when`(userTracker.userProfiles).thenReturn(listOf( 619 UserInfo(USER_ID, "", 0), 620 UserInfo(ENT_USER_ID, "", UserInfo.FLAG_MANAGED_PROFILE) 621 )) 622 623 `when`(keyguardStateController.isUnlocked).thenReturn(true) 624 } 625 626 private class FakeApplicationInfo(val label: CharSequence) : ApplicationInfo() { 627 override fun loadLabel(pm: PackageManager): CharSequence { 628 return label 629 } 630 } 631 632 private fun generateUidForUser(user: Int): Int { 633 return user * UserHandle.PER_USER_RANGE + nextUid++ 634 } 635 636 private fun createMockPermGroupUsage( 637 packageName: String = TEST_PACKAGE_NAME, 638 uid: Int = generateUidForUser(USER_ID), 639 permGroupName: String = PERM_CAMERA, 640 lastAccess: Long = 0L, 641 isActive: Boolean = false, 642 isPhoneCall: Boolean = false, 643 attribution: CharSequence? = null 644 ): PermGroupUsage { 645 val usage = mock(PermGroupUsage::class.java) 646 `when`(usage.packageName).thenReturn(packageName) 647 `when`(usage.uid).thenReturn(uid) 648 `when`(usage.permGroupName).thenReturn(permGroupName) 649 `when`(usage.lastAccess).thenReturn(lastAccess) 650 `when`(usage.isActive).thenReturn(isActive) 651 `when`(usage.isPhoneCall).thenReturn(isPhoneCall) 652 `when`(usage.attribution).thenReturn(attribution) 653 654 return usage 655 } 656 }