1 /* 2 * Copyright (C) 2016 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 package com.android.car; 17 18 import android.content.Context; 19 import android.content.res.Resources; 20 import android.util.Log; 21 22 import com.android.car.CarPowerManagementService.PowerEventProcessingHandler; 23 import com.android.car.CarPowerManagementService.PowerServiceEventListener; 24 25 import java.io.PrintWriter; 26 27 public class SystemStateControllerService implements CarServiceBase, 28 PowerServiceEventListener, PowerEventProcessingHandler { 29 30 private final CarPowerManagementService mCarPowerManagementService; 31 private final CarAudioService mCarAudioService; 32 private final ICarImpl mICarImpl; 33 private final boolean mLockWhenMuting; 34 SystemStateControllerService(Context context, CarPowerManagementService carPowerManagementService, CarAudioService carAudioService, ICarImpl carImpl)35 public SystemStateControllerService(Context context, 36 CarPowerManagementService carPowerManagementService, 37 CarAudioService carAudioService, ICarImpl carImpl) { 38 mCarPowerManagementService = carPowerManagementService; 39 mCarAudioService = carAudioService; 40 mICarImpl = carImpl; 41 Resources res = context.getResources(); 42 mLockWhenMuting = res.getBoolean(R.bool.displayOffMuteLockAllAudio); 43 } 44 45 @Override onPrepareShutdown(boolean shuttingDown)46 public long onPrepareShutdown(boolean shuttingDown) { 47 //TODO add state saving here for things to restore on power on. bug: 32096079 48 return 0; 49 } 50 51 @Override onPowerOn(boolean displayOn)52 public void onPowerOn(boolean displayOn) { 53 if (displayOn) { 54 Log.i(CarLog.TAG_SYS, "Media unmute"); 55 mCarAudioService.unMuteMedia(); 56 } else { 57 Log.i(CarLog.TAG_SYS, "Media mute"); 58 mCarAudioService.muteMediaWithLock(mLockWhenMuting); 59 //TODO store last context and resume or silence radio on display on. bug: 32096079 60 } 61 } 62 63 @Override getWakeupTime()64 public int getWakeupTime() { 65 return 0; 66 } 67 68 @Override onShutdown()69 public void onShutdown() { 70 // TODO bug: 32096079 71 } 72 73 @Override onSleepEntry()74 public void onSleepEntry() { 75 // TODO bug: 32096079 76 } 77 78 @Override onSleepExit()79 public void onSleepExit() { 80 // TODO bug: 32096079 81 } 82 83 @Override init()84 public void init() { 85 mCarPowerManagementService.registerPowerEventListener(this); 86 mCarPowerManagementService.registerPowerEventProcessingHandler(this); 87 } 88 89 @Override release()90 public void release() { 91 } 92 93 @Override dump(PrintWriter writer)94 public void dump(PrintWriter writer) { 95 } 96 } 97