1/* 2 * Copyright (C) 2017 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 17package com.android.settings.fuelgauge.anomaly.action; 18 19import android.content.Context; 20import android.support.annotation.VisibleForTesting; 21 22import com.android.internal.logging.nano.MetricsProto; 23import com.android.settings.fuelgauge.anomaly.Anomaly; 24 25/** 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 29 */ 30public class StopAndBackgroundCheckAction extends AnomalyAction { 31 @VisibleForTesting 32 ForceStopAction mForceStopAction; 33 @VisibleForTesting 34 BackgroundCheckAction mBackgroundCheckAction; 35 36 public StopAndBackgroundCheckAction(Context context) { 37 this(context, new ForceStopAction(context), new BackgroundCheckAction(context)); 38 mActionMetricKey = MetricsProto.MetricsEvent.ACTION_APP_STOP_AND_BACKGROUND_CHECK; 39 } 40 41 @VisibleForTesting 42 StopAndBackgroundCheckAction(Context context, ForceStopAction forceStopAction, 43 BackgroundCheckAction backgroundCheckAction) { 44 super(context); 45 mForceStopAction = forceStopAction; 46 mBackgroundCheckAction = backgroundCheckAction; 47 } 48 49 @Override 50 public void handlePositiveAction(Anomaly anomaly, int metricsKey) { 51 super.handlePositiveAction(anomaly, metricsKey); 52 mForceStopAction.handlePositiveAction(anomaly, metricsKey); 53 mBackgroundCheckAction.handlePositiveAction(anomaly, metricsKey); 54 } 55 56 @Override 57 public boolean isActionActive(Anomaly anomaly) { 58 return mForceStopAction.isActionActive(anomaly) 59 && mBackgroundCheckAction.isActionActive(anomaly); 60 } 61 62 @Override 63 public int getActionType() { 64 return Anomaly.AnomalyActionType.STOP_AND_BACKGROUND_CHECK; 65 } 66} 67