• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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;
18 
19 import android.content.res.Resources;
20 import android.os.Bundle;
21 
22 import javax.inject.Inject;
23 
24 /**
25  * Dialog shown when a package requests access to a USB device or accessory.
26  */
27 public class UsbPermissionActivity extends UsbDialogActivity {
28 
29     private boolean mPermissionGranted = false;
30     private UsbAudioWarningDialogMessage mUsbPermissionMessageHandler;
31 
32     @Inject
UsbPermissionActivity(UsbAudioWarningDialogMessage usbAudioWarningDialogMessage)33     public UsbPermissionActivity(UsbAudioWarningDialogMessage usbAudioWarningDialogMessage) {
34         mUsbPermissionMessageHandler = usbAudioWarningDialogMessage;
35     }
36 
37     @Override
onCreate(Bundle icicle)38     public void onCreate(Bundle icicle) {
39         super.onCreate(icicle);
40         mUsbPermissionMessageHandler.init(UsbAudioWarningDialogMessage.TYPE_PERMISSION,
41                 mDialogHelper);
42     }
43 
44     @Override
onResume()45     protected void onResume() {
46         super.onResume();
47         final boolean useRecordWarning = mDialogHelper.isUsbDevice()
48                 && (mDialogHelper.deviceHasAudioCapture()
49                 && !mDialogHelper.packageHasAudioRecordingPermission());
50 
51         final int titleId = mUsbPermissionMessageHandler.getPromptTitleId();
52         final String title = getString(titleId, mDialogHelper.getAppName(),
53                 mDialogHelper.getDeviceDescription());
54         final int messageId = mUsbPermissionMessageHandler.getMessageId();
55         String message = (messageId != Resources.ID_NULL)
56                 ? getString(messageId, mDialogHelper.getAppName(),
57                 mDialogHelper.getDeviceDescription()) : null;
58         setAlertParams(title, message);
59 
60         // Only show the "always use" checkbox if there is no USB/Record warning
61         if (!useRecordWarning && mDialogHelper.canBeDefault()) {
62             addAlwaysUseCheckbox();
63         }
64         setupAlert();
65     }
66 
67     @Override
onPause()68     protected void onPause() {
69         if (isFinishing()) {
70             mDialogHelper.sendPermissionDialogResponse(mPermissionGranted);
71         }
72         super.onPause();
73     }
74 
75     @Override
onConfirm()76     void onConfirm() {
77         mDialogHelper.grantUidAccessPermission();
78         if (isAlwaysUseChecked()) {
79             mDialogHelper.setDefaultPackage();
80         }
81         mPermissionGranted = true;
82         finish();
83     }
84 }
85