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
diff --git a/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java b/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
index 66026eb..c9a1fb7 100644
--- a/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
+++ b/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
@@ -117,7 +117,7 @@
 
     private Preference mExplore;
 
-    private boolean mDetached;
+    private boolean mNeedsUpdate;
 
     private boolean isVolumeValid() {
         return (mVolume != null) && (mVolume.getType() == VolumeInfo.TYPE_PRIVATE)
@@ -164,18 +164,22 @@
 
         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 @@
         mSummary.setPercent((int) ((usedBytes * 100) / totalBytes));
 
         mMeasure.forceMeasure();
+        mNeedsUpdate = false;
     }
 
     private void addPreference(PreferenceGroup group, Preference pref) {
@@ -314,8 +319,10 @@
 
         mStorageManager.registerListener(mStorageListener);
 
-        if (!mDetached) {
+        if (mNeedsUpdate) {
             update();
+        } else {
+            setTitle();
         }
     }
 
@@ -326,24 +333,11 @@
     }
 
     @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