Loading res/layout/dock_audio_media_enable_dialog.xml 0 → 100644 +24 −0 Original line number Diff line number Diff line <?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" /> src/com/android/settings/bluetooth/DockEventReceiver.java +5 −2 Original line number Diff line number Diff line Loading @@ -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; } Loading src/com/android/settings/bluetooth/DockService.java +117 −72 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -267,7 +268,9 @@ public final class DockService extends Service implements ServiceListener { switch (msgType) { case MSG_TYPE_SHOW_UI: if (device != null) { createDialog(device, state, startId); } break; case MSG_TYPE_DOCKED: Loading Loading @@ -325,6 +328,7 @@ public final class DockService extends Service implements ServiceListener { private boolean msgTypeUndockedPermanent(BluetoothDevice device, int startId) { // Grace period passed. Disconnect. handleUndocked(device); if (device != null) { final SharedPreferences prefs = getPrefs(); if (DEBUG) { Loading @@ -349,6 +353,7 @@ public final class DockService extends Service implements ServiceListener { return true; } } } return false; } Loading @@ -367,7 +372,8 @@ 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 (device != null) { if (!device.equals(mDevice)) { if (mDevice != null) { // Not expected. Cleanup/undock existing handleUndocked(mDevice); Loading @@ -393,6 +399,17 @@ public final class DockService extends Service implements ServiceListener { 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; } Loading Loading @@ -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; Loading Loading @@ -474,35 +495,53 @@ public final class DockService extends Service implements ServiceListener { 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. boolean firstTime = !LocalBluetoothPreferences.hasDockAutoConnectSetting(this, device.getAddress()); boolean firstTime = !LocalBluetoothPreferences.hasDockAutoConnectSetting(this, device.getAddress()); CharSequence[] items = initBtSettings(device, state, firstTime); final AlertDialog.Builder ab = new AlertDialog.Builder(this); ab.setTitle(getString(R.string.bluetooth_dock_settings_title)); // Profiles ab.setMultiChoiceItems(items, mCheckedItems, mMultiClickListener); // 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); 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()); boolean checked = firstTime || LocalBluetoothPreferences.getDockAutoConnectSetting(this, device.getAddress()); rememberCheckbox.setChecked(checked); rememberCheckbox.setOnCheckedChangeListener(mCheckedChangeListener); 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())); } } 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 ab.setPositiveButton(getString(android.R.string.ok), mClickListener); Loading Loading @@ -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); } } }; Loading Loading @@ -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); Loading @@ -841,9 +884,11 @@ public final class DockService extends Service implements ServiceListener { } mDevice = null; mPendingDevice = null; if (device != null) { CachedBluetoothDevice cachedDevice = getCachedBluetoothDevice(device); cachedDevice.disconnect(); } } private CachedBluetoothDevice getCachedBluetoothDevice(BluetoothDevice device) { CachedBluetoothDevice cachedDevice = mDeviceManager.findDevice(device); Loading Loading
res/layout/dock_audio_media_enable_dialog.xml 0 → 100644 +24 −0 Original line number Diff line number Diff line <?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" />
src/com/android/settings/bluetooth/DockEventReceiver.java +5 −2 Original line number Diff line number Diff line Loading @@ -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; } Loading
src/com/android/settings/bluetooth/DockService.java +117 −72 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -267,7 +268,9 @@ public final class DockService extends Service implements ServiceListener { switch (msgType) { case MSG_TYPE_SHOW_UI: if (device != null) { createDialog(device, state, startId); } break; case MSG_TYPE_DOCKED: Loading Loading @@ -325,6 +328,7 @@ public final class DockService extends Service implements ServiceListener { private boolean msgTypeUndockedPermanent(BluetoothDevice device, int startId) { // Grace period passed. Disconnect. handleUndocked(device); if (device != null) { final SharedPreferences prefs = getPrefs(); if (DEBUG) { Loading @@ -349,6 +353,7 @@ public final class DockService extends Service implements ServiceListener { return true; } } } return false; } Loading @@ -367,7 +372,8 @@ 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 (device != null) { if (!device.equals(mDevice)) { if (mDevice != null) { // Not expected. Cleanup/undock existing handleUndocked(mDevice); Loading @@ -393,6 +399,17 @@ public final class DockService extends Service implements ServiceListener { 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; } Loading Loading @@ -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; Loading Loading @@ -474,35 +495,53 @@ public final class DockService extends Service implements ServiceListener { 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. boolean firstTime = !LocalBluetoothPreferences.hasDockAutoConnectSetting(this, device.getAddress()); boolean firstTime = !LocalBluetoothPreferences.hasDockAutoConnectSetting(this, device.getAddress()); CharSequence[] items = initBtSettings(device, state, firstTime); final AlertDialog.Builder ab = new AlertDialog.Builder(this); ab.setTitle(getString(R.string.bluetooth_dock_settings_title)); // Profiles ab.setMultiChoiceItems(items, mCheckedItems, mMultiClickListener); // 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); 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()); boolean checked = firstTime || LocalBluetoothPreferences.getDockAutoConnectSetting(this, device.getAddress()); rememberCheckbox.setChecked(checked); rememberCheckbox.setOnCheckedChangeListener(mCheckedChangeListener); 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())); } } 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 ab.setPositiveButton(getString(android.R.string.ok), mClickListener); Loading Loading @@ -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); } } }; Loading Loading @@ -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); Loading @@ -841,9 +884,11 @@ public final class DockService extends Service implements ServiceListener { } mDevice = null; mPendingDevice = null; if (device != null) { CachedBluetoothDevice cachedDevice = getCachedBluetoothDevice(device); cachedDevice.disconnect(); } } private CachedBluetoothDevice getCachedBluetoothDevice(BluetoothDevice device) { CachedBluetoothDevice cachedDevice = mDeviceManager.findDevice(device); Loading