1 /* 2 * Copyright (C) 2023 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 <sys/types.h> 20 21 #include "common/libs/utils/result.h" 22 #include "common/libs/utils/users.h" 23 #include "host/commands/cvd/selector/instance_database.h" 24 #include "host/commands/cvd/selector/selector_common_parser.h" 25 #include "host/commands/cvd/types.h" 26 27 namespace cuttlefish { 28 namespace selector { 29 30 class InstanceSelector { 31 public: 32 static Result<InstanceSelector> GetSelector( 33 const cvd_common::Args& selector_args, const Queries& extra_queries, 34 const cvd_common::Envs& envs, const uid_t uid); 35 /* 36 * If default, try running single instance group. If multiple, try to find 37 * HOME == SystemWideUserHome. If not exists, give up. 38 * 39 * If group given, find group, and check if all instance names are included 40 * 41 * If group not given, not yet supported. Will be in next CLs 42 */ 43 Result<LocalInstance::Copy> FindInstance( 44 const InstanceDatabase& instance_database); 45 46 private: InstanceSelector(const uid_t uid,const Queries & queries)47 InstanceSelector(const uid_t uid, const Queries& queries) 48 : client_uid_{uid}, queries_(queries) {} 49 static bool IsHomeOverridden(const SelectorCommonParser& common_parser); 50 51 Result<LocalInstance::Copy> FindDefaultInstance( 52 const InstanceDatabase& instance_database); 53 bool HasCuttlefishInstance() const; 54 55 const uid_t client_uid_; 56 const Queries queries_; 57 }; 58 59 } // namespace selector 60 } // namespace cuttlefish 61