Hide Memory usage UI fields if flag is enabled

This change updates the Memory use UI in developer settings to hide
memory fields by default if the AppProfiler PSS deprecation flag is
enabled. A toggle is provided to resume PSS profiling and reinstate the
memory fields, and shows a dialog to reboot if the toggle is updated.

The summary for the "Memory" button in developer settings will show
"Memory profiling disabled" instead of "Avg X GB of Y memory used" if
PSS profiling is not enabled.

Test: With the flag enabled, flash and verify that:
      - The memory fields are hidden by default, and the summary shows
	the expected "Memory profiling disabled" text
      - Clicking the toggle shows the reboot dialog, which will
	correctly change the setting and reboot if accepted, and keep
	the setting and not reboot if denied
      - Check that AppProfiler correctly profiles PSS or RSS based on
	the state of the toggle, which persists across reboots
      - Included UI test for Memory page elements based on flag value.
Bug: 296454553
Change-Id: Ie21791502445a321446cb8110e5800089f47ac58
This commit is contained in:
Kevin Jeon
2023-12-14 18:11:56 -05:00
parent b1ab7f0373
commit 55c8c9b86c
6 changed files with 222 additions and 45 deletions

View File

@@ -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();
}
}
}
}

View File

@@ -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));
});
}