Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright 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 #define LOG_TAG "device"
     18 
     19 #include <vector>
     20 
     21 #include "device.h"
     22 
     23 using std::vector;
     24 
     25 namespace test_vendor_lib {
     26 
     27 std::string Device::ToString() const {
     28   std::string dev = "(" + GetTypeString() + ")" + "@" + address_.ToString();
     29 
     30   return dev;
     31 }
     32 
     33 bool Device::IsAdvertisementAvailable(
     34     std::chrono::milliseconds scan_time) const {
     35   if (advertising_interval_ms_ == std::chrono::milliseconds(0)) return false;
     36 
     37   std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
     38 
     39   std::chrono::steady_clock::time_point last_interval =
     40       ((now - time_stamp_) / advertising_interval_ms_) *
     41           advertising_interval_ms_ +
     42       time_stamp_;
     43 
     44   std::chrono::steady_clock::time_point next_interval =
     45       last_interval + advertising_interval_ms_;
     46 
     47   return ((now + scan_time) >= next_interval);
     48 }
     49 
     50 bool Device::IsPageScanAvailable() const { return true; }
     51 
     52 }  // namespace test_vendor_lib
     53