blob: 74f450974d8d77835e3d5c1912971a05d522b0a1 [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 Qiu9bc1bb92021-04-08 15:41:48 -070018import static android.car.telemetry.CarTelemetryManager.ERROR_NONE;
19
Rui Qiuf6668202021-04-08 15:37:20 -070020import android.annotation.NonNull;
21import android.car.Car;
Rui Qiu9bc1bb92021-04-08 15:41:48 -070022import android.car.telemetry.CarTelemetryManager.AddManifestError;
Rui Qiuf6668202021-04-08 15:37:20 -070023import android.car.telemetry.ICarTelemetryService;
24import android.car.telemetry.ICarTelemetryServiceListener;
Rui Qiu9bc1bb92021-04-08 15:41:48 -070025import android.car.telemetry.ManifestKey;
Rui Qiuf6668202021-04-08 15:37:20 -070026import android.content.Context;
Max Dashoukff9ffbc2021-02-16 11:36:39 -080027import android.util.IndentingPrintWriter;
Rui Qiuf6668202021-04-08 15:37:20 -070028import android.util.Slog;
Max Dashoukff9ffbc2021-02-16 11:36:39 -080029
30import com.android.car.CarServiceBase;
31
32/**
33 * CarTelemetryService manages OEM telemetry collection, processing and communication
34 * with a data upload service.
35 */
Rui Qiuf6668202021-04-08 15:37:20 -070036public class CarTelemetryService extends ICarTelemetryService.Stub implements CarServiceBase {
Max Dashoukff9ffbc2021-02-16 11:36:39 -080037
Rui Qiuf6668202021-04-08 15:37:20 -070038 private static final boolean DEBUG = false;
39 private static final String TAG = CarTelemetryService.class.getSimpleName();
40
41 private final Context mContext;
42
43 private ICarTelemetryServiceListener mListener;
44
45 public CarTelemetryService(Context context) {
46 mContext = context;
Max Dashoukff9ffbc2021-02-16 11:36:39 -080047 }
48
49 @Override
50 public void init() {
Rui Qiuf6668202021-04-08 15:37:20 -070051 // nothing to do
Max Dashoukff9ffbc2021-02-16 11:36:39 -080052 }
53
54 @Override
55 public void release() {
Rui Qiuf6668202021-04-08 15:37:20 -070056 // nothing to do
Max Dashoukff9ffbc2021-02-16 11:36:39 -080057 }
58
59 @Override
60 public void dump(IndentingPrintWriter writer) {
61 writer.println("Car Telemetry service");
62 }
Rui Qiuf6668202021-04-08 15:37:20 -070063
64 /**
65 * Registers a listener with CarTelemetryService for the service to send data to cloud app.
66 */
67 @Override
68 public void setListener(@NonNull ICarTelemetryServiceListener listener) {
Rui Qiu9bc1bb92021-04-08 15:41:48 -070069 // TODO(b/184890506): verify that only a hardcoded app can set the listener
Rui Qiuf6668202021-04-08 15:37:20 -070070 mContext.enforceCallingOrSelfPermission(
71 Car.PERMISSION_USE_CAR_TELEMETRY_SERVICE, "setListener");
72 if (DEBUG) {
73 Slog.d(TAG, "Setting the listener for car telemetry service");
74 }
75 mListener = listener;
76 }
77
78 /**
79 * Clears the listener registered with CarTelemetryService.
80 */
81 @Override
82 public void clearListener() {
83 mContext.enforceCallingOrSelfPermission(
84 Car.PERMISSION_USE_CAR_TELEMETRY_SERVICE, "setListener");
85 if (DEBUG) {
86 Slog.d(TAG, "Clearing listener");
87 }
88 mListener = null;
89 }
Rui Qiu9bc1bb92021-04-08 15:41:48 -070090
91 /**
92 * Allows client to send telemetry manifests.
93 *
94 * @param key the unique key to identify the manifest.
95 * @param manifest the serialized bytes of a Manifest object.
96 * @return {@link AddManifestError} the error code.
97 */
98 @Override
99 public @AddManifestError int addManifest(@NonNull ManifestKey key, @NonNull byte[] manifest) {
100 // TODO(b/184087869): Implement
101 mContext.enforceCallingOrSelfPermission(
102 Car.PERMISSION_USE_CAR_TELEMETRY_SERVICE, "setListener");
103 if (DEBUG) {
104 Slog.d(TAG, "Adding manifest to car telemetry service");
105 }
106 return ERROR_NONE;
107 }
108
109 /**
110 * Removes a manifest based on the key.
111 */
112 @Override
113 public boolean removeManifest(@NonNull ManifestKey key) {
114 // TODO(b/184087869): Implement
115 mContext.enforceCallingOrSelfPermission(
116 Car.PERMISSION_USE_CAR_TELEMETRY_SERVICE, "setListener");
117 if (DEBUG) {
118 Slog.d(TAG, "Removing manifest from car telemetry service");
119 }
120 return true;
121 }
122
123 /**
124 * Removes all manifests.
125 */
126 @Override
127 public void removeAllManifests() {
128 // TODO(b/184087869): Implement
129 mContext.enforceCallingOrSelfPermission(
130 Car.PERMISSION_USE_CAR_TELEMETRY_SERVICE, "setListener");
131 if (DEBUG) {
132 Slog.d(TAG, "Removing all manifest from car telemetry service");
133 }
134 }
135
136 /**
137 * Sends script results associated with the given key using the
138 * {@link ICarTelemetryServiceListener}.
139 */
140 @Override
141 public void sendFinishedReports(@NonNull ManifestKey key) {
142 // TODO(b/184087869): Implement
143 mContext.enforceCallingOrSelfPermission(
144 Car.PERMISSION_USE_CAR_TELEMETRY_SERVICE, "setListener");
145 if (DEBUG) {
146 Slog.d(TAG, "Flushing reports for a manifest");
147 }
148 }
149
150 /**
151 * Sends all script results associated using the {@link ICarTelemetryServiceListener}.
152 */
153 @Override
154 public void sendAllFinishedReports() {
155 // TODO(b/184087869): Implement
156 mContext.enforceCallingOrSelfPermission(
157 Car.PERMISSION_USE_CAR_TELEMETRY_SERVICE, "setListener");
158 if (DEBUG) {
159 Slog.d(TAG, "Flushing all reports");
160 }
161 }
162
163 /**
164 * Sends all errors using the {@link ICarTelemetryServiceListener}.
165 */
166 @Override
167 public void sendScriptExecutionErrors() {
168 // TODO(b/184087869): Implement
169 mContext.enforceCallingOrSelfPermission(
170 Car.PERMISSION_USE_CAR_TELEMETRY_SERVICE, "setListener");
171 if (DEBUG) {
172 Slog.d(TAG, "Flushing script execution errors");
173 }
174 }
Max Dashoukff9ffbc2021-02-16 11:36:39 -0800175}