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 ~PlatformWwan()27PlatformWwan::~PlatformWwan() { 28 if (mWwanApi != nullptr) { 29 LOGD("Platform WWAN closing"); 30 prePalApiCall(); 31 mWwanApi->close(); 32 LOGD("Platform WWAN closed"); 33 } 34 } 35 init()36void PlatformWwan::init() { 37 prePalApiCall(); 38 mWwanApi = chrePalWwanGetApi(CHRE_PAL_WWAN_API_CURRENT_VERSION); 39 if (mWwanApi != nullptr) { 40 mWwanCallbacks.cellInfoResultCallback = 41 PlatformWwanBase::cellInfoResultCallback; 42 if (!mWwanApi->open(&gChrePalSystemApi, &mWwanCallbacks)) { 43 LOGE("WWAN PAL open returned false"); 44 mWwanApi = nullptr; 45 } 46 } else { 47 LOGW("Requested WWAN PAL (version %08" PRIx32 ") not found", 48 CHRE_PAL_WWAN_API_CURRENT_VERSION); 49 } 50 } 51 getCapabilities()52uint32_t PlatformWwan::getCapabilities() { 53 if (mWwanApi != nullptr) { 54 prePalApiCall(); 55 return mWwanApi->getCapabilities(); 56 } else { 57 return CHRE_WWAN_CAPABILITIES_NONE; 58 } 59 } 60 requestCellInfo()61bool PlatformWwan::requestCellInfo() { 62 if (mWwanApi != nullptr) { 63 prePalApiCall(); 64 return mWwanApi->requestCellInfo(); 65 } else { 66 return false; 67 } 68 } 69 releaseCellInfoResult(chreWwanCellInfoResult * result)70void PlatformWwan::releaseCellInfoResult(chreWwanCellInfoResult *result) { 71 if (mWwanApi != nullptr) { 72 prePalApiCall(); 73 mWwanApi->releaseCellInfoResult(result); 74 } 75 } 76 cellInfoResultCallback(struct chreWwanCellInfoResult * result)77void PlatformWwanBase::cellInfoResultCallback( 78 struct chreWwanCellInfoResult *result) { 79 EventLoopManagerSingleton::get()->getWwanRequestManager() 80 .handleCellInfoResult(result); 81 } 82 83 } // namespace chre 84