Allow users to change the length of Bluetooth discoverability to
be two minues, five minutes, an hour, or forever discoverable. This addresses the internal bug 2413429: http://b/issue?id=2413429 and external issue 6348: http://code.google.com/p/android/issues/detail?id=6348 Original Author: Chris Wren <crwen@google.com> Modifications done by: Jaikumar Ganesh<jaikumar@google.com> Change-Id: Ie12e56ac41aa01a161d263c7525b6e021d4eeb1f
This commit is contained in:
committed by
Jaikumar Ganesh
parent
8e7aff2c41
commit
1b0489cb3e
@@ -294,6 +294,24 @@
|
|||||||
<item>TTLS</item>
|
<item>TTLS</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<!-- Bluetooth Settings -->
|
||||||
|
|
||||||
|
<!-- Discoverable mode timeout options -->
|
||||||
|
<string-array name="bluetooth_visibility_timeout_entries">
|
||||||
|
<item>2 Minutes</item>
|
||||||
|
<item>5 Minutes</item>
|
||||||
|
<item>1 Hour</item>
|
||||||
|
<item>Never</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<!-- Values for visibility_duration_entries matching constants in BluetoothSettings. Do not translate. -->
|
||||||
|
<string-array name="bluetooth_visibility_timeout_values" translatable="false">
|
||||||
|
<item>twomin</item>
|
||||||
|
<item>fivemin</item>
|
||||||
|
<item>onehour</item>
|
||||||
|
<item>never</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<!-- Match this with drawable.wifi_signal. --> <skip />
|
<!-- Match this with drawable.wifi_signal. --> <skip />
|
||||||
<!-- Wi-Fi settings. The signal strength a Wi-Fi network has. -->
|
<!-- Wi-Fi settings. The signal strength a Wi-Fi network has. -->
|
||||||
<string-array name="wifi_signal">
|
<string-array name="wifi_signal">
|
||||||
|
@@ -185,9 +185,14 @@
|
|||||||
<string name="bluetooth_visibility">Discoverable</string>
|
<string name="bluetooth_visibility">Discoverable</string>
|
||||||
<!-- Bluetooth settings screen, summary after selecting Discoverable check box -->
|
<!-- Bluetooth settings screen, summary after selecting Discoverable check box -->
|
||||||
<string name="bluetooth_is_discoverable">Discoverable for <xliff:g id="discoverable_time_period">%1$s</xliff:g> seconds\u2026</string>
|
<string name="bluetooth_is_discoverable">Discoverable for <xliff:g id="discoverable_time_period">%1$s</xliff:g> seconds\u2026</string>
|
||||||
|
<!-- Bluetooth settings screen, Discoverable checkbox summary text when Discoverable duration is set to "forever" -->
|
||||||
|
<string name="bluetooth_is_discoverable_always">Discoverable</string>
|
||||||
<!-- Bluetooth settings screen, Discoverable checkbox summary text -->
|
<!-- Bluetooth settings screen, Discoverable checkbox summary text -->
|
||||||
<string name="bluetooth_not_discoverable">Make device discoverable</string>
|
<string name="bluetooth_not_discoverable">Make device discoverable</string>
|
||||||
<!-- Bluetooth settings screen, heading above the list of nearby bluetooth devices -->
|
<!-- Bluetooth settings screen, option name to pick discoverability timeout duration (a list dialog comes up) -->
|
||||||
|
<string name="bluetooth_visibility_timeout">Discoverable timeout</string>
|
||||||
|
<!-- Bluetooth settings screen, Discoverable timout list dialog summary text -->
|
||||||
|
<string name="bluetooth_visibility_timeout_summary">Set how long device will be discoverable</string>
|
||||||
<!-- Bluetooth settings screen, check box label whether or not to allow
|
<!-- Bluetooth settings screen, check box label whether or not to allow
|
||||||
bluetooth voice dialing when lock screen is up-->
|
bluetooth voice dialing when lock screen is up-->
|
||||||
<string name="bluetooth_lock_voice_dialing">Lock voice dialing</string>
|
<string name="bluetooth_lock_voice_dialing">Lock voice dialing</string>
|
||||||
@@ -195,7 +200,7 @@
|
|||||||
<string name="bluetooth_lock_voice_dialing_summary">
|
<string name="bluetooth_lock_voice_dialing_summary">
|
||||||
Prevent use of the bluetooth dialer when the screen is locked
|
Prevent use of the bluetooth dialer when the screen is locked
|
||||||
</string>
|
</string>
|
||||||
|
<!-- Bluetooth settings screen, heading above the list of nearby bluetooth devices -->
|
||||||
<string name="bluetooth_devices">Bluetooth devices</string>
|
<string name="bluetooth_devices">Bluetooth devices</string>
|
||||||
<!-- Bluetooth settings screen, title for the current bluetooth name setting -->
|
<!-- Bluetooth settings screen, title for the current bluetooth name setting -->
|
||||||
<string name="bluetooth_device_name">Device name</string>
|
<string name="bluetooth_device_name">Device name</string>
|
||||||
@@ -250,11 +255,19 @@
|
|||||||
<!-- Strings for asking to the user whether to allow an app to enable discovery mode -->
|
<!-- Strings for asking to the user whether to allow an app to enable discovery mode -->
|
||||||
<string name="bluetooth_ask_discovery" product="default">"An application on your phone is requesting permission to make your phone discoverable by other Bluetooth devices for <xliff:g id="timeout">%1$d</xliff:g> seconds. Do you want to do this?"</string>
|
<string name="bluetooth_ask_discovery" product="default">"An application on your phone is requesting permission to make your phone discoverable by other Bluetooth devices for <xliff:g id="timeout">%1$d</xliff:g> seconds. Do you want to do this?"</string>
|
||||||
|
|
||||||
|
<!-- Strings for asking to the user whether to allow an app to enable lasting discovery mode -->
|
||||||
|
<string name="bluetooth_ask_lasting_discovery" product="tablet">"An application on your tablet is requesting permission to make your tablet always discoverable by other Bluetooth devices. Do you want to do this?"</string>
|
||||||
|
<string name="bluetooth_ask_lasting_discovery" product="default">"An application on your phone is requesting permission to make your phone always discoverable by other Bluetooth devices. Do you want to do this?"</string>
|
||||||
|
|
||||||
<!-- Strings for asking to the user whether to allow an app to enable bluetooth and discovery mode -->
|
<!-- Strings for asking to the user whether to allow an app to enable bluetooth and discovery mode -->
|
||||||
<string name="bluetooth_ask_enablement_and_discovery" product="tablet">"An application on your tablet is requesting permission to turn on Bluetooth and to make your tablet discoverable by other devices for <xliff:g id="timeout">%1$d</xliff:g> seconds. Do you want to do this?"</string>
|
<string name="bluetooth_ask_enablement_and_discovery" product="tablet">"An application on your tablet is requesting permission to turn on Bluetooth and to make your tablet discoverable by other devices for <xliff:g id="timeout">%1$d</xliff:g> seconds. Do you want to do this?"</string>
|
||||||
<!-- Strings for asking to the user whether to allow an app to enable bluetooth and discovery mode -->
|
<!-- Strings for asking to the user whether to allow an app to enable bluetooth and discovery mode -->
|
||||||
<string name="bluetooth_ask_enablement_and_discovery" product="default">"An application on your phone is requesting permission to turn on Bluetooth and to make your phone discoverable by other devices for <xliff:g id="timeout">%1$d</xliff:g> seconds. Do you want to do this?"</string>
|
<string name="bluetooth_ask_enablement_and_discovery" product="default">"An application on your phone is requesting permission to turn on Bluetooth and to make your phone discoverable by other devices for <xliff:g id="timeout">%1$d</xliff:g> seconds. Do you want to do this?"</string>
|
||||||
|
|
||||||
|
<!-- Strings for asking to the user whether to allow an app to enable bluetooth and discovery mode -->
|
||||||
|
<string name="bluetooth_ask_enablement_and_lasting_discovery" product="tablet">"An application on your tablet is requesting permission to turn on Bluetooth and to make your tablet discoverable by other devices. Do you want to do this?"</string>
|
||||||
|
<string name="bluetooth_ask_enablement_and_lasting_discovery" product="default">"An application on your phone is requesting permission to turn on Bluetooth and to make your phone discoverable by other devices. Do you want to do this?"</string>
|
||||||
|
|
||||||
<!-- Strings for msg to display to user while bluetooth is turning on -->
|
<!-- Strings for msg to display to user while bluetooth is turning on -->
|
||||||
<string name="bluetooth_turning_on">"Turning on Bluetooth\u2026"</string>
|
<string name="bluetooth_turning_on">"Turning on Bluetooth\u2026"</string>
|
||||||
|
|
||||||
|
@@ -43,6 +43,14 @@
|
|||||||
android:summaryOff="@string/bluetooth_not_discoverable"
|
android:summaryOff="@string/bluetooth_not_discoverable"
|
||||||
android:persistent="false" />
|
android:persistent="false" />
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:key="bt_discoverable_timeout"
|
||||||
|
android:title="@string/bluetooth_visibility_timeout"
|
||||||
|
android:dependency="bt_discoverable"
|
||||||
|
android:summary="@string/bluetooth_visibility_timeout_summary"
|
||||||
|
android:entries="@array/bluetooth_visibility_timeout_entries"
|
||||||
|
android:entryValues="@array/bluetooth_visibility_timeout_values" />
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="bt_show_received_files"
|
android:key="bt_show_received_files"
|
||||||
android:dependency="bt_checkbox"
|
android:dependency="bt_checkbox"
|
||||||
|
@@ -26,8 +26,11 @@ import android.content.IntentFilter;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
|
import android.preference.ListPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BluetoothDiscoverableEnabler is a helper to manage the "Discoverable"
|
* BluetoothDiscoverableEnabler is a helper to manage the "Discoverable"
|
||||||
@@ -39,14 +42,28 @@ public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChan
|
|||||||
|
|
||||||
private static final String SYSTEM_PROPERTY_DISCOVERABLE_TIMEOUT =
|
private static final String SYSTEM_PROPERTY_DISCOVERABLE_TIMEOUT =
|
||||||
"debug.bt.discoverable_time";
|
"debug.bt.discoverable_time";
|
||||||
/* package */ static final int DEFAULT_DISCOVERABLE_TIMEOUT = 120;
|
|
||||||
|
|
||||||
/* package */ static final String SHARED_PREFERENCES_KEY_DISCOVERABLE_END_TIMESTAMP =
|
static final int DISCOVERABLE_TIMEOUT_TWO_MINUTES = 120;
|
||||||
"discoverable_end_timestamp";
|
static final int DISCOVERABLE_TIMEOUT_FIVE_MINUTES = 300;
|
||||||
|
static final int DISCOVERABLE_TIMEOUT_ONE_HOUR = 3600;
|
||||||
|
static final int DISCOVERABLE_TIMEOUT_NEVER = 0;
|
||||||
|
|
||||||
|
static final String SHARED_PREFERENCES_KEY_DISCOVERABLE_END_TIMESTAMP =
|
||||||
|
"discoverable_end_timestamp";
|
||||||
|
|
||||||
|
private static final String VALUE_DISCOVERABLE_TIMEOUT_TWO_MINUTES = "twomin";
|
||||||
|
private static final String VALUE_DISCOVERABLE_TIMEOUT_FIVE_MINUTES = "fivemin";
|
||||||
|
private static final String VALUE_DISCOVERABLE_TIMEOUT_ONE_HOUR = "onehour";
|
||||||
|
private static final String VALUE_DISCOVERABLE_TIMEOUT_NEVER = "never";
|
||||||
|
|
||||||
|
// no need for this timeout anymore since we have the listPreference default value
|
||||||
|
// leaving now temporary until requestpermissionactivity is modified..
|
||||||
|
static final int DEFAULT_DISCOVERABLE_TIMEOUT = DISCOVERABLE_TIMEOUT_TWO_MINUTES;
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final Handler mUiHandler;
|
private final Handler mUiHandler;
|
||||||
private final CheckBoxPreference mCheckBoxPreference;
|
private final CheckBoxPreference mCheckBoxPreference;
|
||||||
|
private final ListPreference mTimeoutListPreference;
|
||||||
|
|
||||||
private final LocalBluetoothManager mLocalManager;
|
private final LocalBluetoothManager mLocalManager;
|
||||||
|
|
||||||
@@ -69,12 +86,16 @@ public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChan
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public BluetoothDiscoverableEnabler(Context context, CheckBoxPreference checkBoxPreference) {
|
public BluetoothDiscoverableEnabler(Context context,
|
||||||
|
CheckBoxPreference checkBoxPreference, ListPreference timeoutListPreference) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mUiHandler = new Handler();
|
mUiHandler = new Handler();
|
||||||
mCheckBoxPreference = checkBoxPreference;
|
mCheckBoxPreference = checkBoxPreference;
|
||||||
|
mTimeoutListPreference = timeoutListPreference;
|
||||||
|
|
||||||
checkBoxPreference.setPersistent(false);
|
checkBoxPreference.setPersistent(false);
|
||||||
|
// we actually want to persist this since can't infer from BT device state
|
||||||
|
mTimeoutListPreference.setPersistent(true);
|
||||||
|
|
||||||
mLocalManager = LocalBluetoothManager.getInstance(context);
|
mLocalManager = LocalBluetoothManager.getInstance(context);
|
||||||
if (mLocalManager == null) {
|
if (mLocalManager == null) {
|
||||||
@@ -91,7 +112,7 @@ public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChan
|
|||||||
IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
|
IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
|
||||||
mContext.registerReceiver(mReceiver, filter);
|
mContext.registerReceiver(mReceiver, filter);
|
||||||
mCheckBoxPreference.setOnPreferenceChangeListener(this);
|
mCheckBoxPreference.setOnPreferenceChangeListener(this);
|
||||||
|
mTimeoutListPreference.setOnPreferenceChangeListener(this);
|
||||||
handleModeChanged(mLocalManager.getBluetoothAdapter().getScanMode());
|
handleModeChanged(mLocalManager.getBluetoothAdapter().getScanMode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,12 +123,18 @@ public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChan
|
|||||||
|
|
||||||
mUiHandler.removeCallbacks(mUpdateCountdownSummaryRunnable);
|
mUiHandler.removeCallbacks(mUpdateCountdownSummaryRunnable);
|
||||||
mCheckBoxPreference.setOnPreferenceChangeListener(null);
|
mCheckBoxPreference.setOnPreferenceChangeListener(null);
|
||||||
|
mTimeoutListPreference.setOnPreferenceChangeListener(null);
|
||||||
mContext.unregisterReceiver(mReceiver);
|
mContext.unregisterReceiver(mReceiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onPreferenceChange(Preference preference, Object value) {
|
public boolean onPreferenceChange(Preference preference, Object value) {
|
||||||
// Turn on/off BT discoverability
|
if (preference == mCheckBoxPreference) {
|
||||||
setEnabled((Boolean) value);
|
// Turn on/off BT discoverability
|
||||||
|
setEnabled((Boolean) value);
|
||||||
|
} else if (preference == mTimeoutListPreference) {
|
||||||
|
mTimeoutListPreference.setValue((String) value);
|
||||||
|
setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -116,26 +143,52 @@ public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChan
|
|||||||
BluetoothAdapter manager = mLocalManager.getBluetoothAdapter();
|
BluetoothAdapter manager = mLocalManager.getBluetoothAdapter();
|
||||||
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
|
|
||||||
int timeout = getDiscoverableTimeout();
|
int timeout = getDiscoverableTimeout();
|
||||||
manager.setDiscoverableTimeout(timeout);
|
manager.setDiscoverableTimeout(timeout);
|
||||||
|
|
||||||
mCheckBoxPreference.setSummaryOn(
|
long endTimestamp = System.currentTimeMillis() + timeout * 1000L;
|
||||||
mContext.getResources().getString(R.string.bluetooth_is_discoverable, timeout));
|
|
||||||
|
|
||||||
long endTimestamp = System.currentTimeMillis() + timeout * 1000;
|
|
||||||
persistDiscoverableEndTimestamp(endTimestamp);
|
persistDiscoverableEndTimestamp(endTimestamp);
|
||||||
|
|
||||||
manager.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
updateCountdownSummary();
|
||||||
|
|
||||||
|
manager.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE, timeout);
|
||||||
} else {
|
} else {
|
||||||
manager.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE);
|
manager.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateTimerDisplay(int timeout) {
|
||||||
|
if (getDiscoverableTimeout() == DISCOVERABLE_TIMEOUT_NEVER) {
|
||||||
|
mCheckBoxPreference.setSummaryOn(
|
||||||
|
mContext.getResources()
|
||||||
|
.getString(R.string.bluetooth_is_discoverable_always));
|
||||||
|
} else {
|
||||||
|
mCheckBoxPreference.setSummaryOn(
|
||||||
|
mContext.getResources()
|
||||||
|
.getString(R.string.bluetooth_is_discoverable, timeout));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private int getDiscoverableTimeout() {
|
private int getDiscoverableTimeout() {
|
||||||
int timeout = SystemProperties.getInt(SYSTEM_PROPERTY_DISCOVERABLE_TIMEOUT, -1);
|
int timeout = SystemProperties.getInt(SYSTEM_PROPERTY_DISCOVERABLE_TIMEOUT, -1);
|
||||||
if (timeout <= 0) {
|
if (timeout < 0) {
|
||||||
timeout = DEFAULT_DISCOVERABLE_TIMEOUT;
|
String timeoutValue = null;
|
||||||
|
if (mTimeoutListPreference != null && mTimeoutListPreference.getValue() != null) {
|
||||||
|
timeoutValue = mTimeoutListPreference.getValue().toString();
|
||||||
|
} else {
|
||||||
|
mTimeoutListPreference.setValue(VALUE_DISCOVERABLE_TIMEOUT_TWO_MINUTES);
|
||||||
|
return DISCOVERABLE_TIMEOUT_TWO_MINUTES;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timeoutValue.equals(VALUE_DISCOVERABLE_TIMEOUT_NEVER)) {
|
||||||
|
timeout = DISCOVERABLE_TIMEOUT_NEVER;
|
||||||
|
} else if (timeoutValue.equals(VALUE_DISCOVERABLE_TIMEOUT_ONE_HOUR)) {
|
||||||
|
timeout = DISCOVERABLE_TIMEOUT_ONE_HOUR;
|
||||||
|
} else if (timeoutValue.equals(VALUE_DISCOVERABLE_TIMEOUT_FIVE_MINUTES)) {
|
||||||
|
timeout = DISCOVERABLE_TIMEOUT_FIVE_MINUTES;
|
||||||
|
} else {
|
||||||
|
timeout = DISCOVERABLE_TIMEOUT_TWO_MINUTES;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return timeout;
|
return timeout;
|
||||||
@@ -151,7 +204,6 @@ public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChan
|
|||||||
if (mode == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
|
if (mode == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
|
||||||
mCheckBoxPreference.setChecked(true);
|
mCheckBoxPreference.setChecked(true);
|
||||||
updateCountdownSummary();
|
updateCountdownSummary();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
mCheckBoxPreference.setChecked(false);
|
mCheckBoxPreference.setChecked(false);
|
||||||
}
|
}
|
||||||
@@ -173,11 +225,8 @@ public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChan
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String formattedTimeLeft = String.valueOf((endTimestamp - currentTimestamp) / 1000);
|
int timeLeft = (int) ((endTimestamp - currentTimestamp) / 1000L);
|
||||||
|
updateTimerDisplay(timeLeft);
|
||||||
mCheckBoxPreference.setSummaryOn(
|
|
||||||
mContext.getResources().getString(R.string.bluetooth_is_discoverable,
|
|
||||||
formattedTimeLeft));
|
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
mUiHandler.removeCallbacks(mUpdateCountdownSummaryRunnable);
|
mUiHandler.removeCallbacks(mUpdateCountdownSummaryRunnable);
|
||||||
|
@@ -20,8 +20,11 @@ import android.app.Activity;
|
|||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
|
import android.preference.ListPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
|
import android.preference.PreferenceCategory;
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
@@ -38,6 +41,7 @@ public class BluetoothSettings extends DeviceListPreferenceFragment
|
|||||||
|
|
||||||
private static final String KEY_BT_CHECKBOX = "bt_checkbox";
|
private static final String KEY_BT_CHECKBOX = "bt_checkbox";
|
||||||
private static final String KEY_BT_DISCOVERABLE = "bt_discoverable";
|
private static final String KEY_BT_DISCOVERABLE = "bt_discoverable";
|
||||||
|
private static final String KEY_BT_DISCOVERABLE_TIMEOUT = "bt_discoverable_timeout";
|
||||||
private static final String KEY_BT_NAME = "bt_name";
|
private static final String KEY_BT_NAME = "bt_name";
|
||||||
private static final String KEY_BT_SHOW_RECEIVED = "bt_show_received_files";
|
private static final String KEY_BT_SHOW_RECEIVED = "bt_show_received_files";
|
||||||
|
|
||||||
@@ -56,7 +60,8 @@ public class BluetoothSettings extends DeviceListPreferenceFragment
|
|||||||
(CheckBoxPreference) findPreference(KEY_BT_CHECKBOX));
|
(CheckBoxPreference) findPreference(KEY_BT_CHECKBOX));
|
||||||
|
|
||||||
mDiscoverableEnabler = new BluetoothDiscoverableEnabler(activity,
|
mDiscoverableEnabler = new BluetoothDiscoverableEnabler(activity,
|
||||||
(CheckBoxPreference) findPreference(KEY_BT_DISCOVERABLE));
|
(CheckBoxPreference) findPreference(KEY_BT_DISCOVERABLE),
|
||||||
|
(ListPreference) findPreference(KEY_BT_DISCOVERABLE_TIMEOUT));
|
||||||
|
|
||||||
mNamePreference = (BluetoothNamePreference) findPreference(KEY_BT_NAME);
|
mNamePreference = (BluetoothNamePreference) findPreference(KEY_BT_NAME);
|
||||||
}
|
}
|
||||||
|
@@ -157,7 +157,15 @@ public class RequestPermissionActivity extends Activity implements
|
|||||||
builder.setCancelable(false);
|
builder.setCancelable(false);
|
||||||
} else {
|
} else {
|
||||||
// Ask the user whether to turn on discovery mode or not
|
// Ask the user whether to turn on discovery mode or not
|
||||||
builder.setMessage(getString(R.string.bluetooth_ask_enablement_and_discovery, mTimeout));
|
// For lasting discoverable mode there is a different message
|
||||||
|
// TODO(): Revisit this when public APIs for discoverable timeout are introduced.
|
||||||
|
if (mTimeout == BluetoothDiscoverableEnabler.DISCOVERABLE_TIMEOUT_NEVER) {
|
||||||
|
builder.setMessage(
|
||||||
|
getString(R.string.bluetooth_ask_enablement_and_lasting_discovery));
|
||||||
|
} else {
|
||||||
|
builder.setMessage(
|
||||||
|
getString(R.string.bluetooth_ask_enablement_and_discovery, mTimeout));
|
||||||
|
}
|
||||||
builder.setPositiveButton(getString(R.string.yes), this);
|
builder.setPositiveButton(getString(R.string.yes), this);
|
||||||
builder.setNegativeButton(getString(R.string.no), this);
|
builder.setNegativeButton(getString(R.string.no), this);
|
||||||
}
|
}
|
||||||
@@ -243,9 +251,14 @@ public class RequestPermissionActivity extends Activity implements
|
|||||||
|
|
||||||
Log.e(TAG, "Timeout = " + mTimeout);
|
Log.e(TAG, "Timeout = " + mTimeout);
|
||||||
|
|
||||||
if (mTimeout > MAX_DISCOVERABLE_TIMEOUT) {
|
// Right now assuming for simplicity that an app can pick any int value,
|
||||||
mTimeout = MAX_DISCOVERABLE_TIMEOUT;
|
// and if equal to BluetoothDiscoverableEnabler.DISCOVERABLE_TIMEOUT_NEVER
|
||||||
} else if (mTimeout <= 0) {
|
// it will be treated as a request for lasting discoverability.
|
||||||
|
// Alternatively, a check can be added here for enforcing the specific allowed values
|
||||||
|
// as listed in BluetoothDiscoverableEnabler.
|
||||||
|
// We need to make all these value public.
|
||||||
|
|
||||||
|
if (mTimeout <= 0) {
|
||||||
mTimeout = BluetoothDiscoverableEnabler.DEFAULT_DISCOVERABLE_TIMEOUT;
|
mTimeout = BluetoothDiscoverableEnabler.DEFAULT_DISCOVERABLE_TIMEOUT;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@@ -75,7 +75,11 @@ public class RequestPermissionHelperActivity extends AlertActivity implements
|
|||||||
if (mEnableOnly) {
|
if (mEnableOnly) {
|
||||||
tv.setText(getString(R.string.bluetooth_ask_enablement));
|
tv.setText(getString(R.string.bluetooth_ask_enablement));
|
||||||
} else {
|
} else {
|
||||||
tv.setText(getString(R.string.bluetooth_ask_enablement_and_discovery, mTimeout));
|
if (mTimeout == BluetoothDiscoverableEnabler.DISCOVERABLE_TIMEOUT_NEVER) {
|
||||||
|
tv.setText(getString(R.string.bluetooth_ask_enablement_and_lasting_discovery));
|
||||||
|
} else {
|
||||||
|
tv.setText(getString(R.string.bluetooth_ask_enablement_and_discovery, mTimeout));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p.mPositiveButtonText = getString(R.string.yes);
|
p.mPositiveButtonText = getString(R.string.yes);
|
||||||
|
Reference in New Issue
Block a user