Update slice states when on Voip calling
This CL is used to register intent of AudioManager.STREAM_DEVICES_CHANGED_ACTION to know that phone is on VOIP call. When received this intent, media slice will to update UI. Then if audio mode is on-going call, we will hide the slice UI. Bug: 132198606 Test: Test: make -j42 RunSettingsRoboTests Change-Id: Ic17ebd319b3da8f42089d36ba530cfb57c93c4c6
This commit is contained in:
@@ -16,8 +16,15 @@
|
||||
|
||||
package com.android.settings.media;
|
||||
|
||||
import static android.media.AudioManager.STREAM_DEVICES_CHANGED_ACTION;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.media.AudioManager;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
@@ -37,6 +44,7 @@ public class MediaDeviceUpdateWorker extends SliceBackgroundWorker
|
||||
|
||||
private final Context mContext;
|
||||
private final List<MediaDevice> mMediaDevices = new ArrayList<>();
|
||||
private final DevicesChangedBroadcastReceiver mReceiver;
|
||||
|
||||
private String mPackageName;
|
||||
|
||||
@@ -46,6 +54,7 @@ public class MediaDeviceUpdateWorker extends SliceBackgroundWorker
|
||||
public MediaDeviceUpdateWorker(Context context, Uri uri) {
|
||||
super(context, uri);
|
||||
mContext = context;
|
||||
mReceiver = new DevicesChangedBroadcastReceiver();
|
||||
}
|
||||
|
||||
public void setPackageName(String packageName) {
|
||||
@@ -60,12 +69,15 @@ public class MediaDeviceUpdateWorker extends SliceBackgroundWorker
|
||||
}
|
||||
|
||||
mLocalMediaManager.registerCallback(this);
|
||||
final IntentFilter intentFilter = new IntentFilter(STREAM_DEVICES_CHANGED_ACTION);
|
||||
mContext.registerReceiver(mReceiver, intentFilter);
|
||||
mLocalMediaManager.startScan();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSliceUnpinned() {
|
||||
mLocalMediaManager.unregisterCallback(this);
|
||||
mContext.unregisterReceiver(mReceiver);
|
||||
mLocalMediaManager.stopScan();
|
||||
}
|
||||
|
||||
@@ -107,4 +119,14 @@ public class MediaDeviceUpdateWorker extends SliceBackgroundWorker
|
||||
public MediaDevice getCurrentConnectedMediaDevice() {
|
||||
return mLocalMediaManager.getCurrentConnectedDevice();
|
||||
}
|
||||
|
||||
private class DevicesChangedBroadcastReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
if (TextUtils.equals(AudioManager.STREAM_DEVICES_CHANGED_ACTION, action)) {
|
||||
notifySliceChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.core.graphics.drawable.IconCompat;
|
||||
@@ -115,13 +114,11 @@ public class MediaOutputIndicatorSlice implements CustomSliceable {
|
||||
private boolean isVisible() {
|
||||
// To decide Slice's visibility.
|
||||
// Return true if
|
||||
// 1. phone is not in ongoing call mode
|
||||
// 1. AudioMode is not in on-going call
|
||||
// 2. Bluetooth device is connected
|
||||
final TelephonyManager telephonyManager =
|
||||
(TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
return telephonyManager.getCallState() == TelephonyManager.CALL_STATE_IDLE
|
||||
&& (!CollectionUtils.isEmpty(getConnectedA2dpDevices())
|
||||
|| !CollectionUtils.isEmpty(getConnectedHearingAidDevices()));
|
||||
return (!CollectionUtils.isEmpty(getConnectedA2dpDevices())
|
||||
|| !CollectionUtils.isEmpty(getConnectedHearingAidDevices()))
|
||||
&& !com.android.settingslib.Utils.isAudioModeOngoingCall(mContext);
|
||||
}
|
||||
|
||||
private List<BluetoothDevice> getConnectedA2dpDevices() {
|
||||
|
||||
@@ -16,9 +16,16 @@
|
||||
|
||||
package com.android.settings.media;
|
||||
|
||||
import static android.media.AudioManager.STREAM_DEVICES_CHANGED_ACTION;
|
||||
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.media.AudioManager;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
@@ -36,10 +43,15 @@ public class MediaOutputIndicatorWorker extends SliceBackgroundWorker implements
|
||||
|
||||
private static final String TAG = "MediaOutputIndicatorWorker";
|
||||
|
||||
private final DevicesChangedBroadcastReceiver mReceiver;
|
||||
private final Context mContext;
|
||||
|
||||
private LocalBluetoothManager mLocalBluetoothManager;
|
||||
|
||||
public MediaOutputIndicatorWorker(Context context, Uri uri) {
|
||||
super(context, uri);
|
||||
mReceiver = new DevicesChangedBroadcastReceiver();
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -49,6 +61,8 @@ public class MediaOutputIndicatorWorker extends SliceBackgroundWorker implements
|
||||
Log.e(TAG, "Bluetooth is not supported on this device");
|
||||
return;
|
||||
}
|
||||
final IntentFilter intentFilter = new IntentFilter(STREAM_DEVICES_CHANGED_ACTION);
|
||||
mContext.registerReceiver(mReceiver, intentFilter);
|
||||
mLocalBluetoothManager.getEventManager().registerCallback(this);
|
||||
}
|
||||
|
||||
@@ -59,10 +73,11 @@ public class MediaOutputIndicatorWorker extends SliceBackgroundWorker implements
|
||||
return;
|
||||
}
|
||||
mLocalBluetoothManager.getEventManager().unregisterCallback(this);
|
||||
mContext.unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
public void close() {
|
||||
mLocalBluetoothManager = null;
|
||||
}
|
||||
|
||||
@@ -84,4 +99,14 @@ public class MediaOutputIndicatorWorker extends SliceBackgroundWorker implements
|
||||
public void onAudioModeChanged() {
|
||||
notifySliceChange();
|
||||
}
|
||||
|
||||
private class DevicesChangedBroadcastReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
if (TextUtils.equals(AudioManager.STREAM_DEVICES_CHANGED_ACTION, action)) {
|
||||
notifySliceChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -197,15 +196,13 @@ public class MediaOutputSlice implements CustomSliceable {
|
||||
private boolean isVisible() {
|
||||
// To decide Slice's visibility.
|
||||
// Return true if
|
||||
// 1. phone is not in ongoing call mode
|
||||
// 1. AudioMode is not in on-going call
|
||||
// 2. worker is not null
|
||||
// 3. Bluetooth is enabled
|
||||
final TelephonyManager telephonyManager =
|
||||
(TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||
|
||||
return telephonyManager.getCallState() == TelephonyManager.CALL_STATE_IDLE
|
||||
&& adapter.isEnabled()
|
||||
return adapter.isEnabled()
|
||||
&& !com.android.settingslib.Utils.isAudioModeOngoingCall(mContext)
|
||||
&& getWorker() != null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user