1 /* 2 * Copyright (C) 2018 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.garagemode; 18 19 import android.content.Context; 20 import android.os.Looper; 21 import android.util.IndentingPrintWriter; 22 23 import com.android.car.CarServiceBase; 24 import com.android.internal.annotations.VisibleForTesting; 25 26 /** 27 * Main service container for car Garage Mode. 28 * Garage Mode enables idle time in cars. 29 */ 30 public class GarageModeService implements CarServiceBase { 31 32 private final Context mContext; 33 private final Controller mController; 34 GarageModeService(Context context)35 public GarageModeService(Context context) { 36 this(context, null); 37 } 38 39 @VisibleForTesting GarageModeService(Context context, Controller controller)40 protected GarageModeService(Context context, Controller controller) { 41 mContext = context; 42 mController = (controller != null ? controller 43 : new Controller(context, Looper.myLooper())); 44 } 45 46 /** 47 * Initializes GarageMode 48 */ 49 @Override init()50 public void init() { 51 mController.init(); 52 } 53 54 /** 55 * Cleans up GarageMode processes 56 */ 57 @Override release()58 public void release() { 59 mController.release(); 60 } 61 62 /** 63 * Dumps useful information about GarageMode 64 * @param writer Where to dump the information 65 */ 66 @Override dump(IndentingPrintWriter writer)67 public void dump(IndentingPrintWriter writer) { 68 boolean isActive = mController.isGarageModeActive(); 69 writer.println("GarageModeInProgress " + isActive); 70 mController.dump(writer); 71 } 72 73 /** 74 * @return whether GarageMode is in progress. Used by {@link com.android.car.ICarImpl}. 75 */ isGarageModeActive()76 public boolean isGarageModeActive() { 77 return mController.isGarageModeActive(); 78 } 79 80 /** 81 * Forces GarageMode to start. Used by {@link com.android.car.ICarImpl}. 82 */ forceStartGarageMode()83 public void forceStartGarageMode() { 84 mController.initiateGarageMode(null); 85 } 86 87 /** 88 * Stops and resets the GarageMode. Used by {@link com.android.car.ICarImpl}. 89 */ stopAndResetGarageMode()90 public void stopAndResetGarageMode() { 91 mController.resetGarageMode(); 92 } 93 } 94