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

Commit 04721f27 authored by William Escande's avatar William Escande
Browse files

Move notification in its own function

Bug: 271963349
Bug: 262605980
Test: atest ServiceBluetoothTests | no-op change
Change-Id: If7a8060bdd27a51ac3be17fd79c265327611dab5
parent e67af197
Loading
Loading
Loading
Loading
+32 −29
Original line number Diff line number Diff line
@@ -44,7 +44,8 @@ import com.android.internal.annotations.VisibleForTesting;
 * </ul>
 */
class BluetoothAirplaneModeListener extends Handler {
    private static final String TAG = "BluetoothAirplaneModeListener";
    private static final String TAG = BluetoothAirplaneModeListener.class.getSimpleName();

    @VisibleForTesting static final String TOAST_COUNT = "bluetooth_airplane_toast_count";

    // keeps track of whether wifi should remain on in airplane mode
@@ -187,10 +188,32 @@ class BluetoothAirplaneModeListener extends Handler {
                mAirplaneHelper.setSettingsInt(
                        Settings.Global.BLUETOOTH_ON,
                        BluetoothManagerService.BLUETOOTH_ON_AIRPLANE);
                displayUserNotificationIfNeeded();
                return;
            }
        } else {
            BluetoothStatsLog.write(
                    BluetoothStatsLog.AIRPLANE_MODE_SESSION_REPORTED,
                    BluetoothStatsLog.AIRPLANE_MODE_SESSION_REPORTED__PACKAGE_NAME__BLUETOOTH,
                    mIsBluetoothOnBeforeApmToggle,
                    mIsBluetoothOnAfterApmToggle,
                    mAirplaneHelper.isBluetoothOn(),
                    isBluetoothToggledOnApm(),
                    mUserToggledBluetoothDuringApm,
                    mUserToggledBluetoothDuringApmWithinMinute,
                    mIsMediaProfileConnectedBeforeApmToggle);
            mUserToggledBluetoothDuringApm = false;
            mUserToggledBluetoothDuringApmWithinMinute = false;
        }
        mBluetoothManager.onAirplaneModeChanged(isAirplaneModeOn);
    }

    private void displayUserNotificationIfNeeded() {
        if (!isApmEnhancementEnabled() || !isBluetoothToggledOnApm()) {
            if (shouldPopToast()) {
                mAirplaneHelper.showToastMessage();
            }
            return;
        } else {
            if (isWifiEnabledOnApm() && isFirstTimeNotification(APM_WIFI_BT_NOTIFICATION)) {
                try {
@@ -199,12 +222,9 @@ class BluetoothAirplaneModeListener extends Handler {
                            "bluetooth_and_wifi_stays_on_message",
                            APM_WIFI_BT_NOTIFICATION);
                } catch (Exception e) {
                            Log.e(
                                    TAG,
                                    "APM enhancement BT and Wi-Fi stays on notification not shown");
                    Log.e(TAG, "APM enhancement BT and Wi-Fi stays on notification not shown");
                }
                    } else if (!isWifiEnabledOnApm()
                            && isFirstTimeNotification(APM_BT_NOTIFICATION)) {
            } else if (!isWifiEnabledOnApm() && isFirstTimeNotification(APM_BT_NOTIFICATION)) {
                try {
                    sendApmNotification(
                            "bluetooth_stays_on_title",
@@ -215,23 +235,6 @@ class BluetoothAirplaneModeListener extends Handler {
                }
            }
        }
                return;
            }
        } else {
            BluetoothStatsLog.write(
                    BluetoothStatsLog.AIRPLANE_MODE_SESSION_REPORTED,
                    BluetoothStatsLog.AIRPLANE_MODE_SESSION_REPORTED__PACKAGE_NAME__BLUETOOTH,
                    mIsBluetoothOnBeforeApmToggle,
                    mIsBluetoothOnAfterApmToggle,
                    mAirplaneHelper.isBluetoothOn(),
                    isBluetoothToggledOnApm(),
                    mUserToggledBluetoothDuringApm,
                    mUserToggledBluetoothDuringApmWithinMinute,
                    mIsMediaProfileConnectedBeforeApmToggle);
            mUserToggledBluetoothDuringApm = false;
            mUserToggledBluetoothDuringApmWithinMinute = false;
        }
        mBluetoothManager.onAirplaneModeChanged(isAirplaneModeOn);
    }

    @VisibleForTesting