• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016, 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 #ifndef WIFICOND_TESTS_INTEGRATION_PROCESS_UTILS_H_
18 #define WIFICOND_TESTS_INTEGRATION_PROCESS_UTILS_H_
19 
20 #include <time.h>
21 
22 #include <functional>
23 
24 #include <android-base/macros.h>
25 #include <utils/StrongPointer.h>
26 
27 #include "android/net/wifi/nl80211/IWificond.h"
28 
29 namespace android {
30 namespace wificond {
31 namespace tests {
32 namespace integration {
33 
34 // Instantiate one of these and call EnterDevMode() to put wificond into
35 // developer mode.  wificond will be automatically restarted in normal
36 // mode when the ScopedDevModeWificond intance goes out of scope:
37 //
38 // TEST(MyTest, TestCase) {
39 //   ScopedDevModeWificond dev_mode;
40 //   dev_mode.EnterDevMode();
41 //
42 //   // Code can assume that wificond is running in dev mode.
43 //   // wificond will be cleaned up when |dev_mode| is destroyed.
44 //
45 // }
46 class ScopedDevModeWificond final {
47  public:
48   static const uint32_t kSystemServerDeathTimeoutSeconds;
49   static const uint32_t kSystemServerStartTimeoutSeconds;
50   static const uint32_t kWificondDeathTimeoutSeconds;
51   static const uint32_t kWificondStartTimeoutSeconds;
52 
53   ScopedDevModeWificond() = default;
54   ~ScopedDevModeWificond();
55 
56   // You have to explicitly request that we enter dev mode.
57   // This makes avoids the nastiness of restarting a system process
58   // because you instantiated an object.
59   // ASSERTs that wificond starts in dev mode.
60   android::sp<android::net::wifi::nl80211::IWificond> EnterDevModeOrDie();
61   // Returns true iff wificond entered dev mode.
62   android::sp<android::net::wifi::nl80211::IWificond> MaybeEnterDevMode();
63 
64   // This will be called for you in the destructor, but you can do it yourself
65   // if you prefer.
66   void ExitDevMode();
67 
68  private:
69   bool in_dev_mode_ = false;
70 
71   DISALLOW_COPY_AND_ASSIGN(ScopedDevModeWificond);
72 };  // ScopedDevModeWificond
73 
74 // Blocks until either |condition| returns true, or |timeout_seconds| passes.
75 // Returns true iff |condition| returned true.
76 bool WaitForTrue(std::function<bool()> condition, time_t timeout_seconds);
77 
78 // Returns true iff a service is registered as |service_name| with the Binder
79 // service manager.
80 bool IsBinderServiceRegistered(const char* service_name);
81 
82 // Returns true iff the system_server process is running on the system.
83 bool SystemServerIsRunning();
84 
85 // Convenient alias for !SystemServerIsRunning
86 bool SystemServerIsDead();
87 
88 // Returns true iff the wificond process is running on the system.
89 bool WificondIsRunning();
90 
91 // Convenient alias for !WificondIsRunning
92 bool WificondIsDead();
93 
94 // Set the system property that controls whether wificond starts up in
95 // developer mode.  See wificond's main() for what this entails.
96 bool WificondSetDevMode(bool is_on);
97 
98 // Returns true iff the hostapd process is running on the system.
99 bool HostapdIsRunning();
100 
101 // Convenient alias for !HostapdIsRunning
102 bool HostapdIsDead();
103 
104 // Returns true iff the wpa_supplicant process is running on the system.
105 bool SupplicantIsRunning();
106 
107 // Convenient alias for !SupplicantIsRunning
108 bool SupplicantIsDead();
109 
110 }  // namespace integration
111 }  // namespace tests
112 }  // namespace android
113 }  // namespace wificond
114 
115 #endif  // WIFICOND_TESTS_INTEGRATION_PROCESS_UTILS_H_
116