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

Commit c9f80066 authored by Aayush Gupta's avatar Aayush Gupta
Browse files

Merge remote-tracking branch 'origin/lineage-18.1' into v1-r

parents 549611e8 422769ab
Loading
Loading
Loading
Loading
+1 −9
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.app.AlarmManager;
import android.app.AlarmManager.AlarmClockInfo;
import android.app.IActivityManager;
import android.app.SynchronousUserSwitchObserver;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -43,7 +42,6 @@ import android.view.View;

import androidx.lifecycle.Observer;

import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.systemui.R;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dagger.qualifiers.DisplayId;
@@ -231,7 +229,6 @@ public class PhoneStatusBarPolicy

        filter.addAction(AudioManager.ACTION_HEADSET_PLUG);
        filter.addAction(Intent.ACTION_SIM_STATE_CHANGED);
        filter.addAction(BluetoothDevice.ACTION_BATTERY_LEVEL_CHANGED);
        filter.addAction(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED);
        filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE);
        filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE);
@@ -443,9 +440,7 @@ public class PhoneStatusBarPolicy
            if (mBluetooth.isBluetoothConnected()
                    && (mBluetooth.isBluetoothAudioActive()
                    || !mBluetooth.isBluetoothAudioProfileOnly())) {
                List<CachedBluetoothDevice> connectedDevices = mBluetooth.getConnectedDevices();
                int batteryLevel = connectedDevices.isEmpty() ?
                        -1 : connectedDevices.get(0).getBatteryLevel();
                int batteryLevel = mBluetooth.getBatteryLevel();
                if (batteryLevel == 100) {
                    iconId = R.drawable.stat_sys_data_bluetooth_connected_battery_9;
                } else if (batteryLevel >= 90) {
@@ -742,9 +737,6 @@ public class PhoneStatusBarPolicy
                case AudioManager.ACTION_HEADSET_PLUG:
                    updateHeadsetPlug(intent);
                    break;
                case BluetoothDevice.ACTION_BATTERY_LEVEL_CHANGED:
                    updateBluetooth();
                    break;
            }
        }
    };
+2 −0
Original line number Diff line number Diff line
@@ -44,6 +44,8 @@ public interface BluetoothController extends CallbackController<Callback>, Dumpa
    int getBondState(CachedBluetoothDevice device);
    List<CachedBluetoothDevice> getConnectedDevices();

    int getBatteryLevel();

    public interface Callback {
        void onBluetoothStateChange(boolean enabled);
        void onBluetoothDevicesChanged();
+19 −0
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
    private int mConnectionState = BluetoothAdapter.STATE_DISCONNECTED;
    private boolean mAudioProfileOnly;
    private boolean mIsActive;
    private int mBatteryLevel;

    private final H mHandler;
    private int mState;
@@ -107,6 +108,7 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
        pw.print("  mEnabled="); pw.println(mEnabled);
        pw.print("  mConnectionState="); pw.println(stateToString(mConnectionState));
        pw.print("  mAudioProfileOnly="); pw.println(mAudioProfileOnly);
        pw.print("  mBatteryLevel="); pw.println(mBatteryLevel);
        pw.print("  mIsActive="); pw.println(mIsActive);
        pw.print("  mConnectedDevices="); pw.println(mConnectedDevices);
        pw.print("  mCallbacks.size="); pw.println(mHandler.mCallbacks.size());
@@ -255,6 +257,7 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
            mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED);
        }
        updateAudioProfile();
        updateBattery();
    }

    private void updateActive() {
@@ -298,6 +301,22 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa

    }

    @Override
    public int getBatteryLevel() {
        if (!mConnectedDevices.isEmpty()) {
            return mConnectedDevices.get(0).getBatteryLevel();
        }
        return -1;
    }

    private void updateBattery() {
        int batteryLevel = getBatteryLevel();
        if (batteryLevel != mBatteryLevel) {
            mBatteryLevel = batteryLevel;
            mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED);
        }
    }

    @Override
    public void onBluetoothStateChanged(int bluetoothState) {
        if (DEBUG) Log.d(TAG, "BluetoothStateChanged=" + stateToString(bluetoothState));
+5 −0
Original line number Diff line number Diff line
@@ -110,4 +110,9 @@ public class FakeBluetoothController extends BaseLeakChecker<Callback> implement
    public List<CachedBluetoothDevice> getConnectedDevices() {
        return Collections.emptyList();
    }

    @Override
    public int getBatteryLevel() {
        return 0;
    }
}