From 6ebd561960fd2fb5a987b384e39ff168d4470445 Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Thu, 12 May 2016 14:37:11 -0700 Subject: [PATCH] Fixed calls to update() when configuration changed. update() is an expensive operation and should only be called once under normal circumstances (it still needs to be called due to external changes). In particular, it should not be called again on orientation changes. The first approach to solve the orientation change caused the volume title to not be shown when the screen changed on multi window environments; the fix for title issue caused the update to be called again on configuration changes. This change properly fixes both issues by removing the onAttach() / onDetach() methods and using a clearer variable (mNeedsUpdate) to avoid future regressions. BUG: 24508289 BUG: 27989238 Change-Id: I140f5a541cda293f1c476d3b80a5bc8918e18b08 --- .../deviceinfo/PrivateVolumeSettings.java | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java b/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java index 66026ebf250..c9a1fb70a47 100644 --- a/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java +++ b/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java @@ -117,7 +117,7 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment { private Preference mExplore; - private boolean mDetached; + private boolean mNeedsUpdate; private boolean isVolumeValid() { return (mVolume != null) && (mVolume.getType() == VolumeInfo.TYPE_PRIVATE) @@ -164,18 +164,22 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment { mExplore = buildAction(R.string.storage_menu_explore); - mDetached = false; + mNeedsUpdate = true; setHasOptionsMenu(true); } + private void setTitle() { + getActivity().setTitle(mStorageManager.getBestVolumeDescription(mVolume)); + } + private void update() { if (!isVolumeValid()) { getActivity().finish(); return; } - getActivity().setTitle(mStorageManager.getBestVolumeDescription(mVolume)); + setTitle(); // Valid options may have changed getFragmentManager().invalidateOptionsMenu(); @@ -238,6 +242,7 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment { mSummary.setPercent((int) ((usedBytes * 100) / totalBytes)); mMeasure.forceMeasure(); + mNeedsUpdate = false; } private void addPreference(PreferenceGroup group, Preference pref) { @@ -314,8 +319,10 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment { mStorageManager.registerListener(mStorageListener); - if (!mDetached) { + if (mNeedsUpdate) { update(); + } else { + setTitle(); } } @@ -325,25 +332,12 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment { mStorageManager.unregisterListener(mStorageListener); } - @Override - public void onAttach(Context context) { - super.onAttach(context); - mDetached = false; - } - - @Override - public void onDetach() { - super.onDetach(); - mDetached = true; - } - @Override public void onDestroy() { super.onDestroy(); if (mMeasure != null) { mMeasure.onDestroy(); } - mDetached = false; } @Override