Android6.0存储中加入总内存和系统内存项
平台下patches/packages/apps/Settings/里面
1.存储中加入总内存和系统内存项
在 res/values-zh-rCN/strings.xml 中添加
- <string name="write_settings_description" msgid="6868293938839954623">"此权限允许应用修改系统设置。"</string>
- <string name="write_settings_on" msgid="8230580416068832239">"允许"</string>
- <string name="write_settings_off" msgid="5156104383386336233">"不允许"</string>
- + <string name="storage_detail_system">"系统内存"</string>
- + <string name="storage_detail_total">"总内存"</string>
- </resources>
- <string name="write_settings_description" msgid="6868293938839954623">"這項權限允許應用程式修改系統設定。"</string>
- <string name="write_settings_on" msgid="8230580416068832239">"可"</string>
- <string name="write_settings_off" msgid="5156104383386336233">"否"</string>
- + <string name="storage_detail_system">"系统内存"</string>
- + <string name="storage_detail_total">"总内存"</string>
- </resources>
- <string name="write_settings_on">Yes</string>
- <!-- Summary of app not allowed to write system settings [CHAR LIMIT=45] -->
- <string name="write_settings_off">No</string>
- + <string name="storage_detail_total">"Total Data"</string>
- + <string name="storage_detail_system">System Data</string>
- </resources>
/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java 中添加
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- +import java.text.DecimalFormat;
- import android.content.pm.IPackageDataObserver;
- import android.content.pm.PackageInfo;
- import android.content.pm.PackageManager;
- @@ -118,6 +119,8 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
- private int mItemPoolIndex;
- private Preference mExplore;
- + private Preference storage_detail_system;
- + private Preference storage_detail_total;
- private boolean isVolumeValid() {
- return (mVolume != null) && (mVolume.getType() == VolumeInfo.TYPE_PRIVATE)
- @@ -159,6 +162,8 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
- mCurrentUser = mUserManager.getUserInfo(UserHandle.myUserId());
- mExplore = buildAction(R.string.storage_menu_explore);
- + storage_detail_system = buildAction(R.string.storage_detail_system);
- + storage_detail_total = buildAction(R.string.storage_detail_total);
- setHasOptionsMenu(true);
- }
- @@ -216,6 +221,8 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
- addItem(screen, R.string.storage_detail_cached, null, UserHandle.USER_NULL);
- if (showShared) {
- + addPreference(screen, storage_detail_system);
- + addPreference(screen, storage_detail_total);
- addPreference(screen, mExplore);
- }
- @@ -224,13 +231,28 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
- final long freeBytes = file.getFreeSpace();
- final long usedBytes = totalBytes - freeBytes;
- - final BytesResult result = Formatter.formatBytes(getResources(), usedBytes, 0);
- - mSummary.setTitle(TextUtils.expandTemplate(getText(R.string.storage_size_large),
- - result.value, result.units));
- - mSummary.setSummary(getString(R.string.storage_volume_used,
- - Formatter.formatFileSize(context, totalBytes)));
- - mSummary.setPercent((int) ((usedBytes * 100) / totalBytes));
- -
- + if(showShared) {
- + final long systemBytes = (long) ((8.0 * 1024 * 1024 * 1024) - totalBytes);
- + Log.d("zhongyeqing","systemBytes = "+systemBytes);
- + final BytesResult systemresult = Formatter.formatBytes(getResources(), systemBytes, 0);
- + storage_detail_system.setSummary(systemresult.value+systemresult.units);
- + storage_detail_total.setSummary("8.0 GB");
- +
- + final BytesResult result = Formatter.formatBytes(getResources(), systemBytes+usedBytes, 0);
- + mSummary.setTitle(TextUtils.expandTemplate(getText(R.string.storage_size_large),
- + result.value, result.units));
- + mSummary.setSummary(getString(R.string.storage_volume_used,
- + Formatter.formatFileSize(context, (long) (8.0 * 1024 * 1024 * 1024))));
- + mSummary.setPercent((int) (((systemBytes+usedBytes) * 100) / (float) (8.0 * 1024 * 1024 * 1024)));
- +
- + }else{
- + final BytesResult result = Formatter.formatBytes(getResources(), usedBytes, 0);
- + mSummary.setTitle(TextUtils.expandTemplate(getText(R.string.storage_size_large),
- + result.value, result.units));
- + mSummary.setSummary(getString(R.string.storage_volume_used,
- + Formatter.formatFileSize(context, totalBytes)));
- + mSummary.setPercent((int) ((usedBytes * 100) / totalBytes));
- + }
- mMeasure.forceMeasure();
- }
- final long freeBytes = file.getFreeSpace();
- final long usedBytes = totalBytes - freeBytes;
- - final BytesResult result = Formatter.formatBytes(getResources(), usedBytes, 0);
- - mSummary.setTitle(TextUtils.expandTemplate(getText(R.string.storage_size_large),
- - result.value, result.units));
- - mSummary.setSummary(getString(R.string.storage_volume_used,
- - Formatter.formatFileSize(context, totalBytes)));
- - mSummary.setPercent((int) ((usedBytes * 100) / totalBytes));
- + if(VolumeInfo.ID_PRIVATE_INTERNAL.equals(mVolume.getId())) {
- + final long systemBytes = (long) ((8.0 * 1024 * 1024 * 1024) - totalBytes);
- + final BytesResult result = Formatter.formatBytes(getResources(), systemBytes+usedBytes, 0);
- + mSummary.setTitle(TextUtils.expandTemplate(getText(R.string.storage_size_large),
- + result.value, result.units));
- + mSummary.setSummary(getString(R.string.storage_volume_used,
- + Formatter.formatFileSize(context, (long) (8.0 * 1024 * 1024 * 1024)))+"---");
- + mSummary.setPercent((int) (((usedBytes+systemBytes) * 100) / (float)(8.0 * 1024 * 1024 * 1024)));
- + }else{
- + final BytesResult result = Formatter.formatBytes(getResources(), usedBytes, 0);
- + mSummary.setTitle(TextUtils.expandTemplate(getText(R.string.storage_size_large),
- + result.value, result.units));
- + mSummary.setSummary(getString(R.string.storage_volume_used,
- + Formatter.formatFileSize(context, totalBytes)));
- + mSummary.setPercent((int) ((usedBytes * 100) / totalBytes));
- + }
- }
- if (mVolume.getState() == VolumeInfo.STATE_UNMOUNTED) {
/src/com/android/settings/deviceinfo/StorageSettings.java 中添加
- </pre><pre name="code" class="java">int privateCount = 0;
- long privateUsedBytes = 0;
- long privateTotalBytes = 0;
- + long systemBytes = 0;
- final List<VolumeInfo> volumes = mStorageManager.getVolumes();
- Collections.sort(volumes, VolumeInfo.getDescriptionComparator());
- @@ -178,6 +179,9 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
- final File path = vol.getPath();
- privateUsedBytes += path.getTotalSpace() - path.getFreeSpace();
- privateTotalBytes += path.getTotalSpace();
- + if(VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.getId())){
- + systemBytes = (long) ((8.0 * 1024 * 1024 * 1024) - privateTotalBytes);
- + }
- }
- } else if (vol.getType() == VolumeInfo.TYPE_PUBLIC) {
- mExternalCategory.addPreference(
- @@ -217,12 +221,28 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
- }
- }
- - final BytesResult result = Formatter.formatBytes(getResources(), privateUsedBytes, 0);
- - mInternalSummary.setTitle(TextUtils.expandTemplate(getText(R.string.storage_size_large),
- - result.value, result.units));
- - mInternalSummary.setSummary(getString(R.string.storage_volume_used_total,
- - Formatter.formatFileSize(context, privateTotalBytes)));
- + /* Vanzo:zhongyeqing on: Wed, 12 Oct 2016 23:08:22 +0800
- + * TODO: replace this line with your comment
- + if (systemBytes != 0){
- + */
- + // End of Vanzo: zhongyeqing
- + final BytesResult result = Formatter.formatBytes(getResources(),systemBytes+privateUsedBytes, 0);
- + mInternalSummary.setTitle(TextUtils.expandTemplate(getText(R.string.storage_size_large),
- + result.value, result.units));
- + //mInternalSummary.setSummary(getString(R.string.storage_volume_used_total,"8.0 GB"));
- + mInternalSummary.setSummary(getString(R.string.storage_volume_used_total,
- + Formatter.formatFileSize(context, privateTotalBytes+systemBytes)));
- + /* Vanzo:zhongyeqing on: Wed, 12 Oct 2016 23:08:17 +0800
- + * TODO: replace this line with your comment
- + }else{
- + final BytesResult result = Formatter.formatBytes(getResources(), privateUsedBytes, 0);
- + mInternalSummary.setSummary(getString(R.string.storage_volume_used_total,
- + Formatter.formatFileSize(context, privateTotalBytes)));
- +
- + }
- + */
- + // End of Vanzo: zhongyeqing
- if (mInternalCategory.getPreferenceCount() > 0) {
- getPreferenceScreen().addPreference(mInternalCategory);
- }
在 /src/com/android/settings/deviceinfo/StorageVolumePreference.java 中
- final long freeBytes = path.getFreeSpace();
- final long totalBytes = path.getTotalSpace();
- final long usedBytes = totalBytes - freeBytes;
- + final long systemBytes = (long) ((8.0 * 1024 * 1024 * 1024) - totalBytes);
- final String used = Formatter.formatFileSize(context, usedBytes);
- + final String usedSystem = Formatter.formatFileSize(context, usedBytes+systemBytes);
- final String total = Formatter.formatFileSize(context, totalBytes);
- + /* Vanzo:zhongyeqing on: Mon, 15 Aug 2016 14:40:17 +0800
- + * TODO: replace this line with your comment
- setSummary(context.getString(R.string.storage_volume_summary, used, total));
- if (totalBytes != 0) {
- mUsedPercent = (int) ((usedBytes * 100) / totalBytes);
- }
- -
- + */
- + if(VolumeInfo.ID_PRIVATE_INTERNAL.equals(volume.getId())) {
- + setSummary(context.getString(R.string.storage_volume_summary, usedSystem, "8.0 GB"));
- + if (totalBytes != 0) {
- + mUsedPercent = (int) (((usedBytes+systemBytes) * 100) / (float) (8.0 * 1024 * 1024 * 1024));
- + }
- + } else {
- + setSummary(context.getString(R.string.storage_volume_summary, used, total));
- + if (totalBytes != 0) {
- + mUsedPercent = (int) ((usedBytes * 100) / totalBytes);
- + }
- + }
- + // End of Vanzo: zhongyeqing
- if (freeBytes < mStorageManager.getStorageLowBytes(path)) {
- mColor = StorageSettings.COLOR_WARNING;
- icon = context.getDrawable(R.drawable.ic_warning_24dp);
2.下述代码为西语下 存储 和 内存 中的 , 改为 .
/src/com/android/settings/applications/ProcessStatsSummary.java 中
- double freeRam = memInfo.realFreeRam;
- BytesResult usedResult = Formatter.formatBytes(context.getResources(), (long) usedRam,
- Formatter.FLAG_SHORTER);
- - String totalString = Formatter.formatShortFileSize(context, (long) totalRam);
- + String totalString = (Formatter.formatShortFileSize(context, (long) totalRam)).replace(",",".");
- String freeString = Formatter.formatShortFileSize(context, (long) freeRam);
- private void updatePreference(StorageItemPreference pref, long size) {
- - pref.setSummary(Formatter.formatFileSize(getActivity(), size));
- + pref.setSummary((Formatter.formatFileSize(getActivity(), size)).replace(",","."));
- }
再在第一段代码的基础上:
- storage_detail_system.setSummary(systemresult.value+systemresult.units);
变为
- storage_detail_system.setSummary((systemresult.value+systemresult.units).replace(",","."));
- result.value, result.units));
- 变为
- <pre name="code" class="java">(result.value).replace(",","."), result.units));
- <pre name="code" class="java">Formatter.formatFileSize(context, (long) (8.0 * 1024 * 1024 * 1024))));
- <pre name="code" class="java">(Formatter.formatFileSize(context, (long) (8.0 * 1024 * 1024 * 1024))).replace(",",".")));