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

Commit 79a1a59d authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge changes I235d4acf,I0f3aa0c2,I72379c9a,I07a72381 into main

* changes:
  SystemServer: Always set current user context
  Notification helper is no longer airplane exclusif
  SystemServer: re-apply format on managerService
  SystemServer: AutoOn: Add flag
parents a3ff0892 9020925a
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -104,12 +104,12 @@
        </service>

        <service android:process="@string/process"
             android:name="com.android.bluetooth.airplane.NotificationHelperService"
             android:label="Airplane Notification Helper"
             android:name="com.android.bluetooth.notification.NotificationHelperService"
             android:label="Notification Helper"
             android:exported="true"
             android:permission="android.permission.BLUETOOTH_PRIVILEGED">
            <intent-filter>
                <action android:name="android.bluetooth.airplane.action.SEND_NOTIFICATION"/>
                <action android:name="android.bluetooth.notification.action.SEND_TOGGLE_NOTIFICATION"/>
            </intent-filter>
        </service>

+13 −13
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package com.android.bluetooth.airplane;
package com.android.bluetooth.notification;

import static java.util.Objects.requireNonNull;

@@ -47,8 +47,8 @@ public class NotificationHelperService extends Service {
    private static final String APM_BT_ENABLED_NOTIFICATION = "apm_bt_enabled_notification";

    private static final String NOTIFICATION_TAG = "com.android.bluetooth";
    private static final String APM_NOTIFICATION_CHANNEL = "apm_notification_channel";
    private static final String APM_NOTIFICATION_GROUP = "apm_notification_group";
    private static final String NOTIFICATION_CHANNEL = "notification_toggle_channel";
    private static final String NOTIFICATION_GROUP = "notification_toggle_group";

    private static final Map<String, Pair<Integer /* titleId */, Integer /* messageId */>>
            NOTIFICATION_MAP =
@@ -73,24 +73,24 @@ public class NotificationHelperService extends Service {

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        sendAirplaneModeNotification(
                intent.getStringExtra("android.bluetooth.airplane.extra.NOTIFICATION_STATE"));
        sendToggleNotification(
                intent.getStringExtra("android.bluetooth.notification.extra.NOTIFICATION_REASON"));
        return Service.START_NOT_STICKY;
    }

    private void sendAirplaneModeNotification(String notificationState) {
        String logHeader = "sendAirplaneModeNotification(" + notificationState + "): ";
        Pair<Integer, Integer> notificationContent = NOTIFICATION_MAP.get(notificationState);
    private void sendToggleNotification(String notificationReason) {
        String logHeader = "sendToggleNotification(" + notificationReason + "): ";
        Pair<Integer, Integer> notificationContent = NOTIFICATION_MAP.get(notificationReason);
        if (notificationContent == null) {
            Log.e(TAG, logHeader + "unknown action");
            return;
        }

        if (!isFirstTimeNotification(notificationState)) {
        if (!isFirstTimeNotification(notificationReason)) {
            Log.d(TAG, logHeader + "already displayed");
            return;
        }
        Settings.Secure.putInt(getContentResolver(), notificationState, 1);
        Settings.Secure.putInt(getContentResolver(), notificationReason, 1);

        Log.d(TAG, logHeader + "sending");

@@ -104,8 +104,8 @@ public class NotificationHelperService extends Service {

        notificationManager.createNotificationChannel(
                new NotificationChannel(
                        APM_NOTIFICATION_CHANNEL,
                        APM_NOTIFICATION_GROUP,
                        NOTIFICATION_CHANNEL,
                        NOTIFICATION_GROUP,
                        NotificationManager.IMPORTANCE_HIGH));

        String title = getString(notificationContent.first);
@@ -115,7 +115,7 @@ public class NotificationHelperService extends Service {
        notificationManager.notify(
                NOTIFICATION_TAG,
                SystemMessage.ID.NOTE_BT_APM_NOTIFICATION_VALUE,
                new Notification.Builder(this, APM_NOTIFICATION_CHANNEL)
                new Notification.Builder(this, NOTIFICATION_CHANNEL)
                        .setAutoCancel(true)
                        .setLocalOnly(true)
                        .setContentTitle(title)
+7 −0
Original line number Diff line number Diff line
@@ -7,6 +7,13 @@ flag {
    bug: "303552318"
}

flag {
    name: "auto_on_feature"
    namespace: "bluetooth"
    description: "Turn bluetooth on next morning at 5 am"
    bug: "323060869"
}

flag {
    name: "system_server_messenger"
    namespace: "bluetooth"
+3 −3
Original line number Diff line number Diff line
@@ -227,9 +227,9 @@ class BluetoothAirplaneModeListener extends Handler {
        } else {
            if (mFeatureFlags.airplaneRessourcesInApp()) {
                if (isWifiEnabledOnApm()) {
                    mBluetoothManager.sendAirplaneModeNotification(APM_WIFI_BT_NOTIFICATION);
                    mBluetoothManager.sendToggleNotification(APM_WIFI_BT_NOTIFICATION);
                } else {
                    mBluetoothManager.sendAirplaneModeNotification(APM_BT_NOTIFICATION);
                    mBluetoothManager.sendToggleNotification(APM_BT_NOTIFICATION);
                }
                return;
            }
@@ -330,7 +330,7 @@ class BluetoothAirplaneModeListener extends Handler {
            setSettingsSecureInt(APM_USER_TOGGLED_BLUETOOTH, USED);
            if (mFeatureFlags.airplaneRessourcesInApp()) {
                if (isOn) {
                    mBluetoothManager.sendAirplaneModeNotification(APM_BT_ENABLED_NOTIFICATION);
                    mBluetoothManager.sendToggleNotification(APM_BT_ENABLED_NOTIFICATION);
                }
                return;
            }
+23 −25
Original line number Diff line number Diff line
@@ -129,20 +129,20 @@ class BluetoothManagerService {
    }

    // Maximum msec to wait for service restart
    private static final int SERVICE_RESTART_TIME_MS
        = 400 * SystemProperties.getInt("ro.hw_timeout_multiplier", 1);
    private static final int SERVICE_RESTART_TIME_MS =
            400 * SystemProperties.getInt("ro.hw_timeout_multiplier", 1);
    // Maximum msec to wait for restart due to error
    private static final int ERROR_RESTART_TIME_MS
        = 3000 * SystemProperties.getInt("ro.hw_timeout_multiplier", 1);
    private static final int ERROR_RESTART_TIME_MS =
            3000 * SystemProperties.getInt("ro.hw_timeout_multiplier", 1);
    // Maximum msec to delay MESSAGE_USER_SWITCHED
    private static final int USER_SWITCHED_TIME_MS
        = 200 * SystemProperties.getInt("ro.hw_timeout_multiplier", 1);
    private static final int USER_SWITCHED_TIME_MS =
            200 * SystemProperties.getInt("ro.hw_timeout_multiplier", 1);
    // Delay for the addProxy function in msec
    private static final int ADD_PROXY_DELAY_MS
        = 100 * SystemProperties.getInt("ro.hw_timeout_multiplier", 1);
    private static final int ADD_PROXY_DELAY_MS =
            100 * SystemProperties.getInt("ro.hw_timeout_multiplier", 1);
    // Delay for retrying enable and disable in msec
    private static final int ENABLE_DISABLE_DELAY_MS
        = 300 * SystemProperties.getInt("ro.hw_timeout_multiplier", 1);
    private static final int ENABLE_DISABLE_DELAY_MS =
            300 * SystemProperties.getInt("ro.hw_timeout_multiplier", 1);

    @VisibleForTesting static final int MESSAGE_ENABLE = 1;
    @VisibleForTesting static final int MESSAGE_DISABLE = 2;
@@ -429,10 +429,12 @@ class BluetoothManagerService {
    }

    /** Send Intent to the Notification Service in the Bluetooth app */
    Unit sendAirplaneModeNotification(String notificationState) {
        Intent intent = new Intent("android.bluetooth.airplane.action.SEND_NOTIFICATION");
    Unit sendToggleNotification(String notificationReason) {
        Intent intent =
                new Intent("android.bluetooth.notification.action.SEND_TOGGLE_NOTIFICATION");
        intent.setComponent(resolveSystemService(intent));
        intent.putExtra("android.bluetooth.airplane.extra.NOTIFICATION_STATE", notificationState);
        intent.putExtra(
                "android.bluetooth.notification.extra.NOTIFICATION_REASON", notificationReason);
        mContext.startService(intent);
        return Unit.INSTANCE;
    }
@@ -652,7 +654,6 @@ class BluetoothManagerService {
        mBinder = new BluetoothServiceBinder(this, mLooper, mContext, mUserManager);
        mHandler = new BluetoothHandler(mLooper);


        // Observe BLE scan only mode settings change.
        registerForBleScanModeChange();

@@ -1041,7 +1042,6 @@ class BluetoothManagerService {
            return false;
        }


        // TODO(b/262605980): enableBle/disableBle should be on handler thread
        updateBleAppCount(token, true, packageName);

@@ -1295,17 +1295,17 @@ class BluetoothManagerService {

    @VisibleForTesting
    void initialize(UserHandle userHandle) {
        if (mUseNewAirplaneMode) {
        mCurrentUserContext =
                requireNonNull(
                        mContext.createContextAsUser(userHandle, 0),
                        "Current User Context cannot be null");
        if (mUseNewAirplaneMode) {
            AirplaneModeListener.initialize(
                    mLooper,
                    mContentResolver,
                    mState,
                    this::onAirplaneModeChanged,
                    this::sendAirplaneModeNotification,
                    this::sendToggleNotification,
                    this::isMediaProfileConnected,
                    this::getCurrentUserContext,
                    TimeSource.Monotonic.INSTANCE);
@@ -1936,9 +1936,7 @@ class BluetoothManagerService {
                        mBluetoothNotificationManager.createNotificationChannels();
                    }

                    if (mUseNewAirplaneMode) {
                    mCurrentUserContext = mContext.createContextAsUser(userTo, 0);
                    }

                    /* disable and enable BT when detect a user switch */
                    if (mAdapter != null && mState.oneOf(STATE_ON)) {
Loading