1 /* 2 * Copyright (C) 2025 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 #pragma once 18 19 #include <memory> 20 #include <string> 21 #include <unordered_set> 22 23 #include "transport.h" 24 25 // If an adb server uses ADB_LIBUSB_START_DETACHED, all devices started detached. But we need a way 26 // to tell if this setting should be overridden when a device is attached and then intentionally 27 // disconnected and then reconnected (which can happen via `adb reboot` or `adb root/unroot`). 28 class AttachedDevices { 29 public: 30 void RegisterAttach(const std::string& serial); 31 32 void RegisterDetach(const std::string& serial); 33 34 bool ShouldStartDetached(const Connection& connection); 35 36 private: 37 bool IsAttached(const std::string& serial); 38 39 std::mutex attached_devices_mutex_; 40 41 // Stores serial numbers of all devices which have been attached. 42 // Entries are cleared when a device is detached. 43 std::unordered_set<std::string> attached_devices_ GUARDED_BY(attached_devices_mutex_); 44 }; 45 46 extern AttachedDevices attached_devices;