12bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson/****************************************************************************** 22bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson * 35b790feeeb211c42bf78ca3ae9c26aa30e516765Jakub Pawlowski * Copyright 2014 Google, Inc. 42bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson * 52bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson * Licensed under the Apache License, Version 2.0 (the "License"); 62bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson * you may not use this file except in compliance with the License. 72bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson * You may obtain a copy of the License at: 82bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson * 92bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson * http://www.apache.org/licenses/LICENSE-2.0 102bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson * 112bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson * Unless required by applicable law or agreed to in writing, software 122bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson * distributed under the License is distributed on an "AS IS" BASIS, 132bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 142bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson * See the License for the specific language governing permissions and 152bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson * limitations under the License. 162bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson * 172bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson ******************************************************************************/ 182bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson 191b2bd2c8b5b7be80cb4ce0ecf4e021ad16e4a540Marie Janssen#include "AlarmTestHarness.h" 201b2bd2c8b5b7be80cb4ce0ecf4e021ad16e4a540Marie Janssen 211b2bd2c8b5b7be80cb4ce0ecf4e021ad16e4a540Marie Janssen#include <hardware/bluetooth.h> 222bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson 23c196f214c5ae349ec2022f8d3cbaf56910b3b9f8Pavlin Radoslavov#include "osi/include/alarm.h" 24d2e250824fca5c42b87b3b6f5fa19646ffa2d321Pavlin Radoslavov#include "osi/include/wakelock.h" 25ee2aa45def216a3c4d6a23481fa96f1b02a5de8cZach Johnson 26223cecf8b6905fec65c509cf85b20edbdbd28344Pavlin Radoslavovstatic bool is_wake_lock_acquired = false; 27223cecf8b6905fec65c509cf85b20edbdbd28344Pavlin Radoslavov 28b55040cc6448a8847490da807d2b6362aa8cb8d9Myles Watsonstatic int acquire_wake_lock_cb(const char* lock_name) { 29223cecf8b6905fec65c509cf85b20edbdbd28344Pavlin Radoslavov is_wake_lock_acquired = true; 30223cecf8b6905fec65c509cf85b20edbdbd28344Pavlin Radoslavov return BT_STATUS_SUCCESS; 31223cecf8b6905fec65c509cf85b20edbdbd28344Pavlin Radoslavov} 322bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson 33b55040cc6448a8847490da807d2b6362aa8cb8d9Myles Watsonstatic int release_wake_lock_cb(const char* lock_name) { 34223cecf8b6905fec65c509cf85b20edbdbd28344Pavlin Radoslavov is_wake_lock_acquired = false; 35223cecf8b6905fec65c509cf85b20edbdbd28344Pavlin Radoslavov return BT_STATUS_SUCCESS; 362bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson} 372bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson 38223cecf8b6905fec65c509cf85b20edbdbd28344Pavlin Radoslavovstatic bt_os_callouts_t bt_wakelock_callouts = { 39b55040cc6448a8847490da807d2b6362aa8cb8d9Myles Watson sizeof(bt_os_callouts_t), NULL, acquire_wake_lock_cb, release_wake_lock_cb}; 40223cecf8b6905fec65c509cf85b20edbdbd28344Pavlin Radoslavov 412bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnsonvoid AlarmTestHarness::SetUp() { 42ee2aa45def216a3c4d6a23481fa96f1b02a5de8cZach Johnson AllocationTestHarness::SetUp(); 43ee2aa45def216a3c4d6a23481fa96f1b02a5de8cZach Johnson 449713b9476ca58502b2737c8a638c8d707c5b3542Pavlin Radoslavov TIMER_INTERVAL_FOR_WAKELOCK_IN_MS = 500; 452bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson 46223cecf8b6905fec65c509cf85b20edbdbd28344Pavlin Radoslavov wakelock_set_os_callouts(&bt_wakelock_callouts); 472bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson} 482bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson 492bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnsonvoid AlarmTestHarness::TearDown() { 500d6a501d0517c186f11cbee294ae2c509073de91Pavlin Radoslavov alarm_cleanup(); 51d2e250824fca5c42b87b3b6f5fa19646ffa2d321Pavlin Radoslavov wakelock_cleanup(); 52223cecf8b6905fec65c509cf85b20edbdbd28344Pavlin Radoslavov wakelock_set_os_callouts(NULL); 531b2bd2c8b5b7be80cb4ce0ecf4e021ad16e4a540Marie Janssen 54ee2aa45def216a3c4d6a23481fa96f1b02a5de8cZach Johnson AllocationTestHarness::TearDown(); 552bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson} 562bbb33c648fd27233421a721e067d8c0e9012a7eZach Johnson 57b55040cc6448a8847490da807d2b6362aa8cb8d9Myles Watsonbool AlarmTestHarness::WakeLockHeld() { return is_wake_lock_acquired; } 58