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

Commit 5451a645 authored by Cameron Pickett's avatar Cameron Pickett
Browse files

Add headset icon toggle (Framework)

What:
Adds a setting that enables/disables the headset icon from displaying on the
status bar when a wired headset is plugged in.

Why:
Many users have requested this feature because the icon wastes space on their
status bar and is somewhat unnecessary. Also, other UI's for android do not
include a headset icon (Sense, for example), so users may be used to not seeing
the icon and prefer it that way. Users with this preference can now disable
the icon from ever appearing.

Change-Id: I0b066af15e5d2534a29cc7a6b5bea222c30ea1e0
parent f82fa927
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -2446,6 +2446,14 @@ public final class Settings {
         */
        public static final String STATUS_BAR_BRIGHTNESS_TOGGLE = "status_bar_brightness_toggle";

        /**
         * Whether to display headset icon on status bar when headset is plugged in
         * 0: headset icon is never displayed
         * 1: headset icon is displayed when headset is plugged in
         * @hide
         */
        public static final String STATUS_BAR_HEADSET = "status_bar_headset";

        /**
         * Whether to wake the screen with the trackball. The value is boolean (1 or 0).
         * @hide
+18 −7
Original line number Diff line number Diff line
@@ -92,6 +92,9 @@ public class StatusBarPolicy {
    private final Handler mHandler = new StatusBarHandler();
    private final IBatteryStats mBatteryStats;

    // headset
    private boolean mHeadsetPlugged = false;

    // storage
    private StorageManager mStorageManager;

@@ -604,6 +607,8 @@ public class StatusBarPolicy {
    // need another var that superceding mPhoneSignalHidden
    private boolean mShowCmSignal;

    private boolean mShowHeadset;

    class SettingsObserver extends ContentObserver {
        SettingsObserver(Handler handler) {
            super(handler);
@@ -616,6 +621,9 @@ public class StatusBarPolicy {

            resolver.registerContentObserver(Settings.System
                    .getUriFor(Settings.System.STATUS_BAR_CM_SIGNAL_TEXT), false, this);

            resolver.registerContentObserver(Settings.System
                    .getUriFor(Settings.System.STATUS_BAR_HEADSET), false, this);
        }

        @Override public void onChange(boolean selfChange) {
@@ -1386,16 +1394,16 @@ public class StatusBarPolicy {
    }

    private final void updateHeadset(Intent intent) {
        final boolean isConnected = intent.getIntExtra("state", 0) == 1;
        mHeadsetPlugged = intent.getIntExtra("state", 0) == 1;

        if (isConnected) {
        if (mHeadsetPlugged) {
            final boolean hasMicrophone = intent.getIntExtra("microphone", 1) == 1;
            final int iconId = hasMicrophone
                    ? com.android.internal.R.drawable.stat_sys_headset
                    : R.drawable.stat_sys_headset_no_mic;
            mService.setIcon("headset", iconId, 0);
        }
        mService.setIconVisibility("headset", isConnected);
        mService.setIconVisibility("headset", mShowHeadset && mHeadsetPlugged);
    }

    private final void updateBluetooth(Intent intent) {
@@ -1660,5 +1668,8 @@ public class StatusBarPolicy {
                Settings.System.STATUS_BAR_CM_SIGNAL_TEXT, 0) != 0;
        mService.setIconVisibility("phone_signal", !mShowCmSignal);

        mShowHeadset = (Settings.System.getInt(resolver,
                Settings.System.STATUS_BAR_HEADSET, 1) == 1);
        mService.setIconVisibility("headset", mShowHeadset && mHeadsetPlugged);
    }
}