• 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 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> jobs = mController.pendingGarageModeJobs();
74         if (isActive) {
75             writer.println("GarageMode is currently waiting for " + jobs.size() + " jobs:");
76         } else {
77             writer.println("GarageMode was last waiting for " + jobs.size() + " jobs:");
78         }
79         // Dump the names of the jobs that GM is/was waiting for
80         int jobNumber = 1;
81         for (String job : jobs) {
82             writer.println("   " + jobNumber + ": " + job);
83             jobNumber++;
84         }
85     }
86 
87     /**
88      * @return whether GarageMode is in progress. Used by {@link com.android.car.ICarImpl}.
89      */
isGarageModeActive()90     public boolean isGarageModeActive() {
91         return mController.isGarageModeActive();
92     }
93 
94     /**
95      * Forces GarageMode to start. Used by {@link com.android.car.ICarImpl}.
96      */
forceStartGarageMode()97     public void forceStartGarageMode() {
98         mController.initiateGarageMode(null);
99     }
100 
101     /**
102      * Stops and resets the GarageMode. Used by {@link com.android.car.ICarImpl}.
103      */
stopAndResetGarageMode()104     public void stopAndResetGarageMode() {
105         mController.resetGarageMode();
106     }
107 }
108