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.usb.tv;
18 
19 import com.android.systemui.R;
20 
21 /**
22  * Dialog shown when a package requests access to a USB device or accessory on TVs.
23  */
24 public class TvUsbPermissionActivity extends TvUsbDialogActivity {
25     private static final String TAG = TvUsbPermissionActivity.class.getSimpleName();
26 
27     private boolean mPermissionGranted = false;
28 
29     @Override
onResume()30     public void onResume() {
31         super.onResume();
32         final int strId;
33         if (mDialogHelper.isUsbDevice()) {
34             boolean useRecordWarning = mDialogHelper.deviceHasAudioCapture()
35                     && !mDialogHelper.packageHasAudioRecordingPermission();
36             strId = useRecordWarning
37                     ? R.string.usb_device_permission_prompt_warn
38                     : R.string.usb_device_permission_prompt;
39         } else {
40             // UsbAccessory case
41             strId = R.string.usb_accessory_permission_prompt;
42         }
43         CharSequence text = getString(strId, mDialogHelper.getAppName(),
44                 mDialogHelper.getDeviceDescription());
45         initUI(mDialogHelper.getAppName(), text);
46     }
47 
48     @Override
onPause()49     protected void onPause() {
50         if (isFinishing()) {
51             mDialogHelper.sendPermissionDialogResponse(mPermissionGranted);
52         }
53         super.onPause();
54     }
55 
56     @Override
onConfirm()57     void onConfirm() {
58         mDialogHelper.grantUidAccessPermission();
59         mPermissionGranted = true;
60         finish();
61     }
62 }
63