Loading res/layout/battery_header.xml +1 −2 Original line number Diff line number Diff line Loading @@ -46,8 +46,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="12dp" android:textAppearance="@android:style/TextAppearance.Material.Small" android:text="@string/estimated_time_left"/> android:textAppearance="@android:style/TextAppearance.Material.Small"/> </LinearLayout> Loading src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java +2 −1 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import com.android.settings.Utils; import com.android.settings.applications.AppHeaderController; import com.android.settings.applications.LayoutPreference; import com.android.settings.core.PreferenceController; import com.android.settings.dashboard.DashboardFragment; import com.android.settings.enterprise.DevicePolicyManagerWrapper; import com.android.settings.enterprise.DevicePolicyManagerWrapperImpl; import com.android.settings.overlay.FeatureFactory; Loading @@ -56,7 +57,7 @@ import java.util.List; * 2. Battery related controls for app(i.e uninstall, force stop) * */ public class AdvancedPowerUsageDetail extends PowerUsageBase implements public class AdvancedPowerUsageDetail extends DashboardFragment implements ButtonActionDialogFragment.AppButtonsDialogListener { public static final String TAG = "AdvancedPowerUsageDetail"; Loading src/com/android/settings/fuelgauge/BatteryStatsHelperLoader.java 0 → 100644 +60 −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; import android.content.Context; import android.os.BatteryStats; import android.os.Bundle; import android.os.UserManager; import android.support.annotation.VisibleForTesting; import com.android.internal.os.BatteryStatsHelper; import com.android.settings.utils.AsyncLoader; /** * Loader to get new {@link BatteryStatsHelper} in the background */ public class BatteryStatsHelperLoader extends AsyncLoader<BatteryStatsHelper> { @VisibleForTesting UserManager mUserManager; private Bundle mBundle; public BatteryStatsHelperLoader(Context context, Bundle bundle) { super(context); mBundle = bundle; mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE); } @Override public BatteryStatsHelper loadInBackground() { final BatteryStatsHelper statsHelper = new BatteryStatsHelper(getContext(), true); initBatteryStatsHelper(statsHelper); return statsHelper; } @Override protected void onDiscardResult(BatteryStatsHelper result) { } @VisibleForTesting void initBatteryStatsHelper(BatteryStatsHelper statsHelper) { statsHelper.create(mBundle); statsHelper.refreshStats(BatteryStats.STATS_SINCE_CHARGED, mUserManager.getUserProfiles()); } } src/com/android/settings/fuelgauge/PowerUsageAdvanced.java +5 −3 Original line number Diff line number Diff line Loading @@ -126,7 +126,6 @@ public class PowerUsageAdvanced extends PowerUsageBase { @Override public void onResume() { super.onResume(); refreshStats(); } @Override Loading Loading @@ -165,8 +164,11 @@ public class PowerUsageAdvanced extends PowerUsageBase { } @Override protected void refreshStats() { super.refreshStats(); protected void refreshUi() { final Context context = getContext(); if (context == null) { return; } updatePreference(mHistPref); Loading src/com/android/settings/fuelgauge/PowerUsageBase.java +26 −35 Original line number Diff line number Diff line Loading @@ -16,28 +16,23 @@ package com.android.settings.fuelgauge; import android.app.Activity; import android.content.BroadcastReceiver; import android.app.LoaderManager; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.BatteryStats; import android.content.Loader; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.UserManager; import android.support.annotation.VisibleForTesting; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import com.android.internal.os.BatteryStatsHelper; import com.android.settings.R; import com.android.settings.dashboard.DashboardFragment; import com.android.settings.utils.AsyncLoader; /** * Common base class for things that need to show the battery usage graph. */ public abstract class PowerUsageBase extends DashboardFragment { public abstract class PowerUsageBase extends DashboardFragment implements LoaderManager.LoaderCallbacks<BatteryStatsHelper> { // +1 to allow ordering for PowerUsageSummary. @VisibleForTesting Loading @@ -62,27 +57,23 @@ public abstract class PowerUsageBase extends DashboardFragment { mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(getContext()); mBatteryBroadcastReceiver.setBatteryChangedListener(() -> { if (!mHandler.hasMessages(MSG_REFRESH_STATS)) { mHandler.sendEmptyMessageDelayed(MSG_REFRESH_STATS, 500); } getLoaderManager().restartLoader(0, null, this); }); getLoaderManager().initLoader(0, icicle, this); } @Override public void onStart() { super.onStart(); mStatsHelper.clearStats(); } @Override public void onResume() { super.onResume(); BatteryStatsHelper.dropFile(getActivity(), BatteryHistoryDetail.BATTERY_HISTORY_FILE); mBatteryBroadcastReceiver.register(); if (mHandler.hasMessages(MSG_REFRESH_STATS)) { mHandler.removeMessages(MSG_REFRESH_STATS); mStatsHelper.clearStats(); } } @Override Loading @@ -94,7 +85,6 @@ public abstract class PowerUsageBase extends DashboardFragment { @Override public void onStop() { super.onStop(); mHandler.removeMessages(MSG_REFRESH_STATS); } @Override Loading @@ -105,26 +95,27 @@ public abstract class PowerUsageBase extends DashboardFragment { } } protected void refreshStats() { mStatsHelper.refreshStats(BatteryStats.STATS_SINCE_CHARGED, mUm.getUserProfiles()); } protected abstract void refreshUi(); protected void updatePreference(BatteryHistoryPreference historyPref) { historyPref.setStats(mStatsHelper); } static final int MSG_REFRESH_STATS = 100; private final Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case MSG_REFRESH_STATS: mStatsHelper.clearStats(); refreshStats(); break; public Loader<BatteryStatsHelper> onCreateLoader(int id, Bundle args) { return new BatteryStatsHelperLoader(getContext(), args); } @Override public void onLoadFinished(Loader<BatteryStatsHelper> loader, BatteryStatsHelper statsHelper) { mStatsHelper = statsHelper; refreshUi(); } }; @Override public void onLoaderReset(Loader<BatteryStatsHelper> loader) { } } Loading
res/layout/battery_header.xml +1 −2 Original line number Diff line number Diff line Loading @@ -46,8 +46,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="12dp" android:textAppearance="@android:style/TextAppearance.Material.Small" android:text="@string/estimated_time_left"/> android:textAppearance="@android:style/TextAppearance.Material.Small"/> </LinearLayout> Loading
src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java +2 −1 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import com.android.settings.Utils; import com.android.settings.applications.AppHeaderController; import com.android.settings.applications.LayoutPreference; import com.android.settings.core.PreferenceController; import com.android.settings.dashboard.DashboardFragment; import com.android.settings.enterprise.DevicePolicyManagerWrapper; import com.android.settings.enterprise.DevicePolicyManagerWrapperImpl; import com.android.settings.overlay.FeatureFactory; Loading @@ -56,7 +57,7 @@ import java.util.List; * 2. Battery related controls for app(i.e uninstall, force stop) * */ public class AdvancedPowerUsageDetail extends PowerUsageBase implements public class AdvancedPowerUsageDetail extends DashboardFragment implements ButtonActionDialogFragment.AppButtonsDialogListener { public static final String TAG = "AdvancedPowerUsageDetail"; Loading
src/com/android/settings/fuelgauge/BatteryStatsHelperLoader.java 0 → 100644 +60 −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; import android.content.Context; import android.os.BatteryStats; import android.os.Bundle; import android.os.UserManager; import android.support.annotation.VisibleForTesting; import com.android.internal.os.BatteryStatsHelper; import com.android.settings.utils.AsyncLoader; /** * Loader to get new {@link BatteryStatsHelper} in the background */ public class BatteryStatsHelperLoader extends AsyncLoader<BatteryStatsHelper> { @VisibleForTesting UserManager mUserManager; private Bundle mBundle; public BatteryStatsHelperLoader(Context context, Bundle bundle) { super(context); mBundle = bundle; mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE); } @Override public BatteryStatsHelper loadInBackground() { final BatteryStatsHelper statsHelper = new BatteryStatsHelper(getContext(), true); initBatteryStatsHelper(statsHelper); return statsHelper; } @Override protected void onDiscardResult(BatteryStatsHelper result) { } @VisibleForTesting void initBatteryStatsHelper(BatteryStatsHelper statsHelper) { statsHelper.create(mBundle); statsHelper.refreshStats(BatteryStats.STATS_SINCE_CHARGED, mUserManager.getUserProfiles()); } }
src/com/android/settings/fuelgauge/PowerUsageAdvanced.java +5 −3 Original line number Diff line number Diff line Loading @@ -126,7 +126,6 @@ public class PowerUsageAdvanced extends PowerUsageBase { @Override public void onResume() { super.onResume(); refreshStats(); } @Override Loading Loading @@ -165,8 +164,11 @@ public class PowerUsageAdvanced extends PowerUsageBase { } @Override protected void refreshStats() { super.refreshStats(); protected void refreshUi() { final Context context = getContext(); if (context == null) { return; } updatePreference(mHistPref); Loading
src/com/android/settings/fuelgauge/PowerUsageBase.java +26 −35 Original line number Diff line number Diff line Loading @@ -16,28 +16,23 @@ package com.android.settings.fuelgauge; import android.app.Activity; import android.content.BroadcastReceiver; import android.app.LoaderManager; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.BatteryStats; import android.content.Loader; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.UserManager; import android.support.annotation.VisibleForTesting; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import com.android.internal.os.BatteryStatsHelper; import com.android.settings.R; import com.android.settings.dashboard.DashboardFragment; import com.android.settings.utils.AsyncLoader; /** * Common base class for things that need to show the battery usage graph. */ public abstract class PowerUsageBase extends DashboardFragment { public abstract class PowerUsageBase extends DashboardFragment implements LoaderManager.LoaderCallbacks<BatteryStatsHelper> { // +1 to allow ordering for PowerUsageSummary. @VisibleForTesting Loading @@ -62,27 +57,23 @@ public abstract class PowerUsageBase extends DashboardFragment { mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(getContext()); mBatteryBroadcastReceiver.setBatteryChangedListener(() -> { if (!mHandler.hasMessages(MSG_REFRESH_STATS)) { mHandler.sendEmptyMessageDelayed(MSG_REFRESH_STATS, 500); } getLoaderManager().restartLoader(0, null, this); }); getLoaderManager().initLoader(0, icicle, this); } @Override public void onStart() { super.onStart(); mStatsHelper.clearStats(); } @Override public void onResume() { super.onResume(); BatteryStatsHelper.dropFile(getActivity(), BatteryHistoryDetail.BATTERY_HISTORY_FILE); mBatteryBroadcastReceiver.register(); if (mHandler.hasMessages(MSG_REFRESH_STATS)) { mHandler.removeMessages(MSG_REFRESH_STATS); mStatsHelper.clearStats(); } } @Override Loading @@ -94,7 +85,6 @@ public abstract class PowerUsageBase extends DashboardFragment { @Override public void onStop() { super.onStop(); mHandler.removeMessages(MSG_REFRESH_STATS); } @Override Loading @@ -105,26 +95,27 @@ public abstract class PowerUsageBase extends DashboardFragment { } } protected void refreshStats() { mStatsHelper.refreshStats(BatteryStats.STATS_SINCE_CHARGED, mUm.getUserProfiles()); } protected abstract void refreshUi(); protected void updatePreference(BatteryHistoryPreference historyPref) { historyPref.setStats(mStatsHelper); } static final int MSG_REFRESH_STATS = 100; private final Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case MSG_REFRESH_STATS: mStatsHelper.clearStats(); refreshStats(); break; public Loader<BatteryStatsHelper> onCreateLoader(int id, Bundle args) { return new BatteryStatsHelperLoader(getContext(), args); } @Override public void onLoadFinished(Loader<BatteryStatsHelper> loader, BatteryStatsHelper statsHelper) { mStatsHelper = statsHelper; refreshUi(); } }; @Override public void onLoaderReset(Loader<BatteryStatsHelper> loader) { } }