1 /*
2  * Copyright (C) 2023 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 android.permissionmultidevice.cts.accessremotedevicecamera
18 
19 import android.Manifest
20 import android.app.Activity
21 import android.content.Context
22 import android.content.Intent
23 import android.content.pm.PackageManager
24 import android.os.Bundle
25 import android.os.RemoteCallback
26 import android.permissionmultidevice.cts.TestConstants
27 
28 class RequestPermissionActivity : Activity() {
29 
onCreatenull30     override fun onCreate(savedInstanceState: Bundle?) {
31         super.onCreate(savedInstanceState)
32 
33         val deviceId =
34             intent.getIntExtra(
35                 PackageManager.EXTRA_REQUEST_PERMISSIONS_DEVICE_ID,
36                 Context.DEVICE_ID_DEFAULT
37             )
38 
39         requestPermissions(DEVICE_AWARE_PERMISSIONS, 1001, deviceId)
40     }
41 
onRequestPermissionsResultnull42     override fun onRequestPermissionsResult(
43         requestCode: Int,
44         permissions: Array<out String>,
45         grantResults: IntArray,
46         deviceId: Int
47     ) {
48         val resultReceiver =
49             intent.getParcelableExtra(Intent.EXTRA_RESULT_RECEIVER, RemoteCallback::class.java)
50         val result =
51             Bundle().apply {
52                 putStringArray(TestConstants.PERMISSION_RESULT_KEY_PERMISSIONS, permissions)
53                 putIntArray(TestConstants.PERMISSION_RESULT_KEY_GRANT_RESULTS, grantResults)
54                 putInt(TestConstants.PERMISSION_RESULT_KEY_DEVICE_ID, deviceId)
55             }
56 
57         resultReceiver?.sendResult(result)
58         finish()
59     }
60 
61     companion object {
62         private val DEVICE_AWARE_PERMISSIONS = arrayOf(Manifest.permission.CAMERA)
63     }
64 }
65