Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit db62b521 authored by Lei Yu's avatar Lei Yu Committed by android-build-merger
Browse files

Merge "Add location check action for bt anomaly" into oc-dr1-dev am: a6b24388

am: 91dbfc6e

Change-Id: Ib7f5560b4ef44cb14bcf5e3633b09d179816b221
parents c6769468 91dbfc6e
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -4672,11 +4672,11 @@
    <!-- Title for location dialog [CHAR LIMIT=60] -->
    <string name="dialog_location_title">Turn off location?</string>
    <!-- Message body for location dialog [CHAR LIMIT=NONE] -->
    <string name="dialog_location_message" product="default">Your phone cant manage battery normally because <xliff:g id="app">%1$s</xliff:g> keeps requesting your location when you're not using the app.\n\nTo fix this issue, you can turn off location for this app.</string>
    <string name="dialog_location_message" product="default">Your phone can\'t manage battery normally because <xliff:g id="app">%1$s</xliff:g> keeps requesting your location when you\'re not using the app.\n\nTo fix this issue, you can turn off location for this app.</string>
    <!-- Message body for location dialog [CHAR LIMIT=NONE] -->
    <string name="dialog_location_message" product="tablet">Your tablet cant manage battery normally because <xliff:g id="app">%1$s</xliff:g> keeps requesting your location when you're not using the app.\n\nTo fix this issue, you can turn off location for this app.</string>
    <string name="dialog_location_message" product="tablet">Your tablet can\'t manage battery normally because <xliff:g id="app">%1$s</xliff:g> keeps requesting your location when you\'re not using the app.\n\nTo fix this issue, you can turn off location for this app.</string>
    <!-- Message body for location dialog [CHAR LIMIT=NONE] -->
    <string name="dialog_location_message" product="device">Your device cant manage battery normally because <xliff:g id="app">%1$s</xliff:g> keeps requesting your location when you're not using the app.\n\nTo fix this issue, you can turn off location for this app.</string>
    <string name="dialog_location_message" product="device">Your device can\'t manage battery normally because <xliff:g id="app">%1$s</xliff:g> keeps requesting your location when you\'re not using the app.\n\nTo fix this issue, you can turn off location for this app.</string>
    <!-- Text for OK button in location dialog [CHAR LIMIT=30] -->
    <string name="dialog_location_ok">Turn off</string>
+3 −1
Original line number Diff line number Diff line
@@ -45,10 +45,12 @@ public class Anomaly implements Parcelable {

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({AnomalyActionType.FORCE_STOP,
            AnomalyActionType.BACKGROUND_CHECK})
            AnomalyActionType.BACKGROUND_CHECK,
            AnomalyActionType.LOCATION_CHECK})
    public @interface AnomalyActionType {
        int FORCE_STOP = 0;
        int BACKGROUND_CHECK = 1;
        int LOCATION_CHECK = 2;
    }

    @AnomalyType
+15 −1
Original line number Diff line number Diff line
@@ -38,7 +38,8 @@ public class AnomalyDialogFragment extends InstrumentedDialogFragment implements

    @VisibleForTesting
    Anomaly mAnomaly;
    private AnomalyUtils mAnomalyUtils;
    @VisibleForTesting
    AnomalyUtils mAnomalyUtils;

    /**
     * Listener to give the control back to target fragment
@@ -68,6 +69,11 @@ public class AnomalyDialogFragment extends InstrumentedDialogFragment implements
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initAnomalyUtils();
    }

    @VisibleForTesting
    void initAnomalyUtils() {
        mAnomalyUtils = AnomalyUtils.getInstance(getContext());
    }

@@ -114,6 +120,14 @@ public class AnomalyDialogFragment extends InstrumentedDialogFragment implements
                        .setPositiveButton(R.string.dialog_background_check_ok, this)
                        .setNegativeButton(R.string.dlg_cancel, null)
                        .create();
            case Anomaly.AnomalyActionType.LOCATION_CHECK:
                return new AlertDialog.Builder(context)
                        .setTitle(R.string.dialog_location_title)
                        .setMessage(getString(R.string.dialog_location_message,
                                mAnomaly.displayName))
                        .setPositiveButton(R.string.dialog_location_ok, this)
                        .setNegativeButton(R.string.dlg_cancel, null)
                        .create();
            default:
                throw new IllegalArgumentException("unknown type " + mAnomaly.type);
        }
+3 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.support.annotation.VisibleForTesting;
import com.android.settings.fuelgauge.anomaly.action.AnomalyAction;
import com.android.settings.fuelgauge.anomaly.action.BackgroundCheckAction;
import com.android.settings.fuelgauge.anomaly.action.ForceStopAction;
import com.android.settings.fuelgauge.anomaly.action.LocationCheckAction;
import com.android.settings.fuelgauge.anomaly.checker.AnomalyDetector;
import com.android.settings.fuelgauge.anomaly.checker.BluetoothScanAnomalyDetector;
import com.android.settings.fuelgauge.anomaly.checker.WakeLockAnomalyDetector;
@@ -57,8 +58,9 @@ public class AnomalyUtils {
            case Anomaly.AnomalyType.WAKE_LOCK:
                return new ForceStopAction(mContext);
            case Anomaly.AnomalyType.WAKEUP_ALARM:
            case Anomaly.AnomalyType.BLUETOOTH_SCAN:
                return new BackgroundCheckAction(mContext);
            case Anomaly.AnomalyType.BLUETOOTH_SCAN:
                return new LocationCheckAction(mContext);
            default:
                return null;
        }
+59 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.fuelgauge.anomaly.action;

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.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 {

    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;
        mRuntimePermissionPresenter = RuntimePermissionPresenter.getInstance(context);
    }

    @Override
    public void handlePositiveAction(Anomaly anomaly, int metricsKey) {
        mRuntimePermissionPresenter.revokeRuntimePermission(anomaly.packageName,
                LOCATION_PERMISSION);
    }

    @Override
    public boolean isActionActive(Anomaly anomaly) {
        return PermissionChecker.checkPermission(mContext, LOCATION_PERMISSION, -1, anomaly.uid,
                anomaly.packageName) == PermissionChecker.PERMISSION_GRANTED;
    }

    @Override
    public int getActionType() {
        return Anomaly.AnomalyActionType.LOCATION_CHECK;
    }
}
Loading