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

Commit 225baf29 authored by Sal Savage's avatar Sal Savage Committed by Automerger Merge Worker
Browse files

Merge "Listen for locale changed to update the error message text" am: f93e35da am: 8e70ac02

Original change: https://android-review.googlesource.com/c/platform/packages/apps/Bluetooth/+/1653568

Change-Id: Ib3618df9dca164654b8ddc0de4f7744a9fe9e870
parents 447b0d24 8e70ac02
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -17,7 +17,10 @@
package com.android.bluetooth.avrcpcontroller;

import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.media.MediaBrowserCompat.MediaItem;
import android.support.v4.media.MediaMetadataCompat;
@@ -76,6 +79,26 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat {
    public static final String ERROR_RESOLUTION_ACTION_LABEL =
            "android.media.extras.ERROR_RESOLUTION_ACTION_LABEL";

    // Receiver for making sure our error message text matches the system locale
    private class LocaleChangedReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals(Intent.ACTION_LOCALE_CHANGED)) {
                if (sBluetoothMediaBrowserService == null) return;
                MediaSessionCompat session = sBluetoothMediaBrowserService.getSession();
                MediaControllerCompat controller = session.getController();
                PlaybackStateCompat playbackState =
                        controller == null ? null : controller.getPlaybackState();
                if (playbackState != null && playbackState.getErrorMessage() != null) {
                    setErrorPlaybackState();
                }
            }
        }
    }

    private LocaleChangedReceiver mReceiver;

    /**
     * Initialize this BluetoothMediaBrowserService, creating our MediaSessionCompat, MediaPlayer
     * and MediaMetaData, and setting up mechanisms to talk with the AvrcpControllerService.
@@ -94,6 +117,17 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat {
        mSession.setQueue(mMediaQueue);
        setErrorPlaybackState();
        sBluetoothMediaBrowserService = this;

        mReceiver = new LocaleChangedReceiver();
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_LOCALE_CHANGED);
        registerReceiver(mReceiver, filter);
    }

    @Override
    public void onDestroy() {
        unregisterReceiver(mReceiver);
        mReceiver = null;
    }

    List<MediaItem> getContents(final String parentMediaId) {