• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#  Copyright (C) 2025 The Android Open Source Project
2#
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
6#
7#       http://www.apache.org/licenses/LICENSE-2.0
8#
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.
14
15import logging
16from mobly import base_test
17from mobly import test_runner
18from mobly.controllers import android_device
19from utilities.main_utils import common_main
20
21class AndroidRebootTest(base_test.BaseTestClass):
22
23    def setup_class(self):
24        # Setup required for the entire test class. This executes
25        # before any test cases are run.
26        self.android_devices = self.register_controller(android_device)
27        self.num_reboots = self.user_params['num_reboots']
28
29    def test_reboot_and_check_fingerprint_stability(self):
30        # Number of times the reboot operation will be performed.
31        num_reboots = self.num_reboots
32        num_successful_reboots = 0
33
34        # Ensure there is at least one device available.
35        if not self.android_devices:
36            raise AssertionError('No Android devices are registered. Please make '
37                                 'sure at least one device is connected and '
38                                 'configured properly.')
39
40        ad = self.android_devices[0]  # Get the first device object.
41        # Record the fingerprint before the first reboot.
42        initial_fingerprint = ad.adb.shell('getprop ro.build.fingerprint')
43        logging.info('Initial fingerprint: %s', initial_fingerprint)
44
45        for i in range(num_reboots):
46            logging.info('Rebooting: Attempt #%d', i + 1)
47
48            # Reboot the device and wait until it's back online.
49            ad.reboot()
50            ad.wait_for_boot_completion()
51
52            # Check the fingerprint after the reboot.
53            current_fingerprint = ad.adb.shell('getprop ro.build.fingerprint')
54            logging.info('Fingerprint after reboot #%d: %s', i + 1, current_fingerprint)
55
56            # Verify that the fingerprint remains the same after each reboot.
57            if initial_fingerprint != current_fingerprint:
58                raise AssertionError('The ro.build.fingerprint has changed after '
59                                     'reboot #%d. Initial: %s, after: %s' %
60                                     (i + 1, initial_fingerprint, current_fingerprint))
61            else:
62                num_successful_reboots += 1
63
64        logging.info('Reboot Stability Test: %d/%d successful reboots.',
65                     num_successful_reboots, num_reboots)
66
67if __name__ == '__main__':
68    common_main()
69
70