1 /*
2  * Copyright (C) 2017 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 #include "chre/platform/platform_wwan.h"
18 
19 #include <cinttypes>
20 
21 #include "chre/core/event_loop_manager.h"
22 #include "chre/platform/shared/pal_system_api.h"
23 #include "chre/platform/log.h"
24 
25 namespace chre {
26 
27 const chrePalWwanCallbacks PlatformWwanBase::sWwanCallbacks = {
28   PlatformWwanBase::cellInfoResultCallback,
29 };
30 
~PlatformWwan()31 PlatformWwan::~PlatformWwan() {
32   if (mWwanApi != nullptr) {
33     LOGD("Platform WWAN closing");
34     prePalApiCall();
35     mWwanApi->close();
36     LOGD("Platform WWAN closed");
37   }
38 }
39 
init()40 void PlatformWwan::init() {
41   prePalApiCall();
42   mWwanApi = chrePalWwanGetApi(CHRE_PAL_WWAN_API_CURRENT_VERSION);
43   if (mWwanApi != nullptr) {
44     if (!mWwanApi->open(&gChrePalSystemApi, &sWwanCallbacks)) {
45       LOGE("WWAN PAL open returned false");
46       mWwanApi = nullptr;
47     }  else {
48       LOGD("Opened WWAN PAL version 0x%08" PRIx32, mWwanApi->moduleVersion);
49     }
50   } else {
51     LOGW("Requested WWAN PAL (version 0x%08" PRIx32 ") not found",
52          CHRE_PAL_WWAN_API_CURRENT_VERSION);
53   }
54 }
55 
getCapabilities()56 uint32_t PlatformWwan::getCapabilities() {
57   if (mWwanApi != nullptr) {
58     prePalApiCall();
59     return mWwanApi->getCapabilities();
60   } else {
61     return CHRE_WWAN_CAPABILITIES_NONE;
62   }
63 }
64 
requestCellInfo()65 bool PlatformWwan::requestCellInfo() {
66   if (mWwanApi != nullptr) {
67     prePalApiCall();
68     return mWwanApi->requestCellInfo();
69   } else {
70     return false;
71   }
72 }
73 
releaseCellInfoResult(chreWwanCellInfoResult * result)74 void PlatformWwan::releaseCellInfoResult(chreWwanCellInfoResult *result) {
75   if (mWwanApi != nullptr) {
76     prePalApiCall();
77     mWwanApi->releaseCellInfoResult(result);
78   }
79 }
80 
cellInfoResultCallback(struct chreWwanCellInfoResult * result)81 void PlatformWwanBase::cellInfoResultCallback(
82     struct chreWwanCellInfoResult *result) {
83   EventLoopManagerSingleton::get()->getWwanRequestManager()
84       .handleCellInfoResult(result);
85 }
86 
87 }  // namespace chre
88