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