blob: b68e020f94d1f1856bab609122e28154a10f33e6 [file] [log] [blame]
Max Dashoukff9ffbc2021-02-16 11:36:39 -08001/*
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 */
16package com.android.car.telemetry;
17
Rui Qiuf6668202021-04-08 15:37:20 -070018import android.annotation.NonNull;
19import android.car.Car;
20import android.car.telemetry.ICarTelemetryService;
21import android.car.telemetry.ICarTelemetryServiceListener;
22import android.content.Context;
Max Dashoukff9ffbc2021-02-16 11:36:39 -080023import android.util.IndentingPrintWriter;
Rui Qiuf6668202021-04-08 15:37:20 -070024import android.util.Slog;
Max Dashoukff9ffbc2021-02-16 11:36:39 -080025
26import com.android.car.CarServiceBase;
27
28/**
29 * CarTelemetryService manages OEM telemetry collection, processing and communication
30 * with a data upload service.
31 */
Rui Qiuf6668202021-04-08 15:37:20 -070032public class CarTelemetryService extends ICarTelemetryService.Stub implements CarServiceBase {
Max Dashoukff9ffbc2021-02-16 11:36:39 -080033
Rui Qiuf6668202021-04-08 15:37:20 -070034 private static final boolean DEBUG = false;
35 private static final String TAG = CarTelemetryService.class.getSimpleName();
36
37 private final Context mContext;
38
39 private ICarTelemetryServiceListener mListener;
40
41 public CarTelemetryService(Context context) {
42 mContext = context;
Max Dashoukff9ffbc2021-02-16 11:36:39 -080043 }
44
45 @Override
46 public void init() {
Rui Qiuf6668202021-04-08 15:37:20 -070047 // nothing to do
Max Dashoukff9ffbc2021-02-16 11:36:39 -080048 }
49
50 @Override
51 public void release() {
Rui Qiuf6668202021-04-08 15:37:20 -070052 // nothing to do
Max Dashoukff9ffbc2021-02-16 11:36:39 -080053 }
54
55 @Override
56 public void dump(IndentingPrintWriter writer) {
57 writer.println("Car Telemetry service");
58 }
Rui Qiuf6668202021-04-08 15:37:20 -070059
60 /**
61 * Registers a listener with CarTelemetryService for the service to send data to cloud app.
62 */
63 @Override
64 public void setListener(@NonNull ICarTelemetryServiceListener listener) {
65 // TODO(b/150978930): verify that only a hardcoded app can set the listener
66 mContext.enforceCallingOrSelfPermission(
67 Car.PERMISSION_USE_CAR_TELEMETRY_SERVICE, "setListener");
68 if (DEBUG) {
69 Slog.d(TAG, "Setting the listener for car telemetry service");
70 }
71 mListener = listener;
72 }
73
74 /**
75 * Clears the listener registered with CarTelemetryService.
76 */
77 @Override
78 public void clearListener() {
79 mContext.enforceCallingOrSelfPermission(
80 Car.PERMISSION_USE_CAR_TELEMETRY_SERVICE, "setListener");
81 if (DEBUG) {
82 Slog.d(TAG, "Clearing listener");
83 }
84 mListener = null;
85 }
Max Dashoukff9ffbc2021-02-16 11:36:39 -080086}