summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Laurent <elaurent@google.com>2012-10-30 14:12:22 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-10-30 14:12:23 -0700
commitf79daa942005608e56a4a0d7f414fedccd56e467 (patch)
tree2f374c3787b1cd4c80a74ee84b51dc1082622a4f
parent29c4c88be2c2f225a1daff551b4e32ed03cc1bda (diff)
parentf892bc856c6780187db62681d59ca538a173590f (diff)
downloadpackages_apps_settings-f79daa942005608e56a4a0d7f414fedccd56e467.zip
packages_apps_settings-f79daa942005608e56a4a0d7f414fedccd56e467.tar.gz
packages_apps_settings-f79daa942005608e56a4a0d7f414fedccd56e467.tar.bz2
Merge "display audio dialog when connecting low end dock" into jb-mr1-dev
-rw-r--r--res/layout/dock_audio_media_enable_dialog.xml24
-rw-r--r--src/com/android/settings/bluetooth/DockEventReceiver.java7
-rw-r--r--src/com/android/settings/bluetooth/DockService.java189
3 files changed, 146 insertions, 74 deletions
diff --git a/res/layout/dock_audio_media_enable_dialog.xml b/res/layout/dock_audio_media_enable_dialog.xml
new file mode 100644
index 0000000..37ecdfe
--- /dev/null
+++ b/res/layout/dock_audio_media_enable_dialog.xml
@@ -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" />
diff --git a/src/com/android/settings/bluetooth/DockEventReceiver.java b/src/com/android/settings/bluetooth/DockEventReceiver.java
index a3b6b3c..048b098 100644
--- a/src/com/android/settings/bluetooth/DockEventReceiver.java
+++ b/src/com/android/settings/bluetooth/DockEventReceiver.java
@@ -59,8 +59,11 @@ public final class DockEventReceiver extends BroadcastReceiver {
if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())
|| ACTION_DOCK_SHOW_UI.endsWith(intent.getAction())) {
- if (device == null) {
- if (DEBUG) Log.d(TAG, "Device is missing");
+ if ((device == null) && (ACTION_DOCK_SHOW_UI.endsWith(intent.getAction()) ||
+ ((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;
}
diff --git a/src/com/android/settings/bluetooth/DockService.java b/src/com/android/settings/bluetooth/DockService.java
index 943c3f9..ab0e7c7 100644
--- a/src/com/android/settings/bluetooth/DockService.java
+++ b/src/com/android/settings/bluetooth/DockService.java
@@ -36,6 +36,7 @@ import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
+import android.provider.Settings;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -267,7 +268,9 @@ public final class DockService extends Service implements ServiceListener {
switch (msgType) {
case MSG_TYPE_SHOW_UI:
- createDialog(device, state, startId);
+ if (device != null) {
+ createDialog(device, state, startId);
+ }
break;
case MSG_TYPE_DOCKED:
@@ -325,28 +328,30 @@ public final class DockService extends Service implements ServiceListener {
private boolean msgTypeUndockedPermanent(BluetoothDevice device, int startId) {
// Grace period passed. Disconnect.
handleUndocked(device);
- final SharedPreferences prefs = getPrefs();
+ if (device != null) {
+ final SharedPreferences prefs = getPrefs();
- if (DEBUG) {
- Log.d(TAG, "DISABLE_BT_WHEN_UNDOCKED = "
- + prefs.getBoolean(KEY_DISABLE_BT_WHEN_UNDOCKED, false));
- }
+ if (DEBUG) {
+ Log.d(TAG, "DISABLE_BT_WHEN_UNDOCKED = "
+ + prefs.getBoolean(KEY_DISABLE_BT_WHEN_UNDOCKED, false));
+ }
- if (prefs.getBoolean(KEY_DISABLE_BT_WHEN_UNDOCKED, false)) {
- if (hasOtherConnectedDevices(device)) {
- // Don't disable BT if something is connected
- prefs.edit().remove(KEY_DISABLE_BT_WHEN_UNDOCKED).apply();
- } else {
- // BT was disabled when we first docked
- if (DEBUG) {
- Log.d(TAG, "QUEUED BT DISABLE");
+ if (prefs.getBoolean(KEY_DISABLE_BT_WHEN_UNDOCKED, false)) {
+ if (hasOtherConnectedDevices(device)) {
+ // Don't disable BT if something is connected
+ prefs.edit().remove(KEY_DISABLE_BT_WHEN_UNDOCKED).apply();
+ } else {
+ // BT was disabled when we first docked
+ if (DEBUG) {
+ Log.d(TAG, "QUEUED BT DISABLE");
+ }
+ // Queue a delayed msg to disable BT
+ Message newMsg = mServiceHandler.obtainMessage(
+ MSG_TYPE_DISABLE_BT, 0, startId, null);
+ mServiceHandler.sendMessageDelayed(newMsg,
+ DISABLE_BT_GRACE_PERIOD);
+ return true;
}
- // Queue a delayed msg to disable BT
- Message newMsg = mServiceHandler.obtainMessage(
- MSG_TYPE_DISABLE_BT, 0, startId, null);
- mServiceHandler.sendMessageDelayed(newMsg,
- DISABLE_BT_GRACE_PERIOD);
- return true;
}
}
return false;
@@ -367,29 +372,41 @@ public final class DockService extends Service implements ServiceListener {
mServiceHandler.removeMessages(MSG_TYPE_DISABLE_BT);
getPrefs().edit().remove(KEY_DISABLE_BT).apply();
- if (device != null && !device.equals(mDevice)) {
- if (mDevice != null) {
- // Not expected. Cleanup/undock existing
- handleUndocked(mDevice);
- }
+ if (device != null) {
+ if (!device.equals(mDevice)) {
+ if (mDevice != null) {
+ // Not expected. Cleanup/undock existing
+ handleUndocked(mDevice);
+ }
- mDevice = device;
-
- // Register first in case LocalBluetoothProfileManager
- // becomes ready after isManagerReady is called and it
- // would be too late to register a service listener.
- mProfileManager.addServiceListener(this);
- if (mProfileManager.isManagerReady()) {
- handleDocked(device, state, startId);
- // Not needed after all
- mProfileManager.removeServiceListener(this);
- } else {
- final BluetoothDevice d = device;
- mRunnable = new Runnable() {
- public void run() {
- handleDocked(d, state, startId); // FIXME: WTF runnable here?
- }
- };
+ mDevice = device;
+
+ // Register first in case LocalBluetoothProfileManager
+ // becomes ready after isManagerReady is called and it
+ // would be too late to register a service listener.
+ mProfileManager.addServiceListener(this);
+ if (mProfileManager.isManagerReady()) {
+ handleDocked(device, state, startId);
+ // Not needed after all
+ mProfileManager.removeServiceListener(this);
+ } else {
+ final BluetoothDevice d = device;
+ mRunnable = new Runnable() {
+ public void run() {
+ handleDocked(d, state, startId); // FIXME: WTF runnable here?
+ }
+ };
+ 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;
}
}
@@ -427,21 +444,25 @@ public final class DockService extends Service implements ServiceListener {
+ " Device: " + (device == null ? "null" : device.getAliasName()));
}
- if (device == null) {
- Log.w(TAG, "device is null");
- return null;
- }
-
int msgType;
switch (state) {
case Intent.EXTRA_DOCK_STATE_UNDOCKED:
msgType = MSG_TYPE_UNDOCKED_TEMPORARY;
break;
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_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 (device == null) {
+ Log.w(TAG, "device is null");
+ return null;
+ }
msgType = MSG_TYPE_SHOW_UI;
} else {
msgType = MSG_TYPE_DOCKED;
@@ -474,35 +495,53 @@ public final class DockService extends Service implements ServiceListener {
startForeground(0, new Notification());
- // Device in a new dock.
- boolean firstTime = !LocalBluetoothPreferences.hasDockAutoConnectSetting(this, device.getAddress());
+ final AlertDialog.Builder ab = new AlertDialog.Builder(this);
+ View view;
+ LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
- CharSequence[] items = initBtSettings(device, state, firstTime);
+ if (device != null) {
+ // Device in a new dock.
+ boolean firstTime =
+ !LocalBluetoothPreferences.hasDockAutoConnectSetting(this, device.getAddress());
- final AlertDialog.Builder ab = new AlertDialog.Builder(this);
- ab.setTitle(getString(R.string.bluetooth_dock_settings_title));
+ CharSequence[] items = initBtSettings(device, state, firstTime);
- // Profiles
- ab.setMultiChoiceItems(items, mCheckedItems, mMultiClickListener);
+ ab.setTitle(getString(R.string.bluetooth_dock_settings_title));
- // Remember this settings
- LayoutInflater inflater = (LayoutInflater)
- 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);
+ // Profiles
+ ab.setMultiChoiceItems(items, mCheckedItems, mMultiClickListener);
+
+ // Remember this settings
+ view = inflater.inflate(R.layout.remember_dock_setting, null);
+ CheckBox rememberCheckbox = (CheckBox) view.findViewById(R.id.remember);
+
+ // check "Remember setting" by default if no value was saved
+ boolean checked = firstTime ||
+ LocalBluetoothPreferences.getDockAutoConnectSetting(this, device.getAddress());
+ rememberCheckbox.setChecked(checked);
+ rememberCheckbox.setOnCheckedChangeListener(mCheckedChangeListener);
+ if (DEBUG) {
+ Log.d(TAG, "Auto connect = "
+ + LocalBluetoothPreferences.getDockAutoConnectSetting(this, device.getAddress()));
+ }
+ } else {
+ ab.setTitle(getString(R.string.bluetooth_dock_settings_title));
- // check "Remember setting" by default if no value was saved
- boolean checked = firstTime || LocalBluetoothPreferences.getDockAutoConnectSetting(this, device.getAddress());
- rememberCheckbox.setChecked(checked);
- rememberCheckbox.setOnCheckedChangeListener(mCheckedChangeListener);
+ 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 */);
- if (DEBUG) {
- Log.d(TAG, "Auto connect = "
- + LocalBluetoothPreferences.getDockAutoConnectSetting(this, device.getAddress()));
- }
// Ok Button
ab.setPositiveButton(getString(android.R.string.ok), mClickListener);
@@ -536,6 +575,9 @@ public final class DockService extends Service implements ServiceListener {
if (mDevice != null) {
LocalBluetoothPreferences.saveDockAutoConnectSetting(
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,
int startId) {
- if (LocalBluetoothPreferences.getDockAutoConnectSetting(this, device.getAddress())) {
+ if (device != null &&
+ LocalBluetoothPreferences.getDockAutoConnectSetting(this, device.getAddress())) {
// Setting == auto connect
initBtSettings(device, state, false);
applyBtSettings(mDevice, startId);
@@ -841,8 +884,10 @@ public final class DockService extends Service implements ServiceListener {
}
mDevice = null;
mPendingDevice = null;
- CachedBluetoothDevice cachedDevice = getCachedBluetoothDevice(device);
- cachedDevice.disconnect();
+ if (device != null) {
+ CachedBluetoothDevice cachedDevice = getCachedBluetoothDevice(device);
+ cachedDevice.disconnect();
+ }
}
private CachedBluetoothDevice getCachedBluetoothDevice(BluetoothDevice device) {