1 /* 2 * Copyright (C) 2021 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 // This is a sample reader client for ICarTelemetryInternal. 18 // TODO(b/186017953): remove this client when CarTelemetryService is implemented. 19 // 20 // adb remount # make sure run "adb disable-verity" before remounting 21 // adb push $ANDROID_PRODUCT_OUT/system/bin/android.automotive.telemetryd-sampleinternalclient 22 // /system/bin/ 23 // 24 // adb shell /system/bin/android.automotive.telemetryd-sampleinternalclient 25 26 #define LOG_TAG "cartelemetryd_sampleint" 27 28 #include <aidl/android/automotive/telemetry/internal/BnCarDataListener.h> 29 #include <aidl/android/automotive/telemetry/internal/CarDataInternal.h> 30 #include <aidl/android/automotive/telemetry/internal/ICarTelemetryInternal.h> 31 #include <android-base/logging.h> 32 #include <android-base/stringprintf.h> 33 #include <android/binder_manager.h> 34 #include <android/binder_process.h> 35 36 using ::aidl::android::automotive::telemetry::internal::BnCarDataListener; 37 using ::aidl::android::automotive::telemetry::internal::CarDataInternal; 38 using ::aidl::android::automotive::telemetry::internal::ICarDataListener; 39 using ::aidl::android::automotive::telemetry::internal::ICarTelemetryInternal; 40 using ::android::base::StringPrintf; 41 42 class CarDataListenerImpl : public BnCarDataListener { 43 public: 44 ::ndk::ScopedAStatus onCarDataReceived( 45 const std::vector<CarDataInternal>& in_dataList) override; 46 }; 47 onCarDataReceived(const std::vector<CarDataInternal> & dataList)48::ndk::ScopedAStatus CarDataListenerImpl::onCarDataReceived( 49 const std::vector<CarDataInternal>& dataList) { 50 LOG(INFO) << "Received data size = " << dataList.size(); 51 for (const auto data : dataList) { 52 LOG(INFO) << "data.id = " << data.id; 53 } 54 return ::ndk::ScopedAStatus::ok(); 55 } 56 main(int argc,char * argv[])57int main(int argc, char* argv[]) { 58 // The name of the service is described in 59 // https://source.android.com/devices/architecture/aidl/aidl-hals#instance-names 60 const std::string instance = StringPrintf("%s/default", ICarTelemetryInternal::descriptor); 61 LOG(INFO) << "Obtaining: " << instance; 62 std::shared_ptr<ICarTelemetryInternal> service = ICarTelemetryInternal::fromBinder( 63 ndk::SpAIBinder(AServiceManager_getService(instance.c_str()))); 64 if (!service) { 65 LOG(FATAL) << "ICarTelemetryInternal service not found, may be still initializing?"; 66 } 67 68 LOG(INFO) << "Setting the listener"; 69 std::shared_ptr<CarDataListenerImpl> listener = ndk::SharedRefBase::make<CarDataListenerImpl>(); 70 auto status = service->setListener(listener); 71 if (!status.isOk()) { 72 LOG(FATAL) << "Failed to set the listener"; 73 } 74 75 ::ABinderProcess_startThreadPool(); 76 ::ABinderProcess_joinThreadPool(); 77 return 1; // not reachable 78 } 79