blob: cdf5ad50e6a30fb38f73af696237120c83197956 [file] [log] [blame]
keunyoungca515072015-07-10 12:21:47 -07001/*
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
17package com.android.car;
18
Keun-young Parke54ac272016-02-16 19:02:18 -080019import android.car.hardware.CarSensorEvent;
20import android.car.hardware.CarSensorManager;
keunyoungca515072015-07-10 12:21:47 -070021import android.content.Context;
Keun-young Park05f44812016-02-10 15:32:48 -080022import android.util.Log;
keunyoungca515072015-07-10 12:21:47 -070023
keunyoungca515072015-07-10 12:21:47 -070024import java.io.PrintWriter;
25
26//TODO
27public class DayNightModePolicy extends CarSensorService.LogicalSensorHalBase {
28
29 private final Context mContext;
30 private SensorListener mSensorListener;
31 private boolean mIsReady = false;
32 private boolean mStarted = false;
33
34 public DayNightModePolicy(Context context) {
35 mContext = context;
36 }
37
38 @Override
39 public synchronized void init() {
40 mIsReady = true;
41 }
42
43 @Override
44 public synchronized void release() {
45 // TODO Auto-generated method stub
46 }
47
keunyoung1ab8e182015-09-24 09:25:22 -070048 public static CarSensorEvent getDefaultValue(int sensorType) {
Pavel Maltsevdfccc5a2016-04-11 21:56:04 -070049 // There's a race condition and timestamp from vehicle HAL could be slightly less
50 // then current call to SystemClock.elapsedRealtimeNanos() will return.
51 // We want vehicle HAL value always override this default value so we set timestamp to 0.
52 return createEvent(true /* isNight */, 0 /* timestamp */);
keunyoungca515072015-07-10 12:21:47 -070053 }
54
55 @Override
56 public synchronized void registerSensorListener(SensorListener listener) {
57 mSensorListener = listener;
keunyoungca515072015-07-10 12:21:47 -070058 }
59
60 @Override
61 public synchronized void onSensorServiceReady() {
62 // TODO Auto-generated method stub
63 }
64
65 @Override
66 public synchronized boolean isReady() {
67 return mIsReady;
68 }
69
70 @Override
71 public synchronized int[] getSupportedSensors() {
72 // TODO Auto-generated method stub
73 return null;
74 }
75
76 @Override
77 public synchronized boolean requestSensorStart(int sensorType, int rate) {
78 mStarted = true;
79 // TODO Auto-generated method stub
Keun-young Park05f44812016-02-10 15:32:48 -080080 Log.w(CarLog.TAG_SENSOR,
81 "DayNightModePolicy.requestSensorStart, default policy not implemented");
keunyoungca515072015-07-10 12:21:47 -070082 return false;
83 }
84
85 @Override
86 public synchronized void requestSensorStop(int sensorType) {
87 // TODO Auto-generated method stub
88 }
89
Pavel Maltsevdfccc5a2016-04-11 21:56:04 -070090 private static CarSensorEvent createEvent(boolean isNight, long timestamp) {
keunyoung1ab8e182015-09-24 09:25:22 -070091 CarSensorEvent event = new CarSensorEvent(CarSensorManager.SENSOR_TYPE_NIGHT,
Pavel Maltsevdfccc5a2016-04-11 21:56:04 -070092 timestamp, 0, 1);
keunyoung1ab8e182015-09-24 09:25:22 -070093 event.intValues[0] = isNight ? 1 : 0;
94 return event;
95 }
96
keunyoungca515072015-07-10 12:21:47 -070097 @Override
98 public synchronized void dump(PrintWriter writer) {
99 // TODO Auto-generated method stub
100 }
101}