If external storage is emulated, don't show it as separate entries.

The installed app details UI is really complicted for the two-partition
internal and external storage case...  however, in our lovely new world
of emulated external storage, there is no reason for this, since the
external storage is using the same partition as internal storage.  So
in this case, don't show external storage as a separate item, just
combine it into the base app size and data size values.

Change-Id: Iea0e78f2d532ad50e20fef98740c93b2e897890a
diff --git a/src/com/android/settings/applications/ApplicationsState.java b/src/com/android/settings/applications/ApplicationsState.java
index 3256fb2..cca9086 100644
--- a/src/com/android/settings/applications/ApplicationsState.java
+++ b/src/com/android/settings/applications/ApplicationsState.java
@@ -786,7 +786,10 @@
 
     private long getTotalExternalSize(PackageStats ps) {
         if (ps != null) {
+            // We also include the cache size here because for non-emulated
+            // we don't automtically clean cache files.
             return ps.externalCodeSize + ps.externalDataSize
+                    + ps.externalCacheSize
                     + ps.externalMediaSize + ps.externalObbSize;
         }
         return SIZE_INVALID;
@@ -822,7 +825,7 @@
                             long externalCodeSize = stats.externalCodeSize
                                     + stats.externalObbSize;
                             long externalDataSize = stats.externalDataSize
-                                    + stats.externalMediaSize + stats.externalCacheSize;
+                                    + stats.externalMediaSize;
                             long newSize = externalCodeSize + externalDataSize
                                     + getTotalInternalSize(stats);
                             if (entry.size != newSize ||
diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java
index d85c341..22908ab 100644
--- a/src/com/android/settings/applications/InstalledAppDetails.java
+++ b/src/com/android/settings/applications/InstalledAppDetails.java
@@ -384,7 +384,12 @@
         mDataSize = (TextView)view.findViewById(R.id.data_size_text);
         mExternalCodeSize = (TextView)view.findViewById(R.id.external_code_size_text);
         mExternalDataSize = (TextView)view.findViewById(R.id.external_data_size_text);
-        
+
+        if (Environment.isExternalStorageEmulated()) {
+            ((View)mExternalCodeSize.getParent()).setVisibility(View.GONE);
+            ((View)mExternalDataSize.getParent()).setVisibility(View.GONE);
+        }
+
         // Get Control button panel
         View btnPanel = view.findViewById(R.id.control_buttons_panel);
         mForceStopButton = (Button) btnPanel.findViewById(R.id.left_button);
@@ -675,22 +680,28 @@
             
         } else {
             mHaveSizes = true;
-            if (mLastCodeSize != mAppEntry.codeSize) {
-                mLastCodeSize = mAppEntry.codeSize;
-                mAppSize.setText(getSizeStr(mAppEntry.codeSize));
+            long codeSize = mAppEntry.codeSize;
+            long dataSize = mAppEntry.dataSize;
+            if (Environment.isExternalStorageEmulated()) {
+                codeSize += mAppEntry.externalCodeSize;
+                dataSize +=  mAppEntry.externalDataSize;
+            } else {
+                if (mLastExternalCodeSize != mAppEntry.externalCodeSize) {
+                    mLastExternalCodeSize = mAppEntry.externalCodeSize;
+                    mExternalCodeSize.setText(getSizeStr(mAppEntry.externalCodeSize));
+                }
+                if (mLastExternalDataSize !=  mAppEntry.externalDataSize) {
+                    mLastExternalDataSize =  mAppEntry.externalDataSize;
+                    mExternalDataSize.setText(getSizeStr( mAppEntry.externalDataSize));
+                }
             }
-            if (mLastDataSize != mAppEntry.dataSize) {
-                mLastDataSize = mAppEntry.dataSize;
-                mDataSize.setText(getSizeStr(mAppEntry.dataSize));
+            if (mLastCodeSize != codeSize) {
+                mLastCodeSize = codeSize;
+                mAppSize.setText(getSizeStr(codeSize));
             }
-            if (mLastExternalCodeSize != mAppEntry.externalCodeSize) {
-                mLastExternalCodeSize = mAppEntry.externalCodeSize;
-                mExternalCodeSize.setText(getSizeStr(mAppEntry.externalCodeSize));
-            }
-            long nonCacheExtDataSize = mAppEntry.externalDataSize - mAppEntry.externalCacheSize;
-            if (mLastExternalDataSize != nonCacheExtDataSize) {
-                mLastExternalDataSize = nonCacheExtDataSize;
-                mExternalDataSize.setText(getSizeStr(nonCacheExtDataSize));
+            if (mLastDataSize != dataSize) {
+                mLastDataSize = dataSize;
+                mDataSize.setText(getSizeStr(dataSize));
             }
             long cacheSize = mAppEntry.cacheSize + mAppEntry.externalCacheSize;
             if (mLastCacheSize != cacheSize) {
@@ -702,7 +713,7 @@
                 mTotalSize.setText(getSizeStr(mAppEntry.size));
             }
             
-            if ((mAppEntry.dataSize+nonCacheExtDataSize) <= 0 || !mCanClearData) {
+            if ((mAppEntry.dataSize+ mAppEntry.externalDataSize) <= 0 || !mCanClearData) {
                 mClearDataButton.setEnabled(false);
             } else {
                 mClearDataButton.setEnabled(true);
diff --git a/src/com/android/settings/applications/ManageApplications.java b/src/com/android/settings/applications/ManageApplications.java
index 1cc9dcc..1240d43 100644
--- a/src/com/android/settings/applications/ManageApplications.java
+++ b/src/com/android/settings/applications/ManageApplications.java
@@ -341,7 +341,8 @@
                     final int N = mApplications.getCount();
                     for (int i=0; i<N; i++) {
                         ApplicationsState.AppEntry ae = mApplications.getAppEntry(i);
-                        mAppStorage += ae.externalCodeSize + ae.externalDataSize;
+                        mAppStorage += ae.externalCodeSize + ae.externalDataSize
+                                + ae.externalCacheSize;
                     }
                 }
             } else {