blob: 8e7f8635e1b484e73210e792835d1373db431753 [file] [log] [blame]
Enrico Granatab19bc322017-10-12 12:25:06 -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 */
16
17package com.android.car.systeminterface;
18
19import android.content.Context;
Steve Paik87b36fd2018-03-13 19:25:47 -070020
Enrico Granatab19bc322017-10-12 12:25:06 -070021import com.android.car.CarPowerManagementService;
Enrico Granatae23f0342017-10-23 17:17:52 -070022import com.android.car.procfsinspector.ProcessInfo;
Enrico Granata1690a622018-01-22 17:34:46 -080023import com.android.car.storagemonitoring.LifetimeWriteInfoProvider;
Enrico Granatab19bc322017-10-12 12:25:06 -070024import com.android.car.storagemonitoring.UidIoStatsProvider;
25import com.android.car.storagemonitoring.WearInformationProvider;
Steve Paik0f9fc002018-02-09 17:42:00 -080026import com.android.internal.car.ICarServiceHelper;
Steve Paik87b36fd2018-03-13 19:25:47 -070027
Enrico Granatab19bc322017-10-12 12:25:06 -070028import java.io.File;
29import java.time.Duration;
Enrico Granatae23f0342017-10-23 17:17:52 -070030import java.util.List;
Enrico Granatab19bc322017-10-12 12:25:06 -070031import java.util.Objects;
32
33/**
34 * This class contains references to all the different wrapper interfaces between
35 * CarService and the Android OS APIs.
36 */
Gregory Clarka440e812019-02-14 16:05:51 -080037public class SystemInterface implements DisplayInterface, IOInterface,
Enrico Granatab19bc322017-10-12 12:25:06 -070038 StorageMonitoringInterface, SystemStateInterface, TimeInterface,
39 WakeLockInterface {
40 private final DisplayInterface mDisplayInterface;
41 private final IOInterface mIOInterface;
42 private final StorageMonitoringInterface mStorageMonitoringInterface;
43 private final SystemStateInterface mSystemStateInterface;
44 private final TimeInterface mTimeInterface;
45 private final WakeLockInterface mWakeLockInterface;
46
47 SystemInterface(DisplayInterface displayInterface,
48 IOInterface ioInterface,
49 StorageMonitoringInterface storageMonitoringInterface,
50 SystemStateInterface systemStateInterface,
51 TimeInterface timeInterface,
52 WakeLockInterface wakeLockInterface) {
53 mDisplayInterface = displayInterface;
54 mIOInterface = ioInterface;
55 mStorageMonitoringInterface = storageMonitoringInterface;
56 mSystemStateInterface = systemStateInterface;
57 mTimeInterface = timeInterface;
58 mWakeLockInterface = wakeLockInterface;
59 }
60
61 public DisplayInterface getDisplayInterface() { return mDisplayInterface; }
62 public IOInterface getIOInterface() { return mIOInterface; }
63 public SystemStateInterface getSystemStateInterface() { return mSystemStateInterface; }
64 public TimeInterface getTimeInterface() { return mTimeInterface; }
65 public WakeLockInterface getWakeLockInterface() { return mWakeLockInterface; }
Steve Paik0f9fc002018-02-09 17:42:00 -080066 public void setCarServiceHelper(ICarServiceHelper helper) {
67 mSystemStateInterface.setCarServiceHelper(helper);
68 }
Enrico Granatab19bc322017-10-12 12:25:06 -070069
70 @Override
Keun-young Park760fffb2019-02-11 17:43:00 -080071 public File getSystemCarDir() {
72 return mIOInterface.getSystemCarDir();
Enrico Granatab19bc322017-10-12 12:25:06 -070073 }
74
75 @Override
76 public void releaseAllWakeLocks() {
77 mWakeLockInterface.releaseAllWakeLocks();
78 }
79
80 @Override
81 public void switchToPartialWakeLock() {
82 mWakeLockInterface.switchToPartialWakeLock();
83 }
84
85 @Override
86 public void switchToFullWakeLock() {
87 mWakeLockInterface.switchToFullWakeLock();
88 }
89
90 @Override
91 public long getUptime() {
92 return mTimeInterface.getUptime();
93 }
94
95 @Override
96 public long getUptime(boolean includeDeepSleepTime) {
97 return mTimeInterface.getUptime(includeDeepSleepTime);
98 }
99
100 @Override
101 public void scheduleAction(Runnable r, long delayMs) {
102 mTimeInterface.scheduleAction(r, delayMs);
103 }
104
105 @Override
Enrico Granatae23f0342017-10-23 17:17:52 -0700106 public List<ProcessInfo> getRunningProcesses() {
107 return mSystemStateInterface.getRunningProcesses();
108 }
109
110 @Override
Enrico Granatab19bc322017-10-12 12:25:06 -0700111 public void cancelAllActions() {
112 mTimeInterface.cancelAllActions();
113 }
114
115 @Override
Steve Paik87b36fd2018-03-13 19:25:47 -0700116 public void setDisplayBrightness(int brightness) {
117 mDisplayInterface.setDisplayBrightness(brightness);
118 }
119
120 @Override
Enrico Granatab19bc322017-10-12 12:25:06 -0700121 public void setDisplayState(boolean on) {
122 mDisplayInterface.setDisplayState(on);
123 }
124
125 @Override
Keun young Parkfd2afc92019-06-07 14:55:20 -0700126 public void reconfigureSecondaryDisplays() {
127 mDisplayInterface.reconfigureSecondaryDisplays();
128 }
129
130 @Override
Enrico Granatab19bc322017-10-12 12:25:06 -0700131 public void startDisplayStateMonitoring(CarPowerManagementService service) {
132 mDisplayInterface.startDisplayStateMonitoring(service);
133 }
134
135 @Override
136 public void stopDisplayStateMonitoring() {
137 mDisplayInterface.stopDisplayStateMonitoring();
138 }
139
140 @Override
141 public WearInformationProvider[] getFlashWearInformationProviders() {
142 return mStorageMonitoringInterface.getFlashWearInformationProviders();
143 }
144
145 @Override
146 public UidIoStatsProvider getUidIoStatsProvider() {
147 return mStorageMonitoringInterface.getUidIoStatsProvider();
148 }
149
150 @Override
Enrico Granata1690a622018-01-22 17:34:46 -0800151 public LifetimeWriteInfoProvider getLifetimeWriteInfoProvider() {
152 return mStorageMonitoringInterface.getLifetimeWriteInfoProvider();
153 }
154
155 @Override
Enrico Granatab19bc322017-10-12 12:25:06 -0700156 public void shutdown() {
157 mSystemStateInterface.shutdown();
158 }
159
160 @Override
Steve Paik07db5ed2018-09-24 16:48:52 -0700161 public boolean enterDeepSleep() {
162 return mSystemStateInterface.enterDeepSleep();
Enrico Granatab19bc322017-10-12 12:25:06 -0700163 }
164
165 @Override
166 public void scheduleActionForBootCompleted(Runnable action, Duration delay) {
167 mSystemStateInterface.scheduleActionForBootCompleted(action, delay);
168 }
169
170 @Override
171 public boolean isWakeupCausedByTimer() {
172 return mSystemStateInterface.isWakeupCausedByTimer();
173 }
174
175 @Override
176 public boolean isSystemSupportingDeepSleep() {
177 return mSystemStateInterface.isSystemSupportingDeepSleep();
178 }
179
Serik Beketayev74debf22018-10-04 12:18:09 -0700180 @Override
181 public void refreshDisplayBrightness() {
182 mDisplayInterface.refreshDisplayBrightness();
183 }
184
Enrico Granatab19bc322017-10-12 12:25:06 -0700185 public final static class Builder {
186 private DisplayInterface mDisplayInterface;
187 private IOInterface mIOInterface;
188 private StorageMonitoringInterface mStorageMonitoringInterface;
189 private SystemStateInterface mSystemStateInterface;
190 private TimeInterface mTimeInterface;
191 private WakeLockInterface mWakeLockInterface;
192
193 private Builder() {}
194
195 public static Builder newSystemInterface() {
196 return new Builder();
197 }
198
199 public static Builder defaultSystemInterface(Context context) {
Andreas Gampe7ca53cc2018-01-28 13:40:32 -0800200 Objects.requireNonNull(context);
Enrico Granatab19bc322017-10-12 12:25:06 -0700201 Builder builder = newSystemInterface();
202 builder.withWakeLockInterface(new WakeLockInterface.DefaultImpl(context));
203 builder.withDisplayInterface(new DisplayInterface.DefaultImpl(context,
204 builder.mWakeLockInterface));
205 builder.withIOInterface(new IOInterface.DefaultImpl(context));
206 builder.withStorageMonitoringInterface(new StorageMonitoringInterface.DefaultImpl());
207 builder.withSystemStateInterface(new SystemStateInterface.DefaultImpl(context));
208 return builder.withTimeInterface(new TimeInterface.DefaultImpl());
209 }
210
211 public static Builder fromBuilder(Builder otherBuilder) {
212 return newSystemInterface()
213 .withDisplayInterface(otherBuilder.mDisplayInterface)
214 .withIOInterface(otherBuilder.mIOInterface)
215 .withStorageMonitoringInterface(otherBuilder.mStorageMonitoringInterface)
216 .withSystemStateInterface(otherBuilder.mSystemStateInterface)
217 .withTimeInterface(otherBuilder.mTimeInterface)
218 .withWakeLockInterface(otherBuilder.mWakeLockInterface);
219 }
220
221 public Builder withDisplayInterface(DisplayInterface displayInterface) {
222 mDisplayInterface = displayInterface;
223 return this;
224 }
225
226 public Builder withIOInterface(IOInterface ioInterface) {
227 mIOInterface = ioInterface;
228 return this;
229 }
230
231 public Builder withStorageMonitoringInterface(StorageMonitoringInterface
232 storageMonitoringInterface) {
233 mStorageMonitoringInterface = storageMonitoringInterface;
234 return this;
235 }
236
237 public Builder withSystemStateInterface(SystemStateInterface systemStateInterface) {
238 mSystemStateInterface = systemStateInterface;
239 return this;
240 }
241
242 public Builder withTimeInterface(TimeInterface timeInterface) {
243 mTimeInterface = timeInterface;
244 return this;
245 }
246
247 public Builder withWakeLockInterface(WakeLockInterface wakeLockInterface) {
248 mWakeLockInterface = wakeLockInterface;
249 return this;
250 }
251
252 public SystemInterface build() {
253 return new SystemInterface(Objects.requireNonNull(mDisplayInterface),
254 Objects.requireNonNull(mIOInterface),
255 Objects.requireNonNull(mStorageMonitoringInterface),
256 Objects.requireNonNull(mSystemStateInterface),
257 Objects.requireNonNull(mTimeInterface),
258 Objects.requireNonNull(mWakeLockInterface));
259 }
260 }
261}