File: stub_cellular_networks_provider.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (94 lines) | stat: -rw-r--r-- 4,314 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_ASH_COMPONENTS_NETWORK_STUB_CELLULAR_NETWORKS_PROVIDER_H_
#define CHROMEOS_ASH_COMPONENTS_NETWORK_STUB_CELLULAR_NETWORKS_PROVIDER_H_

#include "base/containers/flat_map.h"
#include "base/containers/flat_set.h"
#include "base/memory/raw_ptr.h"
#include "chromeos/ash/components/network/network_state_handler.h"

namespace ash {

// Provides stub cellular for use by NetworkStateHandler. In this context,
// cellular stub networks correspond to networks shown exposed by
// NetworkStateHandler which are not backed by Shill.
//
// StubCellularNetworksProvider provides stub networks by utilizing
// CellularESimProfileHandler to obtain information about installed eSIM
// profiles and merge this information with networks known to Shill.
class COMPONENT_EXPORT(CHROMEOS_NETWORK) StubCellularNetworksProvider
    : public NetworkStateHandler::StubCellularNetworksProvider {
 public:
  StubCellularNetworksProvider();
  ~StubCellularNetworksProvider() override;

  void Init(NetworkStateHandler* network_state_handler,
            CellularESimProfileHandler* cellular_esim_profile_handler,
            ManagedCellularPrefHandler* managed_cellular_pref_handler);

 private:
  friend class StubCellularNetworksProviderTest;

  using IccidEidPair = std::pair<std::string, std::string>;

  // NetworkStateHandler::StubCellularNetworksProvider:
  bool AddOrRemoveStubCellularNetworks(
      NetworkStateHandler::ManagedStateList& network_list,
      NetworkStateHandler::ManagedStateList& new_stub_networks,
      const DeviceState* device) override;
  bool GetStubNetworkMetadata(const std::string& iccid,
                              const DeviceState* cellular_device,
                              std::string* service_path_out,
                              std::string* guid_out) override;

  const std::string& GetGuidForStubIccid(const std::string& iccid);

  // Returns an IccidEidPair corresponding to each eSIM profile and each SIM
  // slot.
  std::vector<IccidEidPair> GetESimAndSlotMetadata(const DeviceState* device);

  // Adds stub cellular networks to |new_stub_networks| list for the metadata in
  // |esim_and_slot_metadata| that does not correspond to networks already
  // present in not already in |all_iccids|.
  bool AddStubNetworks(
      const DeviceState* device,
      const std::vector<IccidEidPair>& esim_and_slot_metadata,
      const base::flat_set<std::string>& all_iccids,
      NetworkStateHandler::ManagedStateList& new_stub_networks);

  // Removes all non-Shill stub cellular networks from |network_list| that are
  // not required anymore viz. 1) Stub networks for which a corresponding entry
  // already exists in |shill_iccids| 2) Stub networks that do not have
  // corresponding entry in |esim_and_slot_metadata| or a slot info entry on
  // given |device| (e.g. eSIM profile was removed or pSIM was removed from the
  // slot) 3) Stub networks that do not reflect the correct managed by policy
  // state. If both |esim_slot_metadata| and |shill_iccids| are nullptr, then
  // all stub networks are removed.
  bool RemoveCellularNetworks(
      const std::vector<IccidEidPair>* esim_and_slot_metadata,
      const base::flat_set<std::string>* shill_iccids,
      NetworkStateHandler::ManagedStateList& network_list);

  // Iterates through the provided stub networks and updates any network that is
  // found to have an outdated managed state. This allows the UI to more quickly
  // update when a cellular network transitions to become unmanaged or
  // vice-versa.
  bool UpdateCellularNetworks(
      NetworkStateHandler::ManagedStateList& network_list);

  raw_ptr<NetworkStateHandler> network_state_handler_ = nullptr;
  raw_ptr<CellularESimProfileHandler> cellular_esim_profile_handler_ = nullptr;
  raw_ptr<ManagedCellularPrefHandler, DanglingUntriaged>
      managed_cellular_pref_handler_ = nullptr;

  // Map which stores the GUID used for stubs created by this class. Each
  // network should use a consistent GUID throughout a session.
  base::flat_map<std::string, std::string> iccid_to_guid_map_;
};

}  // namespace ash

#endif  // CHROMEOS_ASH_COMPONENTS_NETWORK_STUB_CELLULAR_NETWORKS_PROVIDER_H_