File: cellular_esim_uninstall_handler.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 (208 lines) | stat: -rw-r--r-- 8,384 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// 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_CELLULAR_ESIM_UNINSTALL_HANDLER_H_
#define CHROMEOS_ASH_COMPONENTS_NETWORK_CELLULAR_ESIM_UNINSTALL_HANDLER_H_

#include <memory>

#include "base/component_export.h"
#include "base/containers/circular_deque.h"
#include "base/containers/flat_set.h"
#include "base/containers/queue.h"
#include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "base/time/time.h"
#include "chromeos/ash/components/dbus/hermes/hermes_response_status.h"
#include "chromeos/ash/components/network/cellular_esim_profile_handler.h"
#include "chromeos/ash/components/network/cellular_inhibitor.h"
#include "chromeos/ash/components/network/network_state_handler.h"
#include "chromeos/ash/components/network/network_state_handler_observer.h"
#include "dbus/object_path.h"

namespace ash {

class CellularESimProfileHandler;
class CellularInhibitor;
class ManagedCellularPrefHandler;
class NetworkConfigurationHandler;
class NetworkConnectionHandler;
class NetworkState;

// Handles Uninstallation of an eSIM profile and it's corresponding network.
//
// Uninstalling and eSIM network involves interacting with both Shill and Hermes
// in the following sequence:
// 1. Disconnect Network with Shill
// 2. Inhibit Cellular Scans
// 3. Request Installed eSIM profiles from Hermes
// 4. Disable eSIM profile through Hermes
// 5. Uninstall eSIM profile in Hermes
// 6. Remove Shill configuration for Network
// 7. Uninhibit Cellular Scans
//
// Uninstallation requests are queued and run in order.
//
// Note: This class doesn't check and remove stale Shill eSIM services anymore
// because it might remove usable eSIM services incorrectly. This may cause some
// issues where some stale networks showing in UI because its Shill
// configuration doesn't get removed properly during the uninstallation.
// TODO(b/210726568)
class COMPONENT_EXPORT(CHROMEOS_NETWORK) CellularESimUninstallHandler
    : public NetworkStateHandlerObserver {
 public:
  // TODO(b/271854446): Make these private once the migration has landed.
  // These values are persisted to logs. Entries should not be renumbered and
  // numeric values should never be reused.
  enum class UninstallESimResult {
    kSuccess = 0,
    kNetworkNotFound = 1,
    kDisconnectFailed = 2,
    kInhibitFailed = 3,
    kRefreshProfilesFailed = 4,
    kDisableProfileFailed = 5,
    kUninstallProfileFailed = 6,
    kRemoveServiceFailed = 7,
    kMaxValue = kRemoveServiceFailed
  };

  // Timeout when waiting for network list change after removing network
  // service. Service removal continues with next service.
  static const base::TimeDelta kNetworkListWaitTimeout;

  CellularESimUninstallHandler();
  CellularESimUninstallHandler(const CellularESimUninstallHandler&) = delete;
  CellularESimUninstallHandler& operator=(const CellularESimUninstallHandler&) =
      delete;
  ~CellularESimUninstallHandler() override;

  void Init(CellularInhibitor* cellular_inhibitor,
            CellularESimProfileHandler* cellular_esim_profile_handler,
            ManagedCellularPrefHandler* managed_cellular_pref_handler,
            NetworkConfigurationHandler* network_configuration_handler,
            NetworkConnectionHandler* network_connection_handler,
            NetworkStateHandler* network_state_handler);

  // Callback that returns true or false to indicate the success or failure of
  // an uninstallation request.
  using UninstallRequestCallback = base::OnceCallback<void(bool success)>;

  // Uninstalls an ESim profile and network with given |iccid| and
  // |esim_profile_path| that is installed in Euicc with the given
  // |euicc_path|.
  void UninstallESim(const std::string& iccid,
                     const dbus::ObjectPath& esim_profile_path,
                     const dbus::ObjectPath& euicc_path,
                     UninstallRequestCallback callback);

  // Resets memory ie. Removes all eSIM profiles on the Euicc with given
  // |euicc_path|.
  void ResetEuiccMemory(const dbus::ObjectPath& euicc_path,
                        UninstallRequestCallback callback);

 private:
  // NetworkStateHandlerObserver:
  void NetworkListChanged() override;
  void OnShuttingDown() override;

  friend class CellularESimUninstallHandlerTest;

  enum class UninstallState {
    kIdle,
    kCheckingNetworkState,
    kDisconnectingNetwork,
    kInhibitingShill,
    kRequestingInstalledProfiles,
    kDisablingProfile,
    kUninstallingProfile,
    kRemovingShillService,
    kWaitingForNetworkListUpdate,
  };
  friend std::ostream& operator<<(std::ostream& stream,
                                  const UninstallState& step);

  // Represents ESim uninstallation request parameters. Requests are queued and
  // processed one at a time. |esim_profile_path| and |euicc_path| are nullopt
  // for stale eSIM service removal requests. These requests skip directly to
  // Shill configuration removal.
  struct UninstallRequest {
    UninstallRequest(const std::optional<std::string>& iccid,
                     const std::optional<dbus::ObjectPath>& esim_profile_path,
                     const std::optional<dbus::ObjectPath>& euicc_path,
                     bool reset_euicc,
                     UninstallRequestCallback callback);
    ~UninstallRequest();
    std::optional<std::string> iccid;
    std::optional<dbus::ObjectPath> esim_profile_path;
    std::optional<dbus::ObjectPath> euicc_path;
    bool reset_euicc;
    base::flat_set<std::string> removed_service_paths;
    UninstallRequestCallback callback;
    std::unique_ptr<CellularInhibitor::InhibitLock> inhibit_lock;
  };
  friend std::ostream& operator<<(std::ostream& stream,
                                  const UninstallRequest& request);

  void ProcessPendingUninstallRequests();
  void TransitionToUninstallState(UninstallState next_state);
  void CompleteCurrentRequest(UninstallESimResult result);

  std::string GetIdForCurrentRequest() const;
  const NetworkState* GetNetworkStateForCurrentRequest() const;

  void CheckActiveNetworkState();

  void AttemptNetworkDisconnect(const NetworkState* network);
  void OnDisconnectSuccess();
  void OnDisconnectFailure(const std::string& error_name);

  void AttemptShillInhibit();
  void OnShillInhibit(
      std::unique_ptr<CellularInhibitor::InhibitLock> inhibit_lock);

  void AttemptRequestInstalledProfiles();
  void OnRefreshProfileListResult(
      std::unique_ptr<CellularInhibitor::InhibitLock> inhibit_lock);

  void AttemptDisableProfile();
  void OnDisableProfile(HermesResponseStatus status);

  void AttemptUninstallProfile();
  void OnUninstallProfile(const base::flat_set<std::string>& removed_iccids,
                          HermesResponseStatus status);

  void AttemptRemoveShillService();
  void OnRemoveServiceSuccess(const std::string& removed_service_path);
  void OnRemoveServiceFailure(const std::string& error_name);
  void OnNetworkListWaitTimeout();

  std::optional<dbus::ObjectPath> GetEnabledCellularESimProfilePath();
  NetworkStateHandler::NetworkStateList GetESimCellularNetworks() const;
  const NetworkState* GetNextResetServiceToRemove() const;
  base::flat_set<std::string> GetAllIccidsOnEuicc(
      const dbus::ObjectPath& euicc_path);

  UninstallState state_ = UninstallState::kIdle;
  base::circular_deque<std::unique_ptr<UninstallRequest>> uninstall_requests_;

  base::OneShotTimer network_list_wait_timer_;

  raw_ptr<CellularInhibitor> cellular_inhibitor_ = nullptr;
  raw_ptr<CellularESimProfileHandler> cellular_esim_profile_handler_ = nullptr;
  raw_ptr<ManagedCellularPrefHandler, DanglingUntriaged>
      managed_cellular_pref_handler_ = nullptr;
  raw_ptr<NetworkConfigurationHandler> network_configuration_handler_ = nullptr;
  raw_ptr<NetworkConnectionHandler> network_connection_handler_ = nullptr;
  raw_ptr<NetworkStateHandler> network_state_handler_ = nullptr;
  size_t last_service_count_removal_for_testing_ = 0;
  base::ScopedObservation<NetworkStateHandler, NetworkStateHandlerObserver>
      network_state_handler_observer_{this};

  base::WeakPtrFactory<CellularESimUninstallHandler> weak_ptr_factory_{this};
};

}  // namespace ash

#endif  // CHROMEOS_ASH_COMPONENTS_NETWORK_CELLULAR_ESIM_UNINSTALL_HANDLER_H_