summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/bluetooth
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/settings/bluetooth')
-rw-r--r--src/com/android/settings/bluetooth/BluetoothDevicePreference.java2
-rw-r--r--src/com/android/settings/bluetooth/BluetoothNameDialogFragment.java2
-rwxr-xr-xsrc/com/android/settings/bluetooth/BluetoothPairingDialog.java51
-rw-r--r--src/com/android/settings/bluetooth/BluetoothPairingRequest.java4
-rw-r--r--src/com/android/settings/bluetooth/BluetoothPermissionRequest.java25
-rwxr-xr-xsrc/com/android/settings/bluetooth/BluetoothSettings.java170
-rwxr-xr-xsrc/com/android/settings/bluetooth/CachedBluetoothDevice.java2
-rwxr-xr-xsrc/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java8
-rw-r--r--src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java6
-rwxr-xr-xsrc/com/android/settings/bluetooth/DeviceProfilesSettings.java126
-rw-r--r--src/com/android/settings/bluetooth/MessageAccessSettings.java167
-rwxr-xr-xsrc/com/android/settings/bluetooth/Utils.java17
12 files changed, 220 insertions, 360 deletions
diff --git a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
index e8bad0c..eca0cca 100644
--- a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
+++ b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
@@ -318,6 +318,6 @@ public final class BluetoothDevicePreference extends Preference implements
return R.drawable.ic_bt_headset_hfp;
}
}
- return 0;
+ return R.drawable.ic_settings_bluetooth2;
}
}
diff --git a/src/com/android/settings/bluetooth/BluetoothNameDialogFragment.java b/src/com/android/settings/bluetooth/BluetoothNameDialogFragment.java
index bf0356c..4466aea 100644
--- a/src/com/android/settings/bluetooth/BluetoothNameDialogFragment.java
+++ b/src/com/android/settings/bluetooth/BluetoothNameDialogFragment.java
@@ -92,7 +92,6 @@ public final class BluetoothNameDialogFragment extends DialogFragment implements
mDeviceNameEdited = savedInstanceState.getBoolean(KEY_NAME_EDITED, false);
}
mAlertDialog = new AlertDialog.Builder(getActivity())
- .setIcon(android.R.drawable.ic_dialog_info)
.setTitle(R.string.bluetooth_rename_device)
.setView(createDialogView(deviceName))
.setPositiveButton(R.string.bluetooth_rename_button,
@@ -178,7 +177,6 @@ public final class BluetoothNameDialogFragment extends DialogFragment implements
mDeviceNameUpdated = true;
mDeviceNameEdited = false;
mDeviceNameView.setText(mLocalAdapter.getName());
- getActivity().setTitle(mLocalAdapter.getName());
}
}
diff --git a/src/com/android/settings/bluetooth/BluetoothPairingDialog.java b/src/com/android/settings/bluetooth/BluetoothPairingDialog.java
index 9922042..02eed99 100755
--- a/src/com/android/settings/bluetooth/BluetoothPairingDialog.java
+++ b/src/com/android/settings/bluetooth/BluetoothPairingDialog.java
@@ -175,7 +175,8 @@ public final class BluetoothPairingDialog extends AlertActivity implements
private View createPinEntryView(String deviceName) {
View view = getLayoutInflater().inflate(R.layout.bluetooth_pin_entry, null);
- TextView messageView = (TextView) view.findViewById(R.id.message);
+ TextView messageViewCaption = (TextView) view.findViewById(R.id.message_caption);
+ TextView messageViewContent = (TextView) view.findViewById(R.id.message_subhead);
TextView messageView2 = (TextView) view.findViewById(R.id.message_below_pin);
CheckBox alphanumericPin = (CheckBox) view.findViewById(R.id.alphanumeric_pin);
mPairingView = (EditText) view.findViewById(R.id.text);
@@ -194,7 +195,7 @@ public final class BluetoothPairingDialog extends AlertActivity implements
break;
case BluetoothDevice.PAIRING_VARIANT_PASSKEY:
- messageId1 = R.string.bluetooth_enter_passkey_msg;
+ messageId1 = R.string.bluetooth_enter_pin_msg;
messageId2 = R.string.bluetooth_enter_passkey_other_device;
// Maximum of 6 digits for passkey
maxLength = BLUETOOTH_PASSKEY_MAX_LENGTH;
@@ -206,9 +207,8 @@ public final class BluetoothPairingDialog extends AlertActivity implements
return null;
}
- // HTML escape deviceName, Format the message string, then parse HTML style tags
- String messageText = getString(messageId1, Html.escapeHtml(deviceName));
- messageView.setText(Html.fromHtml(messageText));
+ messageViewCaption.setText(messageId1);
+ messageViewContent.setText(deviceName);
messageView2.setText(messageId2);
mPairingView.setInputType(InputType.TYPE_CLASS_NUMBER);
mPairingView.setFilters(new InputFilter[] {
@@ -219,33 +219,46 @@ public final class BluetoothPairingDialog extends AlertActivity implements
private View createView(CachedBluetoothDeviceManager deviceManager) {
View view = getLayoutInflater().inflate(R.layout.bluetooth_pin_confirm, null);
- // Escape device name to avoid HTML injection.
+ // Escape device name to avoid HTML injection.
String name = Html.escapeHtml(deviceManager.getName(mDevice));
- TextView messageView = (TextView) view.findViewById(R.id.message);
-
- String messageText; // formatted string containing HTML style tags
+ TextView messageViewCaption = (TextView) view.findViewById(R.id.message_caption);
+ TextView messageViewContent = (TextView) view.findViewById(R.id.message_subhead);
+ TextView pairingViewCaption = (TextView) view.findViewById(R.id.pairing_caption);
+ TextView pairingViewContent = (TextView) view.findViewById(R.id.pairing_subhead);
+ TextView messagePairing = (TextView) view.findViewById(R.id.pairing_code_message);
+
+ String messageCaption = null;
+ String pairingContent = null;
switch (mType) {
+ case BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY:
+ case BluetoothDevice.PAIRING_VARIANT_DISPLAY_PIN:
case BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION:
- messageText = getString(R.string.bluetooth_confirm_passkey_msg,
- name, mPairingKey);
+ messageCaption = getString(R.string.bluetooth_enter_pin_msg);
+ pairingContent = mPairingKey;
break;
case BluetoothDevice.PAIRING_VARIANT_CONSENT:
case BluetoothDevice.PAIRING_VARIANT_OOB_CONSENT:
- messageText = getString(R.string.bluetooth_incoming_pairing_msg, name);
- break;
-
- case BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY:
- case BluetoothDevice.PAIRING_VARIANT_DISPLAY_PIN:
- messageText = getString(R.string.bluetooth_display_passkey_pin_msg, name,
- mPairingKey);
+ messageCaption = getString(R.string.bluetooth_enter_pin_msg);
break;
default:
Log.e(TAG, "Incorrect pairing type received, not creating view");
return null;
}
- messageView.setText(Html.fromHtml(messageText));
+
+ if (messageViewCaption != null) {
+ messageViewCaption.setText(messageCaption);
+ messageViewContent.setText(name);
+ }
+
+ if (pairingContent != null) {
+ pairingViewCaption.setVisibility(View.VISIBLE);
+ pairingViewContent.setVisibility(View.VISIBLE);
+ pairingViewContent.setText(pairingContent);
+ messagePairing.setVisibility(View.VISIBLE);
+ }
+
return view;
}
diff --git a/src/com/android/settings/bluetooth/BluetoothPairingRequest.java b/src/com/android/settings/bluetooth/BluetoothPairingRequest.java
index ea36fee..44198d3 100644
--- a/src/com/android/settings/bluetooth/BluetoothPairingRequest.java
+++ b/src/com/android/settings/bluetooth/BluetoothPairingRequest.java
@@ -90,7 +90,9 @@ public final class BluetoothPairingRequest extends BroadcastReceiver {
.setContentText(res.getString(R.string.bluetooth_notif_message, name))
.setContentIntent(pending)
.setAutoCancel(true)
- .setDefaults(Notification.DEFAULT_SOUND);
+ .setDefaults(Notification.DEFAULT_SOUND)
+ .setColor(res.getColor(
+ com.android.internal.R.color.system_notification_accent_color));
NotificationManager manager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
diff --git a/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java b/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java
index c3b93be..1ede05b 100644
--- a/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java
+++ b/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java
@@ -122,17 +122,20 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver {
break;
}
Notification notification = new Notification.Builder(context)
- .setContentTitle(title)
- .setTicker(message)
- .setContentText(message)
- .setSmallIcon(android.R.drawable.stat_sys_data_bluetooth)
- .setAutoCancel(true)
- .setPriority(Notification.PRIORITY_MAX)
- .setOnlyAlertOnce(false)
- .setDefaults(Notification.DEFAULT_ALL)
- .setContentIntent(PendingIntent.getActivity(context, 0, connectionAccessIntent, 0))
- .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0))
- .build();
+ .setContentTitle(title)
+ .setTicker(message)
+ .setContentText(message)
+ .setSmallIcon(android.R.drawable.stat_sys_data_bluetooth)
+ .setAutoCancel(true)
+ .setPriority(Notification.PRIORITY_MAX)
+ .setOnlyAlertOnce(false)
+ .setDefaults(Notification.DEFAULT_ALL)
+ .setContentIntent(PendingIntent.getActivity(context, 0,
+ connectionAccessIntent, 0))
+ .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0))
+ .setColor(context.getResources().getColor(
+ com.android.internal.R.color.system_notification_accent_color))
+ .build();
notification.flags |= Notification.FLAG_NO_CLEAR; /* cannot be set with the builder */
diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java
index f1125bc..ec288f3 100755
--- a/src/com/android/settings/bluetooth/BluetoothSettings.java
+++ b/src/com/android/settings/bluetooth/BluetoothSettings.java
@@ -18,28 +18,39 @@ package com.android.settings.bluetooth;
import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
+import android.app.Activity;
+import android.app.AlertDialog;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
+import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceCategory;
+import android.preference.PreferenceFragment;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
import android.util.Log;
+import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+import android.widget.EditText;
import android.widget.TextView;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.search.Index;
import com.android.settings.search.Indexable;
import com.android.settings.search.SearchIndexableRaw;
import com.android.settings.widget.SwitchBar;
@@ -58,19 +69,20 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
private static final int MENU_ID_SCAN = Menu.FIRST;
private static final int MENU_ID_RENAME_DEVICE = Menu.FIRST + 1;
private static final int MENU_ID_SHOW_RECEIVED = Menu.FIRST + 2;
- private static final int MENU_ID_MESSAGE_ACCESS = Menu.FIRST + 3;
/* Private intent to show the list of received files */
private static final String BTOPP_ACTION_OPEN_RECEIVED_FILES =
"android.btopp.intent.action.OPEN_RECEIVED_FILES";
+ private static View mSettingsDialogView = null;
+
private BluetoothEnabler mBluetoothEnabler;
private PreferenceGroup mPairedDevicesCategory;
private PreferenceGroup mAvailableDevicesCategory;
private boolean mAvailableDevicesCategoryIsPresent;
- private boolean mActivityStarted;
+ private boolean mInitialScanStarted;
private TextView mEmptyView;
private SwitchBar mSwitchBar;
@@ -86,13 +98,14 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED)) {
- updateDeviceName();
+ updateDeviceName(context);
}
}
- private void updateDeviceName() {
+ private void updateDeviceName(Context context) {
if (mLocalAdapter.isEnabled() && mMyDevicePreference != null) {
- mMyDevicePreference.setTitle(mLocalAdapter.getName());
+ mMyDevicePreference.setSummary(context.getResources().getString(
+ R.string.bluetooth_is_visible_message, mLocalAdapter.getName()));
}
}
};
@@ -105,7 +118,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
- mActivityStarted = (savedInstanceState == null); // don't auto start scan after rotation
+ mInitialScanStarted = (savedInstanceState != null); // don't auto start scan after rotation
mEmptyView = (TextView) getView().findViewById(android.R.id.empty);
getListView().setEmptyView(mEmptyView);
@@ -140,6 +153,9 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
}
super.onResume();
+ // Make the device visible to other devices.
+ mLocalAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
+
if (isUiRestricted()) {
setDeviceListGroup(getPreferenceScreen());
removeAllDevices();
@@ -149,11 +165,8 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
getActivity().registerReceiver(mReceiver, mIntentFilter);
if (mLocalAdapter != null) {
- updateContent(mLocalAdapter.getBluetoothState(), mActivityStarted);
+ updateContent(mLocalAdapter.getBluetoothState());
}
-
- // Make the device visible to other devices.
- mLocalAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
}
@Override
@@ -163,14 +176,14 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
mBluetoothEnabler.pause();
}
+ // Make the device only visible to connected devices.
+ mLocalAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE);
+
if (isUiRestricted()) {
return;
}
getActivity().unregisterReceiver(mReceiver);
-
- // Make the device only visible to connected devices.
- mLocalAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE);
}
@Override
@@ -191,12 +204,6 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
menu.add(Menu.NONE, MENU_ID_SHOW_RECEIVED, 0, R.string.bluetooth_show_received_files)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
- // Message Access API is still not finished, once completed we undo this check.
- // Bug 16232864
- if (android.os.SystemProperties.get("show_bluetooth_message_access").equals("true")){
- menu.add(Menu.NONE, MENU_ID_MESSAGE_ACCESS, 0, R.string.bluetooth_show_message_access)
- .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
- }
super.onCreateOptionsMenu(menu, inflater);
}
@@ -218,23 +225,28 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
Intent intent = new Intent(BTOPP_ACTION_OPEN_RECEIVED_FILES);
getActivity().sendBroadcast(intent);
return true;
-
- case MENU_ID_MESSAGE_ACCESS:
- if (getActivity() instanceof SettingsActivity) {
- ((SettingsActivity) getActivity()).startPreferencePanel(
- MessageAccessSettings.class.getCanonicalName(), null,
- R.string.bluetooth_show_message_access, null, this, 0);
- }
- return true;
}
return super.onOptionsItemSelected(item);
}
private void startScanning() {
- if (isUiRestricted()) return;
+ if (isUiRestricted()) {
+ return;
+ }
+
if (!mAvailableDevicesCategoryIsPresent) {
getPreferenceScreen().addPreference(mAvailableDevicesCategory);
+ mAvailableDevicesCategoryIsPresent = true;
}
+
+ if (mAvailableDevicesCategory != null) {
+ setDeviceListGroup(mAvailableDevicesCategory);
+ removeAllDevices();
+ }
+
+ mLocalManager.getCachedDeviceManager().clearCachedDevices();
+ mAvailableDevicesCategory.removeAll();
+ mInitialScanStarted = true;
mLocalAdapter.startScanning(true);
}
@@ -245,16 +257,18 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
}
private void addDeviceCategory(PreferenceGroup preferenceGroup, int titleId,
- BluetoothDeviceFilter.Filter filter) {
+ BluetoothDeviceFilter.Filter filter, boolean addCachedDevices) {
preferenceGroup.setTitle(titleId);
getPreferenceScreen().addPreference(preferenceGroup);
setFilter(filter);
setDeviceListGroup(preferenceGroup);
- addCachedDevices();
+ if (addCachedDevices) {
+ addCachedDevices();
+ }
preferenceGroup.setEnabled(true);
}
- private void updateContent(int bluetoothState, boolean scanState) {
+ private void updateContent(int bluetoothState) {
final PreferenceScreen preferenceScreen = getPreferenceScreen();
int messageId = 0;
@@ -277,9 +291,13 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
}
addDeviceCategory(mPairedDevicesCategory,
R.string.bluetooth_preference_paired_devices,
- BluetoothDeviceFilter.BONDED_DEVICE_FILTER);
+ BluetoothDeviceFilter.BONDED_DEVICE_FILTER, true);
int numberOfPairedDevices = mPairedDevicesCategory.getPreferenceCount();
+ if (isUiRestricted() || numberOfPairedDevices <= 0) {
+ preferenceScreen.removePreference(mPairedDevicesCategory);
+ }
+
// Available devices category
if (mAvailableDevicesCategory == null) {
mAvailableDevicesCategory = new BluetoothProgressCategory(getActivity());
@@ -289,30 +307,17 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
}
addDeviceCategory(mAvailableDevicesCategory,
R.string.bluetooth_preference_found_devices,
- BluetoothDeviceFilter.UNBONDED_DEVICE_FILTER);
+ BluetoothDeviceFilter.UNBONDED_DEVICE_FILTER, mInitialScanStarted);
int numberOfAvailableDevices = mAvailableDevicesCategory.getPreferenceCount();
- mAvailableDevicesCategoryIsPresent = true;
-
- if (numberOfAvailableDevices == 0) {
- preferenceScreen.removePreference(mAvailableDevicesCategory);
- mAvailableDevicesCategoryIsPresent = false;
- }
- if (numberOfPairedDevices == 0) {
- preferenceScreen.removePreference(mPairedDevicesCategory);
- if (scanState == true) {
- mActivityStarted = false;
- startScanning();
- } else {
- if (!mAvailableDevicesCategoryIsPresent) {
- getPreferenceScreen().addPreference(mAvailableDevicesCategory);
- }
- }
+ if (!mInitialScanStarted) {
+ startScanning();
}
if (mMyDevicePreference == null) {
mMyDevicePreference = new Preference(getActivity());
}
+
mMyDevicePreference.setSummary(getResources().getString(
R.string.bluetooth_is_visible_message, mLocalAdapter.getName()));
mMyDevicePreference.setSelectable(false);
@@ -349,7 +354,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
@Override
public void onBluetoothStateChanged(int bluetoothState) {
super.onBluetoothStateChanged(bluetoothState);
- updateContent(bluetoothState, true);
+ updateContent(bluetoothState);
}
@Override
@@ -361,30 +366,69 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
}
}
- @Override
public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
setDeviceListGroup(getPreferenceScreen());
removeAllDevices();
- updateContent(mLocalAdapter.getBluetoothState(), false);
+ updateContent(mLocalAdapter.getBluetoothState());
}
private final View.OnClickListener mDeviceProfilesListener = new View.OnClickListener() {
public void onClick(View v) {
// User clicked on advanced options icon for a device in the list
- if (v.getTag() instanceof CachedBluetoothDevice) {
- if (isUiRestricted()) return;
-
- CachedBluetoothDevice device = (CachedBluetoothDevice) v.getTag();
+ if (!(v.getTag() instanceof CachedBluetoothDevice)) {
+ Log.w(TAG, "onClick() called for other View: " + v);
+ return;
+ }
- Bundle args = new Bundle(1);
- args.putParcelable(DeviceProfilesSettings.EXTRA_DEVICE, device.getDevice());
+ final CachedBluetoothDevice device = (CachedBluetoothDevice) v.getTag();
+ final Activity activity = getActivity();
+ DeviceProfilesSettings profileFrag = (DeviceProfilesSettings)activity.
+ getFragmentManager().findFragmentById(R.id.bluetooth_fragment_settings);
- ((SettingsActivity) getActivity()).startPreferencePanel(
- DeviceProfilesSettings.class.getName(), args,
- R.string.bluetooth_device_advanced_title, null, null, 0);
- } else {
- Log.w(TAG, "onClick() called for other View: " + v); // TODO remove
+ if (mSettingsDialogView != null){
+ ViewGroup parent = (ViewGroup) mSettingsDialogView.getParent();
+ if (parent != null) {
+ parent.removeView(mSettingsDialogView);
+ }
}
+ if (profileFrag == null) {
+ LayoutInflater inflater = getActivity().getLayoutInflater();
+ mSettingsDialogView = inflater.inflate(R.layout.bluetooth_device_settings, null);
+ profileFrag = (DeviceProfilesSettings)activity.getFragmentManager()
+ .findFragmentById(R.id.bluetooth_fragment_settings);
+ }
+
+ final View dialogLayout = mSettingsDialogView;
+ AlertDialog.Builder settingsDialog = new AlertDialog.Builder(activity);
+ profileFrag.setDevice(device);
+ final EditText deviceName = (EditText)dialogLayout.findViewById(R.id.name);
+ deviceName.setText(device.getName(), TextView.BufferType.EDITABLE);
+ settingsDialog.setView(dialogLayout);
+ settingsDialog.setTitle(R.string.bluetooth_preference_paired_devices);
+ settingsDialog.setPositiveButton(R.string.okay,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ EditText deviceName = (EditText)dialogLayout.findViewById(R.id.name);
+ device.setName(deviceName.getText().toString());
+ }
+ });
+ final Context context = v.getContext();
+ settingsDialog.setNegativeButton(R.string.forget,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ device.unpair();
+ com.android.settings.bluetooth.Utils.updateSearchIndex(activity,
+ BluetoothSettings.class.getName(), device.getName(),
+ context.getResources().getString(R.string.bluetooth_settings),
+ R.drawable.ic_settings_bluetooth2, false);
+ }
+ });
+
+ AlertDialog dialog = settingsDialog.create();
+ dialog.create();
+ dialog.show();
}
};
diff --git a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
index a7104df..3b64ade 100755
--- a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
+++ b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
@@ -539,7 +539,7 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
if (bondState == BluetoothDevice.BOND_NONE) {
mProfiles.clear();
mConnectAfterPairing = false; // cancel auto-connect
- setPhonebookPermissionChoice(ACCESS_ALLOWED);
+ setPhonebookPermissionChoice(ACCESS_UNKNOWN);
setMessagePermissionChoice(ACCESS_UNKNOWN);
mPhonebookRejectedTimes = 0;
savePhonebookRejectTimes();
diff --git a/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java b/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java
index ff282cc..0b53b1a 100755
--- a/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java
+++ b/src/com/android/settings/bluetooth/CachedBluetoothDeviceManager.java
@@ -86,7 +86,9 @@ final class CachedBluetoothDeviceManager {
BluetoothDevice device) {
CachedBluetoothDevice newDevice = new CachedBluetoothDevice(mContext, adapter,
profileManager, device);
- mCachedDevices.add(newDevice);
+ synchronized (mCachedDevices) {
+ mCachedDevices.add(newDevice);
+ }
return newDevice;
}
@@ -110,6 +112,10 @@ final class CachedBluetoothDeviceManager {
return device.getAddress();
}
+ public synchronized void clearCachedDevices() {
+ mCachedDevices.clear();
+ }
+
public synchronized void onScanningStateChanged(boolean started) {
if (!started) return;
diff --git a/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java b/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
index f482ecd..e7208b5 100644
--- a/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
+++ b/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
@@ -167,6 +167,12 @@ public abstract class DeviceListPreferenceFragment extends
}
void createDevicePreference(CachedBluetoothDevice cachedDevice) {
+ if (mDeviceListGroup == null) {
+ Log.w(TAG, "Trying to create a device preference before the list group/category "
+ + "exists!");
+ return;
+ }
+
BluetoothDevicePreference preference = new BluetoothDevicePreference(
getActivity(), cachedDevice);
diff --git a/src/com/android/settings/bluetooth/DeviceProfilesSettings.java b/src/com/android/settings/bluetooth/DeviceProfilesSettings.java
index fb7668f..64c807f 100755
--- a/src/com/android/settings/bluetooth/DeviceProfilesSettings.java
+++ b/src/com/android/settings/bluetooth/DeviceProfilesSettings.java
@@ -17,6 +17,7 @@
package com.android.settings.bluetooth;
import android.app.AlertDialog;
+import android.app.Fragment;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
@@ -36,6 +37,7 @@ import android.text.TextWatcher;
import android.app.Dialog;
import android.widget.Button;
import android.text.Editable;
+
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.search.Index;
@@ -52,15 +54,12 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
implements CachedBluetoothDevice.Callback, Preference.OnPreferenceChangeListener {
private static final String TAG = "DeviceProfilesSettings";
- private static final String KEY_RENAME_DEVICE = "rename_device";
private static final String KEY_PROFILE_CONTAINER = "profile_container";
private static final String KEY_UNPAIR = "unpair";
private static final String KEY_PBAP_SERVER = "PBAP Server";
- public static final String EXTRA_DEVICE = "device";
- private RenameEditTextPreference mRenameDeviceNamePref;
- private LocalBluetoothManager mManager;
private CachedBluetoothDevice mCachedDevice;
+ private LocalBluetoothManager mManager;
private LocalBluetoothProfileManager mProfileManager;
private PreferenceGroup mProfileContainer;
@@ -72,66 +71,18 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
private AlertDialog mDisconnectDialog;
private boolean mProfileGroupIsRemoved;
- private class RenameEditTextPreference implements TextWatcher{
- public void afterTextChanged(Editable s) {
- Dialog d = mDeviceNamePref.getDialog();
- if (d instanceof AlertDialog) {
- ((AlertDialog) d).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(s.length() > 0);
- }
- }
-
- // TextWatcher interface
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- // not used
- }
-
- // TextWatcher interface
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- // not used
- }
- }
-
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- BluetoothDevice device;
- if (savedInstanceState != null) {
- device = savedInstanceState.getParcelable(EXTRA_DEVICE);
- } else {
- Bundle args = getArguments();
- device = args.getParcelable(EXTRA_DEVICE);
- }
-
addPreferencesFromResource(R.xml.bluetooth_device_advanced);
getPreferenceScreen().setOrderingAsAdded(false);
mProfileContainer = (PreferenceGroup) findPreference(KEY_PROFILE_CONTAINER);
- mDeviceNamePref = (EditTextPreference) findPreference(KEY_RENAME_DEVICE);
- if (device == null) {
- Log.w(TAG, "Activity started without a remote Bluetooth device");
- finish();
- return; // TODO: test this failure path
- }
- mRenameDeviceNamePref = new RenameEditTextPreference();
mManager = LocalBluetoothManager.getInstance(getActivity());
CachedBluetoothDeviceManager deviceManager =
mManager.getCachedDeviceManager();
mProfileManager = mManager.getProfileManager();
- mCachedDevice = deviceManager.findDevice(device);
- if (mCachedDevice == null) {
- Log.w(TAG, "Device not found, cannot connect to it");
- finish();
- return; // TODO: test this failure path
- }
-
- String deviceName = mCachedDevice.getName();
- mDeviceNamePref.setSummary(deviceName);
- mDeviceNamePref.setText(deviceName);
- mDeviceNamePref.setOnPreferenceChangeListener(this);
-
- // Add a preference for each profile
- addPreferencesForProfiles();
}
@Override
@@ -141,12 +92,14 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
mDisconnectDialog.dismiss();
mDisconnectDialog = null;
}
+ if (mCachedDevice != null) {
+ mCachedDevice.unregisterCallback(this);
+ }
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
- outState.putParcelable(EXTRA_DEVICE, mCachedDevice.getDevice());
}
@Override
@@ -154,18 +107,13 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
super.onResume();
mManager.setForegroundActivity(getActivity());
- mCachedDevice.registerCallback(this);
- if(mCachedDevice.getBondState() == BluetoothDevice.BOND_NONE)
- finish();
- refresh();
- EditText et = mDeviceNamePref.getEditText();
- if (et != null) {
- et.addTextChangedListener(mRenameDeviceNamePref);
- Dialog d = mDeviceNamePref.getDialog();
- if (d instanceof AlertDialog) {
- Button b = ((AlertDialog) d).getButton(AlertDialog.BUTTON_POSITIVE);
- b.setEnabled(et.getText().length() > 0);
+ if (mCachedDevice != null) {
+ mCachedDevice.registerCallback(this);
+ if (mCachedDevice.getBondState() == BluetoothDevice.BOND_NONE) {
+ finish();
+ return;
}
+ refresh();
}
}
@@ -173,11 +121,25 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
public void onPause() {
super.onPause();
- mCachedDevice.unregisterCallback(this);
+ if (mCachedDevice != null) {
+ mCachedDevice.unregisterCallback(this);
+ }
+
mManager.setForegroundActivity(null);
}
+ public void setDevice(CachedBluetoothDevice cachedDevice) {
+ mCachedDevice = cachedDevice;
+
+ mCachedDevice.registerCallback(this);
+ if (isResumed()) {
+ addPreferencesForProfiles();
+ refresh();
+ }
+ }
+
private void addPreferencesForProfiles() {
+ mProfileContainer.removeAll();
for (LocalBluetoothProfile profile : mCachedDevice.getConnectableProfiles()) {
Preference pref = createProfilePreference(profile);
mProfileContainer.addPreference(pref);
@@ -238,28 +200,6 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
return pref;
}
- @Override
- public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
- String key = preference.getKey();
- if (key.equals(KEY_UNPAIR)) {
- unpairDevice();
- finish();
- final Context context = preference.getContext();
-
- SearchIndexableRaw data = new SearchIndexableRaw(context);
- data.className = BluetoothSettings.class.getName();
- data.title = mCachedDevice.getName();
- data.screenTitle = context.getResources().getString(R.string.bluetooth_settings);
- data.iconResId = R.drawable.ic_settings_bluetooth2;
- data.enabled = false;
-
- Index.getInstance(context).updateFromSearchIndexableData(data);
- return true;
- }
-
- return super.onPreferenceTreeClick(screen, preference);
- }
-
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == mDeviceNamePref) {
mCachedDevice.setName((String) newValue);
@@ -331,14 +271,16 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
mDisconnectDialog, disconnectListener, title, Html.fromHtml(message));
}
+ @Override
public void onDeviceAttributesChanged() {
refresh();
}
private void refresh() {
- String deviceName = mCachedDevice.getName();
- mDeviceNamePref.setSummary(deviceName);
- mDeviceNamePref.setText(deviceName);
+ final EditText deviceNameField = (EditText) getView().findViewById(R.id.name);
+ if (deviceNameField != null) {
+ deviceNameField.setText(mCachedDevice.getName());
+ }
refreshProfiles();
}
@@ -391,8 +333,4 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
private int getProfilePreferenceIndex(int profIndex) {
return mProfileContainer.getOrder() + profIndex * 10;
}
-
- private void unpairDevice() {
- mCachedDevice.unpair();
- }
}
diff --git a/src/com/android/settings/bluetooth/MessageAccessSettings.java b/src/com/android/settings/bluetooth/MessageAccessSettings.java
deleted file mode 100644
index 913357c..0000000
--- a/src/com/android/settings/bluetooth/MessageAccessSettings.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright (C) 2014 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.
- */
-
-package com.android.settings.bluetooth;
-
-import android.accounts.Account;
-import android.accounts.AccountManager;
-import android.app.ActivityManagerNative;
-import android.content.Context;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.graphics.drawable.Drawable;
-import android.os.Bundle;
-import android.os.UserHandle;
-import android.preference.SwitchPreference;
-import android.preference.Preference;
-import android.preference.PreferenceGroup;
-import android.preference.PreferenceScreen;
-import android.provider.SearchIndexableResource;
-import android.util.Log;
-
-import com.android.settings.accounts.AuthenticatorHelper;
-import com.android.settings.R;
-import com.android.settings.SettingsPreferenceFragment;
-import com.android.settings.Utils;
-import com.android.settings.search.BaseSearchIndexProvider;
-import com.android.settings.search.Indexable;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class MessageAccessSettings extends SettingsPreferenceFragment
- implements AuthenticatorHelper.OnAccountsUpdateListener, Indexable {
- private static final String TAG = "MessageAccessSettings";
- private static final String GMAIL_PACKAGE_NAME = "com.google.android.gm";
- private static final String EMAIL_PACKAGE_NAME = "com.google.android.email";
-
- private Account[] mAccounts;
- private UserHandle mUserHandle;
- private PreferenceGroup mAvailableAccounts;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // TODO: Define behavior for managed profile. See: http://b/16287773
- mUserHandle = new UserHandle(UserHandle.myUserId());
-
- addPreferencesFromResource(R.xml.bluetooth_message_access);
- }
-
- @Override
- public void onResume() {
- super.onResume();
- initPreferences();
- }
-
- @Override
- public void onAccountsUpdate(final UserHandle userHandle) {
- mAccounts = AccountManager.get(getActivity()).getAccountsAsUser(
- mUserHandle.getIdentifier());
-
- final int mAccountsSize = mAccounts.length;
- for (int i = 0; i < mAccountsSize; ++i){
- Log.d(TAG, String.format("account.type = %s\n", mAccounts[i].type));
- }
- }
-
- /**
- * Retrieves the email icon for a given account's email preference
- *
- * @param accountPref The user's account to retrieve the icon from.
- *
- * @return The drawable representing the icon of the user's email preference
- **/
- private Drawable getIcon(AccountPreference accountPref){
- Drawable icon = null;
-
- // Currently only two types of icons are allowed.
- final String packageName = accountPref.account.type.equals("com.google")
- ? GMAIL_PACKAGE_NAME : EMAIL_PACKAGE_NAME;
-
- try{
- icon = getPackageManager().getApplicationIcon(packageName);
- }catch(NameNotFoundException nnfe){
- icon = null;
- }
-
- return icon;
- }
-
- private void initPreferences() {
- final PreferenceScreen preferenceScreen = getPreferenceScreen();
- mAvailableAccounts = (PreferenceGroup)preferenceScreen.findPreference("accounts");
- mAccounts = AccountManager.get(getActivity()).getAccountsAsUser(
- mUserHandle.getIdentifier());
-
- final int mAccountsSize = mAccounts.length;
- for (int i = 0; i < mAccountsSize; ++i){
- AccountPreference accountPref = new AccountPreference(getActivity(), mAccounts[i]);
- Drawable icon = getIcon(accountPref);
- if (icon != null){
- accountPref.setIcon(icon);
- }
- mAvailableAccounts.addPreference(accountPref);
- }
- }
-
- private class AccountPreference extends SwitchPreference
- implements Preference.OnPreferenceChangeListener{
- private Account account;
-
- AccountPreference(Context context, Account account){
- super(context);
- this.account = account;
- setTitle(account.type);
- setSummary(account.name);
-
- setOnPreferenceChangeListener(this);
- }
-
- @Override
- public boolean onPreferenceChange(Preference preference, Object val) {
- if (preference instanceof AccountPreference){
- final AccountPreference accountPref = (AccountPreference) preference;
-
- if (((Boolean)val).booleanValue()){
- // Enable paired deviced to connect, fill in once API is available
- Log.w(TAG, String.format(
- "User has turned on '%s' for Bluetooth message access.",
- accountPref.account.name));
- } else {
- // Disable paired deviced to connect, fill in once API is available
- Log.w(TAG, String.format(
- "User has turned off '%s' for Bluetooth message access.",
- accountPref.account.name));
- }
- }
- return true;
- }
- }
-
- public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
- new BaseSearchIndexProvider() {
- @Override
- public List<SearchIndexableResource> getXmlResourcesToIndex(
- Context context, boolean enabled) {
- List<SearchIndexableResource> indexables = new ArrayList<SearchIndexableResource>();
- SearchIndexableResource indexable = new SearchIndexableResource(context);
- indexable.xmlResId = R.xml.bluetooth_message_access;
- indexables.add(indexable);
- return indexables;
- }
- };
-}
diff --git a/src/com/android/settings/bluetooth/Utils.java b/src/com/android/settings/bluetooth/Utils.java
index 1970400..e9230de 100755
--- a/src/com/android/settings/bluetooth/Utils.java
+++ b/src/com/android/settings/bluetooth/Utils.java
@@ -24,6 +24,8 @@ import android.content.DialogInterface;
import android.widget.Toast;
import com.android.settings.R;
+import com.android.settings.search.Index;
+import com.android.settings.search.SearchIndexableRaw;
/**
* Utils is a helper class that contains constants for various
@@ -101,4 +103,19 @@ final class Utils {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}
}
+
+ /**
+ * Update the search Index for a specific class name and resources.
+ */
+ public static void updateSearchIndex(Context context, String className, String title,
+ String screenTitle, int iconResId, boolean enabled) {
+ SearchIndexableRaw data = new SearchIndexableRaw(context);
+ data.className = className;
+ data.title = title;
+ data.screenTitle = screenTitle;
+ data.iconResId = iconResId;
+ data.enabled = enabled;
+
+ Index.getInstance(context).updateFromSearchIndexableData(data);
+ }
}