• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

packages/apps/Settings


Commit MetaInfo

Revisãoc955d8ee1d2b134f8c41989b545b7b3ed830d058 (tree)
Hora2011-05-28 05:28:41
AutorJaikumar Ganesh <jaikumar@goog...>
CommiterAndroid (Google) Code Review

Mensagem de Log

Merge "Allow users to change the length of BT disoverability. DO NOT MERGE" into gingerbread

Mudança Sumário

Diff

--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -255,6 +255,24 @@
255255 <item>TTLS</item>
256256 </string-array>
257257
258+ <!-- Bluetooth Settings -->
259+
260+ <!-- Discoverable mode timeout options -->
261+ <string-array name="bluetooth_visibility_timeout_entries">
262+ <item>2 Minutes</item>
263+ <item>5 Minutes</item>
264+ <item>1 Hour</item>
265+ <item>Never</item>
266+ </string-array>
267+
268+ <!-- Values for visibility_duration_entries matching constants in BluetoothSettings. Do not translate. -->
269+ <string-array name="bluetooth_visibility_timeout_values" translatable="false">
270+ <item>twomin</item>
271+ <item>fivemin</item>
272+ <item>onehour</item>
273+ <item>never</item>
274+ </string-array>
275+
258276 <!-- Match this with drawable.wifi_signal. --> <skip />
259277 <!-- Wi-Fi settings. The signal strength a Wi-Fi network has. -->
260278 <string-array name="wifi_signal">
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -184,9 +184,14 @@
184184 <string name="bluetooth_visibility">Discoverable</string>
185185 <!-- Bluetooth settings screen, summary after selecting Discoverable check box -->
186186 <string name="bluetooth_is_discoverable">Discoverable for <xliff:g id="discoverable_time_period">%1$s</xliff:g> seconds\u2026</string>
187+ <!-- Bluetooth settings screen, Discoverable checkbox summary text when Discoverable duration is set to "forever" -->
188+ <string name="bluetooth_is_discoverable_always">Discoverable</string>
187189 <!-- Bluetooth settings screen, Discoverable checkbox summary text -->
188190 <string name="bluetooth_not_discoverable">Make device discoverable</string>
189- <!-- Bluetooth settings screen, heading above the list of nearby bluetooth devices -->
191+ <!-- Bluetooth settings screen, option name to pick discoverability timeout duration (a list dialog comes up) -->
192+ <string name="bluetooth_visibility_timeout">Discoverable timeout</string>
193+ <!-- Bluetooth settings screen, Discoverable timout list dialog summary text -->
194+ <string name="bluetooth_visibility_timeout_summary">Set how long device will be discoverable</string>
190195 <!-- Bluetooth settings screen, check box label whether or not to allow
191196 bluetooth voice dialing when lock screen is up-->
192197 <string name="bluetooth_lock_voice_dialing">Lock voice dialing</string>
@@ -194,7 +199,7 @@
194199 <string name="bluetooth_lock_voice_dialing_summary">
195200 Prevent use of the bluetooth dialer when the screen is locked
196201 </string>
197-
202+ <!-- Bluetooth settings screen, heading above the list of nearby bluetooth devices -->
198203 <string name="bluetooth_devices">Bluetooth devices</string>
199204 <!-- Bluetooth settings screen, title for the current bluetooth name setting -->
200205 <string name="bluetooth_device_name">Device name</string>
@@ -243,9 +248,15 @@
243248 <!-- Strings for asking to the user whether to allow an app to enable discovery mode -->
244249 <string name="bluetooth_ask_discovery">"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>
245250
251+ <!-- Strings for asking to the user whether to allow an app to enable lasting discovery mode -->
252+ <string name="bluetooth_ask_lasting_discovery">"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>
253+
246254 <!-- Strings for asking to the user whether to allow an app to enable bluetooth and discovery mode -->
247255 <string name="bluetooth_ask_enablement_and_discovery">"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>
248256
257+ <!-- Strings for asking to the user whether to allow an app to enable bluetooth and discovery mode -->
258+ <string name="bluetooth_ask_enablement_and_lasting_discovery">"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>
259+
249260 <!-- Strings for msg to display to user while bluetooth is turning on -->
250261 <string name="bluetooth_turning_on">"Turning on Bluetooth\u2026"</string>
251262
--- a/res/xml/bluetooth_settings.xml
+++ b/res/xml/bluetooth_settings.xml
@@ -40,6 +40,14 @@
4040 android:summaryOff="@string/bluetooth_not_discoverable"
4141 android:persistent="false" />
4242
43+ <ListPreference
44+ android:key="bt_discoverable_timeout"
45+ android:title="@string/bluetooth_visibility_timeout"
46+ android:dependency="bt_discoverable"
47+ android:summary="@string/bluetooth_visibility_timeout_summary"
48+ android:entries="@array/bluetooth_visibility_timeout_entries"
49+ android:entryValues="@array/bluetooth_visibility_timeout_values" />
50+
4351 <Preference
4452 android:key="bt_scan"
4553 android:dependency="bt_checkbox"
--- a/src/com/android/settings/bluetooth/BluetoothDiscoverableEnabler.java
+++ b/src/com/android/settings/bluetooth/BluetoothDiscoverableEnabler.java
@@ -26,8 +26,11 @@ import android.content.IntentFilter;
2626 import android.content.SharedPreferences;
2727 import android.os.Handler;
2828 import android.os.SystemProperties;
29+import android.preference.ListPreference;
2930 import android.preference.Preference;
3031 import android.preference.CheckBoxPreference;
32+import android.provider.Settings;
33+import android.util.Log;
3134
3235 /**
3336 * BluetoothDiscoverableEnabler is a helper to manage the "Discoverable"
@@ -39,14 +42,28 @@ public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChan
3942
4043 private static final String SYSTEM_PROPERTY_DISCOVERABLE_TIMEOUT =
4144 "debug.bt.discoverable_time";
42- /* package */ static final int DEFAULT_DISCOVERABLE_TIMEOUT = 120;
4345
44- /* package */ static final String SHARED_PREFERENCES_KEY_DISCOVERABLE_END_TIMESTAMP =
45- "discoverable_end_timestamp";
46+ static final int DISCOVERABLE_TIMEOUT_TWO_MINUTES = 120;
47+ static final int DISCOVERABLE_TIMEOUT_FIVE_MINUTES = 300;
48+ static final int DISCOVERABLE_TIMEOUT_ONE_HOUR = 3600;
49+ static final int DISCOVERABLE_TIMEOUT_NEVER = 0;
50+
51+ static final String SHARED_PREFERENCES_KEY_DISCOVERABLE_END_TIMESTAMP =
52+ "discoverable_end_timestamp";
53+
54+ private static final String VALUE_DISCOVERABLE_TIMEOUT_TWO_MINUTES = "twomin";
55+ private static final String VALUE_DISCOVERABLE_TIMEOUT_FIVE_MINUTES = "fivemin";
56+ private static final String VALUE_DISCOVERABLE_TIMEOUT_ONE_HOUR = "onehour";
57+ private static final String VALUE_DISCOVERABLE_TIMEOUT_NEVER = "never";
58+
59+ // no need for this timeout anymore since we have the listPreference default value
60+ // leaving now temporary until requestpermissionactivity is modified..
61+ static final int DEFAULT_DISCOVERABLE_TIMEOUT = DISCOVERABLE_TIMEOUT_TWO_MINUTES;
4662
4763 private final Context mContext;
4864 private final Handler mUiHandler;
4965 private final CheckBoxPreference mCheckBoxPreference;
66+ private final ListPreference mTimeoutListPreference;
5067
5168 private final LocalBluetoothManager mLocalManager;
5269
@@ -69,12 +86,16 @@ public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChan
6986 }
7087 };
7188
72- public BluetoothDiscoverableEnabler(Context context, CheckBoxPreference checkBoxPreference) {
89+ public BluetoothDiscoverableEnabler(Context context,
90+ CheckBoxPreference checkBoxPreference, ListPreference timeoutListPreference) {
7391 mContext = context;
7492 mUiHandler = new Handler();
7593 mCheckBoxPreference = checkBoxPreference;
94+ mTimeoutListPreference = timeoutListPreference;
7695
7796 checkBoxPreference.setPersistent(false);
97+ // we actually want to persist this since can't infer from BT device state
98+ mTimeoutListPreference.setPersistent(true);
7899
79100 mLocalManager = LocalBluetoothManager.getInstance(context);
80101 if (mLocalManager == null) {
@@ -91,7 +112,7 @@ public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChan
91112 IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
92113 mContext.registerReceiver(mReceiver, filter);
93114 mCheckBoxPreference.setOnPreferenceChangeListener(this);
94-
115+ mTimeoutListPreference.setOnPreferenceChangeListener(this);
95116 handleModeChanged(mLocalManager.getBluetoothAdapter().getScanMode());
96117 }
97118
@@ -102,12 +123,18 @@ public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChan
102123
103124 mUiHandler.removeCallbacks(mUpdateCountdownSummaryRunnable);
104125 mCheckBoxPreference.setOnPreferenceChangeListener(null);
126+ mTimeoutListPreference.setOnPreferenceChangeListener(null);
105127 mContext.unregisterReceiver(mReceiver);
106128 }
107129
108130 public boolean onPreferenceChange(Preference preference, Object value) {
109- // Turn on/off BT discoverability
110- setEnabled((Boolean) value);
131+ if (preference == mCheckBoxPreference) {
132+ // Turn on/off BT discoverability
133+ setEnabled((Boolean) value);
134+ } else if (preference == mTimeoutListPreference) {
135+ mTimeoutListPreference.setValue((String) value);
136+ setEnabled(true);
137+ }
111138
112139 return true;
113140 }
@@ -116,26 +143,52 @@ public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChan
116143 BluetoothAdapter manager = mLocalManager.getBluetoothAdapter();
117144
118145 if (enable) {
119-
120146 int timeout = getDiscoverableTimeout();
121147 manager.setDiscoverableTimeout(timeout);
122148
123- mCheckBoxPreference.setSummaryOn(
124- mContext.getResources().getString(R.string.bluetooth_is_discoverable, timeout));
125-
126- long endTimestamp = System.currentTimeMillis() + timeout * 1000;
149+ long endTimestamp = System.currentTimeMillis() + timeout * 1000L;
127150 persistDiscoverableEndTimestamp(endTimestamp);
128151
129- manager.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
152+ updateCountdownSummary();
153+
154+ manager.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE, timeout);
130155 } else {
131156 manager.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE);
132157 }
133158 }
134159
160+ private void updateTimerDisplay(int timeout) {
161+ if (getDiscoverableTimeout() == DISCOVERABLE_TIMEOUT_NEVER) {
162+ mCheckBoxPreference.setSummaryOn(
163+ mContext.getResources()
164+ .getString(R.string.bluetooth_is_discoverable_always));
165+ } else {
166+ mCheckBoxPreference.setSummaryOn(
167+ mContext.getResources()
168+ .getString(R.string.bluetooth_is_discoverable, timeout));
169+ }
170+ }
171+
135172 private int getDiscoverableTimeout() {
136173 int timeout = SystemProperties.getInt(SYSTEM_PROPERTY_DISCOVERABLE_TIMEOUT, -1);
137- if (timeout <= 0) {
138- timeout = DEFAULT_DISCOVERABLE_TIMEOUT;
174+ if (timeout < 0) {
175+ String timeoutValue = null;
176+ if (mTimeoutListPreference != null && mTimeoutListPreference.getValue() != null) {
177+ timeoutValue = mTimeoutListPreference.getValue().toString();
178+ } else {
179+ mTimeoutListPreference.setValue(VALUE_DISCOVERABLE_TIMEOUT_TWO_MINUTES);
180+ return DISCOVERABLE_TIMEOUT_TWO_MINUTES;
181+ }
182+
183+ if (timeoutValue.equals(VALUE_DISCOVERABLE_TIMEOUT_NEVER)) {
184+ timeout = DISCOVERABLE_TIMEOUT_NEVER;
185+ } else if (timeoutValue.equals(VALUE_DISCOVERABLE_TIMEOUT_ONE_HOUR)) {
186+ timeout = DISCOVERABLE_TIMEOUT_ONE_HOUR;
187+ } else if (timeoutValue.equals(VALUE_DISCOVERABLE_TIMEOUT_FIVE_MINUTES)) {
188+ timeout = DISCOVERABLE_TIMEOUT_FIVE_MINUTES;
189+ } else {
190+ timeout = DISCOVERABLE_TIMEOUT_TWO_MINUTES;
191+ }
139192 }
140193
141194 return timeout;
@@ -151,7 +204,6 @@ public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChan
151204 if (mode == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
152205 mCheckBoxPreference.setChecked(true);
153206 updateCountdownSummary();
154-
155207 } else {
156208 mCheckBoxPreference.setChecked(false);
157209 }
@@ -173,11 +225,8 @@ public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChan
173225 return;
174226 }
175227
176- String formattedTimeLeft = String.valueOf((endTimestamp - currentTimestamp) / 1000);
177-
178- mCheckBoxPreference.setSummaryOn(
179- mContext.getResources().getString(R.string.bluetooth_is_discoverable,
180- formattedTimeLeft));
228+ int timeLeft = (int) ((endTimestamp - currentTimestamp) / 1000L);
229+ updateTimerDisplay(timeLeft);
181230
182231 synchronized (this) {
183232 mUiHandler.removeCallbacks(mUpdateCountdownSummaryRunnable);
--- a/src/com/android/settings/bluetooth/BluetoothSettings.java
+++ b/src/com/android/settings/bluetooth/BluetoothSettings.java
@@ -31,9 +31,13 @@ import android.content.IntentFilter;
3131 import android.os.Bundle;
3232 import android.os.ParcelUuid;
3333 import android.preference.CheckBoxPreference;
34+import android.preference.ListPreference;
3435 import android.preference.Preference;
3536 import android.preference.PreferenceActivity;
3637 import android.preference.PreferenceScreen;
38+import android.preference.PreferenceCategory;
39+import android.preference.PreferenceScreen;
40+import android.text.TextUtils;
3741 import android.view.ContextMenu;
3842 import android.view.MenuItem;
3943 import android.view.View;
@@ -55,6 +59,7 @@ public class BluetoothSettings extends PreferenceActivity
5559 private static final String KEY_BT_CHECKBOX = "bt_checkbox";
5660 private static final String KEY_BT_DISCOVERABLE = "bt_discoverable";
5761 private static final String KEY_BT_DEVICE_LIST = "bt_device_list";
62+ private static final String KEY_BT_DISCOVERABLE_TIMEOUT = "bt_discoverable_timeout";
5863 private static final String KEY_BT_NAME = "bt_name";
5964 private static final String KEY_BT_SCAN = "bt_scan";
6065
@@ -141,9 +146,9 @@ public class BluetoothSettings extends PreferenceActivity
141146 this,
142147 (CheckBoxPreference) findPreference(KEY_BT_CHECKBOX));
143148
144- mDiscoverableEnabler = new BluetoothDiscoverableEnabler(
145- this,
146- (CheckBoxPreference) findPreference(KEY_BT_DISCOVERABLE));
149+ mDiscoverableEnabler = new BluetoothDiscoverableEnabler(this,
150+ (CheckBoxPreference) findPreference(KEY_BT_DISCOVERABLE),
151+ (ListPreference) findPreference(KEY_BT_DISCOVERABLE_TIMEOUT));
147152
148153 mNamePreference = (BluetoothNamePreference) findPreference(KEY_BT_NAME);
149154
--- a/src/com/android/settings/bluetooth/RequestPermissionActivity.java
+++ b/src/com/android/settings/bluetooth/RequestPermissionActivity.java
@@ -157,7 +157,15 @@ public class RequestPermissionActivity extends Activity implements
157157 builder.setCancelable(false);
158158 } else {
159159 // Ask the user whether to turn on discovery mode or not
160- builder.setMessage(getString(R.string.bluetooth_ask_enablement_and_discovery, mTimeout));
160+ // For lasting discoverable mode there is a different message
161+ // TODO(): Revisit this when public APIs for discoverable timeout are introduced.
162+ if (mTimeout == BluetoothDiscoverableEnabler.DISCOVERABLE_TIMEOUT_NEVER) {
163+ builder.setMessage(
164+ getString(R.string.bluetooth_ask_enablement_and_lasting_discovery));
165+ } else {
166+ builder.setMessage(
167+ getString(R.string.bluetooth_ask_enablement_and_discovery, mTimeout));
168+ }
161169 builder.setPositiveButton(getString(R.string.yes), this);
162170 builder.setNegativeButton(getString(R.string.no), this);
163171 }
@@ -243,9 +251,14 @@ public class RequestPermissionActivity extends Activity implements
243251
244252 Log.e(TAG, "Timeout = " + mTimeout);
245253
246- if (mTimeout > MAX_DISCOVERABLE_TIMEOUT) {
247- mTimeout = MAX_DISCOVERABLE_TIMEOUT;
248- } else if (mTimeout <= 0) {
254+ // Right now assuming for simplicity that an app can pick any int value,
255+ // and if equal to BluetoothDiscoverableEnabler.DISCOVERABLE_TIMEOUT_NEVER
256+ // it will be treated as a request for lasting discoverability.
257+ // Alternatively, a check can be added here for enforcing the specific allowed values
258+ // as listed in BluetoothDiscoverableEnabler.
259+ // We need to make all these value public.
260+
261+ if (mTimeout <= 0) {
249262 mTimeout = BluetoothDiscoverableEnabler.DEFAULT_DISCOVERABLE_TIMEOUT;
250263 }
251264 } else {
--- a/src/com/android/settings/bluetooth/RequestPermissionHelperActivity.java
+++ b/src/com/android/settings/bluetooth/RequestPermissionHelperActivity.java
@@ -75,7 +75,11 @@ public class RequestPermissionHelperActivity extends AlertActivity implements
7575 if (mEnableOnly) {
7676 tv.setText(getString(R.string.bluetooth_ask_enablement));
7777 } else {
78- tv.setText(getString(R.string.bluetooth_ask_enablement_and_discovery, mTimeout));
78+ if (mTimeout == BluetoothDiscoverableEnabler.DISCOVERABLE_TIMEOUT_NEVER) {
79+ tv.setText(getString(R.string.bluetooth_ask_enablement_and_lasting_discovery));
80+ } else {
81+ tv.setText(getString(R.string.bluetooth_ask_enablement_and_discovery, mTimeout));
82+ }
7983 }
8084
8185 p.mPositiveButtonText = getString(R.string.yes);