Merge "Hide Memory usage UI fields if flag is enabled" into main
This commit is contained in:
@@ -16,20 +16,26 @@
|
||||
package com.android.settings.applications;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.icu.text.MessageFormat;
|
||||
import android.os.Bundle;
|
||||
import android.os.Flags;
|
||||
import android.provider.Settings;
|
||||
import android.text.format.Formatter;
|
||||
import android.text.format.Formatter.BytesResult;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.Preference.OnPreferenceClickListener;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SummaryPreference;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.applications.ProcStatsData.MemInfo;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.development.DisableDevSettingsDialogFragment;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
@@ -37,6 +43,8 @@ import java.util.Map;
|
||||
|
||||
public class ProcessStatsSummary extends ProcessStatsBase implements OnPreferenceClickListener {
|
||||
|
||||
private static final String KEY_PREF_SCREEN = "app_list";
|
||||
private static final String KEY_MEMORY_INFO_PREF_GROUP = "memory_info";
|
||||
private static final String KEY_STATUS_HEADER = "status_header";
|
||||
|
||||
private static final String KEY_PERFORMANCE = "performance";
|
||||
@@ -44,7 +52,9 @@ public class ProcessStatsSummary extends ProcessStatsBase implements OnPreferenc
|
||||
private static final String KEY_AVERAGY_USED = "average_used";
|
||||
private static final String KEY_FREE = "free";
|
||||
private static final String KEY_APP_LIST = "apps_list";
|
||||
private static final String KEY_FORCE_ENABLE_PSS_PROFILING = "force_enable_pss_profiling";
|
||||
|
||||
private PreferenceCategory mMemoryInfoPrefCategory;
|
||||
private SummaryPreference mSummaryPref;
|
||||
|
||||
private Preference mPerformance;
|
||||
@@ -52,12 +62,14 @@ public class ProcessStatsSummary extends ProcessStatsBase implements OnPreferenc
|
||||
private Preference mAverageUsed;
|
||||
private Preference mFree;
|
||||
private Preference mAppListPreference;
|
||||
private SwitchPreference mForceEnablePssProfiling;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
addPreferencesFromResource(R.xml.process_stats_summary);
|
||||
mMemoryInfoPrefCategory = (PreferenceCategory) findPreference(KEY_MEMORY_INFO_PREF_GROUP);
|
||||
mSummaryPref = (SummaryPreference) findPreference(KEY_STATUS_HEADER);
|
||||
mPerformance = findPreference(KEY_PERFORMANCE);
|
||||
mTotalMemory = findPreference(KEY_TOTAL_MEMORY);
|
||||
@@ -65,11 +77,37 @@ public class ProcessStatsSummary extends ProcessStatsBase implements OnPreferenc
|
||||
mFree = findPreference(KEY_FREE);
|
||||
mAppListPreference = findPreference(KEY_APP_LIST);
|
||||
mAppListPreference.setOnPreferenceClickListener(this);
|
||||
|
||||
// This preference is only applicable if the flag for PSS deprecation in AppProfiler is
|
||||
// enabled. Otherwise, it can immediately be hidden.
|
||||
mForceEnablePssProfiling =
|
||||
(SwitchPreference) findPreference(KEY_FORCE_ENABLE_PSS_PROFILING);
|
||||
if (Flags.removeAppProfilerPssCollection()) {
|
||||
mForceEnablePssProfiling.setOnPreferenceClickListener(this);
|
||||
// Make the toggle reflect the current state of the global setting.
|
||||
mForceEnablePssProfiling.setChecked(isPssProfilingForceEnabled(getContext()));
|
||||
} else {
|
||||
mForceEnablePssProfiling.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshPreferences() {
|
||||
// The memory fields should be static if the flag is not enabled.
|
||||
if (!Flags.removeAppProfilerPssCollection()) {
|
||||
return;
|
||||
}
|
||||
mMemoryInfoPrefCategory.setVisible(mForceEnablePssProfiling.isChecked());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshUi() {
|
||||
Context context = getContext();
|
||||
refreshPreferences();
|
||||
|
||||
// If PSS collection is not enabled, none of the following work needs to be done.
|
||||
if (Flags.removeAppProfilerPssCollection() && !isPssProfilingForceEnabled(context)) {
|
||||
return;
|
||||
}
|
||||
|
||||
MemInfo memInfo = mStatsManager.getMemInfo();
|
||||
|
||||
@@ -100,7 +138,8 @@ public class ProcessStatsSummary extends ProcessStatsBase implements OnPreferenc
|
||||
String durationString = getString(sDurationLabels[mDurationIndex]);
|
||||
int numApps = mStatsManager.getEntries().size();
|
||||
MessageFormat msgFormat = new MessageFormat(
|
||||
getResources().getString(R.string.memory_usage_apps_summary), Locale.getDefault());
|
||||
getResources().getString(R.string.memory_usage_apps_summary),
|
||||
Locale.getDefault());
|
||||
Map<String, Object> arguments = new HashMap<>();
|
||||
arguments.put("count", numApps);
|
||||
arguments.put("time", durationString);
|
||||
@@ -131,7 +170,34 @@ public class ProcessStatsSummary extends ProcessStatsBase implements OnPreferenc
|
||||
.setSourceMetricsCategory(getMetricsCategory())
|
||||
.launch();
|
||||
return true;
|
||||
} else if (preference == mForceEnablePssProfiling) {
|
||||
DisableDevSettingsDialogFragment.show(this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isPssProfilingForceEnabled(Context context) {
|
||||
ContentResolver cr = context.getContentResolver();
|
||||
return Settings.Global.getInt(cr, Settings.Global.FORCE_ENABLE_PSS_PROFILING, 0) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the reboot confirmation button is clicked.
|
||||
*/
|
||||
public void onRebootDialogConfirmed() {
|
||||
Context context = getContext();
|
||||
ContentResolver cr = context.getContentResolver();
|
||||
Settings.Global.putInt(cr, Settings.Global.FORCE_ENABLE_PSS_PROFILING,
|
||||
mForceEnablePssProfiling.isChecked() ? 1 : 0);
|
||||
refreshPreferences();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the reboot deny button is clicked.
|
||||
*/
|
||||
public void onRebootDialogCanceled() {
|
||||
// Set the toggle to reflect the state of the setting, which should not have changed.
|
||||
mForceEnablePssProfiling.setChecked(isPssProfilingForceEnabled(getContext()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.applications.ProcessStatsSummary;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
|
||||
public class DisableDevSettingsDialogFragment extends InstrumentedDialogFragment
|
||||
@@ -42,7 +44,7 @@ public class DisableDevSettingsDialogFragment extends InstrumentedDialogFragment
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public static void show(DevelopmentSettingsDashboardFragment host) {
|
||||
public static void show(SettingsPreferenceFragment host) {
|
||||
final DisableDevSettingsDialogFragment dialog = new DisableDevSettingsDialogFragment();
|
||||
dialog.setTargetFragment(host, 0 /* requestCode */);
|
||||
// We need to handle data changes and switch state based on which button user clicks,
|
||||
@@ -75,18 +77,31 @@ public class DisableDevSettingsDialogFragment extends InstrumentedDialogFragment
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Fragment fragment = getTargetFragment();
|
||||
if (!(fragment instanceof DevelopmentSettingsDashboardFragment)){
|
||||
if (!(fragment instanceof DevelopmentSettingsDashboardFragment)
|
||||
&& !(fragment instanceof ProcessStatsSummary)) {
|
||||
Log.e(TAG, "getTargetFragment return unexpected type");
|
||||
}
|
||||
|
||||
final DevelopmentSettingsDashboardFragment host =
|
||||
(DevelopmentSettingsDashboardFragment) fragment;
|
||||
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||
host.onDisableDevelopmentOptionsConfirmed();
|
||||
PowerManager pm = getContext().getSystemService(PowerManager.class);
|
||||
pm.reboot(null);
|
||||
} else {
|
||||
host.onDisableDevelopmentOptionsRejected();
|
||||
if (fragment instanceof DevelopmentSettingsDashboardFragment) {
|
||||
final DevelopmentSettingsDashboardFragment host =
|
||||
(DevelopmentSettingsDashboardFragment) fragment;
|
||||
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||
host.onDisableDevelopmentOptionsConfirmed();
|
||||
PowerManager pm = getContext().getSystemService(PowerManager.class);
|
||||
pm.reboot(null);
|
||||
} else {
|
||||
host.onDisableDevelopmentOptionsRejected();
|
||||
}
|
||||
} else if (fragment instanceof ProcessStatsSummary) {
|
||||
final ProcessStatsSummary host =
|
||||
(ProcessStatsSummary) fragment;
|
||||
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||
host.onRebootDialogConfirmed();
|
||||
PowerManager pm = getContext().getSystemService(PowerManager.class);
|
||||
pm.reboot(null);
|
||||
} else {
|
||||
host.onRebootDialogCanceled();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
package com.android.settings.development;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Flags;
|
||||
import android.provider.Settings;
|
||||
import android.text.format.Formatter;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
@@ -65,9 +67,13 @@ public class MemoryUsagePreferenceController extends DeveloperOptionsPreferenceC
|
||||
(long) memInfo.realUsedRam);
|
||||
final String totalResult = Formatter.formatShortFileSize(mContext,
|
||||
(long) memInfo.realTotalRam);
|
||||
ThreadUtils.postOnMainThread(
|
||||
() -> mPreference.setSummary(mContext.getString(R.string.memory_summary,
|
||||
usedResult, totalResult)));
|
||||
boolean displayMemorySummary = !Flags.removeAppProfilerPssCollection();
|
||||
displayMemorySummary |= Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.FORCE_ENABLE_PSS_PROFILING, 0) == 1;
|
||||
String summary = displayMemorySummary
|
||||
? mContext.getString(R.string.memory_summary, usedResult, totalResult)
|
||||
: mContext.getString(R.string.pss_profiling_disabled);
|
||||
ThreadUtils.postOnMainThread(() -> mPreference.setSummary(summary));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user