display audio dialog when connecting low end dock

Display a dialog to enable the use of the dock audio connection
when a low end dock is connected for the first time.

Modify DockService to process docked and undocked messages even if
the device indicated is null (meaning the dock is not a bluetooth dock)
only for low end docks.

Bug 7302106.

Change-Id: I331d83a74fecf5f26b24bfc178342df414bd8153
This commit is contained in:
Eric Laurent
2012-10-29 17:56:46 -07:00
parent c2c9d5bde1
commit f892bc856c
3 changed files with 147 additions and 75 deletions

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2012 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.
-->
<CheckBox
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dock_audio_media_enable_cb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/bluetooth_dock_settings_a2dp"
android:focusable="true"
android:clickable="true" />

View File

@@ -59,8 +59,11 @@ public final class DockEventReceiver extends BroadcastReceiver {
if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction()) if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())
|| ACTION_DOCK_SHOW_UI.endsWith(intent.getAction())) { || ACTION_DOCK_SHOW_UI.endsWith(intent.getAction())) {
if (device == null) { if ((device == null) && (ACTION_DOCK_SHOW_UI.endsWith(intent.getAction()) ||
if (DEBUG) Log.d(TAG, "Device is missing"); ((state != Intent.EXTRA_DOCK_STATE_UNDOCKED) &&
(state != Intent.EXTRA_DOCK_STATE_LE_DESK)))) {
if (DEBUG) Log.d(TAG,
"Wrong state: "+state+" or intent: "+intent.toString()+" with null device");
return; return;
} }

View File

@@ -36,6 +36,7 @@ import android.os.HandlerThread;
import android.os.IBinder; import android.os.IBinder;
import android.os.Looper; import android.os.Looper;
import android.os.Message; import android.os.Message;
import android.provider.Settings;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@@ -267,7 +268,9 @@ public final class DockService extends Service implements ServiceListener {
switch (msgType) { switch (msgType) {
case MSG_TYPE_SHOW_UI: case MSG_TYPE_SHOW_UI:
if (device != null) {
createDialog(device, state, startId); createDialog(device, state, startId);
}
break; break;
case MSG_TYPE_DOCKED: case MSG_TYPE_DOCKED:
@@ -325,6 +328,7 @@ public final class DockService extends Service implements ServiceListener {
private boolean msgTypeUndockedPermanent(BluetoothDevice device, int startId) { private boolean msgTypeUndockedPermanent(BluetoothDevice device, int startId) {
// Grace period passed. Disconnect. // Grace period passed. Disconnect.
handleUndocked(device); handleUndocked(device);
if (device != null) {
final SharedPreferences prefs = getPrefs(); final SharedPreferences prefs = getPrefs();
if (DEBUG) { if (DEBUG) {
@@ -349,6 +353,7 @@ public final class DockService extends Service implements ServiceListener {
return true; return true;
} }
} }
}
return false; return false;
} }
@@ -367,7 +372,8 @@ public final class DockService extends Service implements ServiceListener {
mServiceHandler.removeMessages(MSG_TYPE_DISABLE_BT); mServiceHandler.removeMessages(MSG_TYPE_DISABLE_BT);
getPrefs().edit().remove(KEY_DISABLE_BT).apply(); getPrefs().edit().remove(KEY_DISABLE_BT).apply();
if (device != null && !device.equals(mDevice)) { if (device != null) {
if (!device.equals(mDevice)) {
if (mDevice != null) { if (mDevice != null) {
// Not expected. Cleanup/undock existing // Not expected. Cleanup/undock existing
handleUndocked(mDevice); handleUndocked(mDevice);
@@ -393,6 +399,17 @@ public final class DockService extends Service implements ServiceListener {
return true; return true;
} }
} }
} else {
// display dialog to enable dock for media audio only in the case of low end docks and
// if not already selected by user
int dockAudioMediaEnabled = Settings.Global.getInt(getContentResolver(),
Settings.Global.DOCK_AUDIO_MEDIA_ENABLED, -1);
if (dockAudioMediaEnabled == -1 &&
state == Intent.EXTRA_DOCK_STATE_LE_DESK) {
handleDocked(null, state, startId);
return true;
}
}
return false; return false;
} }
@@ -427,21 +444,25 @@ public final class DockService extends Service implements ServiceListener {
+ " Device: " + (device == null ? "null" : device.getAliasName())); + " Device: " + (device == null ? "null" : device.getAliasName()));
} }
if (device == null) {
Log.w(TAG, "device is null");
return null;
}
int msgType; int msgType;
switch (state) { switch (state) {
case Intent.EXTRA_DOCK_STATE_UNDOCKED: case Intent.EXTRA_DOCK_STATE_UNDOCKED:
msgType = MSG_TYPE_UNDOCKED_TEMPORARY; msgType = MSG_TYPE_UNDOCKED_TEMPORARY;
break; break;
case Intent.EXTRA_DOCK_STATE_DESK: case Intent.EXTRA_DOCK_STATE_DESK:
case Intent.EXTRA_DOCK_STATE_LE_DESK:
case Intent.EXTRA_DOCK_STATE_HE_DESK: case Intent.EXTRA_DOCK_STATE_HE_DESK:
case Intent.EXTRA_DOCK_STATE_CAR: case Intent.EXTRA_DOCK_STATE_CAR:
if (device == null) {
Log.w(TAG, "device is null");
return null;
}
/// Fall Through ///
case Intent.EXTRA_DOCK_STATE_LE_DESK:
if (DockEventReceiver.ACTION_DOCK_SHOW_UI.equals(intent.getAction())) { if (DockEventReceiver.ACTION_DOCK_SHOW_UI.equals(intent.getAction())) {
if (device == null) {
Log.w(TAG, "device is null");
return null;
}
msgType = MSG_TYPE_SHOW_UI; msgType = MSG_TYPE_SHOW_UI;
} else { } else {
msgType = MSG_TYPE_DOCKED; msgType = MSG_TYPE_DOCKED;
@@ -474,35 +495,53 @@ public final class DockService extends Service implements ServiceListener {
startForeground(0, new Notification()); startForeground(0, new Notification());
final AlertDialog.Builder ab = new AlertDialog.Builder(this);
View view;
LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
if (device != null) {
// Device in a new dock. // Device in a new dock.
boolean firstTime = !LocalBluetoothPreferences.hasDockAutoConnectSetting(this, device.getAddress()); boolean firstTime =
!LocalBluetoothPreferences.hasDockAutoConnectSetting(this, device.getAddress());
CharSequence[] items = initBtSettings(device, state, firstTime); CharSequence[] items = initBtSettings(device, state, firstTime);
final AlertDialog.Builder ab = new AlertDialog.Builder(this);
ab.setTitle(getString(R.string.bluetooth_dock_settings_title)); ab.setTitle(getString(R.string.bluetooth_dock_settings_title));
// Profiles // Profiles
ab.setMultiChoiceItems(items, mCheckedItems, mMultiClickListener); ab.setMultiChoiceItems(items, mCheckedItems, mMultiClickListener);
// Remember this settings // Remember this settings
LayoutInflater inflater = (LayoutInflater) view = inflater.inflate(R.layout.remember_dock_setting, null);
getSystemService(LAYOUT_INFLATER_SERVICE);
float pixelScaleFactor = getResources().getDisplayMetrics().density;
View view = inflater.inflate(R.layout.remember_dock_setting, null);
CheckBox rememberCheckbox = (CheckBox) view.findViewById(R.id.remember); CheckBox rememberCheckbox = (CheckBox) view.findViewById(R.id.remember);
// check "Remember setting" by default if no value was saved // check "Remember setting" by default if no value was saved
boolean checked = firstTime || LocalBluetoothPreferences.getDockAutoConnectSetting(this, device.getAddress()); boolean checked = firstTime ||
LocalBluetoothPreferences.getDockAutoConnectSetting(this, device.getAddress());
rememberCheckbox.setChecked(checked); rememberCheckbox.setChecked(checked);
rememberCheckbox.setOnCheckedChangeListener(mCheckedChangeListener); rememberCheckbox.setOnCheckedChangeListener(mCheckedChangeListener);
int viewSpacingLeft = (int) (14 * pixelScaleFactor);
int viewSpacingRight = (int) (14 * pixelScaleFactor);
ab.setView(view, viewSpacingLeft, 0 /* top */, viewSpacingRight, 0 /* bottom */);
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "Auto connect = " Log.d(TAG, "Auto connect = "
+ LocalBluetoothPreferences.getDockAutoConnectSetting(this, device.getAddress())); + LocalBluetoothPreferences.getDockAutoConnectSetting(this, device.getAddress()));
} }
} else {
ab.setTitle(getString(R.string.bluetooth_dock_settings_title));
view = inflater.inflate(R.layout.dock_audio_media_enable_dialog, null);
CheckBox audioMediaCheckbox =
(CheckBox) view.findViewById(R.id.dock_audio_media_enable_cb);
boolean checked = Settings.Global.getInt(getContentResolver(),
Settings.Global.DOCK_AUDIO_MEDIA_ENABLED, 0) == 1;
audioMediaCheckbox.setChecked(checked);
audioMediaCheckbox.setOnCheckedChangeListener(mCheckedChangeListener);
}
float pixelScaleFactor = getResources().getDisplayMetrics().density;
int viewSpacingLeft = (int) (14 * pixelScaleFactor);
int viewSpacingRight = (int) (14 * pixelScaleFactor);
ab.setView(view, viewSpacingLeft, 0 /* top */, viewSpacingRight, 0 /* bottom */);
// Ok Button // Ok Button
ab.setPositiveButton(getString(android.R.string.ok), mClickListener); ab.setPositiveButton(getString(android.R.string.ok), mClickListener);
@@ -536,6 +575,9 @@ public final class DockService extends Service implements ServiceListener {
if (mDevice != null) { if (mDevice != null) {
LocalBluetoothPreferences.saveDockAutoConnectSetting( LocalBluetoothPreferences.saveDockAutoConnectSetting(
DockService.this, mDevice.getAddress(), isChecked); DockService.this, mDevice.getAddress(), isChecked);
} else {
Settings.Global.putInt(getContentResolver(),
Settings.Global.DOCK_AUDIO_MEDIA_ENABLED, isChecked ? 1 : 0);
} }
} }
}; };
@@ -823,7 +865,8 @@ public final class DockService extends Service implements ServiceListener {
private synchronized void handleDocked(BluetoothDevice device, int state, private synchronized void handleDocked(BluetoothDevice device, int state,
int startId) { int startId) {
if (LocalBluetoothPreferences.getDockAutoConnectSetting(this, device.getAddress())) { if (device != null &&
LocalBluetoothPreferences.getDockAutoConnectSetting(this, device.getAddress())) {
// Setting == auto connect // Setting == auto connect
initBtSettings(device, state, false); initBtSettings(device, state, false);
applyBtSettings(mDevice, startId); applyBtSettings(mDevice, startId);
@@ -841,9 +884,11 @@ public final class DockService extends Service implements ServiceListener {
} }
mDevice = null; mDevice = null;
mPendingDevice = null; mPendingDevice = null;
if (device != null) {
CachedBluetoothDevice cachedDevice = getCachedBluetoothDevice(device); CachedBluetoothDevice cachedDevice = getCachedBluetoothDevice(device);
cachedDevice.disconnect(); cachedDevice.disconnect();
} }
}
private CachedBluetoothDevice getCachedBluetoothDevice(BluetoothDevice device) { private CachedBluetoothDevice getCachedBluetoothDevice(BluetoothDevice device) {
CachedBluetoothDevice cachedDevice = mDeviceManager.findDevice(device); CachedBluetoothDevice cachedDevice = mDeviceManager.findDevice(device);