1 /*
2  * Copyright (C) 2019 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 package com.android.experimentalcar;
18 
19 import android.car.experimental.DriverAwarenessEvent;
20 import android.car.experimental.DriverAwarenessSupplierService;
21 import android.content.Intent;
22 import android.os.IBinder;
23 import android.os.SystemClock;
24 import android.util.Log;
25 
26 /**
27  * Simple example of how an external driver awareness supplier service could be implemented.
28  */
29 public class SampleExternalDriverAwarenessSupplier extends DriverAwarenessSupplierService {
30 
31     private static final String TAG = "SampleExternalDriverAwarenessSupplier";
32     private static final float INITIAL_DRIVER_AWARENESS_VALUE = 1.0f;
33     private static final long MAX_STALENESS_MILLIS = 100L;
34 
35     @Override
getMaxStalenessMillis()36     public long getMaxStalenessMillis() {
37         return MAX_STALENESS_MILLIS;
38     }
39 
40     @Override
onReady()41     public void onReady() {
42         // send an initial event, as required by the IDriverAwarenessSupplierCallback spec
43         onDriverAwarenessUpdated(new DriverAwarenessEvent(SystemClock.elapsedRealtime(),
44                 INITIAL_DRIVER_AWARENESS_VALUE));
45     }
46 
47     @Override
onBind(Intent intent)48     public IBinder onBind(Intent intent) {
49         logd("onBind, intent: " + intent);
50         return super.onBind(intent);
51     }
52 
logd(String message)53     private static void logd(String message) {
54         if (Log.isLoggable(TAG, Log.DEBUG)) {
55             Log.d(TAG, message);
56         }
57     }
58 }
59