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