aboutsummaryrefslogtreecommitdiff
path: root/tests/PowerTestService
diff options
context:
space:
mode:
authorSteve Paik <spaik@google.com>2018-03-01 18:07:38 -0800
committerSteve Paik <spaik@google.com>2018-03-13 18:35:19 -0700
commitb40de197fb9b60bcbb20c243ba6b1a41e25e2e67 (patch)
treed4f3b6b46795fa1ef76c6d446199e1325c912dda /tests/PowerTestService
parentf95ae8ecd35900c376111a6b5c4a00129f0fe42d (diff)
downloadCar-b40de197fb9b60bcbb20c243ba6b1a41e25e2e67.tar.gz
Add CarPowerManagerNative
Add native interface to interace with CarPowerManagementService. This CL consists of the following pieces: - PowerTestService: Test code to exercise the native itnerface. - libcarpowermanager.so: Shared library to be included by native services that want to interact with CarPowerManagementService. Bug: 32061842 Test: PowerTestService Change-Id: Ife320d09f02961f9de65b214c8b3dc394fc39396 Merged-In: I8cfabd36f5d5b72727f04b5ba184ec44e83d79c2
Diffstat (limited to 'tests/PowerTestService')
-rw-r--r--tests/PowerTestService/Android.mk49
-rw-r--r--tests/PowerTestService/com.android.car.powertestservice.rc21
-rw-r--r--tests/PowerTestService/sepolicy/com.android.car.powertestservice.te6
-rw-r--r--tests/PowerTestService/sepolicy/file_contexts1
-rw-r--r--tests/PowerTestService/src/main.cpp81
5 files changed, 158 insertions, 0 deletions
diff --git a/tests/PowerTestService/Android.mk b/tests/PowerTestService/Android.mk
new file mode 100644
index 0000000000..aefea30215
--- /dev/null
+++ b/tests/PowerTestService/Android.mk
@@ -0,0 +1,49 @@
+# Copyright (C) 2018 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.
+
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := com.android.car.powertestservice
+
+BOARD_SEPOLICY_DIRS += \
+ packages/services/Car/tests/PowerTestService/sepolicy
+
+LOCAL_SRC_FILES := \
+ src/main.cpp
+
+LOCAL_CFLAGS += \
+ -Wall \
+ -Wextra \
+ -Werror \
+ -Wno-unused-parameter
+
+LOCAL_C_INCLUDES += \
+ frameworks/base/include \
+ packages/services/Car/car-lib/native/include
+
+LOCAL_SHARED_LIBRARIES := \
+ libbinder \
+ libcarpowermanager \
+ liblog \
+ libutils
+
+LOCAL_MODULE_CLASS := EXECUTABLES
+
+LOCAL_INIT_RC := com.android.car.powertestservice.rc
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_EXECUTABLE)
+
diff --git a/tests/PowerTestService/com.android.car.powertestservice.rc b/tests/PowerTestService/com.android.car.powertestservice.rc
new file mode 100644
index 0000000000..db272375bf
--- /dev/null
+++ b/tests/PowerTestService/com.android.car.powertestservice.rc
@@ -0,0 +1,21 @@
+# Copyright (C) 2018 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.
+
+service com.android.car.powertestservice /system/bin/com.android.car.powertestservice
+ class core
+ user system
+ group system
+
+on boot && property:boot.car_service_created=1
+ start com.android.car.powertestservice
diff --git a/tests/PowerTestService/sepolicy/com.android.car.powertestservice.te b/tests/PowerTestService/sepolicy/com.android.car.powertestservice.te
new file mode 100644
index 0000000000..d27f6c0d33
--- /dev/null
+++ b/tests/PowerTestService/sepolicy/com.android.car.powertestservice.te
@@ -0,0 +1,6 @@
+type powertestservice, domain, coredomain;
+type powertestservice_exec, exec_type, file_type;
+
+init_daemon_domain(powertestservice)
+
+allow system_app powertestservice:binder call;
diff --git a/tests/PowerTestService/sepolicy/file_contexts b/tests/PowerTestService/sepolicy/file_contexts
new file mode 100644
index 0000000000..7be7605f41
--- /dev/null
+++ b/tests/PowerTestService/sepolicy/file_contexts
@@ -0,0 +1 @@
+/system/bin/com\.android\.car\.powertestservice u:object_r:powertestservice_exec:s0
diff --git a/tests/PowerTestService/src/main.cpp b/tests/PowerTestService/src/main.cpp
new file mode 100644
index 0000000000..acd14edc33
--- /dev/null
+++ b/tests/PowerTestService/src/main.cpp
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#define LOG_TAG "PowerTestService"
+
+#include <signal.h>
+#include <utils/Log.h>
+
+#include <binder/IPCThreadState.h>
+#include <binder/ProcessState.h>
+#include <binder/IServiceManager.h>
+#include <binder/IBinder.h>
+#include <binder/IInterface.h>
+
+#include "android/car/ICar.h"
+#include "android/car/hardware/power/ICarPower.h"
+#include "CarPowerManager.h"
+
+using namespace android;
+using namespace android::binder;
+using namespace android::car;
+using namespace android::car::hardware::power;
+
+static std::atomic_bool run(true);
+
+void onStateChanged(CarPowerManager::State state) {
+ ALOGE("onStateChanged callback = %d", state);
+ // Stop the loop
+ run = false;
+}
+
+int main(int, char**)
+{
+ int retVal;
+
+ sp<ProcessState> processSelf(ProcessState::self());
+ processSelf->startThreadPool();
+ ALOGE(LOG_TAG " started");
+
+ std::unique_ptr<CarPowerManager> carPowerManager(new CarPowerManager());
+
+ do {
+ retVal = carPowerManager->setListener(onStateChanged);
+ } while (retVal != 0);
+
+ do {
+ CarPowerManager::BootReason bootReason;
+ // Test code
+ retVal = carPowerManager->getBootReason(&bootReason);
+
+ if (retVal == 0) {
+ ALOGE("bootreason = %d", bootReason);
+ } else {
+ ALOGE("ERROR: Could not read bootReason!!");
+ }
+
+ sleep(5);
+ } while (run);
+
+ // Unregister the listener
+ carPowerManager->clearListener();
+
+ // Wait for threads to finish, and then exit.
+ IPCThreadState::self()->joinThreadPool();
+ ALOGE(LOG_TAG " joined and going down");
+ return 0;
+}
+