1 # Copyright (C) 2016 The Android Open Source Project
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 class Bootctl(object):
16 def __init__(self, device):
18 self.base = ["bootctl"]
21 return self.device.shell_nocheck(self.base + [cmd])
23 def get_number_slots(self):
24 """returns number of slots"""
26 return int(self._exec("get-number-slots")[1])
28 def get_current_slot(self):
29 """returns current slot number"""
31 return int(self._exec("get-current-slot")[1])
33 def mark_boot_successful(self):
34 """returns true on success, false on failure"""
36 return self._exec("mark-boot-successful")[0] == 0
38 def set_active_boot_slot(self, slot):
39 """returns true on success, false on failure"""
41 return self._exec("set-active-boot-slot " + str(slot))[0] == 0
43 def set_slot_as_unbootable_slot(self, slot):
44 """returns true on success, false on failure"""
46 return self._exec("set-slot-as-unbootable " + str(slot))[0] == 0
48 def is_slot_bootable(self, slot):
49 """Returns true if slot is bootable"""
51 return self._exec("is-slot-bootable " + str(slot))[0] == 0
53 def is_slot_marked_successful(self, slot):
54 """returns true on success, false on failure"""
56 return self._exec("is-slot-marked-successful " + str(slot))[0] == 0
58 def get_suffix(self, slot):
59 """returns suffix string for specified slot number"""
61 return self._exec("get-suffix " + str(slot))[1].strip()