blob: 63821c50f37d4dfd03e8394f09045e02baecf43a [file] [log] [blame]
Keun-young Parkd73afae2016-04-08 20:03:32 -07001/*
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 */
16package com.android.car;
17
Keun-young Parkd73afae2016-04-08 20:03:32 -070018import android.content.Context;
Keun-young Park3cb89102016-05-05 13:16:03 -070019import android.content.res.Resources;
Keun-young Parkd73afae2016-04-08 20:03:32 -070020import android.util.Log;
21
22import com.android.car.CarPowerManagementService.PowerEventProcessingHandler;
23import com.android.car.CarPowerManagementService.PowerServiceEventListener;
24
25import java.io.PrintWriter;
26
27public class SystemStateControllerService implements CarServiceBase,
28 PowerServiceEventListener, PowerEventProcessingHandler {
29
30 private final CarPowerManagementService mCarPowerManagementService;
Keun-young Park3cb89102016-05-05 13:16:03 -070031 private final CarAudioService mCarAudioService;
Keun-young Park5ce1c8a2016-04-11 16:56:16 -070032 private final ICarImpl mICarImpl;
Keun-young Park3cb89102016-05-05 13:16:03 -070033 private final boolean mLockWhenMuting;
Keun-young Parkd73afae2016-04-08 20:03:32 -070034
35 public SystemStateControllerService(Context context,
Pavel Maltsev0d07c762016-11-03 16:40:15 -070036 CarPowerManagementService carPowerManagementService,
Keun-young Park3cb89102016-05-05 13:16:03 -070037 CarAudioService carAudioService, ICarImpl carImpl) {
Pavel Maltsev0d07c762016-11-03 16:40:15 -070038 mCarPowerManagementService = carPowerManagementService;
Keun-young Park3cb89102016-05-05 13:16:03 -070039 mCarAudioService = carAudioService;
Keun-young Park5ce1c8a2016-04-11 16:56:16 -070040 mICarImpl = carImpl;
Keun-young Park3cb89102016-05-05 13:16:03 -070041 Resources res = context.getResources();
42 mLockWhenMuting = res.getBoolean(R.bool.displayOffMuteLockAllAudio);
Keun-young Parkd73afae2016-04-08 20:03:32 -070043 }
44
45 @Override
46 public long onPrepareShutdown(boolean shuttingDown) {
Keun-young Parkf9215202016-10-10 12:34:08 -070047 //TODO add state saving here for things to restore on power on. bug: 32096079
Keun-young Parkd73afae2016-04-08 20:03:32 -070048 return 0;
49 }
50
51 @Override
52 public void onPowerOn(boolean displayOn) {
53 if (displayOn) {
Pavel Maltsev0d07c762016-11-03 16:40:15 -070054 Log.i(CarLog.TAG_SYS, "Media unmute");
55 mCarAudioService.unMuteMedia();
Keun-young Parkd73afae2016-04-08 20:03:32 -070056 } else {
Pavel Maltsev0d07c762016-11-03 16:40:15 -070057 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 Parkd73afae2016-04-08 20:03:32 -070060 }
61 }
62
63 @Override
64 public int getWakeupTime() {
65 return 0;
66 }
67
68 @Override
69 public void onShutdown() {
Keun-young Parkf9215202016-10-10 12:34:08 -070070 // TODO bug: 32096079
Keun-young Parkd73afae2016-04-08 20:03:32 -070071 }
72
73 @Override
74 public void onSleepEntry() {
Keun-young Parkf9215202016-10-10 12:34:08 -070075 // TODO bug: 32096079
Keun-young Parkd73afae2016-04-08 20:03:32 -070076 }
77
78 @Override
79 public void onSleepExit() {
Keun-young Parkf9215202016-10-10 12:34:08 -070080 // TODO bug: 32096079
Keun-young Parkd73afae2016-04-08 20:03:32 -070081 }
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 Parkd73afae2016-04-08 20:03:32 -070095 }
96}