Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5c3301b0 authored by Fan Zhang's avatar Fan Zhang
Browse files

Add configs to display/hide a few tiles in device info page

- Displaying/hiding Emergency info, branded account, device header
  widget are now driven by config flags
- Also refactored controllers to use BasePreferenceController

Change-Id: Ie601ebf689e0744c6a05a2cca5513fa43ef355e0
Fixes: 119607340
Test: robotests
parent c2448a1e
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -143,6 +143,15 @@
    <!-- Whether or not homepage should display user's account avatar -->
    <bool name="config_show_avatar_in_homepage">false</bool>

    <!-- Whether or not emergency info tile should display in device info page -->
    <bool name="config_show_emergency_info_in_device_info">true</bool>

    <!-- Whether or not branded account info tile should display in device info page -->
    <bool name="config_show_branded_account_in_device_info">true</bool>

    <!-- Whether or not device header widget tile should display in device info page -->
    <bool name="config_show_device_header_in_device_info">true</bool>

    <!-- Whether or not TopLevelSettings should force rounded icon for injected tiles -->
    <bool name="config_force_rounded_icon_TopLevelSettings">true</bool>

+8 −5
Original line number Diff line number Diff line
@@ -25,7 +25,8 @@
        android:key="my_device_info_header"
        android:order="0"
        android:layout="@layout/settings_entity_header"
        android:selectable="false"/>
        android:selectable="false"
        settings:isPreferenceVisible="false"/>

    <!-- Device name -->
    <com.android.settings.widget.ValidatedEditTextPreference
@@ -33,6 +34,7 @@
        android:order="1"
        android:title="@string/my_device_info_device_name_preference_title"
        android:summary="@string/summary_placeholder"
        settings:controller="com.android.settings.deviceinfo.DeviceNamePreferenceController"
        settings:enableCopying="true"/>

    <!-- Account name -->
@@ -40,7 +42,8 @@
        android:key="branded_account"
        android:order="2"
        android:title="@string/my_device_info_account_preference_title"
        android:summary="@string/summary_placeholder"/>
        android:summary="@string/summary_placeholder"
        settings:controller="com.android.settings.deviceinfo.BrandedAccountPreferenceController"/>

    <!-- Phone number -->
    <Preference
@@ -50,15 +53,15 @@
        android:summary="@string/summary_placeholder"
        android:selectable="false"
        settings:allowDynamicSummaryInSlice="true"
        settings:controller=
            "com.android.settings.deviceinfo.PhoneNumberPreferenceController"
        settings:controller="com.android.settings.deviceinfo.PhoneNumberPreferenceController"
        settings:enableCopying="true"/>

    <Preference
        android:key="emergency_info"
        android:order="4"
        android:title="@string/emergency_info_title"
        android:summary="@string/summary_placeholder"/>
        android:summary="@string/summary_placeholder"
        settings:controller="com.android.settings.accounts.EmergencyInfoPreferenceController"/>

    <!-- Legal information -->
    <Preference
+19 −19
Original line number Diff line number Diff line
@@ -22,27 +22,25 @@ import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.os.UserHandle;
import android.os.UserManager;
import android.text.TextUtils;
import android.util.FeatureFlagUtils;

import androidx.preference.Preference;

import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.search.SearchIndexableRaw;
import com.android.settingslib.core.AbstractPreferenceController;

import java.util.List;

public class EmergencyInfoPreferenceController extends AbstractPreferenceController
        implements PreferenceControllerMixin {
public class EmergencyInfoPreferenceController extends BasePreferenceController {

    public static final String ACTION_EDIT_EMERGENCY_INFO = "android.settings.EDIT_EMERGENCY_INFO";

    private static final String KEY_EMERGENCY_INFO = "emergency_info";
    private static final String PACKAGE_NAME_EMERGENCY = "com.android.emergency";

    public EmergencyInfoPreferenceController(Context context) {
        super(context);
    public EmergencyInfoPreferenceController(Context context, String preferenceKey) {
        super(context, preferenceKey);
    }

    @Override
@@ -56,6 +54,7 @@ public class EmergencyInfoPreferenceController extends AbstractPreferenceControl
        }
    }

    @Override
    public void updateState(Preference preference) {
        UserInfo info = mContext.getSystemService(UserManager.class).getUserInfo(
                UserHandle.myUserId());
@@ -64,7 +63,7 @@ public class EmergencyInfoPreferenceController extends AbstractPreferenceControl

    @Override
    public boolean handlePreferenceTreeClick(Preference preference) {
        if (KEY_EMERGENCY_INFO.equals(preference.getKey())) {
        if (TextUtils.equals(getPreferenceKey(), preference.getKey())) {
            Intent intent = new Intent(getIntentAction(mContext));
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            mContext.startActivity(intent);
@@ -74,18 +73,19 @@ public class EmergencyInfoPreferenceController extends AbstractPreferenceControl
    }

    @Override
    public boolean isAvailable() {
        Intent intent = new Intent(getIntentAction(mContext)).setPackage(getPackageName(mContext));
        List<ResolveInfo> infos = mContext.getPackageManager().queryIntentActivities(intent, 0);
        return infos != null && !infos.isEmpty();
    public int getAvailabilityStatus() {
        if (!mContext.getResources().getBoolean(R.bool.config_show_emergency_info_in_device_info)) {
            return UNSUPPORTED_ON_DEVICE;
        }

    @Override
    public String getPreferenceKey() {
        return KEY_EMERGENCY_INFO;
        final Intent intent = new Intent(getIntentAction(mContext)).setPackage(
                getPackageName(mContext));
        final List<ResolveInfo> infos = mContext.getPackageManager().queryIntentActivities(intent,
                0);
        return infos != null && !infos.isEmpty()
                ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
    }

    private String getIntentAction(Context context) {
    private static String getIntentAction(Context context) {
        if (FeatureFlagUtils.isEnabled(context, FeatureFlagUtils.SAFETY_HUB)) {
            return context.getResources().getString(R.string.config_emergency_intent_action);
        }
@@ -93,7 +93,7 @@ public class EmergencyInfoPreferenceController extends AbstractPreferenceControl
        return ACTION_EDIT_EMERGENCY_INFO;
    }

    private String getPackageName(Context context) {
    private static String getPackageName(Context context) {
        if (FeatureFlagUtils.isEnabled(context, FeatureFlagUtils.SAFETY_HUB)) {
            return context.getResources().getString(R.string.config_emergency_package_name);
        }
+7 −4
Original line number Diff line number Diff line
@@ -32,11 +32,10 @@ import com.android.settings.core.SubSettingLauncher;
import com.android.settings.overlay.FeatureFactory;

public class BrandedAccountPreferenceController extends BasePreferenceController {
    private static final String KEY_PREFERENCE_TITLE = "branded_account";
    private final Account[] mAccounts;

    public BrandedAccountPreferenceController(Context context) {
        super(context, KEY_PREFERENCE_TITLE);
    public BrandedAccountPreferenceController(Context context, String key) {
        super(context, key);
        final AccountFeatureProvider accountFeatureProvider = FeatureFactory.getFactory(
                mContext).getAccountFeatureProvider();
        mAccounts = accountFeatureProvider.getAccounts(mContext);
@@ -44,6 +43,10 @@ public class BrandedAccountPreferenceController extends BasePreferenceController

    @Override
    public int getAvailabilityStatus() {
        if (!mContext.getResources().getBoolean(
                R.bool.config_show_branded_account_in_device_info)) {
            return UNSUPPORTED_ON_DEVICE;
        }
        if (mAccounts != null && mAccounts.length > 0) {
            return AVAILABLE;
        }
@@ -55,7 +58,7 @@ public class BrandedAccountPreferenceController extends BasePreferenceController
        super.displayPreference(screen);
        final AccountFeatureProvider accountFeatureProvider = FeatureFactory.getFactory(
                mContext).getAccountFeatureProvider();
        final Preference accountPreference = screen.findPreference(KEY_PREFERENCE_TITLE);
        final Preference accountPreference = screen.findPreference(getPreferenceKey());
        if (accountPreference != null && (mAccounts == null || mAccounts.length == 0)) {
            screen.removePreference(accountPreference);
            return;
+3 −10
Original line number Diff line number Diff line
@@ -43,8 +43,6 @@ public class DeviceNamePreferenceController extends BasePreferenceController
        LifecycleObserver,
        OnSaveInstanceState,
        OnCreate {
    private static final String PREF_KEY = "device_name";
    public static final int DEVICE_NAME_SET_WARNING_ID = 1;
    private static final String KEY_PENDING_DEVICE_NAME = "key_pending_device_name";
    private String mDeviceName;
    protected WifiManager mWifiManager;
@@ -54,8 +52,8 @@ public class DeviceNamePreferenceController extends BasePreferenceController
    private DeviceNamePreferenceHost mHost;
    private String mPendingDeviceName;

    public DeviceNamePreferenceController(Context context) {
        super(context, PREF_KEY);
    public DeviceNamePreferenceController(Context context, String key) {
        super(context, key);

        mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        mWifiDeviceNameTextValidator = new WifiDeviceNameTextValidator();
@@ -67,7 +65,7 @@ public class DeviceNamePreferenceController extends BasePreferenceController
    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);
        mPreference = (ValidatedEditTextPreference) screen.findPreference(PREF_KEY);
        mPreference = screen.findPreference(getPreferenceKey());
        final CharSequence deviceName = getSummary();
        mPreference.setSummary(deviceName);
        mPreference.setText(deviceName.toString());
@@ -94,11 +92,6 @@ public class DeviceNamePreferenceController extends BasePreferenceController
                : UNSUPPORTED_ON_DEVICE;
    }

    @Override
    public String getPreferenceKey() {
        return PREF_KEY;
    }

    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        mPendingDeviceName = (String) newValue;
Loading