Home | History | Annotate | Download | only in action
      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 
     17 package com.android.settings.fuelgauge.anomaly.action;
     18 
     19 import android.content.Context;
     20 import android.util.Pair;
     21 
     22 import com.android.internal.logging.nano.MetricsProto;
     23 import com.android.settings.fuelgauge.anomaly.Anomaly;
     24 import com.android.settings.overlay.FeatureFactory;
     25 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
     26 
     27 /**
     28  * Abstract class for anomaly action, which is triggered if we need to handle the anomaly
     29  */
     30 public abstract class AnomalyAction {
     31     protected Context mContext;
     32     protected int mActionMetricKey;
     33 
     34     private MetricsFeatureProvider mMetricsFeatureProvider;
     35 
     36     public AnomalyAction(Context context) {
     37         mContext = context;
     38         mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
     39     }
     40 
     41     /**
     42      * handle the action when user clicks positive button
     43      *
     44      * @param anomaly    about the app that we need to handle
     45      * @param contextMetricsKey key for the page that invokes the action
     46      * @see com.android.internal.logging.nano.MetricsProto
     47      */
     48     public void handlePositiveAction(Anomaly anomaly, int contextMetricsKey) {
     49         mMetricsFeatureProvider.action(mContext, mActionMetricKey, anomaly.packageName,
     50                 Pair.create(MetricsProto.MetricsEvent.FIELD_CONTEXT, contextMetricsKey));
     51     }
     52 
     53     /**
     54      * Check whether the action is active for {@code anomaly}
     55      *
     56      * @param anomaly about the app that we need to handle
     57      * @return {@code true} if action is active, otherwise return {@code false}
     58      */
     59     public abstract boolean isActionActive(Anomaly anomaly);
     60 
     61     @Anomaly.AnomalyActionType
     62     public abstract int getActionType();
     63 }
     64