Add metric action log for anomaly action
Change AnomalyAction to abstract class and log the action there. Bug: 37681923 Test: RunSettingsRoboTests Change-Id: Ied7a269d4a3f8fcb978165af6e17a9c9952fea49
This commit is contained in:
@@ -16,26 +16,47 @@
|
||||
|
||||
package com.android.settings.fuelgauge.anomaly.action;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.fuelgauge.anomaly.Anomaly;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
/**
|
||||
* Interface for anomaly action, which is triggered if we need to handle the anomaly
|
||||
* Abstract class for anomaly action, which is triggered if we need to handle the anomaly
|
||||
*/
|
||||
public interface AnomalyAction {
|
||||
public abstract class AnomalyAction {
|
||||
protected Context mContext;
|
||||
protected int mActionMetricKey;
|
||||
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
|
||||
public AnomalyAction(Context context) {
|
||||
mContext = context;
|
||||
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
||||
}
|
||||
|
||||
/**
|
||||
* handle the action when user clicks positive button
|
||||
* @param anomaly about the app that we need to handle
|
||||
* @param metricsKey key for the page that invokes the action
|
||||
*
|
||||
* @param anomaly about the app that we need to handle
|
||||
* @param contextMetricsKey key for the page that invokes the action
|
||||
* @see com.android.internal.logging.nano.MetricsProto
|
||||
*/
|
||||
void handlePositiveAction(Anomaly anomaly, int metricsKey);
|
||||
public void handlePositiveAction(Anomaly anomaly, int contextMetricsKey) {
|
||||
mMetricsFeatureProvider.action(mContext, mActionMetricKey, anomaly.packageName,
|
||||
Pair.create(MetricsProto.MetricsEvent.FIELD_CONTEXT, contextMetricsKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the action is active for {@code anomaly}
|
||||
*
|
||||
* @param anomaly about the app that we need to handle
|
||||
* @return {@code true} if action is active, otherwise return {@code false}
|
||||
*/
|
||||
boolean isActionActive(Anomaly anomaly);
|
||||
int getActionType();
|
||||
public abstract boolean isActionActive(Anomaly anomaly);
|
||||
|
||||
public abstract int getActionType();
|
||||
}
|
||||
|
@@ -19,28 +19,26 @@ package com.android.settings.fuelgauge.anomaly.action;
|
||||
import android.app.AppOpsManager;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.fuelgauge.anomaly.Anomaly;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
/**
|
||||
* Background check action for anomaly app, which means to stop app running in the background
|
||||
*/
|
||||
public class BackgroundCheckAction implements AnomalyAction {
|
||||
public class BackgroundCheckAction extends AnomalyAction {
|
||||
|
||||
private Context mContext;
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private AppOpsManager mAppOpsManager;
|
||||
|
||||
public BackgroundCheckAction(Context context) {
|
||||
mContext = context;
|
||||
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
||||
super(context);
|
||||
mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
|
||||
mActionMetricKey = MetricsProto.MetricsEvent.ACTION_APP_BACKGROUND_CHECK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePositiveAction(Anomaly anomaly, int metricsKey) {
|
||||
// TODO(b/37681923): add metric log here if possible
|
||||
public void handlePositiveAction(Anomaly anomaly, int contextMetricsKey) {
|
||||
super.handlePositiveAction(anomaly, contextMetricsKey);
|
||||
|
||||
mAppOpsManager.setMode(AppOpsManager.OP_RUN_IN_BACKGROUND, anomaly.uid, anomaly.packageName,
|
||||
AppOpsManager.MODE_IGNORED);
|
||||
}
|
||||
|
@@ -21,43 +21,32 @@ import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.fuelgauge.anomaly.Anomaly;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Force stop action for anomaly app, which means to stop the app which causes anomaly
|
||||
*/
|
||||
public class ForceStopAction implements AnomalyAction {
|
||||
public class ForceStopAction extends AnomalyAction {
|
||||
private static final String TAG = "ForceStopAction";
|
||||
|
||||
private Context mContext;
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private ActivityManager mActivityManager;
|
||||
private PackageManager mPackageManager;
|
||||
|
||||
public ForceStopAction(Context context) {
|
||||
mContext = context;
|
||||
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
||||
super(context);
|
||||
mActivityManager = (ActivityManager) context.getSystemService(
|
||||
Context.ACTIVITY_SERVICE);
|
||||
mPackageManager = context.getPackageManager();
|
||||
mActionMetricKey = MetricsProto.MetricsEvent.ACTION_APP_FORCE_STOP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePositiveAction(Anomaly anomaly, int metricsKey) {
|
||||
final String packageName = anomaly.packageName;
|
||||
// force stop the package
|
||||
mMetricsFeatureProvider.action(mContext,
|
||||
MetricsProto.MetricsEvent.ACTION_APP_FORCE_STOP, packageName,
|
||||
Pair.create(MetricsProto.MetricsEvent.FIELD_CONTEXT, metricsKey));
|
||||
public void handlePositiveAction(Anomaly anomaly, int contextMetricsKey) {
|
||||
super.handlePositiveAction(anomaly, contextMetricsKey);
|
||||
|
||||
mActivityManager.forceStopPackage(packageName);
|
||||
mActivityManager.forceStopPackage(anomaly.packageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -20,28 +20,28 @@ import android.content.Context;
|
||||
import android.content.pm.permission.RuntimePermissionPresenter;
|
||||
import android.support.v4.content.PermissionChecker;
|
||||
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.fuelgauge.anomaly.Anomaly;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
/**
|
||||
* Location action for anomaly app, which means to turn off location permission for this app
|
||||
*/
|
||||
public class LocationCheckAction implements AnomalyAction {
|
||||
public class LocationCheckAction extends AnomalyAction {
|
||||
|
||||
private static final String TAG = "LocationCheckAction";
|
||||
private static final String LOCATION_PERMISSION = "android.permission-group.LOCATION";
|
||||
|
||||
private final Context mContext;
|
||||
private final RuntimePermissionPresenter mRuntimePermissionPresenter;
|
||||
|
||||
public LocationCheckAction(Context context) {
|
||||
mContext = context;
|
||||
super(context);
|
||||
mRuntimePermissionPresenter = RuntimePermissionPresenter.getInstance(context);
|
||||
mActionMetricKey = MetricsProto.MetricsEvent.ACTION_APP_LOCATION_CHECK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePositiveAction(Anomaly anomaly, int metricsKey) {
|
||||
public void handlePositiveAction(Anomaly anomaly, int contextMetricsKey) {
|
||||
super.handlePositiveAction(anomaly, contextMetricsKey);
|
||||
mRuntimePermissionPresenter.revokeRuntimePermission(anomaly.packageName,
|
||||
LOCATION_PERMISSION);
|
||||
}
|
||||
|
Reference in New Issue
Block a user