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 '../modal'; 18import {FORCE_RESET_MESSAGE} from './recording_ui_utils'; 19 20export function couldNotClaimInterface( 21 onReset: () => Promise<void>, onCancel: () => void) { 22 let hasPressedAButton = false; 23 showModal({ 24 title: 'Could not claim the USB interface', 25 content: m( 26 'div', 27 m('text', 28 'This can happen if you have the Android Debug Bridge ' + 29 '(adb) running on your workstation or any other tool which is ' + 30 'taking exclusive access of the USB interface.'), 31 m('br'), 32 m('br'), 33 m('text.small-font', 34 'Resetting will cause the ADB server to disconnect and ' + 35 'will try to reassign the interface to the current browser.'), 36 ), 37 buttons: [ 38 { 39 text: FORCE_RESET_MESSAGE, 40 primary: true, 41 id: 'force_USB_interface', 42 action: () => { 43 hasPressedAButton = true; 44 onReset(); 45 }, 46 }, 47 { 48 text: 'Cancel', 49 primary: false, 50 id: 'cancel_USB_interface', 51 action: () => { 52 hasPressedAButton = true; 53 onCancel(); 54 }, 55 }, 56 ], 57 }).then(() => { 58 // If the user has clicked away from the modal, we interpret that as a 59 // 'Cancel'. 60 if (!hasPressedAButton) { 61 onCancel(); 62 } 63 }); 64} 65