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

Commit 78bf68c4 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Display the current connected audio device"

parents 58b90eb5 6692b47d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -172,5 +172,6 @@ public interface VolumeDialogController {
        void onScreenOff();
        void onShowSafetyWarning(int flags);
        void onAccessibilityModeChanged(Boolean showA11yStream);
        void onConnectedDeviceChanged(String deviceName);
    }
}
+25 −0
Original line number Diff line number Diff line
<!--
    Copyright (C) 2018 The Android Open Source Project

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0"
        android:tint="?android:attr/colorForeground">
    <path
        android:pathData="M6.99,11L3,15l3.99,4v-3H14v-2H6.99v-3zM21,9l-3.99,-4v3H10v2h7.01v3L21,9z"
        android:fillColor="#FFFFFF"/>
</vector>
 No newline at end of file
+25 −14
Original line number Diff line number Diff line
@@ -38,6 +38,16 @@
            android:maxLines="1"
            android:textColor="?android:attr/colorControlNormal"
            android:textAppearance="?android:attr/textAppearanceSmall" />
        <LinearLayout
            android:id="@+id/output_chooser"
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:minWidth="48dp"
            android:minHeight="48dp"
            android:paddingTop="10dp"
            android:background="?android:selectableItemBackgroundBorderless"
            android:gravity="center">
            <TextView
                android:id="@+id/volume_row_connected_device"
                android:visibility="gone"
@@ -47,15 +57,16 @@
                android:maxLines="1"
                android:textAppearance="@style/TextAppearance.QS.DetailItemSecondary" />
            <com.android.keyguard.AlphaOptimizedImageButton
            android:id="@+id/output_chooser"
            style="@style/VolumeButtons"
                android:id="@+id/output_chooser_button"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:background="?android:selectableItemBackgroundBorderless"
            android:layout_width="@dimen/volume_button_size"
            android:layout_height="wrap_content"
                style="@style/VolumeButtons"
                android:layout_centerVertical="true"
            android:src="@drawable/ic_volume_expand_animation"
                android:src="@drawable/ic_swap"
                android:soundEffectsEnabled="false" />
        </LinearLayout>
    </LinearLayout>
    <FrameLayout
        android:id="@+id/volume_row_slider_frame"
        android:padding="10dp"
+3 −0
Original line number Diff line number Diff line
@@ -514,5 +514,8 @@ public class OutputChooserDialog extends Dialog

        @Override
        public void onAccessibilityModeChanged(Boolean showA11yStream) {}

        @Override
        public void onConnectedDeviceChanged(String deviceName) {}
    };
}
 No newline at end of file
+47 −0
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.database.ContentObserver;
import android.media.AudioDeviceCallback;
import android.media.AudioDeviceInfo;
import android.media.AudioManager;
import android.media.AudioSystem;
import android.media.IVolumeController;
@@ -105,6 +107,8 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa
    private boolean mShowA11yStream;
    private boolean mShowVolumeDialog;
    private boolean mShowSafetyWarning;
    private DeviceCallback mDeviceCallback = new DeviceCallback();
    private AudioDeviceInfo mConnectedDevice;

    private boolean mDestroyed;
    private VolumePolicy mVolumePolicy;
@@ -180,6 +184,7 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa
        } catch (SecurityException e) {
            Log.w(TAG, "No access to media sessions", e);
        }
        mAudio.registerAudioDeviceCallback(mDeviceCallback, mWorker);
    }

    public void setVolumePolicy(VolumePolicy policy) {
@@ -205,6 +210,7 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa
        mMediaSessions.destroy();
        mObserver.destroy();
        mReceiver.destroy();
        mAudio.unregisterAudioDeviceCallback(mDeviceCallback);
        mWorkerThread.quitSafely();
    }

@@ -664,6 +670,7 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa
                case USER_ACTIVITY: onUserActivityW(); break;
                case SHOW_SAFETY_WARNING: onShowSafetyWarningW(msg.arg1); break;
                case ACCESSIBILITY_MODE_CHANGED: onAccessibilityModeChanged((Boolean) msg.obj);

            }
        }
    }
@@ -803,6 +810,18 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa
                });
            }
        }

        @Override
        public void onConnectedDeviceChanged(String deviceName) {
            for (final Map.Entry<Callbacks, Handler> entry : mCallbackMap.entrySet()) {
                entry.getValue().post(new Runnable() {
                    @Override
                    public void run() {
                        entry.getKey().onConnectedDeviceChanged(deviceName);
                    }
                });
            }
        }
    }


@@ -1005,6 +1024,34 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa
        }
    }

    protected final class DeviceCallback extends AudioDeviceCallback {
        public void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) {
            for (AudioDeviceInfo info : addedDevices) {
                if (info.isSink()
                        && (info.getType() == AudioDeviceInfo.TYPE_BLUETOOTH_A2DP
                        || info.getType() == AudioDeviceInfo.TYPE_BLUETOOTH_SCO)) {
                    mConnectedDevice = info;
                    mCallbacks.onConnectedDeviceChanged(info.getProductName().toString());
                }
            }
        }

        public void onAudioDevicesRemoved(AudioDeviceInfo[] removedDevices) {
            if (mConnectedDevice == null) {
                mCallbacks.onConnectedDeviceChanged(null);
                return;
            }
            for (AudioDeviceInfo info : removedDevices) {
                if (info.isSink() == mConnectedDevice.isSink()
                        && Objects.equals(info.getProductName(), mConnectedDevice.getProductName())
                        && info.getType() == mConnectedDevice.getType()) {
                    mConnectedDevice = null;
                    mCallbacks.onConnectedDeviceChanged(null);
                }
            }
        }
    }

    public interface UserActivityListener {
        void onUserActivity();
    }
Loading