Files
packages_apps_Settings/src/com/android/settings/fuelgauge/anomaly/AnomalyPreferenceController.java
jackqdyulei df6dd14799 Framework for the anomaly detection.
This cl adds the following components for anomaly dection:
1. AnomalyLoader: run all the anomaly checks in the background
2. Anomaly: Data class to represent what anomaly it is
3. Detector: Different kinds of anomaly detector with common interface
4. Action:  Suggestions when facing anomaly(Force stop, uninstall)
5. AnomalyDialogFragment: show the confirm dialog for action
6. AnomalyPreferenceController: handle update and click for
anomalyPreference, since it will be used in multiple fragments.
7. AnomalyUtils: utility class for anomaly

This cl also adds skeleton for the wakelock check and action. Following
cls will add real implementation about it.

Bug: 36924669
Test: RunSettingsRoboTests
Change-Id: I89fc4b6963757869b93791b4275ca53c04ab9604
2017-05-01 16:03:09 -07:00

77 lines
2.8 KiB
Java

/*
* 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;
import android.support.annotation.VisibleForTesting;
import android.support.v14.preference.PreferenceFragment;
import android.support.v7.preference.Preference;
import java.util.List;
/**
* Manager that responsible for updating anomaly preference and handling preference click.
*/
public class AnomalyPreferenceController {
private static final String TAG = "AnomalyPreferenceController";
@VisibleForTesting
static final String ANOMALY_KEY = "high_usage";
private static final int REQUEST_ANOMALY_ACTION = 0;
private PreferenceFragment mFragment;
@VisibleForTesting
Preference mAnomalyPreference;
@VisibleForTesting
List<Anomaly> mAnomalies;
public AnomalyPreferenceController(PreferenceFragment fragment) {
mFragment = fragment;
mAnomalyPreference = mFragment.getPreferenceScreen().findPreference(ANOMALY_KEY);
hideAnomalyPreference();
}
public boolean onPreferenceTreeClick(Preference preference) {
if (mAnomalies != null && ANOMALY_KEY.equals(preference.getKey())) {
if (mAnomalies.size() == 1) {
final Anomaly anomaly = mAnomalies.get(0);
AnomalyDialogFragment dialogFragment = AnomalyDialogFragment.newInstance(anomaly);
dialogFragment.setTargetFragment(mFragment, REQUEST_ANOMALY_ACTION);
dialogFragment.show(mFragment.getFragmentManager(), TAG);
} else {
//TODO(b/37681665): start a new fragment to handle it
}
return true;
}
return false;
}
/**
* Update anomaly preference based on {@code anomalies}, also store a reference
* of {@paramref anomalies}, which would be used in {@link #onPreferenceTreeClick(Preference)}
*
* @param anomalies used to update the summary, this method will store a reference of it
*/
public void updateAnomalyPreference(List<Anomaly> anomalies) {
mAnomalies = anomalies;
mAnomalyPreference.setVisible(true);
//TODO(b/36924669): update summary for anomaly preference
}
public void hideAnomalyPreference() {
mAnomalyPreference.setVisible(false);
}
}