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.Car; 20 import android.car.hardware.CarSensorEvent; 21 import android.car.hardware.CarSensorManager; 22 import android.content.Context; 23 import android.os.SystemClock; 24 import android.util.Log; 25 26 import com.android.car.hal.SensorHalServiceBase.SensorListener; 27 28 import java.io.PrintWriter; 29 30 //TODO 31 public class DayNightModePolicy extends CarSensorService.LogicalSensorHalBase { 32 33 private final Context mContext; 34 private SensorListener mSensorListener; 35 private boolean mIsReady = false; 36 private boolean mStarted = false; 37 DayNightModePolicy(Context context)38 public DayNightModePolicy(Context context) { 39 mContext = context; 40 } 41 42 @Override init()43 public synchronized void init() { 44 mIsReady = true; 45 } 46 47 @Override release()48 public synchronized void release() { 49 // TODO Auto-generated method stub 50 } 51 getDefaultValue(int sensorType)52 public static CarSensorEvent getDefaultValue(int sensorType) { 53 return createEvent(true /* isNight */); 54 } 55 56 @Override registerSensorListener(SensorListener listener)57 public synchronized void registerSensorListener(SensorListener listener) { 58 mSensorListener = listener; 59 if (mIsReady) { 60 mSensorListener.onSensorHalReady(this); 61 } 62 } 63 64 @Override onSensorServiceReady()65 public synchronized void onSensorServiceReady() { 66 // TODO Auto-generated method stub 67 } 68 69 @Override isReady()70 public synchronized boolean isReady() { 71 return mIsReady; 72 } 73 74 @Override getSupportedSensors()75 public synchronized int[] getSupportedSensors() { 76 // TODO Auto-generated method stub 77 return null; 78 } 79 80 @Override requestSensorStart(int sensorType, int rate)81 public synchronized boolean requestSensorStart(int sensorType, int rate) { 82 mStarted = true; 83 // TODO Auto-generated method stub 84 Log.w(CarLog.TAG_SENSOR, 85 "DayNightModePolicy.requestSensorStart, default policy not implemented"); 86 return false; 87 } 88 89 @Override requestSensorStop(int sensorType)90 public synchronized void requestSensorStop(int sensorType) { 91 // TODO Auto-generated method stub 92 } 93 createEvent(boolean isNight)94 private static CarSensorEvent createEvent(boolean isNight) { 95 CarSensorEvent event = new CarSensorEvent(CarSensorManager.SENSOR_TYPE_NIGHT, 96 SystemClock.elapsedRealtimeNanos(), 0, 1); 97 event.intValues[0] = isNight ? 1 : 0; 98 return event; 99 } 100 101 @Override dump(PrintWriter writer)102 public synchronized void dump(PrintWriter writer) { 103 // TODO Auto-generated method stub 104 } 105 } 106