• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2020 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 #include "update_engine/cros/excluder_chromeos.h"
18 
19 #include <memory>
20 #include <vector>
21 
22 #include <base/logging.h>
23 #include <base/strings/string_piece.h>
24 #include <base/strings/string_number_conversions.h>
25 #include <base/strings/string_split.h>
26 
27 #include "update_engine/common/constants.h"
28 #include "update_engine/common/system_state.h"
29 
30 using std::string;
31 using std::vector;
32 
33 namespace chromeos_update_engine {
34 
CreateExcluder()35 std::unique_ptr<ExcluderInterface> CreateExcluder() {
36   return std::make_unique<ExcluderChromeOS>();
37 }
38 
Exclude(const string & name)39 bool ExcluderChromeOS::Exclude(const string& name) {
40   auto* prefs = SystemState::Get()->prefs();
41   auto key = prefs->CreateSubKey({kExclusionPrefsSubDir, name});
42   return prefs->SetString(key, "");
43 }
44 
IsExcluded(const string & name)45 bool ExcluderChromeOS::IsExcluded(const string& name) {
46   auto* prefs = SystemState::Get()->prefs();
47   auto key = prefs->CreateSubKey({kExclusionPrefsSubDir, name});
48   return prefs->Exists(key);
49 }
50 
Reset()51 bool ExcluderChromeOS::Reset() {
52   auto* prefs = SystemState::Get()->prefs();
53   bool ret = true;
54   vector<string> keys;
55   if (!prefs->GetSubKeys(kExclusionPrefsSubDir, &keys))
56     return false;
57   for (const auto& key : keys)
58     if (!(ret &= prefs->Delete(key)))
59       LOG(ERROR) << "Failed to delete exclusion pref for " << key;
60   return ret;
61 }
62 
63 }  // namespace chromeos_update_engine
64