Home | History | Annotate | Download | only in metricsd
      1 /*
      2  * Copyright (C) 2015 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 // Client interface to IMetricsCollectorService.
     18 
     19 #include "metrics/metrics_collector_service_client.h"
     20 
     21 #include <base/logging.h>
     22 #include <binder/IServiceManager.h>
     23 #include <utils/String16.h>
     24 
     25 #include "android/brillo/metrics/IMetricsCollectorService.h"
     26 
     27 namespace {
     28 const char kMetricsCollectorServiceName[] =
     29     "android.brillo.metrics.IMetricsCollectorService";
     30 }
     31 
     32 bool MetricsCollectorServiceClient::Init() {
     33   const android::String16 name(kMetricsCollectorServiceName);
     34   metrics_collector_service_ = android::interface_cast<
     35       android::brillo::metrics::IMetricsCollectorService>(
     36       android::defaultServiceManager()->checkService(name));
     37 
     38   if (metrics_collector_service_ == nullptr)
     39     LOG(ERROR) << "Unable to lookup service " << kMetricsCollectorServiceName;
     40 
     41   return metrics_collector_service_ != nullptr;
     42 }
     43 
     44 bool MetricsCollectorServiceClient::notifyUserCrash() {
     45   if (metrics_collector_service_ == nullptr)
     46     return false;
     47 
     48   metrics_collector_service_->notifyUserCrash();
     49   return true;
     50 }
     51