• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3#   Copyright 2021 - The Android Open Source Project
4#
5#   Licensed under the Apache License, Version 2.0 (the "License");
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11#   Unless required by applicable law or agreed to in writing, software
12#   distributed under the License is distributed on an "AS IS" BASIS,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16
17import typing
18if typing.TYPE_CHECKING:
19    from acts.controllers.fuchsia_device import FuchsiaDevice
20
21
22class FuchsiaSessionManagerLib():
23    def __init__(self, fuchsia_device):
24        self.device: FuchsiaDevice = fuchsia_device
25
26    def resumeSession(self):
27        """Resumes a previously paused session
28
29        Returns:
30            Dictionary:
31                error: None, unless an error occurs
32                result: 'Success' or None if error
33        """
34        try:
35            self.device.ffx.run(
36                "component start /core/session-manager/session:session")
37            return {'error': None, 'result': 'Success'}
38        except Exception as e:
39            return {'error': e, 'result': None}
40
41    def pauseSession(self):
42        """Pause the session, allowing for later resumption
43
44        Returns:
45            Dictionary:
46                error: None, unless an error occurs
47                result: 'Success', 'NoSessionToPause', or None if error
48        """
49        result = self.device.ffx.run(
50            "component stop -r /core/session-manager/session:session",
51            skip_status_code_check=True)
52
53        if result.exit_status == 0:
54            return {'error': None, 'result': 'Success'}
55        else:
56            if "InstanceNotFound" in result.stderr:
57                return {'error': None, 'result': 'NoSessionToPause'}
58            else:
59                return {'error': result, 'result': None}
60