1// Copyright (C) 2022 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15import m from 'mithril'; 16 17import {showModal} from '../../widgets/modal'; 18 19import {FORCE_RESET_MESSAGE} from './recording_ui_utils'; 20 21export function couldNotClaimInterface( 22 onReset: () => Promise<void>, 23 onCancel: () => void, 24) { 25 let hasPressedAButton = false; 26 showModal({ 27 title: 'Could not claim the USB interface', 28 content: m( 29 'div', 30 m( 31 'text', 32 'This can happen if you have the Android Debug Bridge ' + 33 '(adb) running on your workstation or any other tool which is ' + 34 'taking exclusive access of the USB interface.', 35 ), 36 m('br'), 37 m('br'), 38 m( 39 'text.small-font', 40 'Resetting will cause the ADB server to disconnect and ' + 41 'will try to reassign the interface to the current browser.', 42 ), 43 ), 44 buttons: [ 45 { 46 text: FORCE_RESET_MESSAGE, 47 primary: true, 48 id: 'force_USB_interface', 49 action: () => { 50 hasPressedAButton = true; 51 onReset(); 52 }, 53 }, 54 { 55 text: 'Cancel', 56 primary: false, 57 id: 'cancel_USB_interface', 58 action: () => { 59 hasPressedAButton = true; 60 onCancel(); 61 }, 62 }, 63 ], 64 }).then(() => { 65 // If the user has clicked away from the modal, we interpret that as a 66 // 'Cancel'. 67 if (!hasPressedAButton) { 68 onCancel(); 69 } 70 }); 71} 72