--- /dev/null
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "ipc_constants.h"
+
+namespace android {
+namespace wificond {
+namespace ipc_constants {
+
+const char kServiceName[] = "wificond";
+const char kDevModeServiceName[] = "wificond-dev";
+const char kDevModePropertyKey[] = "wificond.dev-mode-on";
+
+} // namespace ipc_constants
+} // namespace wificond
+} // namespace android
+
--- /dev/null
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef WIFICOND_IPC_CONSTANTS_H_
+#define WIFICOND_IPC_CONSTANTS_H_
+
+namespace android {
+namespace wificond {
+namespace ipc_constants {
+
+extern const char kServiceName[];
+extern const char kDevModeServiceName[];
+extern const char kDevModePropertyKey[];
+
+} // namespace ipc_constants
+} // namespace wificond
+} // namespace android
+
+#endif // WIFICOND_IPC_CONSTANTS_H_
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
#include <binder/ProcessState.h>
+#include <cutils/properties.h>
#include <utils/String16.h>
+#include "ipc_constants.h"
#include "looper_backed_event_loop.h"
#include "server.h"
using android::net::wifi::IWificond;
+using android::wificond::ipc_constants::kDevModePropertyKey;
+using android::wificond::ipc_constants::kDevModeServiceName;
+using android::wificond::ipc_constants::kServiceName;
namespace {
void RegisterServiceOrCrash(const android::sp<android::IBinder>& service) {
android::sp<android::IServiceManager> sm = android::defaultServiceManager();
CHECK_EQ(sm != NULL, true) << "Could not obtain IServiceManager";
- CHECK_EQ(sm->addService(android::String16("wificond"), service),
+
+ const int8_t dev_mode_on = property_get_bool(kDevModePropertyKey, 0);
+ const char* service_name = (dev_mode_on) ? kDevModeServiceName : kServiceName;
+ CHECK_EQ(sm->addService(android::String16(service_name), service),
android::NO_ERROR);
}
#include <ctime>
+#include <android-base/logging.h>
#include <android-base/strings.h>
#include <binder/IServiceManager.h>
+#include <cutils/properties.h>
#include <utils/Errors.h>
#include <utils/String16.h>
#include <utils/StrongPointer.h>
#include "android/net/wifi/IApInterface.h"
#include "android/net/wifi/IWificond.h"
+#include "ipc_constants.h"
+#include "server.h"
#include "tests/shell_utils.h"
using android::String16;
using android::base::Trim;
using android::net::wifi::IApInterface;
using android::net::wifi::IWificond;
+using android::wificond::ipc_constants::kDevModePropertyKey;
+using android::wificond::ipc_constants::kDevModeServiceName;
+using android::wificond::ipc_constants::kServiceName;
using android::wificond::tests::integration::RunShellCommand;
namespace android {
const uint32_t kWificondDeathTimeoutSeconds = 10;
const uint32_t kWificondStartTimeoutSeconds = 10;
-const char kWificondServiceName[] = "wificond";
-
bool WificondIsRunning() {
std::string output;
RunShellCommand("pgrep -c ^wificond$", &output);
return false;
}
-bool IsRegistered() {
+bool IsRegisteredAs(const char* service_name) {
sp<IBinder> service =
- defaultServiceManager()->checkService(String16(kWificondServiceName));
+ defaultServiceManager()->checkService(String16(service_name));
return service.get() != nullptr;
}
+bool SetDevMode(bool is_on) {
+ return property_set(kDevModePropertyKey, (is_on) ? "1" : "0") == 0;
+}
+
+class SandboxedTest : public ::testing::Test {
+ protected:
+ void SetUp() override {
+ RunShellCommand("stop wificond");
+ EXPECT_TRUE(SetDevMode(true));
+ RunShellCommand("start wificond");
+ auto in_dev_mode = std::bind(IsRegisteredAs, kDevModeServiceName);
+ EXPECT_TRUE(WaitForTrue(in_dev_mode, kWificondStartTimeoutSeconds));
+ }
+
+ void TearDown() override {
+ RunShellCommand("stop wificond");
+ SetDevMode(false);
+ RunShellCommand("start wificond");
+ }
+}; // class SandboxedTest
+
} // namespace
EXPECT_TRUE(WaitForTrue(WificondIsDead, kWificondDeathTimeoutSeconds));
// Confirm that the service manager has no binder for wificond.
- EXPECT_FALSE(IsRegistered());
+ EXPECT_FALSE(IsRegisteredAs(kServiceName));
+ EXPECT_FALSE(IsRegisteredAs(kDevModeServiceName));
+ EXPECT_TRUE(SetDevMode(false)); // Clear dev mode
// Start wificond.
RunShellCommand("start wificond");
EXPECT_TRUE(WaitForTrue(WificondIsRunning, kWificondStartTimeoutSeconds));
// wificond should eventually register with the service manager.
- EXPECT_TRUE(WaitForTrue(IsRegistered, kWificondStartTimeoutSeconds));
+ EXPECT_TRUE(WaitForTrue(std::bind(IsRegisteredAs, kServiceName),
+ kWificondStartTimeoutSeconds));
}
-TEST(LifeCycleTest, CanCreateApInterfaces) {
- // Restart wificond and wait for it to come back.
- RunShellCommand("stop wificond");
- RunShellCommand("start wificond");
- EXPECT_TRUE(WaitForTrue(IsRegistered, kWificondStartTimeoutSeconds));
-
+TEST_F(SandboxedTest, CanCreateApInterfaces) {
sp<IWificond> service;
- ASSERT_EQ(getService(String16(kWificondServiceName), &service), NO_ERROR);
+ ASSERT_EQ(NO_ERROR, getService(String16(kDevModeServiceName), &service));
// We should be able to create an AP interface.
sp<IApInterface> ap_interface;