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