Add new method to get URI to monitor battery history data is updated
we will reload the database battery history data if its content is changed, which can be done through monitored the database content observer (a part of this patch cl/383366685) Bug: 192613268 Test: make SettingsRoboTests Change-Id: I24ab154b1dfa00ca4bf4e6f7b308f5061578bcb5
This commit is contained in:
@@ -19,8 +19,11 @@ import android.app.settings.SettingsEnums;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.database.ContentObserver;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.BatteryManager;
|
import android.os.BatteryManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -31,6 +34,7 @@ import androidx.loader.content.Loader;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
|
import com.android.settings.fuelgauge.BatteryBroadcastReceiver;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
@@ -63,6 +67,17 @@ public class PowerUsageAdvanced extends PowerUsageBase {
|
|||||||
private BatteryChartPreferenceController mBatteryChartPreferenceController;
|
private BatteryChartPreferenceController mBatteryChartPreferenceController;
|
||||||
private BatteryAppListPreferenceController mBatteryAppListPreferenceController;
|
private BatteryAppListPreferenceController mBatteryAppListPreferenceController;
|
||||||
|
|
||||||
|
private final ContentObserver mBatteryObserver =
|
||||||
|
new ContentObserver(new Handler()) {
|
||||||
|
@Override
|
||||||
|
public void onChange(boolean selfChange) {
|
||||||
|
Log.d(TAG, "onBatteryContentChange: " + selfChange);
|
||||||
|
mIsChartDataLoaded = false;
|
||||||
|
restartBatteryStatsLoader(
|
||||||
|
BatteryBroadcastReceiver.BatteryUpdateType.MANUAL);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
@@ -104,6 +119,20 @@ public class PowerUsageAdvanced extends PowerUsageBase {
|
|||||||
super.onPause();
|
super.onPause();
|
||||||
// Resets the flag to reload usage data in onResume() callback.
|
// Resets the flag to reload usage data in onResume() callback.
|
||||||
mIsChartDataLoaded = false;
|
mIsChartDataLoaded = false;
|
||||||
|
final Uri uri = mPowerUsageFeatureProvider.getBatteryHistoryUri();
|
||||||
|
if (uri != null) {
|
||||||
|
getContext().getContentResolver().unregisterContentObserver(mBatteryObserver);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
final Uri uri = mPowerUsageFeatureProvider.getBatteryHistoryUri();
|
||||||
|
if (uri != null) {
|
||||||
|
getContext().getContentResolver().registerContentObserver(
|
||||||
|
uri, /*notifyForDescendants*/ true, mBatteryObserver);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -18,6 +18,7 @@ package com.android.settings.fuelgauge;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
import android.util.SparseIntArray;
|
import android.util.SparseIntArray;
|
||||||
|
|
||||||
import com.android.internal.os.BatterySipper;
|
import com.android.internal.os.BatterySipper;
|
||||||
@@ -141,4 +142,9 @@ public interface PowerUsageFeatureProvider {
|
|||||||
* Returns battery history data with corresponding timestamp key.
|
* Returns battery history data with corresponding timestamp key.
|
||||||
*/
|
*/
|
||||||
Map<Long, Map<String, BatteryHistEntry>> getBatteryHistory(Context context);
|
Map<Long, Map<String, BatteryHistEntry>> getBatteryHistory(Context context);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@link Uri} to monitor battery history data is update.
|
||||||
|
*/
|
||||||
|
Uri getBatteryHistoryUri();
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,7 @@ package com.android.settings.fuelgauge;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.util.SparseIntArray;
|
import android.util.SparseIntArray;
|
||||||
|
|
||||||
@@ -167,4 +168,9 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
|
|||||||
public Map<Long, Map<String, BatteryHistEntry>> getBatteryHistory(Context context) {
|
public Map<Long, Map<String, BatteryHistEntry>> getBatteryHistory(Context context) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Uri getBatteryHistoryUri() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user