Merge "Fix LoaderCallback.onLoadFinished uncalled issue" into tm-qpr-dev
This commit is contained in:
@@ -55,7 +55,6 @@ public class PowerUsageAdvanced extends PowerUsageBase {
|
||||
private static final String KEY_REFRESH_TYPE = "refresh_type";
|
||||
private static final String KEY_BATTERY_GRAPH = "battery_graph";
|
||||
private static final String KEY_APP_LIST = "app_list";
|
||||
private static final int LOADER_BATTERY_USAGE_STATS = 2;
|
||||
|
||||
@VisibleForTesting
|
||||
BatteryHistoryPreference mHistPref;
|
||||
@@ -188,7 +187,7 @@ public class PowerUsageAdvanced extends PowerUsageBase {
|
||||
// Uses customized battery history loader if chart design is enabled.
|
||||
if (mIsChartGraphEnabled && !mIsChartDataLoaded) {
|
||||
mIsChartDataLoaded = true;
|
||||
getLoaderManager().restartLoader(LOADER_BATTERY_USAGE_STATS, bundle,
|
||||
restartLoader(LoaderIndex.BATTERY_HISTORY_LOADER, bundle,
|
||||
mBatteryHistoryLoaderCallbacks);
|
||||
} else if (!mIsChartGraphEnabled) {
|
||||
super.restartBatteryStatsLoader(refreshType);
|
||||
|
@@ -24,6 +24,7 @@ import android.os.Bundle;
|
||||
import android.os.UserManager;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.loader.app.LoaderManager;
|
||||
@@ -33,17 +34,19 @@ import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.fuelgauge.BatteryBroadcastReceiver;
|
||||
import com.android.settings.fuelgauge.BatteryUtils;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* Common base class for things that need to show the battery usage graph.
|
||||
*/
|
||||
public abstract class PowerUsageBase extends DashboardFragment {
|
||||
|
||||
private static final String TAG = "PowerUsageBase";
|
||||
private static final String KEY_REFRESH_TYPE = "refresh_type";
|
||||
private static final String KEY_INCLUDE_HISTORY = "include_history";
|
||||
|
||||
private static final int LOADER_BATTERY_USAGE_STATS = 1;
|
||||
|
||||
@VisibleForTesting
|
||||
static final String KEY_REFRESH_TYPE = "refresh_type";
|
||||
@VisibleForTesting
|
||||
static final String KEY_INCLUDE_HISTORY = "include_history";
|
||||
@VisibleForTesting
|
||||
BatteryUsageStats mBatteryUsageStats;
|
||||
|
||||
@@ -55,6 +58,21 @@ public abstract class PowerUsageBase extends DashboardFragment {
|
||||
final BatteryUsageStatsLoaderCallbacks mBatteryUsageStatsLoaderCallbacks =
|
||||
new BatteryUsageStatsLoaderCallbacks();
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({
|
||||
LoaderIndex.BATTERY_USAGE_STATS_LOADER,
|
||||
LoaderIndex.BATTERY_INFO_LOADER,
|
||||
LoaderIndex.BATTERY_TIP_LOADER,
|
||||
LoaderIndex.BATTERY_HISTORY_LOADER
|
||||
|
||||
})
|
||||
public @interface LoaderIndex {
|
||||
int BATTERY_USAGE_STATS_LOADER = 0;
|
||||
int BATTERY_INFO_LOADER = 1;
|
||||
int BATTERY_TIP_LOADER = 2;
|
||||
int BATTERY_HISTORY_LOADER = 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
@@ -91,10 +109,28 @@ public abstract class PowerUsageBase extends DashboardFragment {
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putInt(KEY_REFRESH_TYPE, refreshType);
|
||||
bundle.putBoolean(KEY_INCLUDE_HISTORY, isBatteryHistoryNeeded());
|
||||
getLoaderManager().restartLoader(LOADER_BATTERY_USAGE_STATS, bundle,
|
||||
restartLoader(LoaderIndex.BATTERY_USAGE_STATS_LOADER, bundle,
|
||||
mBatteryUsageStatsLoaderCallbacks);
|
||||
}
|
||||
|
||||
protected LoaderManager getLoaderManagerForCurrentFragment() {
|
||||
return LoaderManager.getInstance(this);
|
||||
}
|
||||
|
||||
protected void restartLoader(int loaderId, Bundle bundle,
|
||||
LoaderManager.LoaderCallbacks<?> loaderCallbacks) {
|
||||
LoaderManager loaderManager = getLoaderManagerForCurrentFragment();
|
||||
Loader<?> loader = loaderManager.getLoader(
|
||||
loaderId);
|
||||
if (loader != null && !loader.isReset()) {
|
||||
loaderManager.restartLoader(loaderId, bundle,
|
||||
loaderCallbacks);
|
||||
} else {
|
||||
loaderManager.initLoader(loaderId, bundle,
|
||||
loaderCallbacks);
|
||||
}
|
||||
}
|
||||
|
||||
protected void onLoadFinished(@BatteryUpdateType int refreshType) {
|
||||
refreshUi(refreshType);
|
||||
}
|
||||
|
@@ -64,11 +64,6 @@ public class PowerUsageSummary extends PowerUsageBase implements
|
||||
@VisibleForTesting
|
||||
static final String KEY_BATTERY_USAGE = "battery_usage_summary";
|
||||
|
||||
@VisibleForTesting
|
||||
static final int BATTERY_INFO_LOADER = 1;
|
||||
@VisibleForTesting
|
||||
static final int BATTERY_TIP_LOADER = 2;
|
||||
|
||||
@VisibleForTesting
|
||||
PowerUsageFeatureProvider mPowerFeatureProvider;
|
||||
@VisibleForTesting
|
||||
@@ -241,7 +236,7 @@ public class PowerUsageSummary extends PowerUsageBase implements
|
||||
|
||||
@VisibleForTesting
|
||||
void restartBatteryTipLoader() {
|
||||
getLoaderManager().restartLoader(BATTERY_TIP_LOADER, Bundle.EMPTY, mBatteryTipsCallbacks);
|
||||
restartLoader(LoaderIndex.BATTERY_TIP_LOADER, Bundle.EMPTY, mBatteryTipsCallbacks);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -274,8 +269,7 @@ public class PowerUsageSummary extends PowerUsageBase implements
|
||||
if (!mIsBatteryPresent) {
|
||||
return;
|
||||
}
|
||||
getLoaderManager().restartLoader(BATTERY_INFO_LOADER, Bundle.EMPTY,
|
||||
mBatteryInfoLoaderCallbacks);
|
||||
restartLoader(LoaderIndex.BATTERY_INFO_LOADER, Bundle.EMPTY, mBatteryInfoLoaderCallbacks);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
Reference in New Issue
Block a user