Merge "Updates/fixes to memory settings" into mnc-dev

This commit is contained in:
Jason Monk
2015-05-07 17:45:39 +00:00
committed by Android (Google) Code Review
7 changed files with 95 additions and 50 deletions

View File

@@ -1222,18 +1222,25 @@
<item>Always allow</item> <item>Always allow</item>
</string-array> </string-array>
<!-- [CHAR LIMIT=30] Labels for memory states --> <!-- [CHAR LIMIT=40] Labels for memory states -->
<string-array name="ram_states"> <string-array name="ram_states">
<!-- Normal desired memory state. --> <!-- Normal desired memory state. -->
<item>normal</item> <item>Good performance</item>
<!-- Moderate memory state, not as good as normal. --> <!-- Moderate memory state, not as good as normal. -->
<item>moderate</item> <item>Ok performance</item>
<!-- Memory is running low. --> <!-- Memory is running low. -->
<item>low</item> <item>Poor performance</item>
<!-- Memory is critical. --> <!-- Memory is critical. -->
<item>critical</item> <item>Very poor performance</item>
</string-array> </string-array>
<array name="ram_colors">
<item>@color/memory_normal</item>
<item>@color/memory_moderate</item>
<item>@color/memory_low</item>
<item>@color/memory_critical</item>
</array>
<!-- Display color space adjustment modes for accessibility --> <!-- Display color space adjustment modes for accessibility -->
<string-array name="daltonizer_type_entries" translatable="false"> <string-array name="daltonizer_type_entries" translatable="false">
<item>@string/daltonizer_mode_deuteranomaly</item> <item>@string/daltonizer_mode_deuteranomaly</item>

View File

@@ -87,6 +87,11 @@
<drawable name="fp_enrollment_header_landscape">#009688</drawable> <drawable name="fp_enrollment_header_landscape">#009688</drawable>
<color name="memory_normal">#ff009587</color>
<color name="memory_moderate">#ffF3B300</color>
<color name="memory_low">#ffff9700</color>
<color name="memory_critical">#ffff5621</color>
<color name="memory_avg_use">#ff384248</color> <color name="memory_avg_use">#ff384248</color>
<color name="memory_max_use">#ff009587</color> <color name="memory_max_use">#ff009587</color>
<color name="memory_remaining">#ffced7db</color> <color name="memory_remaining">#ffced7db</color>

View File

@@ -4223,9 +4223,6 @@
<string name="process_stats_type_foreground">Foreground</string> <string name="process_stats_type_foreground">Foreground</string>
<!-- [CHAR LIMIT=NONE] Label for process stats, text for stats type --> <!-- [CHAR LIMIT=NONE] Label for process stats, text for stats type -->
<string name="process_stats_type_cached">Cached</string> <string name="process_stats_type_cached">Cached</string>
<!-- [CHAR LIMIT=NONE] Label for process stats, duration of time the stats are over -->
<string name="process_stats_memory_status">Memory is
<xliff:g id="memstate">%1$s</xliff:g></string>
<!-- [CHAR LIMIT=NONE] Label OS "process" app --> <!-- [CHAR LIMIT=NONE] Label OS "process" app -->
<string name="process_stats_os_label">Android OS</string> <string name="process_stats_os_label">Android OS</string>
<!-- [CHAR LIMIT=NONE] Name of OS "process" for all native processes --> <!-- [CHAR LIMIT=NONE] Name of OS "process" for all native processes -->
@@ -6624,11 +6621,8 @@
<!-- Formatting for memory description [CHAR LIMIT=25] --> <!-- Formatting for memory description [CHAR LIMIT=25] -->
<string name="memory_use_running_format"><xliff:g id="memory" example="30MB">%1$s</xliff:g> / <xliff:g id="running" example="Always running">%2$s</xliff:g></string> <string name="memory_use_running_format"><xliff:g id="memory" example="30MB">%1$s</xliff:g> / <xliff:g id="running" example="Always running">%2$s</xliff:g></string>
<!-- Label for process (singular) [CHAR LIMIT=25] -->
<string name="process">Process</string>
<!-- Label for process [CHAR LIMIT=25] --> <!-- Label for process [CHAR LIMIT=25] -->
<string name="process_format">Process <xliff:g id="count" example="3">%1$d</xliff:g></string> <string name="process_format"><xliff:g id="app_name" example="Settings">%1$s</xliff:g> (<xliff:g id="count" example="3">%2$d</xliff:g>)</string>
<!-- Label for whether app is allowed to use a lot ef power [CHAR LIMIT=25]--> <!-- Label for whether app is allowed to use a lot ef power [CHAR LIMIT=25]-->
<string name="high_power" translatable="false">High power</string> <string name="high_power" translatable="false">High power</string>

View File

@@ -101,7 +101,14 @@ public class ProcStatsData {
} }
public int getMemState() { public int getMemState() {
return mMemState; int factor = mStats.mMemFactor;
if (factor == ProcessStats.ADJ_NOTHING) {
return ProcessStats.ADJ_MEM_FACTOR_NORMAL;
}
if (factor >= ProcessStats.ADJ_SCREEN_ON) {
factor -= ProcessStats.ADJ_SCREEN_ON;
}
return factor;
} }
public MemInfo getMemInfo() { public MemInfo getMemInfo() {
@@ -318,9 +325,11 @@ public class ProcStatsData {
double weightToRam; double weightToRam;
double totalRam; double totalRam;
double totalScale; double totalScale;
long memTotalTime;
private MemInfo(Context context, ProcessStats.TotalMemoryUseCollection totalMem, private MemInfo(Context context, ProcessStats.TotalMemoryUseCollection totalMem,
long memTotalTime) { long memTotalTime) {
this.memTotalTime = memTotalTime;
calculateWeightInfo(context, totalMem, memTotalTime); calculateWeightInfo(context, totalMem, memTotalTime);
double usedRam = (usedWeight * 1024) / memTotalTime; double usedRam = (usedWeight * 1024) / memTotalTime;

View File

@@ -32,6 +32,7 @@ import android.graphics.drawable.ColorDrawable;
import android.os.Bundle; import android.os.Bundle;
import android.os.Process; import android.os.Process;
import android.preference.PreferenceCategory; import android.preference.PreferenceCategory;
import android.text.TextUtils;
import android.text.format.Formatter; import android.text.format.Formatter;
import android.util.ArrayMap; import android.util.ArrayMap;
import android.util.Log; import android.util.Log;
@@ -241,11 +242,7 @@ public class ProcessStatsDetail extends SettingsPreferenceFragment
if (entry.mPackage.equals("os")) { if (entry.mPackage.equals("os")) {
entry.mLabel = entry.mName; entry.mLabel = entry.mName;
} else { } else {
if (mApp.mEntries.size() > 1) { entry.mLabel = getProcessName(mApp.mUiLabel, entry);
entry.mLabel = getString(R.string.process_format, (ie + 1));
} else {
entry.mLabel = getString(R.string.process);
}
} }
entries.add(entry); entries.add(entry);
} }
@@ -256,10 +253,11 @@ public class ProcessStatsDetail extends SettingsPreferenceFragment
processPref.setLayoutResource(R.layout.process_preference_category); processPref.setLayoutResource(R.layout.process_preference_category);
processPref.setTitle(entry.mLabel); processPref.setTitle(entry.mLabel);
long memoryUse = Math.max((long)(entry.mRunWeight * mWeightToRam), long duration = Math.max(entry.mRunDuration, entry.mBgDuration);
(long)(entry.mBgWeight * mWeightToRam)); long memoryUse = Math.max((long) (entry.mRunWeight * mWeightToRam),
(long) (entry.mBgWeight * mWeightToRam));
String memoryString = Formatter.formatShortFileSize(getActivity(), memoryUse); String memoryString = Formatter.formatShortFileSize(getActivity(), memoryUse);
CharSequence frequency = ProcStatsPackageEntry.getFrequency(entry.mRunDuration CharSequence frequency = ProcStatsPackageEntry.getFrequency(duration
/ (float)mTotalTime, getActivity()); / (float)mTotalTime, getActivity());
processPref.setSummary( processPref.setSummary(
getString(R.string.memory_use_running_format, memoryString, frequency)); getString(R.string.memory_use_running_format, memoryString, frequency));
@@ -268,6 +266,32 @@ public class ProcessStatsDetail extends SettingsPreferenceFragment
} }
} }
private static String capitalize(String processName) {
char c = processName.charAt(0);
if (!Character.isLowerCase(c)) {
return processName;
}
return Character.toUpperCase(c) + processName.substring(1);
}
private static String getProcessName(String appLabel, ProcStatsEntry entry) {
String processName = entry.mName;
if (processName.contains(":")) {
return capitalize(processName.substring(processName.lastIndexOf(':') + 1));
}
if (processName.startsWith(entry.mPackage)) {
if (processName.length() == entry.mPackage.length()) {
return appLabel;
}
int start = entry.mPackage.length();
if (processName.charAt(start) == '.') {
start++;
}
return capitalize(processName.substring(start));
}
return processName;
}
final static Comparator<ProcStatsEntry.Service> sServiceCompare final static Comparator<ProcStatsEntry.Service> sServiceCompare
= new Comparator<ProcStatsEntry.Service>() { = new Comparator<ProcStatsEntry.Service>() {
@Override @Override

View File

@@ -67,7 +67,7 @@ public class ProcessStatsPreference extends Preference {
setIcon(new ColorDrawable(0)); setIcon(new ColorDrawable(0));
} }
boolean statsForeground = entry.mRunWeight > entry.mBgWeight; boolean statsForeground = entry.mRunWeight > entry.mBgWeight;
setSummary(statsForeground ? entry.getRunningFrequency(getContext()) setSummary(entry.mRunDuration > entry.mBgDuration ? entry.getRunningFrequency(getContext())
: entry.getBackgroundFrequency(getContext())); : entry.getBackgroundFrequency(getContext()));
mAvgRatio = (statsForeground ? entry.mAvgRunMem : entry.mAvgBgMem) / maxMemory; mAvgRatio = (statsForeground ? entry.mAvgRunMem : entry.mAvgBgMem) / maxMemory;
mMaxRatio = (statsForeground ? entry.mMaxRunMem : entry.mMaxBgMem) / maxMemory - mAvgRatio; mMaxRatio = (statsForeground ? entry.mMaxRunMem : entry.mMaxBgMem) / maxMemory - mAvgRatio;

View File

@@ -16,7 +16,9 @@
package com.android.settings.applications; package com.android.settings.applications;
import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Bundle; import android.os.Bundle;
import android.preference.Preference; import android.preference.Preference;
@@ -28,7 +30,6 @@ import android.util.TimeUtils;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.SubMenu;
import android.widget.TextView; import android.widget.TextView;
import com.android.internal.app.ProcessStats; import com.android.internal.app.ProcessStats;
@@ -102,8 +103,6 @@ public class ProcessStatsUi extends InstrumentedPreferenceFragment {
private PreferenceGroup mAppListGroup; private PreferenceGroup mAppListGroup;
private TextView mMemStatus; private TextView mMemStatus;
private long mTotalTime;
private long[] mMemTimes = new long[ProcessStats.ADJ_MEM_FACTOR_COUNT]; private long[] mMemTimes = new long[ProcessStats.ADJ_MEM_FACTOR_COUNT];
private LinearColorBar mColors; private LinearColorBar mColors;
private TextView mMemUsed; private TextView mMemUsed;
@@ -200,7 +199,7 @@ public class ProcessStatsUi extends InstrumentedPreferenceFragment {
args.putBoolean(ProcessStatsDetail.EXTRA_USE_USS, mUseUss); args.putBoolean(ProcessStatsDetail.EXTRA_USE_USS, mUseUss);
args.putDouble(ProcessStatsDetail.EXTRA_WEIGHT_TO_RAM, args.putDouble(ProcessStatsDetail.EXTRA_WEIGHT_TO_RAM,
mStatsManager.getMemInfo().weightToRam); mStatsManager.getMemInfo().weightToRam);
args.putLong(ProcessStatsDetail.EXTRA_TOTAL_TIME, mTotalTime); args.putLong(ProcessStatsDetail.EXTRA_TOTAL_TIME, memTotalTime);
args.putFloat(ProcessStatsDetail.EXTRA_MAX_MEMORY_USAGE, mMaxMemoryUsage); args.putFloat(ProcessStatsDetail.EXTRA_MAX_MEMORY_USAGE, mMaxMemoryUsage);
args.putDouble(ProcessStatsDetail.EXTRA_TOTAL_SCALE, mStatsManager.getMemInfo().totalScale); args.putDouble(ProcessStatsDetail.EXTRA_TOTAL_SCALE, mStatsManager.getMemInfo().totalScale);
((SettingsActivity) getActivity()).startPreferencePanel( ((SettingsActivity) getActivity()).startPreferencePanel(
@@ -216,11 +215,8 @@ public class ProcessStatsUi extends InstrumentedPreferenceFragment {
.setAlphabeticShortcut('r'); .setAlphabeticShortcut('r');
refresh.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | refresh.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |
MenuItem.SHOW_AS_ACTION_WITH_TEXT); MenuItem.SHOW_AS_ACTION_WITH_TEXT);
SubMenu subMenu = menu.addSubMenu(R.string.menu_proc_stats_duration); menu.add(0, MENU_DURATION, 0, R.string.menu_proc_stats_duration);
for (int i=0; i<NUM_DURATIONS; i++) {
mDurationMenus[i] = subMenu.add(0, MENU_DURATION+i, 0, sDurationLabels[i])
.setCheckable(true);
}
// Hide these for now, until their need is determined. // Hide these for now, until their need is determined.
// mShowPercentageMenu = menu.add(0, MENU_SHOW_PERCENTAGE, 0, R.string.menu_show_percentage) // mShowPercentageMenu = menu.add(0, MENU_SHOW_PERCENTAGE, 0, R.string.menu_show_percentage)
// .setAlphabeticShortcut('p') // .setAlphabeticShortcut('p')
@@ -286,8 +282,7 @@ public class ProcessStatsUi extends InstrumentedPreferenceFragment {
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
final int id = item.getItemId(); switch (item.getItemId()) {
switch (id) {
case MENU_STATS_REFRESH: case MENU_STATS_REFRESH:
mStatsManager.refreshStats(false); mStatsManager.refreshStats(false);
refreshUi(); refreshUi();
@@ -318,13 +313,23 @@ public class ProcessStatsUi extends InstrumentedPreferenceFragment {
} }
refreshUi(); refreshUi();
return true; return true;
default: case MENU_DURATION:
if (id >= MENU_DURATION && id < (MENU_DURATION + NUM_DURATIONS)) { CharSequence[] durations = new CharSequence[sDurationLabels.length];
mStatsManager.setDuration(sDurations[id - MENU_DURATION]); for (int i = 0; i < sDurationLabels.length; i++) {
durations[i] = getString(sDurationLabels[i]);
}
new AlertDialog.Builder(getContext())
.setTitle(item.getTitle())
.setItems(durations, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mStatsManager.setDuration(sDurations[which]);
refreshUi(); refreshUi();
} }
return false; }).show();
return true;
} }
return false;
} }
/** /**
@@ -360,7 +365,6 @@ public class ProcessStatsUi extends InstrumentedPreferenceFragment {
private void refreshUi() { private void refreshUi() {
updateMenus(); updateMenus();
mAppListGroup.removeAll(); mAppListGroup.removeAll();
mAppListGroup.setOrderingAsAdded(false); mAppListGroup.setOrderingAsAdded(false);
mHeader.setOrder(-1); mHeader.setOrder(-1);
@@ -368,12 +372,8 @@ public class ProcessStatsUi extends InstrumentedPreferenceFragment {
final long elapsedTime = mStatsManager.getElapsedTime(); final long elapsedTime = mStatsManager.getElapsedTime();
memTotalTime = mTotalTime;
final Context context = getActivity(); final Context context = getActivity();
// TODO: More Colors. // TODO: More Colors.
mColors.setColors(context.getColor(R.color.running_processes_apps_ram),
context.getColor(R.color.running_processes_apps_ram),
context.getColor(R.color.running_processes_free_ram));
// For computing the ratio to show, we want to count the baseline cached RAM we // For computing the ratio to show, we want to count the baseline cached RAM we
// need (at which point we start killing processes) as used RAM, so that if we // need (at which point we start killing processes) as used RAM, so that if we
@@ -383,30 +383,36 @@ public class ProcessStatsUi extends InstrumentedPreferenceFragment {
// match the real physical RAM, scale those to the actual physical RAM. No problem! // match the real physical RAM, scale those to the actual physical RAM. No problem!
MemInfo memInfo = mStatsManager.getMemInfo(); MemInfo memInfo = mStatsManager.getMemInfo();
memTotalTime = memInfo.memTotalTime;
double usedRam = memInfo.realUsedRam;
double totalRam = memInfo.realTotalRam;
double freeRam = memInfo.realFreeRam;
String durationString = Utils.formatElapsedTime(context, elapsedTime, false); String durationString = Utils.formatElapsedTime(context, elapsedTime, false);
String usedString = Formatter.formatShortFileSize(context, (long) memInfo.realUsedRam); String usedString = Formatter.formatShortFileSize(context, (long) usedRam);
String totalString = Formatter.formatShortFileSize(context, (long) memInfo.realTotalRam); String totalString = Formatter.formatShortFileSize(context, (long) totalRam);
CharSequence memString; CharSequence memString;
CharSequence[] memStatesStr = getResources().getTextArray(R.array.ram_states); CharSequence[] memStatesStr = getResources().getTextArray(R.array.ram_states);
int memState = mStatsManager.getMemState(); int memState = mStatsManager.getMemState();
int memColor;
if (memState >= 0 && memState < memStatesStr.length) { if (memState >= 0 && memState < memStatesStr.length) {
memString = memStatesStr[memState]; memString = memStatesStr[memState];
memColor = getResources().getIntArray(R.array.ram_colors)[memState];
} else { } else {
memString = "?"; memString = "?";
memColor = context.getColor(R.color.running_processes_apps_ram);
} }
mColors.setColors(memColor, memColor, context.getColor(R.color.running_processes_free_ram));
if (mShowPercentage) { if (mShowPercentage) {
mMemUsed.setText(context.getString( mMemUsed.setText(context.getString(
R.string.process_stats_total_duration_percentage, R.string.process_stats_total_duration_percentage,
Utils.formatPercentage((long) memInfo.realUsedRam, (long) memInfo.realTotalRam), Utils.formatPercentage((long) usedRam, (long) totalRam),
durationString)); durationString));
} else { } else {
mMemUsed.setText(context.getString(R.string.process_stats_total_duration, mMemUsed.setText(context.getString(R.string.process_stats_total_duration,
usedString, totalString, durationString)); usedString, totalString, durationString));
} }
mMemStatus.setText(context.getString(R.string.process_stats_memory_status, mMemStatus.setText(memString);
memString)); float usedRatio = (float)(usedRam / (freeRam + usedRam));
float usedRatio = (float)(memInfo.realUsedRam
/ (memInfo.realFreeRam + memInfo.realUsedRam));
mColors.setRatios(usedRatio, 0, 1-usedRatio); mColors.setRatios(usedRatio, 0, 1-usedRatio);
List<ProcStatsPackageEntry> pkgEntries = mStatsManager.getEntries(); List<ProcStatsPackageEntry> pkgEntries = mStatsManager.getEntries();