• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.car;
18 
19 import android.car.hardware.CarSensorEvent;
20 import android.car.hardware.CarSensorManager;
21 import android.content.Context;
22 import android.util.Log;
23 
24 import com.android.car.hal.SensorHalService.SensorListener;
25 import java.io.PrintWriter;
26 
27 //TODO implement default one based on time or other sensors. bug: 32066909
28 public class DayNightModePolicy extends CarSensorService.LogicalSensor {
29 
30     private final Context mContext;
31     private SensorListener mSensorListener;
32     private boolean mIsReady = false;
33     private boolean mStarted = false;
34 
35     private static final int[] SUPPORTED_SENSORS = { CarSensorManager.SENSOR_TYPE_NIGHT };
36 
DayNightModePolicy(Context context)37     public DayNightModePolicy(Context context) {
38         mContext = context;
39     }
40 
41     @Override
init()42     public synchronized void init() {
43         mIsReady = true;
44     }
45 
46     @Override
release()47     public synchronized void release() {
48     }
49 
getDefaultValue(int sensorType)50     public static CarSensorEvent getDefaultValue(int sensorType) {
51         // There's a race condition and timestamp from vehicle HAL could be slightly less
52         // then current call to SystemClock.elapsedRealtimeNanos() will return.
53         // We want vehicle HAL value always override this default value so we set timestamp to 0.
54         return createEvent(true /* isNight */, 0 /* timestamp */);
55     }
56 
registerSensorListener(SensorListener listener)57     public synchronized void registerSensorListener(SensorListener listener) {
58         mSensorListener = listener;
59     }
60 
61     @Override
onSensorServiceReady()62     public synchronized void onSensorServiceReady() {
63     }
64 
65     @Override
isReady()66     public synchronized boolean isReady() {
67         return mIsReady;
68     }
69 
70     @Override
getSupportedSensors()71     public synchronized int[] getSupportedSensors() {
72         return SUPPORTED_SENSORS;
73     }
74 
75     @Override
requestSensorStart(int sensorType, int rate)76     public synchronized boolean requestSensorStart(int sensorType, int rate) {
77         mStarted = true;
78         Log.w(CarLog.TAG_SENSOR,
79                 "DayNightModePolicy.requestSensorStart, default policy not implemented");
80         return false;
81     }
82 
83     @Override
requestSensorStop(int sensorType)84     public synchronized void requestSensorStop(int sensorType) {
85     }
86 
createEvent(boolean isNight, long timestamp)87     private static CarSensorEvent createEvent(boolean isNight, long timestamp) {
88         CarSensorEvent event = new CarSensorEvent(CarSensorManager.SENSOR_TYPE_NIGHT,
89                 timestamp, 0, 1);
90         event.intValues[0] = isNight ? 1 : 0;
91         return event;
92     }
93 
94     @Override
dump(PrintWriter writer)95     public synchronized void dump(PrintWriter writer) {
96     }
97 }
98