2 * Copyright (C) 2017 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings.fuelgauge.anomaly.action;
19 import android.content.Context;
20 import android.support.annotation.VisibleForTesting;
22 import com.android.internal.logging.nano.MetricsProto;
23 import com.android.settings.fuelgauge.anomaly.Anomaly;
26 * Force stop and background check action for anomaly app, this action will
27 * 1. Force stop the app
28 * 2. Turn on background check
30 public class StopAndBackgroundCheckAction extends AnomalyAction {
32 ForceStopAction mForceStopAction;
34 BackgroundCheckAction mBackgroundCheckAction;
36 public StopAndBackgroundCheckAction(Context context) {
37 this(context, new ForceStopAction(context), new BackgroundCheckAction(context));
38 mActionMetricKey = MetricsProto.MetricsEvent.ACTION_APP_STOP_AND_BACKGROUND_CHECK;
42 StopAndBackgroundCheckAction(Context context, ForceStopAction forceStopAction,
43 BackgroundCheckAction backgroundCheckAction) {
45 mForceStopAction = forceStopAction;
46 mBackgroundCheckAction = backgroundCheckAction;
50 public void handlePositiveAction(Anomaly anomaly, int metricsKey) {
51 super.handlePositiveAction(anomaly, metricsKey);
52 mForceStopAction.handlePositiveAction(anomaly, metricsKey);
53 mBackgroundCheckAction.handlePositiveAction(anomaly, metricsKey);
57 public boolean isActionActive(Anomaly anomaly) {
58 return mForceStopAction.isActionActive(anomaly)
59 && mBackgroundCheckAction.isActionActive(anomaly);
63 public int getActionType() {
64 return Anomaly.AnomalyActionType.STOP_AND_BACKGROUND_CHECK;