Added ability for user to automatically accept/deny Bluetooth Phonebook Syncs
Bug: 16040292 Change-Id: Ieeaa014052f53787cf7057578e0b2ac048dc6eb1
This commit is contained in:
@@ -76,11 +76,11 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
|
||||
|
||||
// Following constants indicate the user's choices of Phone book/message access settings
|
||||
// User hasn't made any choice or settings app has wiped out the memory
|
||||
final static int ACCESS_UNKNOWN = 0;
|
||||
public final static int ACCESS_UNKNOWN = 0;
|
||||
// User has accepted the connection and let Settings app remember the decision
|
||||
final static int ACCESS_ALLOWED = 1;
|
||||
public final static int ACCESS_ALLOWED = 1;
|
||||
// User has rejected the connection and let Settings app remember the decision
|
||||
final static int ACCESS_REJECTED = 2;
|
||||
public final static int ACCESS_REJECTED = 2;
|
||||
|
||||
// how many times did User reject the connection to make the rejected persist.
|
||||
final static int PERSIST_REJECTED_TIMES_LIMIT = 2;
|
||||
|
@@ -55,6 +55,7 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
|
||||
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;
|
||||
@@ -181,6 +182,16 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
|
||||
Preference pref = createProfilePreference(profile);
|
||||
mProfileContainer.addPreference(pref);
|
||||
}
|
||||
|
||||
final int pbapPermission = mCachedDevice.getPhonebookPermissionChoice();
|
||||
// Only provide PBAP cabability if the client device has requested PBAP.
|
||||
if (pbapPermission != CachedBluetoothDevice.ACCESS_UNKNOWN) {
|
||||
final PbapServerProfile psp = mManager.getProfileManager().getPbapProfile();
|
||||
CheckBoxPreference pbapPref = createProfilePreference(psp);
|
||||
pbapPref.setChecked(pbapPermission == CachedBluetoothDevice.ACCESS_ALLOWED);
|
||||
mProfileContainer.addPreference(pbapPref);
|
||||
}
|
||||
|
||||
showOrHideProfileGroup();
|
||||
}
|
||||
|
||||
@@ -205,6 +216,7 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
|
||||
*/
|
||||
private CheckBoxPreference createProfilePreference(LocalBluetoothProfile profile) {
|
||||
CheckBoxPreference pref = new CheckBoxPreference(getActivity());
|
||||
pref.setLayoutResource(R.layout.preference_start_widget);
|
||||
pref.setKey(profile.toString());
|
||||
pref.setTitle(profile.getNameResource(mCachedDevice.getDevice()));
|
||||
pref.setPersistent(false);
|
||||
@@ -265,6 +277,15 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
|
||||
private void onProfileClicked(LocalBluetoothProfile profile, CheckBoxPreference profilePref) {
|
||||
BluetoothDevice device = mCachedDevice.getDevice();
|
||||
|
||||
if (profilePref.getKey().equals(KEY_PBAP_SERVER)) {
|
||||
final int newPermission = mCachedDevice.getPhonebookPermissionChoice()
|
||||
== CachedBluetoothDevice.ACCESS_ALLOWED ? CachedBluetoothDevice.ACCESS_REJECTED
|
||||
: CachedBluetoothDevice.ACCESS_ALLOWED;
|
||||
mCachedDevice.setPhonebookPermissionChoice(newPermission);
|
||||
profilePref.setChecked(newPermission == CachedBluetoothDevice.ACCESS_ALLOWED);
|
||||
return;
|
||||
}
|
||||
|
||||
int status = profile.getConnectionStatus(device);
|
||||
boolean isConnected =
|
||||
status == BluetoothProfile.STATE_CONNECTED;
|
||||
@@ -351,7 +372,6 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment
|
||||
*/
|
||||
profilePref.setEnabled(!mCachedDevice.isBusy());
|
||||
profilePref.setChecked(profile.isPreferred(device));
|
||||
profilePref.setSummary(profile.getSummaryResourceForDevice(device));
|
||||
}
|
||||
|
||||
private LocalBluetoothProfile getProfileOf(Preference pref) {
|
||||
|
@@ -118,16 +118,17 @@ final class PbapServerProfile implements LocalBluetoothProfile {
|
||||
}
|
||||
|
||||
public int getNameResource(BluetoothDevice device) {
|
||||
return 0;
|
||||
return R.string.bluetooth_profile_pbap;
|
||||
}
|
||||
|
||||
public int getSummaryResourceForDevice(BluetoothDevice device) {
|
||||
return 0;
|
||||
return R.string.bluetooth_profile_pbap_summary;
|
||||
}
|
||||
|
||||
public int getDrawableResource(BluetoothClass btClass) {
|
||||
return 0;
|
||||
return R.drawable.ic_bt_cellphone;
|
||||
}
|
||||
|
||||
protected void finalize() {
|
||||
if (V) Log.d(TAG, "finalize()");
|
||||
if (mService != null) {
|
||||
|
Reference in New Issue
Block a user