1 /* 2 * Copyright (C) 2018 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 #define LOG_TAG "PowerTestService" 18 19 #include <signal.h> 20 #include <utils/Log.h> 21 22 #include <binder/IPCThreadState.h> 23 #include <binder/ProcessState.h> 24 #include <binder/IServiceManager.h> 25 #include <binder/IBinder.h> 26 #include <binder/IInterface.h> 27 28 #include "android/car/ICar.h" 29 #include "android/car/hardware/power/ICarPower.h" 30 #include "CarPowerManager.h" 31 32 using namespace android; 33 using namespace android::binder; 34 using namespace android::car; 35 using namespace android::car::hardware::power; 36 37 static std::atomic_bool run(true); 38 onStateChanged(CarPowerManager::State state)39void onStateChanged(CarPowerManager::State state) { 40 ALOGE("onStateChanged callback = %d", state); 41 // Stop the loop 42 run = false; 43 } 44 main(int,char **)45int main(int, char**) 46 { 47 int retVal; 48 49 sp<ProcessState> processSelf(ProcessState::self()); 50 processSelf->startThreadPool(); 51 ALOGE(LOG_TAG " started"); 52 53 std::unique_ptr<CarPowerManager> carPowerManager(new CarPowerManager()); 54 55 do { 56 retVal = carPowerManager->setListener(onStateChanged); 57 } while (retVal != 0); 58 59 do { 60 CarPowerManager::BootReason bootReason; 61 // Test code 62 retVal = carPowerManager->getBootReason(&bootReason); 63 64 if (retVal == 0) { 65 ALOGE("bootreason = %d", bootReason); 66 } else { 67 ALOGE("ERROR: Could not read bootReason!!"); 68 } 69 70 sleep(5); 71 } while (run); 72 73 // Unregister the listener 74 carPowerManager->clearListener(); 75 76 // Wait for threads to finish, and then exit. 77 IPCThreadState::self()->joinThreadPool(); 78 ALOGE(LOG_TAG " joined and going down"); 79 return 0; 80 } 81 82