Keun-young Park | d73afae | 2016-04-08 20:03:32 -0700 | [diff] [blame] | 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 | |
Keun-young Park | d73afae | 2016-04-08 20:03:32 -0700 | [diff] [blame] | 18 | import android.content.Context; |
Keun-young Park | 3cb8910 | 2016-05-05 13:16:03 -0700 | [diff] [blame] | 19 | import android.content.res.Resources; |
Keun-young Park | d73afae | 2016-04-08 20:03:32 -0700 | [diff] [blame] | 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; |
Keun-young Park | 3cb8910 | 2016-05-05 13:16:03 -0700 | [diff] [blame] | 31 | private final CarAudioService mCarAudioService; |
Keun-young Park | 5ce1c8a | 2016-04-11 16:56:16 -0700 | [diff] [blame] | 32 | private final ICarImpl mICarImpl; |
Keun-young Park | 3cb8910 | 2016-05-05 13:16:03 -0700 | [diff] [blame] | 33 | private final boolean mLockWhenMuting; |
Keun-young Park | d73afae | 2016-04-08 20:03:32 -0700 | [diff] [blame] | 34 | |
| 35 | public SystemStateControllerService(Context context, |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 36 | CarPowerManagementService carPowerManagementService, |
Keun-young Park | 3cb8910 | 2016-05-05 13:16:03 -0700 | [diff] [blame] | 37 | CarAudioService carAudioService, ICarImpl carImpl) { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 38 | mCarPowerManagementService = carPowerManagementService; |
Keun-young Park | 3cb8910 | 2016-05-05 13:16:03 -0700 | [diff] [blame] | 39 | mCarAudioService = carAudioService; |
Keun-young Park | 5ce1c8a | 2016-04-11 16:56:16 -0700 | [diff] [blame] | 40 | mICarImpl = carImpl; |
Keun-young Park | 3cb8910 | 2016-05-05 13:16:03 -0700 | [diff] [blame] | 41 | Resources res = context.getResources(); |
| 42 | mLockWhenMuting = res.getBoolean(R.bool.displayOffMuteLockAllAudio); |
Keun-young Park | d73afae | 2016-04-08 20:03:32 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public long onPrepareShutdown(boolean shuttingDown) { |
Keun-young Park | f921520 | 2016-10-10 12:34:08 -0700 | [diff] [blame] | 47 | //TODO add state saving here for things to restore on power on. bug: 32096079 |
Keun-young Park | d73afae | 2016-04-08 20:03:32 -0700 | [diff] [blame] | 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public void onPowerOn(boolean displayOn) { |
| 53 | if (displayOn) { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 54 | Log.i(CarLog.TAG_SYS, "Media unmute"); |
| 55 | mCarAudioService.unMuteMedia(); |
Keun-young Park | d73afae | 2016-04-08 20:03:32 -0700 | [diff] [blame] | 56 | } else { |
Pavel Maltsev | 0d07c76 | 2016-11-03 16:40:15 -0700 | [diff] [blame] | 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 |
Keun-young Park | d73afae | 2016-04-08 20:03:32 -0700 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public int getWakeupTime() { |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public void onShutdown() { |
Keun-young Park | f921520 | 2016-10-10 12:34:08 -0700 | [diff] [blame] | 70 | // TODO bug: 32096079 |
Keun-young Park | d73afae | 2016-04-08 20:03:32 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public void onSleepEntry() { |
Keun-young Park | f921520 | 2016-10-10 12:34:08 -0700 | [diff] [blame] | 75 | // TODO bug: 32096079 |
Keun-young Park | d73afae | 2016-04-08 20:03:32 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public void onSleepExit() { |
Keun-young Park | f921520 | 2016-10-10 12:34:08 -0700 | [diff] [blame] | 80 | // TODO bug: 32096079 |
Keun-young Park | d73afae | 2016-04-08 20:03:32 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public void init() { |
| 85 | mCarPowerManagementService.registerPowerEventListener(this); |
| 86 | mCarPowerManagementService.registerPowerEventProcessingHandler(this); |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public void release() { |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public void dump(PrintWriter writer) { |
Keun-young Park | d73afae | 2016-04-08 20:03:32 -0700 | [diff] [blame] | 95 | } |
| 96 | } |