[Expressive design] Update AppDataUsage.

Migrate EntityHeader to IntroPReference.
Remove background of SpinnerPreference.

Bug: 349681531
Flag: EXEMPT migration
Test: atest AppDataUsageTest
Change-Id: Icb91c418a67489e3069f958356a9675f279ee5f8
This commit is contained in:
Yuchen
2024-12-13 06:56:00 +00:00
parent 224c16db50
commit c7635b1705
5 changed files with 70 additions and 50 deletions

View File

@@ -18,6 +18,7 @@ import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND;
import static com.android.settings.datausage.lib.AppDataUsageRepository.getAppUid;
import static com.android.settings.datausage.lib.AppDataUsageRepository.getAppUidList;
import static com.android.settings.spa.app.appinfo.AppInfoSettingsProvider.startAppInfoSettings;
import android.app.Activity;
import android.app.settings.SettingsEnums;
@@ -45,13 +46,14 @@ import com.android.settings.datausage.lib.AppDataUsageDetailsRepository;
import com.android.settings.datausage.lib.NetworkTemplates;
import com.android.settings.fuelgauge.datasaver.DynamicDenylistManager;
import com.android.settings.network.SubscriptionUtil;
import com.android.settings.widget.EntityHeaderController;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.AppItem;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.RestrictedSwitchPreference;
import com.android.settingslib.net.UidDetail;
import com.android.settingslib.net.UidDetailProvider;
import com.android.settingslib.widget.IntroPreference;
import kotlin.Unit;
@@ -65,6 +67,8 @@ public class AppDataUsage extends DataUsageBaseFragment implements OnPreferenceC
private static final String TAG = "AppDataUsage";
static final String ARG_APP_ITEM = "app_item";
@VisibleForTesting
static final String ARG_APP_HEADER = "app_header";
static final String ARG_NETWORK_TEMPLATE = "network_template";
static final String ARG_NETWORK_CYCLES = "network_cycles";
static final String ARG_SELECTED_CYCLE = "selected_cycle";
@@ -176,7 +180,7 @@ public class AppDataUsage extends DataUsageBaseFragment implements OnPreferenceC
removePreference(KEY_RESTRICT_BACKGROUND);
}
addEntityHeader();
setupIntroPreference();
}
@Override
@@ -320,32 +324,32 @@ public class AppDataUsage extends DataUsageBaseFragment implements OnPreferenceC
}
@VisibleForTesting
void addEntityHeader() {
String pkg = mPackages.size() != 0 ? mPackages.valueAt(0) : null;
int uid = 0;
if (pkg != null) {
void setupIntroPreference() {
final Preference pref = getPreferenceScreen().findPreference(ARG_APP_HEADER);
if (pref != null) {
pref.setIcon(mIcon);
pref.setTitle(mLabel);
pref.setSelectable(true);
}
}
@Override
public boolean onPreferenceTreeClick(Preference preference) {
if (!(preference instanceof IntroPreference)) return false;
String pkg = !mPackages.isEmpty() ? mPackages.valueAt(0) : null;
if (mAppItem.key > 0 && pkg != null) {
try {
uid = mPackageManager.getPackageUidAsUser(pkg,
int uid = mPackageManager.getPackageUidAsUser(pkg,
UserHandle.getUserId(mAppItem.key));
startAppInfoSettings(pkg, uid, this, 0 /* request */,
FeatureFactory.getFeatureFactory().getMetricsFeatureProvider()
.getMetricsCategory(this));
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "Skipping UID because cannot find package " + pkg);
}
}
final boolean showInfoButton = mAppItem.key > 0;
final Activity activity = getActivity();
final Preference pref = EntityHeaderController
.newInstance(activity, this, null /* header */)
.setUid(uid)
.setHasAppInfoLink(showInfoButton)
.setButtonActions(EntityHeaderController.ActionType.ACTION_NONE,
EntityHeaderController.ActionType.ACTION_NONE)
.setIcon(mIcon)
.setLabel(mLabel)
.setPackageName(pkg)
.done(getPrefContext());
getPreferenceScreen().addPreference(pref);
return true;
}
@Override

View File

@@ -17,7 +17,6 @@
package com.android.settings.datausage
import android.content.Context
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.res.stringResource
@@ -28,6 +27,7 @@ import com.android.settings.datausage.lib.NetworkUsageDetailsData
import com.android.settings.spa.preference.ComposePreferenceController
import com.android.settingslib.spa.widget.preference.Preference
import com.android.settingslib.spa.widget.preference.PreferenceModel
import com.android.settingslib.spa.widget.ui.Category
import com.android.settingslib.spaprivileged.framework.compose.getPlaceholder
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.map
@@ -60,7 +60,7 @@ class AppDataUsageSummaryController(context: Context, preferenceKey: String) :
@Composable
override fun Content() {
Column {
Category {
val totalUsage by totalUsageFlow.collectAsStateWithLifecycle(emptyDataUsage)
val foregroundUsage by foregroundUsageFlow.collectAsStateWithLifecycle(emptyDataUsage)
val backgroundUsage by backgroundUsageFlow.collectAsStateWithLifecycle(emptyDataUsage)

View File

@@ -25,8 +25,10 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
import com.android.settingslib.widget.GroupSectionDividerMixin;
public class SpinnerPreference extends Preference implements CycleAdapter.SpinnerInterface {
public class SpinnerPreference extends Preference implements CycleAdapter.SpinnerInterface,
GroupSectionDividerMixin {
private CycleAdapter mAdapter;
@Nullable