• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/instance_database_types.h"
25 #include "host/commands/cvd/selector/selector_common_parser.h"
26 #include "host/commands/cvd/types.h"
27 
28 namespace cuttlefish {
29 namespace selector {
30 
31 class GroupSelector {
32  public:
33   static Result<GroupSelector> GetSelector(
34       const cvd_common::Args& selector_args, const Queries& extra_queries,
35       const cvd_common::Envs& envs, const uid_t uid);
36   /*
37    * If default, try running single instance group. If multiple, try to find
38    * HOME == SystemWideUserHome. If not exists, give up.
39    *
40    * If group given, find group, and check if all instance names are included
41    *
42    * If group not given, not yet supported. Will be in next CLs
43    */
44   Result<LocalInstanceGroup> FindGroup(
45       const InstanceDatabase& instance_database);
46 
47  private:
GroupSelector(const uid_t uid,const Queries & queries)48   GroupSelector(const uid_t uid, const Queries& queries)
49       : client_uid_{uid}, queries_{queries} {}
50 
51   // used by Select()
52   static bool IsHomeOverridden(const SelectorCommonParser& common_parser);
53 
54   Result<LocalInstanceGroup> FindDefaultGroup(
55       const InstanceDatabase& instance_database);
56 
57   const uid_t client_uid_;
58   const Queries queries_;
59 };
60 
61 }  // namespace selector
62 }  // namespace cuttlefish
63