• 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 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
70     @ExcludeFromCodeCoverageGeneratedReport(reason = DUMP_INFO)
dump(IndentingPrintWriter writer)71     public void dump(IndentingPrintWriter writer) {
72         boolean isActive = mController.isGarageModeActive();
73         writer.println("GarageModeInProgress " + isActive);
74         mController.dump(writer);
75     }
76 
77     /**
78      * @return whether GarageMode is in progress. Used by {@link com.android.car.ICarImpl}.
79      */
isGarageModeActive()80     public boolean isGarageModeActive() {
81         return mController.isGarageModeActive();
82     }
83 
84     /**
85      * Forces GarageMode to start. Used by {@link com.android.car.ICarImpl}.
86      */
forceStartGarageMode()87     public void forceStartGarageMode() {
88         mController.initiateGarageMode(null);
89     }
90 
91     /**
92      * Stops and resets the GarageMode. Used by {@link com.android.car.ICarImpl}.
93      */
stopAndResetGarageMode()94     public void stopAndResetGarageMode() {
95         mController.resetGarageMode();
96     }
97 }
98