Enrico Granata | b19bc32 | 2017-10-12 12:25:06 -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 | |
| 17 | package com.android.car.systeminterface; |
| 18 | |
| 19 | import android.content.Context; |
Steve Paik | 87b36fd | 2018-03-13 19:25:47 -0700 | [diff] [blame] | 20 | |
Enrico Granata | b19bc32 | 2017-10-12 12:25:06 -0700 | [diff] [blame] | 21 | import com.android.car.CarPowerManagementService; |
Enrico Granata | e23f034 | 2017-10-23 17:17:52 -0700 | [diff] [blame] | 22 | import com.android.car.procfsinspector.ProcessInfo; |
Enrico Granata | 1690a62 | 2018-01-22 17:34:46 -0800 | [diff] [blame] | 23 | import com.android.car.storagemonitoring.LifetimeWriteInfoProvider; |
Enrico Granata | b19bc32 | 2017-10-12 12:25:06 -0700 | [diff] [blame] | 24 | import com.android.car.storagemonitoring.UidIoStatsProvider; |
| 25 | import com.android.car.storagemonitoring.WearInformationProvider; |
Steve Paik | 0f9fc00 | 2018-02-09 17:42:00 -0800 | [diff] [blame] | 26 | import com.android.internal.car.ICarServiceHelper; |
Steve Paik | 87b36fd | 2018-03-13 19:25:47 -0700 | [diff] [blame] | 27 | |
Enrico Granata | b19bc32 | 2017-10-12 12:25:06 -0700 | [diff] [blame] | 28 | import java.io.File; |
| 29 | import java.time.Duration; |
Enrico Granata | e23f034 | 2017-10-23 17:17:52 -0700 | [diff] [blame] | 30 | import java.util.List; |
Enrico Granata | b19bc32 | 2017-10-12 12:25:06 -0700 | [diff] [blame] | 31 | import 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 Clark | a440e81 | 2019-02-14 16:05:51 -0800 | [diff] [blame] | 37 | public class SystemInterface implements DisplayInterface, IOInterface, |
Enrico Granata | b19bc32 | 2017-10-12 12:25:06 -0700 | [diff] [blame] | 38 | 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 Paik | 0f9fc00 | 2018-02-09 17:42:00 -0800 | [diff] [blame] | 66 | public void setCarServiceHelper(ICarServiceHelper helper) { |
| 67 | mSystemStateInterface.setCarServiceHelper(helper); |
| 68 | } |
Enrico Granata | b19bc32 | 2017-10-12 12:25:06 -0700 | [diff] [blame] | 69 | |
| 70 | @Override |
Keun-young Park | 760fffb | 2019-02-11 17:43:00 -0800 | [diff] [blame] | 71 | public File getSystemCarDir() { |
| 72 | return mIOInterface.getSystemCarDir(); |
Enrico Granata | b19bc32 | 2017-10-12 12:25:06 -0700 | [diff] [blame] | 73 | } |
| 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 Granata | e23f034 | 2017-10-23 17:17:52 -0700 | [diff] [blame] | 106 | public List<ProcessInfo> getRunningProcesses() { |
| 107 | return mSystemStateInterface.getRunningProcesses(); |
| 108 | } |
| 109 | |
| 110 | @Override |
Enrico Granata | b19bc32 | 2017-10-12 12:25:06 -0700 | [diff] [blame] | 111 | public void cancelAllActions() { |
| 112 | mTimeInterface.cancelAllActions(); |
| 113 | } |
| 114 | |
| 115 | @Override |
Steve Paik | 87b36fd | 2018-03-13 19:25:47 -0700 | [diff] [blame] | 116 | public void setDisplayBrightness(int brightness) { |
| 117 | mDisplayInterface.setDisplayBrightness(brightness); |
| 118 | } |
| 119 | |
| 120 | @Override |
Enrico Granata | b19bc32 | 2017-10-12 12:25:06 -0700 | [diff] [blame] | 121 | public void setDisplayState(boolean on) { |
| 122 | mDisplayInterface.setDisplayState(on); |
| 123 | } |
| 124 | |
| 125 | @Override |
Keun young Park | fd2afc9 | 2019-06-07 14:55:20 -0700 | [diff] [blame] | 126 | public void reconfigureSecondaryDisplays() { |
| 127 | mDisplayInterface.reconfigureSecondaryDisplays(); |
| 128 | } |
| 129 | |
| 130 | @Override |
Enrico Granata | b19bc32 | 2017-10-12 12:25:06 -0700 | [diff] [blame] | 131 | 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 Granata | 1690a62 | 2018-01-22 17:34:46 -0800 | [diff] [blame] | 151 | public LifetimeWriteInfoProvider getLifetimeWriteInfoProvider() { |
| 152 | return mStorageMonitoringInterface.getLifetimeWriteInfoProvider(); |
| 153 | } |
| 154 | |
| 155 | @Override |
Enrico Granata | b19bc32 | 2017-10-12 12:25:06 -0700 | [diff] [blame] | 156 | public void shutdown() { |
| 157 | mSystemStateInterface.shutdown(); |
| 158 | } |
| 159 | |
| 160 | @Override |
Steve Paik | 07db5ed | 2018-09-24 16:48:52 -0700 | [diff] [blame] | 161 | public boolean enterDeepSleep() { |
| 162 | return mSystemStateInterface.enterDeepSleep(); |
Enrico Granata | b19bc32 | 2017-10-12 12:25:06 -0700 | [diff] [blame] | 163 | } |
| 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 Beketayev | 74debf2 | 2018-10-04 12:18:09 -0700 | [diff] [blame] | 180 | @Override |
| 181 | public void refreshDisplayBrightness() { |
| 182 | mDisplayInterface.refreshDisplayBrightness(); |
| 183 | } |
| 184 | |
Enrico Granata | b19bc32 | 2017-10-12 12:25:06 -0700 | [diff] [blame] | 185 | 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 Gampe | 7ca53cc | 2018-01-28 13:40:32 -0800 | [diff] [blame] | 200 | Objects.requireNonNull(context); |
Enrico Granata | b19bc32 | 2017-10-12 12:25:06 -0700 | [diff] [blame] | 201 | 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 | } |