diff options
52 files changed, 665 insertions, 393 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 1500d8b..2565914 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -15,6 +15,7 @@ <uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> <uses-permission android:name="android.permission.MASTER_CLEAR" /> + <uses-permission android:name="android.permission.USE_CREDENTIALS" /> <uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH" /> <uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER" /> <uses-permission android:name="android.permission.READ_CONTACTS" /> @@ -424,7 +425,7 @@ <activity android:name=".bluetooth.ConnectSpecificProfilesActivity" android:label="@string/bluetooth_connect_specific_profiles_title" /> - <activity android:name=".bluetooth.BluetoothPinDialog" + <activity android:name=".bluetooth.BluetoothPairingDialog" android:label="@string/bluetooth_pin_entry" android:theme="@*android:style/Theme.Dialog.Alert"> <intent-filter> @@ -433,7 +434,7 @@ </intent-filter> </activity> - <receiver android:name=".bluetooth.BluetoothPinRequest"> + <receiver android:name=".bluetooth.BluetoothPairingRequest"> <intent-filter> <action android:name="android.bluetooth.intent.action.PAIRING_REQUEST" /> <action android:name="android.bluetooth.intent.action.PAIRING_CANCEL" /> diff --git a/res/drawable/ic_settings_about.png b/res/drawable/ic_settings_about.png Binary files differnew file mode 100755 index 0000000..16db056 --- /dev/null +++ b/res/drawable/ic_settings_about.png diff --git a/res/drawable/ic_settings_accessibility.png b/res/drawable/ic_settings_accessibility.png Binary files differnew file mode 100755 index 0000000..16db056 --- /dev/null +++ b/res/drawable/ic_settings_accessibility.png diff --git a/res/drawable/ic_settings_applications.png b/res/drawable/ic_settings_applications.png Binary files differnew file mode 100755 index 0000000..16db056 --- /dev/null +++ b/res/drawable/ic_settings_applications.png diff --git a/res/drawable/ic_settings_call.png b/res/drawable/ic_settings_call.png Binary files differnew file mode 100755 index 0000000..16db056 --- /dev/null +++ b/res/drawable/ic_settings_call.png diff --git a/res/drawable/ic_settings_date_time.png b/res/drawable/ic_settings_date_time.png Binary files differnew file mode 100755 index 0000000..16db056 --- /dev/null +++ b/res/drawable/ic_settings_date_time.png diff --git a/res/drawable/ic_settings_language.png b/res/drawable/ic_settings_language.png Binary files differnew file mode 100755 index 0000000..16db056 --- /dev/null +++ b/res/drawable/ic_settings_language.png diff --git a/res/drawable/ic_settings_search.png b/res/drawable/ic_settings_search.png Binary files differnew file mode 100755 index 0000000..16db056 --- /dev/null +++ b/res/drawable/ic_settings_search.png diff --git a/res/drawable/ic_settings_security.png b/res/drawable/ic_settings_security.png Binary files differnew file mode 100755 index 0000000..16db056 --- /dev/null +++ b/res/drawable/ic_settings_security.png diff --git a/res/drawable/ic_settings_sound_display.png b/res/drawable/ic_settings_sound_display.png Binary files differnew file mode 100755 index 0000000..16db056 --- /dev/null +++ b/res/drawable/ic_settings_sound_display.png diff --git a/res/drawable/ic_settings_speech.png b/res/drawable/ic_settings_speech.png Binary files differnew file mode 100755 index 0000000..16db056 --- /dev/null +++ b/res/drawable/ic_settings_speech.png diff --git a/res/drawable/ic_settings_storage.png b/res/drawable/ic_settings_storage.png Binary files differnew file mode 100755 index 0000000..16db056 --- /dev/null +++ b/res/drawable/ic_settings_storage.png diff --git a/res/drawable/ic_settings_sync.png b/res/drawable/ic_settings_sync.png Binary files differnew file mode 100755 index 0000000..16db056 --- /dev/null +++ b/res/drawable/ic_settings_sync.png diff --git a/res/drawable/ic_settings_wireless.png b/res/drawable/ic_settings_wireless.png Binary files differnew file mode 100755 index 0000000..16db056 --- /dev/null +++ b/res/drawable/ic_settings_wireless.png diff --git a/res/layout/preference_icon.xml b/res/layout/preference_icon.xml new file mode 100644 index 0000000..d6bce0e --- /dev/null +++ b/res/layout/preference_icon.xml @@ -0,0 +1,63 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2006 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. +--> + +<!-- Layout for a Preference in a PreferenceActivity. The + Preference is able to place a specific widget for its particular + type in the "widget_frame" layout. --> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+android:id/widget_frame" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:minHeight="?android:attr/listPreferredItemHeight" + android:gravity="center_vertical" + android:paddingRight="?android:attr/scrollbarSize"> + + <ImageView + android:id="@+id/icon" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginLeft="12dip" + android:layout_marginRight="6dip" + android:layout_gravity="center" /> + + <RelativeLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginLeft="6dip" + android:layout_marginRight="6dip" + android:layout_marginTop="6dip" + android:layout_marginBottom="6dip" + android:layout_weight="1"> + + <TextView android:id="@+android:id/title" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:singleLine="true" + android:textAppearance="?android:attr/textAppearanceLarge" + android:ellipsize="marquee" + android:fadingEdge="horizontal" /> + + <TextView android:id="@+android:id/summary" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@android:id/title" + android:layout_alignLeft="@android:id/title" + android:textAppearance="?android:attr/textAppearanceSmall" + android:maxLines="2" /> + + </RelativeLayout> + +</LinearLayout> diff --git a/res/values/attrs.xml b/res/values/attrs.xml index 9bf79f9..0a2c5c5 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -18,4 +18,7 @@ <declare-styleable name="WifiEncryptionState"> <attr name="state_encrypted" format="boolean" /> </declare-styleable> + <declare-styleable name="IconPreferenceScreen"> + <attr name="icon" format="reference" /> + </declare-styleable> </resources> diff --git a/res/values/strings.xml b/res/values/strings.xml index 3091f7a..5a72057 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -489,6 +489,8 @@ <string name="security_settings_title">Security & location</string> <!-- Main Settings screen setting option summary text for the item tot ake you to the security and location screen --> <string name="security_settings_summary">Set My Location, screen unlock, SIM card lock, credential storage lock</string> + <!-- Main Settings screen setting option summary text for the item to take you to the CDMA security and location screen --> + <string name="cdma_security_settings_summary">Set My Location, screen unlock, credential storage lock</string> <!-- In the security screen, the header title for settings related to Passwords--> <string name="security_passwords_title">Passwords</string> @@ -508,15 +510,24 @@ <string name="bluetooth_pin_entry">Bluetooth pairing request</string> <!-- Title for the bluetooth device info screen. --> <string name="bluetooth_device_info">Bluetooth device info</string> - <!-- Message when bluetooth dialog for pin entry is shwoing --> + <!-- Message when bluetooth dialog for pin entry is showing --> <string name="bluetooth_enter_pin_msg"><xliff:g id="device_name">%1$s</xliff:g>\n\nType PIN to pair.\n(Try 0000 or 1234.)</string> + <!-- Message when bluetooth dialog for passkey entry is showing --> + <string name="bluetooth_enter_passkey_msg"><xliff:g id="device_name">%1$s</xliff:g>\n\nType passkey to pair.\n</string> + <!-- Message when bluetooth dialog for confirmation of passkey is showing --> + <string name="bluetooth_confirm_passkey_msg">To pair with \u0022<xliff:g id="device_name">%1$s</xliff:g>\u0022, confirm that it is showing the passkey: <xliff:g id="passkey">%2$d</xliff:g>.</string> + <!-- Button text for accepting an incoming pairing request --> + <string name="bluetooth_pairing_accept">Pair</string> + <!-- Button text for declining an incoming pairing request --> + <string name="bluetooth_pairing_decline">Don\u0027t Pair</string> <!-- Title for BT error dialogs. --> <string name="bluetooth_error_title">Attention</string> <!-- Message for the error dialog when BT pairing fails generically. --> <string name="bluetooth_pairing_error_message">There was a problem pairing with <xliff:g id="device_name">%1$s</xliff:g>.</string> - <!-- Message for the error dialog when BT pairing fails because the PIN entered is incorrect. --> - <string name="bluetooth_pairing_pin_error_message">There was a problem pairing with <xliff:g id="device_name">%1$s</xliff:g> because the typed PIN is incorrect.</string> + <!-- Message for the error dialog when BT pairing fails because the PIN / + Passkey entered is incorrect. --> + <string name="bluetooth_pairing_pin_error_message">There was a problem pairing with <xliff:g id="device_name">%1$s</xliff:g> because the typed PIN or Passkey is incorrect.</string> <!-- Message for the error dialog when BT pairing fails because the other device is down. --> <string name="bluetooth_pairing_device_down_error_message">Cannot establish communication with <xliff:g id="device_name">%1$s</xliff:g>.</string> <!-- Message for the error dialog when BT pairing fails because the other device rejected the pairing. --> @@ -856,10 +867,10 @@ <!-- Sound settings screen, setting option summary text when check box is clear --> <string name="play_media_notification_sounds_enable_summary_off">Play sound for SD card notifications</string> - <!-- Main Settings screen setting option name to go into the screen for data sync settings--> - <string name="sync_settings">Data synchronization</string> + <!-- Acounts & Sync settings screen setting option name to go into the screen for data sync settings--> + <string name="sync_settings">Accounts & synchronization</string> <!-- Main Settings screen setting option summary text for the itme to go into the screen with data sync settings--> - <string name="sync_settings_summary">Select which applications are synchronized</string> + <string name="sync_settings_summary">Add or remove accounts and change account settings</string> <!-- Main Settings screen, setting option name to go into search settings --> <string name="search_settings">Search</string> @@ -1142,6 +1153,12 @@ <string name="location_street_level">When locating, accurate to street level (deselect to conserve battery)</string> <!-- Security & location settings screen, setting summary when Enable GPS satellites check box is clear --> <string name="location_gps_disabled">Locate to street-level (requires more battery plus view of sky)</string> + <!-- Security & location settings screen, setting check box label if Assisted GPS should be enabled --> + <string name="assisted_gps">Enable assisted GPS</string> + <!-- Security & location settings screen, setting summary when Assisted GPS check box is selected --> + <string name="assisted_gps_enabled">Use server to assist GPS (deselect to reduce network usage)</string> + <!-- Security & location settings screen, setting summary when Assisted GPS check box is clear --> + <string name="assisted_gps_disabled">Use server to assist GPS (select to improve GPS performance)</string> <!-- Setting title for allow sending location to google --> <string name="use_location_title">Share with Google</string> <!-- Title of dialog to user requesting use of location information to improve services --> @@ -1372,7 +1389,7 @@ found in the list of installed applications.</string> <string name="computing_size">Computing\u2026</string> <string name="invalid_size_value">Unable to compute package size</string> <!-- String displayed when list is empty --> - <string name="empty_list_msg">You do not have any third-party apps installed.</string> + <string name="empty_list_msg">You do not have any third-party applications installed.</string> <!-- Manage applications, version string displayed in app snippet --> <string name="version_text">version <xliff:g id="version_num">%1$s</xliff:g></string> @@ -1811,6 +1828,8 @@ found in the list of installed applications.</string> <!-- Power Control Widget --> <string name="gadget_title">Power Control</string> + <string name="gadget_toggle_wifi">Updating Wi-Fi setting</string> + <string name="gadget_toggle_bluetooth">Updating Bluetooth setting</string> <string name="vpn_settings_activity_title">VPN settings</string> diff --git a/res/xml/security_settings.xml b/res/xml/security_settings.xml index 8dd9d89..5b90dba 100644 --- a/res/xml/security_settings.xml +++ b/res/xml/security_settings.xml @@ -33,6 +33,12 @@ android:summaryOff="@string/location_gps_disabled"/> <CheckBoxPreference + android:key="assisted_gps" + android:title="@string/assisted_gps" + android:summaryOn="@string/assisted_gps_enabled" + android:summaryOff="@string/assisted_gps_disabled"/> + + <CheckBoxPreference android:key="use_location" android:title="@string/use_location_title" android:persistent="false" diff --git a/res/xml/settings.xml b/res/xml/settings.xml index 9ca581a..b7b5fb8 100644 --- a/res/xml/settings.xml +++ b/res/xml/settings.xml @@ -16,64 +16,72 @@ <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:settings="http://schemas.android.com/apk/res/com.android.settings" android:title="@string/settings_label" android:key="parent"> - - <PreferenceScreen + + <com.android.settings.IconPreferenceScreen android:title="@string/radio_controls_title" + settings:icon="@drawable/ic_settings_wireless" android:summary="@string/radio_controls_summary"> <intent android:action="android.intent.action.MAIN" android:targetPackage="com.android.settings" android:targetClass="com.android.settings.WirelessSettings" /> - </PreferenceScreen> + </com.android.settings.IconPreferenceScreen> - <PreferenceScreen + <com.android.settings.IconPreferenceScreen android:key="call_settings" + settings:icon="@drawable/ic_settings_call" android:title="@string/call_settings_title" android:summary="@string/call_settings_summary"> <intent android:action="android.intent.action.MAIN" android:targetPackage="com.android.phone" android:targetClass="com.android.phone.CallFeaturesSetting" /> - </PreferenceScreen> + </com.android.settings.IconPreferenceScreen> <!-- Sound and Display --> - - <PreferenceScreen + + <com.android.settings.IconPreferenceScreen + settings:icon="@drawable/ic_settings_sound_display" android:title="@string/sound_and_display_settings" android:summary="@string/sound_and_display_settings_summary"> <intent android:action="android.intent.action.MAIN" android:targetPackage="com.android.settings" android:targetClass="com.android.settings.SoundAndDisplaySettings" /> - </PreferenceScreen> + </com.android.settings.IconPreferenceScreen> <!-- Data Sync. The settings activity will ensure this is resolved to an activity on the system image, otherwise it will remove this preference. --> - - <PreferenceScreen + + <com.android.settings.IconPreferenceScreen + settings:icon="@drawable/ic_settings_sync" android:title="@string/sync_settings" android:summary="@string/sync_settings_summary" android:key="sync_settings"> <intent android:action="android.settings.SYNC_SETTINGS" /> - </PreferenceScreen> + </com.android.settings.IconPreferenceScreen> <!-- Security & Privacy --> - - <PreferenceScreen + + <com.android.settings.IconPreferenceScreen + settings:icon="@drawable/ic_settings_security" android:title="@string/security_settings_title" - android:summary="@string/security_settings_summary"> + android:summary="@string/security_settings_summary" + android:key="security_settings"> <intent android:action="android.intent.action.MAIN" android:targetPackage="com.android.settings" android:targetClass="com.android.settings.SecuritySettings" /> - </PreferenceScreen> + </com.android.settings.IconPreferenceScreen> <!-- Application Settings --> - - <PreferenceScreen + + <com.android.settings.IconPreferenceScreen + settings:icon="@drawable/ic_settings_applications" android:title="@string/applications_settings" android:summary="@string/applications_settings_summary" android:key="applications_settings"> @@ -81,39 +89,42 @@ android:action="android.intent.action.MAIN" android:targetPackage="com.android.settings" android:targetClass="com.android.settings.ApplicationSettings" /> - </PreferenceScreen> + </com.android.settings.IconPreferenceScreen> <!-- Storage --> - - <PreferenceScreen + + <com.android.settings.IconPreferenceScreen + settings:icon="@drawable/ic_settings_storage" android:title="@string/storage_settings_title" android:summary="@string/storage_settings_summary"> <intent android:action="android.intent.action.MAIN" android:targetPackage="com.android.settings" android:targetClass="com.android.settings.deviceinfo.Memory" /> - </PreferenceScreen> + </com.android.settings.IconPreferenceScreen> <!-- Date & Time --> - - <PreferenceScreen + + <com.android.settings.IconPreferenceScreen + settings:icon="@drawable/ic_settings_date_time" android:title="@string/date_and_time_settings_title" android:summary="@string/date_and_time_settings_summary"> <intent android:action="android.intent.action.MAIN" android:targetPackage="com.android.settings" android:targetClass="com.android.settings.DateTimeSettings" /> - </PreferenceScreen> + </com.android.settings.IconPreferenceScreen> <!-- Language --> - <PreferenceScreen + <com.android.settings.IconPreferenceScreen + settings:icon="@drawable/ic_settings_language" android:title="@string/language_settings" android:summary="@string/language_settings_summary"> <intent android:action="android.intent.action.MAIN" android:targetPackage="com.android.settings" android:targetClass="com.android.settings.LanguageSettings" /> - </PreferenceScreen> + </com.android.settings.IconPreferenceScreen> <!-- Search. The settings activity will ensure that this is resolved to an @@ -123,44 +134,48 @@ android.app.SearchManager.INTENT_ACTION_SEARCH_SETTINGS. --> - <PreferenceScreen + <com.android.settings.IconPreferenceScreen + settings:icon="@drawable/ic_settings_search" android:title="@string/search_settings" android:summary="@string/search_settings_summary" android:key="search_settings"> <intent android:action="android.search.action.SEARCH_SETTINGS" /> - </PreferenceScreen> + </com.android.settings.IconPreferenceScreen> <!-- Accessibility feedback --> - <PreferenceScreen + <com.android.settings.IconPreferenceScreen + settings:icon="@drawable/ic_settings_accessibility" android:title="@string/accessibility_settings_title" android:summary="@string/accessibility_settings_summary"> <intent android:action="android.intent.action.MAIN" android:targetPackage="com.android.settings" android:targetClass="com.android.settings.AccessibilitySettings" /> - </PreferenceScreen> + </com.android.settings.IconPreferenceScreen> <!-- Text-To-Speech --> - - <PreferenceScreen + + <com.android.settings.IconPreferenceScreen + settings:icon="@drawable/ic_settings_speech" android:title="@string/tts_settings" android:summary="@string/tts_settings_summary"> <intent android:action="android.intent.action.MAIN" android:targetPackage="com.android.settings" android:targetClass="com.android.settings.TextToSpeechSettings" /> - </PreferenceScreen> + </com.android.settings.IconPreferenceScreen> <!-- About Device --> - - <PreferenceScreen + + <com.android.settings.IconPreferenceScreen + settings:icon="@drawable/ic_settings_about" android:title="@string/about_settings" android:summary="@string/about_settings_summary"> <intent android:action="android.intent.action.MAIN" android:targetPackage="com.android.settings" android:targetClass="com.android.settings.DeviceInfoSettings" /> - </PreferenceScreen> + </com.android.settings.IconPreferenceScreen> </PreferenceScreen> diff --git a/res/xml/wireless_settings.xml b/res/xml/wireless_settings.xml index 4731fb3..de62687 100644 --- a/res/xml/wireless_settings.xml +++ b/res/xml/wireless_settings.xml @@ -22,13 +22,12 @@ android:key="toggle_wifi" android:title="@string/wifi_quick_toggle_title" android:summary="@string/wifi_quick_toggle_summary" - android:persistent="false" - android:dependency="toggle_airplane" /> + android:persistent="false" /> <PreferenceScreen + android:key="wifi_settings" android:title="@string/wifi_settings" - android:summary="@string/wifi_settings_summary" - android:dependency="toggle_airplane"> + android:summary="@string/wifi_settings_summary" > <intent android:action="android.intent.action.MAIN" android:targetPackage="com.android.settings" @@ -53,9 +52,9 @@ </PreferenceScreen> <PreferenceScreen + android:key="vpn_settings" android:title="@string/vpn_settings_title" - android:summary="@string/vpn_settings_summary" - android:dependency="toggle_airplane"> + android:summary="@string/vpn_settings_summary" > <intent android:action="android.intent.action.MAIN" android:targetPackage="com.android.settings" diff --git a/src/com/android/settings/AirplaneModeEnabler.java b/src/com/android/settings/AirplaneModeEnabler.java index f105712..45411b2 100644 --- a/src/com/android/settings/AirplaneModeEnabler.java +++ b/src/com/android/settings/AirplaneModeEnabler.java @@ -74,7 +74,7 @@ public class AirplaneModeEnabler implements Preference.OnPreferenceChangeListene mCheckBoxPref.setOnPreferenceChangeListener(null); } - static boolean isAirplaneModeOn(Context context) { + public static boolean isAirplaneModeOn(Context context) { return Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) != 0; } diff --git a/src/com/android/settings/ApnPreference.java b/src/com/android/settings/ApnPreference.java index 74fb902..710eda2 100644 --- a/src/com/android/settings/ApnPreference.java +++ b/src/com/android/settings/ApnPreference.java @@ -107,7 +107,7 @@ public class ApnPreference extends Preference implements return getKey().equals(mSelectedKey); } - public void setChecked(boolean checked) { + public void setChecked() { mSelectedKey = getKey(); } diff --git a/src/com/android/settings/ApnSettings.java b/src/com/android/settings/ApnSettings.java index 2624990..00ef3a7 100644 --- a/src/com/android/settings/ApnSettings.java +++ b/src/com/android/settings/ApnSettings.java @@ -178,7 +178,7 @@ public class ApnSettings extends PreferenceActivity implements pref.setSelectable(selectable); if (selectable) { if ((mSelectedKey != null) && mSelectedKey.equals(key)) { - pref.setChecked(true); + pref.setChecked(); } apnList.addPreference(pref); } else { diff --git a/src/com/android/settings/BandMode.java b/src/com/android/settings/BandMode.java index 1297cad..a8c7833 100644 --- a/src/com/android/settings/BandMode.java +++ b/src/com/android/settings/BandMode.java @@ -97,7 +97,7 @@ public class BandMode extends Activity { } }; - private class BandListItem { + static private class BandListItem { private int mBandMode = Phone.BM_UNSPECIFIED; public BandListItem(int bm) { diff --git a/src/com/android/settings/BatteryInfo.java b/src/com/android/settings/BatteryInfo.java index eb7ddb4..4c25570 100644 --- a/src/com/android/settings/BatteryInfo.java +++ b/src/com/android/settings/BatteryInfo.java @@ -67,7 +67,7 @@ public class BatteryInfo extends Activity { */ private final String tenthsToFixedString(int x) { int tens = x / 10; - return new String("" + tens + "." + (x - 10*tens)); + return Integer.toString(tens) + "." + (x - 10 * tens); } /** diff --git a/src/com/android/settings/IconPreferenceScreen.java b/src/com/android/settings/IconPreferenceScreen.java new file mode 100644 index 0000000..c7c5303 --- /dev/null +++ b/src/com/android/settings/IconPreferenceScreen.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2009 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; + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.drawable.Drawable; +import android.preference.Preference; +import android.util.AttributeSet; +import android.view.View; +import android.widget.ImageView; + +public class IconPreferenceScreen extends Preference { + + private Drawable mIcon; + + public IconPreferenceScreen(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public IconPreferenceScreen(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + setLayoutResource(R.layout.preference_icon); + TypedArray a = context.obtainStyledAttributes(attrs, + R.styleable.IconPreferenceScreen, defStyle, 0); + mIcon = a.getDrawable(R.styleable.IconPreferenceScreen_icon); + } + + @Override + public void onBindView(View view) { + super.onBindView(view); + ImageView imageView = (ImageView) view.findViewById(R.id.icon); + if (imageView != null && mIcon != null) { + imageView.setImageDrawable(mIcon); + } + } +} diff --git a/src/com/android/settings/LanguageSettings.java b/src/com/android/settings/LanguageSettings.java index cbab390..4b805ed 100644 --- a/src/com/android/settings/LanguageSettings.java +++ b/src/com/android/settings/LanguageSettings.java @@ -54,8 +54,6 @@ public class LanguageSettings extends PreferenceActivity { private String mLastInputMethodId; private String mLastTickedInputMethodId; - private String mRootDirectory; - static public String getInputMethodIdFromKey(String key) { return key; } diff --git a/src/com/android/settings/ManageApplications.java b/src/com/android/settings/ManageApplications.java index 0d4895e..d352544 100644 --- a/src/com/android/settings/ManageApplications.java +++ b/src/com/android/settings/ManageApplications.java @@ -760,7 +760,7 @@ public class ManageApplications extends ListActivity implements // internal structure used to track added and deleted packages when // the activity has focus - class AddRemoveInfo { + static class AddRemoveInfo { String pkgName; boolean add; public AddRemoveInfo(String pPkgName, boolean pAdd) { diff --git a/src/com/android/settings/RadioInfo.java b/src/com/android/settings/RadioInfo.java index 257122b..27d8c7e 100644 --- a/src/com/android/settings/RadioInfo.java +++ b/src/com/android/settings/RadioInfo.java @@ -256,21 +256,21 @@ public class RadioInfo extends Activity { } }; - private class OemCommands { + static private class OemCommands { - public final int OEM_QXDM_SDLOG_DEFAULT_FILE_SIZE = 32; - public final int OEM_QXDM_SDLOG_DEFAULT_MASK = 0; - public final int OEM_QXDM_SDLOG_DEFAULT_MAX_INDEX = 8; + public static final int OEM_QXDM_SDLOG_DEFAULT_FILE_SIZE = 32; + public static final int OEM_QXDM_SDLOG_DEFAULT_MASK = 0; + public static final int OEM_QXDM_SDLOG_DEFAULT_MAX_INDEX = 8; - final int SIZE_OF_INT = 4; - final int OEM_FEATURE_ENABLE = 1; - final int OEM_FEATURE_DISABLE = 0; - final int OEM_SIMPE_FEAUTURE_LEN = 1; + static final int SIZE_OF_INT = 4; + static final int OEM_FEATURE_ENABLE = 1; + static final int OEM_FEATURE_DISABLE = 0; + static final int OEM_SIMPE_FEAUTURE_LEN = 1; - final int OEM_QXDM_SDLOG_FUNCTAG = 0x00010000; - final int OEM_QXDM_SDLOG_LEN = 4; - final int OEM_PS_AUTO_ATTACH_FUNCTAG = 0x00020000; - final int OEM_CIPHERING_FUNCTAG = 0x00020001; + static final int OEM_QXDM_SDLOG_FUNCTAG = 0x00010000; + static final int OEM_QXDM_SDLOG_LEN = 4; + static final int OEM_PS_AUTO_ATTACH_FUNCTAG = 0x00020000; + static final int OEM_CIPHERING_FUNCTAG = 0x00020001; /** * The OEM interface to store QXDM to SD. @@ -958,8 +958,7 @@ public class RadioInfo extends Activity { private void displayQxdmEnableResult() { String status = mQxdmLogEnabled ? "Start QXDM Log" : "Stop QXDM Log"; - DialogInterface mProgressPanel = new AlertDialog. - Builder(this).setMessage(status).show(); + new AlertDialog.Builder(this).setMessage(status).show(); mHandler.postDelayed( new Runnable() { diff --git a/src/com/android/settings/SdCardSettings.java b/src/com/android/settings/SdCardSettings.java index 637babe..67f3550 100644 --- a/src/com/android/settings/SdCardSettings.java +++ b/src/com/android/settings/SdCardSettings.java @@ -108,48 +108,41 @@ public class SdCardSettings extends Activity } catch (RemoteException ex) { } - String scanVolume = null; // this no longer exists: SystemProperties.get(MediaScanner.CURRENT_VOLUME_PROPERTY, ""); - boolean scanning = "external".equals(scanVolume); - - if (scanning) { - setLayout(mScanningLayout); - } else { - String status = Environment.getExternalStorageState(); - boolean readOnly = false; - - if (status.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) { - status = Environment.MEDIA_MOUNTED; - readOnly = true; - } + String status = Environment.getExternalStorageState(); + boolean readOnly = false; + + if (status.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) { + status = Environment.MEDIA_MOUNTED; + readOnly = true; + } - if (status.equals(Environment.MEDIA_MOUNTED)) { - try { - File path = Environment.getExternalStorageDirectory(); - StatFs stat = new StatFs(path.getPath()); - long blockSize = stat.getBlockSize(); - long totalBlocks = stat.getBlockCount(); - long availableBlocks = stat.getAvailableBlocks(); - - mTotalSize.setText(formatSize(totalBlocks * blockSize)); - mUsedSize.setText(formatSize((totalBlocks - availableBlocks) * blockSize)); - mAvailableSize.setText(formatSize(availableBlocks * blockSize)); - } catch (IllegalArgumentException e) { - // this can occur if the SD card is removed, but we haven't received the - // ACTION_MEDIA_REMOVED Intent yet. - status = Environment.MEDIA_REMOVED; - } - - mReadOnlyStatus.setVisibility(readOnly ? View.VISIBLE : View.GONE); - setLayout(mMountedLayout); - } else if (status.equals(Environment.MEDIA_UNMOUNTED)) { - setLayout(mUnmountedLayout); - } else if (status.equals(Environment.MEDIA_REMOVED)) { - setLayout(mRemovedLayout); - } else if (status.equals(Environment.MEDIA_SHARED)) { - setLayout(mSharedLayout); - } else if (status.equals(Environment.MEDIA_BAD_REMOVAL)) { - setLayout(mBadRemovalLayout); + if (status.equals(Environment.MEDIA_MOUNTED)) { + try { + File path = Environment.getExternalStorageDirectory(); + StatFs stat = new StatFs(path.getPath()); + long blockSize = stat.getBlockSize(); + long totalBlocks = stat.getBlockCount(); + long availableBlocks = stat.getAvailableBlocks(); + + mTotalSize.setText(formatSize(totalBlocks * blockSize)); + mUsedSize.setText(formatSize((totalBlocks - availableBlocks) * blockSize)); + mAvailableSize.setText(formatSize(availableBlocks * blockSize)); + } catch (IllegalArgumentException e) { + // this can occur if the SD card is removed, but we haven't received the + // ACTION_MEDIA_REMOVED Intent yet. + status = Environment.MEDIA_REMOVED; } + + mReadOnlyStatus.setVisibility(readOnly ? View.VISIBLE : View.GONE); + setLayout(mMountedLayout); + } else if (status.equals(Environment.MEDIA_UNMOUNTED)) { + setLayout(mUnmountedLayout); + } else if (status.equals(Environment.MEDIA_REMOVED)) { + setLayout(mRemovedLayout); + } else if (status.equals(Environment.MEDIA_SHARED)) { + setLayout(mSharedLayout); + } else if (status.equals(Environment.MEDIA_BAD_REMOVAL)) { + setLayout(mBadRemovalLayout); } } @@ -191,8 +184,6 @@ public class SdCardSettings extends Activity } }; - - private int mStatus; private IMountService mMountService; private CheckBox mMassStorage; diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java index d9f4952..e181e6e 100644 --- a/src/com/android/settings/SecuritySettings.java +++ b/src/com/android/settings/SecuritySettings.java @@ -80,6 +80,7 @@ public class SecuritySettings extends PreferenceActivity implements private static final String LOCATION_CATEGORY = "location_category"; private static final String LOCATION_NETWORK = "location_network"; private static final String LOCATION_GPS = "location_gps"; + private static final String ASSISTED_GPS = "assisted_gps"; // Credential storage public static final String ACTION_ADD_CREDENTIAL = @@ -110,6 +111,7 @@ public class SecuritySettings extends PreferenceActivity implements private CheckBoxPreference mNetwork; private CheckBoxPreference mGps; + private CheckBoxPreference mAssistedGps; // These provide support for receiving notification when Location Manager settings change. // This is necessary because the Network Location Provider can change settings @@ -132,6 +134,7 @@ public class SecuritySettings extends PreferenceActivity implements mNetwork = (CheckBoxPreference) getPreferenceScreen().findPreference(LOCATION_NETWORK); mGps = (CheckBoxPreference) getPreferenceScreen().findPreference(LOCATION_GPS); + mAssistedGps = (CheckBoxPreference) getPreferenceScreen().findPreference(ASSISTED_GPS); mUseLocation = (CheckBoxPreference) getPreferenceScreen().findPreference(USE_LOCATION); // Vendor specific @@ -299,8 +302,13 @@ public class SecuritySettings extends PreferenceActivity implements Settings.Secure.setLocationProviderEnabled(getContentResolver(), LocationManager.NETWORK_PROVIDER, mNetwork.isChecked()); } else if (preference == mGps) { + boolean enabled = mGps.isChecked(); Settings.Secure.setLocationProviderEnabled(getContentResolver(), - LocationManager.GPS_PROVIDER, mGps.isChecked()); + LocationManager.GPS_PROVIDER, enabled); + mAssistedGps.setEnabled(enabled); + } else if (preference == mAssistedGps) { + Settings.Secure.putInt(getContentResolver(), Settings.Secure.ASSISTED_GPS_ENABLED, + mAssistedGps.isChecked() ? 1 : 0); } else if (preference == mUseLocation) { //normally called on the toggle click if (mUseLocation.isChecked()) { @@ -342,10 +350,14 @@ public class SecuritySettings extends PreferenceActivity implements */ private void updateToggles() { ContentResolver res = getContentResolver(); + boolean gpsEnabled = Settings.Secure.isLocationProviderEnabled( + res, LocationManager.GPS_PROVIDER); mNetwork.setChecked(Settings.Secure.isLocationProviderEnabled( res, LocationManager.NETWORK_PROVIDER)); - mGps.setChecked(Settings.Secure.isLocationProviderEnabled( - res, LocationManager.GPS_PROVIDER)); + mGps.setChecked(gpsEnabled); + mAssistedGps.setChecked(Settings.Secure.getInt(res, + Settings.Secure.ASSISTED_GPS_ENABLED, 2) == 1); + mAssistedGps.setEnabled(gpsEnabled); mUseLocation.setChecked(Settings.Secure.getInt(res, Settings.Secure.USE_LOCATION_FOR_SERVICES, 2) == 1); } diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java index 4f888ff..d44800d 100644 --- a/src/com/android/settings/Settings.java +++ b/src/com/android/settings/Settings.java @@ -20,6 +20,7 @@ import android.os.Bundle; import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; import android.provider.Settings.System; +import android.telephony.TelephonyManager; public class Settings extends PreferenceActivity { @@ -34,6 +35,17 @@ public class Settings extends PreferenceActivity { addPreferencesFromResource(R.xml.settings); + int activePhoneType = TelephonyManager.getDefault().getPhoneType(); + + // do not display SIM lock for CDMA phone + if (TelephonyManager.PHONE_TYPE_CDMA == activePhoneType) { + findPreference("security_settings").setSummary( + R.string.cdma_security_settings_summary); + } else { + findPreference("security_settings").setSummary( + R.string.security_settings_summary); + } + PreferenceGroup parent = (PreferenceGroup) findPreference(KEY_PARENT); Utils.updatePreferenceToSpecificActivityOrRemove(this, parent, KEY_SYNC_SETTINGS, 0); Utils.updatePreferenceToSpecificActivityOrRemove(this, parent, KEY_SEARCH_SETTINGS, 0); diff --git a/src/com/android/settings/UsageStats.java b/src/com/android/settings/UsageStats.java index 89caa54..fcb6990 100755 --- a/src/com/android/settings/UsageStats.java +++ b/src/com/android/settings/UsageStats.java @@ -187,7 +187,7 @@ public class UsageStats extends Activity implements OnItemSelectedListener { holder.launchCount.setText(String.valueOf(pkgStats.launchCount)); holder.usageTime.setText(String.valueOf(pkgStats.usageTime)+" ms"); } else { - Log.w(TAG, "No usage stats info for package:"+pkgStats.packageName); + Log.w(TAG, "No usage stats info for package:" + position); } return convertView; } diff --git a/src/com/android/settings/WirelessSettings.java b/src/com/android/settings/WirelessSettings.java index d112915..f160bac 100644 --- a/src/com/android/settings/WirelessSettings.java +++ b/src/com/android/settings/WirelessSettings.java @@ -21,14 +21,18 @@ import com.android.settings.wifi.WifiEnabler; import android.net.wifi.WifiManager; import android.os.Bundle; -import android.preference.PreferenceActivity; import android.preference.CheckBoxPreference; +import android.preference.Preference; +import android.preference.PreferenceActivity; +import android.provider.Settings; public class WirelessSettings extends PreferenceActivity { private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane"; private static final String KEY_TOGGLE_BLUETOOTH = "toggle_bluetooth"; private static final String KEY_TOGGLE_WIFI = "toggle_wifi"; + private static final String KEY_WIFI_SETTINGS = "wifi_settings"; + private static final String KEY_VPN_SETTINGS = "vpn_settings"; private WifiEnabler mWifiEnabler; private AirplaneModeEnabler mAirplaneModeEnabler; @@ -63,18 +67,27 @@ public class WirelessSettings extends PreferenceActivity { private void initToggles() { + Preference airplanePreference = findPreference(KEY_TOGGLE_AIRPLANE); + Preference wifiPreference = findPreference(KEY_TOGGLE_WIFI); + Preference btPreference = findPreference(KEY_TOGGLE_BLUETOOTH); + Preference wifiSettings = findPreference(KEY_WIFI_SETTINGS); + Preference vpnSettings = findPreference(KEY_VPN_SETTINGS); + mWifiEnabler = new WifiEnabler( - this, - (WifiManager) getSystemService(WIFI_SERVICE), - (CheckBoxPreference) findPreference(KEY_TOGGLE_WIFI)); - + this, (WifiManager) getSystemService(WIFI_SERVICE), + (CheckBoxPreference) wifiPreference); mAirplaneModeEnabler = new AirplaneModeEnabler( - this, - (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE)); - - mBtEnabler = new BluetoothEnabler( - this, - (CheckBoxPreference) findPreference(KEY_TOGGLE_BLUETOOTH)); + this, (CheckBoxPreference) airplanePreference); + mBtEnabler = new BluetoothEnabler(this, (CheckBoxPreference) btPreference); + + // manually set up dependencies for Wifi if its radio is not toggleable in airplane mode + String toggleableRadios = Settings.System.getString(getContentResolver(), + Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS); + if (toggleableRadios == null || !toggleableRadios.contains(Settings.System.RADIO_WIFI)) { + wifiPreference.setDependency(airplanePreference.getKey()); + wifiSettings.setDependency(airplanePreference.getKey()); + vpnSettings.setDependency(airplanePreference.getKey()); + } } - + } diff --git a/src/com/android/settings/ZoneList.java b/src/com/android/settings/ZoneList.java index 2877f00..aaaf989 100644 --- a/src/com/android/settings/ZoneList.java +++ b/src/com/android/settings/ZoneList.java @@ -160,7 +160,7 @@ public class ZoneList extends ListActivity { try { XmlResourceParser xrp = getResources().getXml(R.xml.timezones); while (xrp.next() != XmlResourceParser.START_TAG) - ; + continue; xrp.next(); while (xrp.getEventType() != XmlResourceParser.END_TAG) { while (xrp.getEventType() != XmlResourceParser.START_TAG) { diff --git a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java index 7053ff5..a49ea75 100644 --- a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java +++ b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java @@ -102,11 +102,11 @@ public class BluetoothDevicePreference extends Preference implements LocalBlueto @Override protected void onBindView(View view) { - super.onBindView(view); - // Disable this view if the bluetooth enable/disable preference view is off setDependency("bt_checkbox"); + super.onBindView(view); + ImageView btClass = (ImageView) view.findViewById(R.id.btClass); btClass.setImageResource(mLocalDevice.getBtClassDrawable()); btClass.setAlpha(isEnabled() ? 255 : sDimAlpha); diff --git a/src/com/android/settings/bluetooth/BluetoothDiscoverableEnabler.java b/src/com/android/settings/bluetooth/BluetoothDiscoverableEnabler.java index 58fb569..665fba4 100644 --- a/src/com/android/settings/bluetooth/BluetoothDiscoverableEnabler.java +++ b/src/com/android/settings/bluetooth/BluetoothDiscoverableEnabler.java @@ -38,20 +38,20 @@ import android.preference.CheckBoxPreference; */ public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChangeListener { private static final String TAG = "BluetoothDiscoverableEnabler"; - + private static final String SYSTEM_PROPERTY_DISCOVERABLE_TIMEOUT = "debug.bt.discoverable_time"; - private static final int DISCOVERABLE_TIMEOUT = 120; + private static final int DISCOVERABLE_TIMEOUT = 120; private static final String SHARED_PREFERENCES_KEY_DISCOVERABLE_END_TIMESTAMP = "discoverable_end_timestamp"; - + private final Context mContext; private final Handler mUiHandler; private final CheckBoxPreference mCheckBoxPreference; - + private final LocalBluetoothManager mLocalManager; - + private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -66,17 +66,17 @@ public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChan private final Runnable mUpdateCountdownSummaryRunnable = new Runnable() { public void run() { - updateCountdownSummary(); - } + updateCountdownSummary(); + } }; public BluetoothDiscoverableEnabler(Context context, CheckBoxPreference checkBoxPreference) { mContext = context; mUiHandler = new Handler(); mCheckBoxPreference = checkBoxPreference; - + checkBoxPreference.setPersistent(false); - + mLocalManager = LocalBluetoothManager.getInstance(context); if (mLocalManager == null) { // Bluetooth not supported @@ -92,30 +92,30 @@ public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChan IntentFilter filter = new IntentFilter(BluetoothIntent.SCAN_MODE_CHANGED_ACTION); mContext.registerReceiver(mReceiver, filter); mCheckBoxPreference.setOnPreferenceChangeListener(this); - + handleModeChanged(mLocalManager.getBluetoothManager().getScanMode()); } - + public void pause() { if (mLocalManager == null) { return; } - + mUiHandler.removeCallbacks(mUpdateCountdownSummaryRunnable); mCheckBoxPreference.setOnPreferenceChangeListener(null); mContext.unregisterReceiver(mReceiver); } - + public boolean onPreferenceChange(Preference preference, Object value) { // Turn on/off BT discoverability setEnabled((Boolean) value); - + return true; } - + private void setEnabled(final boolean enable) { BluetoothDevice manager = mLocalManager.getBluetoothManager(); - + if (enable) { int timeout = getDiscoverableTimeout(); @@ -126,7 +126,7 @@ public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChan long endTimestamp = System.currentTimeMillis() + timeout * 1000; persistDiscoverableEndTimestamp(endTimestamp); - + manager.setScanMode(BluetoothDevice.SCAN_MODE_CONNECTABLE_DISCOVERABLE); } else { manager.setScanMode(BluetoothDevice.SCAN_MODE_CONNECTABLE); @@ -138,7 +138,7 @@ public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChan if (timeout <= 0) { timeout = DISCOVERABLE_TIMEOUT; } - + return timeout; } @@ -147,44 +147,44 @@ public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChan editor.putLong(SHARED_PREFERENCES_KEY_DISCOVERABLE_END_TIMESTAMP, endTimestamp); editor.commit(); } - + private void handleModeChanged(int mode) { if (mode == BluetoothDevice.SCAN_MODE_CONNECTABLE_DISCOVERABLE) { mCheckBoxPreference.setChecked(true); updateCountdownSummary(); - + } else { mCheckBoxPreference.setChecked(false); } } - + private void updateCountdownSummary() { int mode = mLocalManager.getBluetoothManager().getScanMode(); if (mode != BluetoothDevice.SCAN_MODE_CONNECTABLE_DISCOVERABLE) { return; } - + long currentTimestamp = System.currentTimeMillis(); long endTimestamp = mLocalManager.getSharedPreferences().getLong( SHARED_PREFERENCES_KEY_DISCOVERABLE_END_TIMESTAMP, 0); - + if (currentTimestamp > endTimestamp) { // We're still in discoverable mode, but maybe there isn't a timeout. mCheckBoxPreference.setSummaryOn(null); return; } - + String formattedTimeLeft = String.valueOf((endTimestamp - currentTimestamp) / 1000); - + mCheckBoxPreference.setSummaryOn( mContext.getResources().getString(R.string.bluetooth_is_discoverable, formattedTimeLeft)); - + synchronized (this) { mUiHandler.removeCallbacks(mUpdateCountdownSummaryRunnable); mUiHandler.postDelayed(mUpdateCountdownSummaryRunnable, 1000); } } - - + + } diff --git a/src/com/android/settings/bluetooth/BluetoothEventRedirector.java b/src/com/android/settings/bluetooth/BluetoothEventRedirector.java index af64c98..4768735 100644 --- a/src/com/android/settings/bluetooth/BluetoothEventRedirector.java +++ b/src/com/android/settings/bluetooth/BluetoothEventRedirector.java @@ -17,6 +17,7 @@ package com.android.settings.bluetooth; import android.bluetooth.BluetoothA2dp; +import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothError; import android.bluetooth.BluetoothHeadset; @@ -37,52 +38,53 @@ import com.android.settings.bluetooth.LocalBluetoothProfileManager.Profile; public class BluetoothEventRedirector { private static final String TAG = "BluetoothEventRedirector"; private static final boolean V = LocalBluetoothManager.V; - + private LocalBluetoothManager mManager; - + private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (V) { Log.v(TAG, "Received " + intent.getAction()); } - + String action = intent.getAction(); String address = intent.getStringExtra(BluetoothIntent.ADDRESS); - + if (action.equals(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION)) { int state = intent.getIntExtra(BluetoothIntent.BLUETOOTH_STATE, BluetoothError.ERROR); mManager.setBluetoothStateInt(state); } else if (action.equals(BluetoothIntent.DISCOVERY_STARTED_ACTION)) { mManager.onScanningStateChanged(true); - + } else if (action.equals(BluetoothIntent.DISCOVERY_COMPLETED_ACTION)) { mManager.onScanningStateChanged(false); - + } else if (action.equals(BluetoothIntent.REMOTE_DEVICE_FOUND_ACTION)) { short rssi = intent.getShortExtra(BluetoothIntent.RSSI, Short.MIN_VALUE); - mManager.getLocalDeviceManager().onDeviceAppeared(address, rssi); - + int btClass = intent.getIntExtra(BluetoothIntent.CLASS, BluetoothClass.ERROR); + String name = intent.getStringExtra(BluetoothIntent.NAME); + mManager.getLocalDeviceManager().onDeviceAppeared(address, rssi, btClass, name); + } else if (action.equals(BluetoothIntent.REMOTE_DEVICE_DISAPPEARED_ACTION)) { mManager.getLocalDeviceManager().onDeviceDisappeared(address); - + } else if (action.equals(BluetoothIntent.REMOTE_NAME_UPDATED_ACTION)) { mManager.getLocalDeviceManager().onDeviceNameUpdated(address); - + } else if (action.equals(BluetoothIntent.BOND_STATE_CHANGED_ACTION)) { int bondState = intent.getIntExtra(BluetoothIntent.BOND_STATE, BluetoothError.ERROR); mManager.getLocalDeviceManager().onBondingStateChanged(address, bondState); if (bondState == BluetoothDevice.BOND_NOT_BONDED) { int reason = intent.getIntExtra(BluetoothIntent.REASON, BluetoothError.ERROR); - if (reason == BluetoothDevice.UNBOND_REASON_AUTH_FAILED || - reason == BluetoothDevice.UNBOND_REASON_AUTH_REJECTED || + if (reason == BluetoothDevice.UNBOND_REASON_AUTH_REJECTED || reason == BluetoothDevice.UNBOND_REASON_REMOTE_DEVICE_DOWN) { mManager.getLocalDeviceManager().onBondingError(address, reason); } } - + } else if (action.equals(BluetoothIntent.HEADSET_STATE_CHANGED_ACTION)) { int newState = intent.getIntExtra(BluetoothIntent.HEADSET_STATE, 0); int oldState = intent.getIntExtra(BluetoothIntent.HEADSET_PREVIOUS_STATE, 0); @@ -107,7 +109,7 @@ public class BluetoothEventRedirector { } else if (action.equals(BluetoothIntent.REMOTE_DEVICE_CLASS_UPDATED_ACTION)) { mManager.getLocalDeviceManager().onBtClassChanged(address); - + } } }; @@ -118,29 +120,29 @@ public class BluetoothEventRedirector { public void start() { IntentFilter filter = new IntentFilter(); - + // Bluetooth on/off broadcasts filter.addAction(BluetoothIntent.BLUETOOTH_STATE_CHANGED_ACTION); - + // Discovery broadcasts filter.addAction(BluetoothIntent.DISCOVERY_STARTED_ACTION); filter.addAction(BluetoothIntent.DISCOVERY_COMPLETED_ACTION); filter.addAction(BluetoothIntent.REMOTE_DEVICE_DISAPPEARED_ACTION); filter.addAction(BluetoothIntent.REMOTE_DEVICE_FOUND_ACTION); filter.addAction(BluetoothIntent.REMOTE_NAME_UPDATED_ACTION); - + // Pairing broadcasts filter.addAction(BluetoothIntent.BOND_STATE_CHANGED_ACTION); - + // Fine-grained state broadcasts filter.addAction(BluetoothA2dp.SINK_STATE_CHANGED_ACTION); filter.addAction(BluetoothIntent.HEADSET_STATE_CHANGED_ACTION); filter.addAction(BluetoothIntent.REMOTE_DEVICE_CLASS_UPDATED_ACTION); - + mManager.getContext().registerReceiver(mBroadcastReceiver, filter); } - + public void stop() { - mManager.getContext().unregisterReceiver(mBroadcastReceiver); + mManager.getContext().unregisterReceiver(mBroadcastReceiver); } } diff --git a/src/com/android/settings/bluetooth/BluetoothPinDialog.java b/src/com/android/settings/bluetooth/BluetoothPairingDialog.java index 087fbb2..04a3722 100644 --- a/src/com/android/settings/bluetooth/BluetoothPinDialog.java +++ b/src/com/android/settings/bluetooth/BluetoothPairingDialog.java @@ -16,6 +16,7 @@ package com.android.settings.bluetooth; +import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothIntent; import android.content.BroadcastReceiver; @@ -26,6 +27,7 @@ import android.content.IntentFilter; import android.os.Bundle; import android.text.Editable; import android.text.InputFilter; +import android.text.InputType; import android.text.TextWatcher; import android.text.InputFilter.LengthFilter; import android.util.Log; @@ -39,36 +41,39 @@ import com.android.internal.app.AlertController; import com.android.settings.R; /** - * BluetoothPinDialog asks the user to enter a PIN for pairing with a remote - * Bluetooth device. It is an activity that appears as a dialog. + * BluetoothPairingDialog asks the user to enter a PIN / Passkey / simple confirmation + * for pairing with a remote Bluetooth device. It is an activity that appears as a dialog. */ -public class BluetoothPinDialog extends AlertActivity implements DialogInterface.OnClickListener, +public class BluetoothPairingDialog extends AlertActivity implements DialogInterface.OnClickListener, TextWatcher { - private static final String TAG = "BluetoothPinDialog"; + private static final String TAG = "BluetoothPairingDialog"; private final int BLUETOOTH_PIN_MAX_LENGTH = 16; + private final int BLUETOOTH_PASSKEY_MAX_LENGTH = 6; private LocalBluetoothManager mLocalManager; private String mAddress; - private EditText mPinView; + private int mType; + private int mConfirmationPasskey; + private EditText mPairingView; private Button mOkButton; private static final String INSTANCE_KEY_PAIRING_CANCELED = "received_pairing_canceled"; private boolean mReceivedPairingCanceled; - + private BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (!BluetoothIntent.PAIRING_CANCEL_ACTION.equals(intent.getAction())) { return; } - + String address = intent.getStringExtra(BluetoothIntent.ADDRESS); if (address == null || address.equals(mAddress)) { onReceivedPairingCanceled(); } } }; - + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -81,11 +86,34 @@ public class BluetoothPinDialog extends AlertActivity implements DialogInterface BluetoothIntent.PAIRING_REQUEST_ACTION); finish(); } - + mLocalManager = LocalBluetoothManager.getInstance(this); mAddress = intent.getStringExtra(BluetoothIntent.ADDRESS); - - // Set up the "dialog" + mType = intent.getIntExtra(BluetoothIntent.PAIRING_VARIANT, BluetoothClass.ERROR); + if (mType == BluetoothDevice.PAIRING_VARIANT_PIN) { + createUserEntryDialog(); + } else if (mType == BluetoothDevice.PAIRING_VARIANT_PASSKEY) { + createUserEntryDialog(); + } else if (mType == BluetoothDevice.PAIRING_VARIANT_CONFIRMATION){ + mConfirmationPasskey = + intent.getIntExtra(BluetoothIntent.PASSKEY, BluetoothClass.ERROR); + if (mConfirmationPasskey == BluetoothClass.ERROR) { + Log.e(TAG, "Invalid ConfirmationPasskey received, not showing any dialog"); + return; + } + createConfirmationDialog(); + } else { + Log.e(TAG, "Incorrect pairing type received, not showing any dialog"); + } + + /* + * Leave this registered through pause/resume since we still want to + * finish the activity in the background if pairing is canceled. + */ + registerReceiver(mReceiver, new IntentFilter(BluetoothIntent.PAIRING_CANCEL_ACTION)); + } + + private void createUserEntryDialog() { final AlertController.AlertParams p = mAlertParams; p.mIconId = android.R.drawable.ic_dialog_info; p.mTitle = getString(R.string.bluetooth_pin_entry); @@ -95,21 +123,54 @@ public class BluetoothPinDialog extends AlertActivity implements DialogInterface p.mNegativeButtonText = getString(android.R.string.cancel); p.mNegativeButtonListener = this; setupAlert(); - + mOkButton = mAlert.getButton(DialogInterface.BUTTON_POSITIVE); mOkButton.setEnabled(false); + } - /* - * Leave this registered through pause/resume since we still want to - * finish the activity in the background if pairing is canceled. - */ - registerReceiver(mReceiver, new IntentFilter(BluetoothIntent.PAIRING_CANCEL_ACTION)); + private View createView() { + View view = getLayoutInflater().inflate(R.layout.bluetooth_pin_entry, null); + + String name = mLocalManager.getLocalDeviceManager().getName(mAddress); + TextView messageView = (TextView) view.findViewById(R.id.message); + mPairingView = (EditText) view.findViewById(R.id.text); + mPairingView.addTextChangedListener(this); + + if (mType == BluetoothDevice.PAIRING_VARIANT_PIN) { + messageView.setText(getString(R.string.bluetooth_enter_pin_msg, name)); + // Maximum of 16 characters in a PIN adb sync + mPairingView.setFilters(new InputFilter[] { + new LengthFilter(BLUETOOTH_PIN_MAX_LENGTH) }); + } else if (mType == BluetoothDevice.PAIRING_VARIANT_PASSKEY){ + messageView.setText(getString(R.string.bluetooth_enter_passkey_msg, name)); + // Maximum of 6 digits for passkey + mPairingView.setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED); + mPairingView.setFilters(new InputFilter[] { + new LengthFilter(BLUETOOTH_PASSKEY_MAX_LENGTH)}); + } else { + mPairingView.setVisibility(View.GONE); + messageView.setText(getString(R.string.bluetooth_confirm_passkey_msg, name, + mConfirmationPasskey)); + } + return view; + } + + private void createConfirmationDialog() { + final AlertController.AlertParams p = mAlertParams; + p.mIconId = android.R.drawable.ic_dialog_info; + p.mTitle = getString(R.string.bluetooth_pin_entry); + p.mView = createView(); + p.mPositiveButtonText = getString(R.string.bluetooth_pairing_accept); + p.mPositiveButtonListener = this; + p.mNegativeButtonText = getString(R.string.bluetooth_pairing_decline); + p.mNegativeButtonListener = this; + setupAlert(); } @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); - + mReceivedPairingCanceled = savedInstanceState.getBoolean(INSTANCE_KEY_PAIRING_CANCELED); if (mReceivedPairingCanceled) { onReceivedPairingCanceled(); @@ -119,30 +180,15 @@ public class BluetoothPinDialog extends AlertActivity implements DialogInterface @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - + outState.putBoolean(INSTANCE_KEY_PAIRING_CANCELED, mReceivedPairingCanceled); } @Override protected void onDestroy() { super.onDestroy(); - - unregisterReceiver(mReceiver); - } - private View createView() { - View view = getLayoutInflater().inflate(R.layout.bluetooth_pin_entry, null); - - String name = mLocalManager.getLocalDeviceManager().getName(mAddress); - TextView messageView = (TextView) view.findViewById(R.id.message); - messageView.setText(getString(R.string.bluetooth_enter_pin_msg, name)); - - mPinView = (EditText) view.findViewById(R.id.text); - mPinView.addTextChangedListener(this); - // Maximum of 16 characters in a PIN - mPinView.setFilters(new InputFilter[] { new LengthFilter(BLUETOOTH_PIN_MAX_LENGTH) }); - - return view; + unregisterReceiver(mReceiver); } public void afterTextChanged(Editable s) { @@ -153,39 +199,50 @@ public class BluetoothPinDialog extends AlertActivity implements DialogInterface private void onReceivedPairingCanceled() { mReceivedPairingCanceled = true; - + TextView messageView = (TextView) findViewById(R.id.message); messageView.setText(getString(R.string.bluetooth_pairing_error_message, mLocalManager.getLocalDeviceManager().getName(mAddress))); - - mPinView.setVisibility(View.GONE); - mPinView.clearFocus(); - mPinView.removeTextChangedListener(this); + mPairingView.setVisibility(View.GONE); + mPairingView.clearFocus(); + mPairingView.removeTextChangedListener(this); + + mOkButton = mAlert.getButton(DialogInterface.BUTTON_POSITIVE); mOkButton.setEnabled(true); + mOkButton.setText(android.R.string.ok); mAlert.getButton(DialogInterface.BUTTON_NEGATIVE).setVisibility(View.GONE); } - - private void onPair(String pin) { - byte[] pinBytes = BluetoothDevice.convertPinToBytes(pin); - - if (pinBytes == null) { - return; + + private void onPair(String value) { + if (mType == BluetoothDevice.PAIRING_VARIANT_PIN) { + byte[] pinBytes = BluetoothDevice.convertPinToBytes(value); + if (pinBytes == null) { + return; + } + mLocalManager.getBluetoothManager().setPin(mAddress, pinBytes); + } else if (mType == BluetoothDevice.PAIRING_VARIANT_PASSKEY) { + int passkey = Integer.getInteger(value); + mLocalManager.getBluetoothManager().setPasskey(mAddress, passkey); + } else { + mLocalManager.getBluetoothManager().setPairingConfirmation(mAddress, true); } - - mLocalManager.getBluetoothManager().setPin(mAddress, pinBytes); } private void onCancel() { - mLocalManager.getBluetoothManager().cancelBondProcess(mAddress); + if (mType == BluetoothDevice.PAIRING_VARIANT_CONFIRMATION) { + mLocalManager.getBluetoothManager().setPairingConfirmation(mAddress, false); + } else { + mLocalManager.getBluetoothManager().cancelBondProcess(mAddress); + } } - + public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: - onPair(mPinView.getText().toString()); + onPair(mPairingView.getText().toString()); break; - + case DialogInterface.BUTTON_NEGATIVE: onCancel(); break; diff --git a/src/com/android/settings/bluetooth/BluetoothPinRequest.java b/src/com/android/settings/bluetooth/BluetoothPairingRequest.java index 619052d..d57628a 100644 --- a/src/com/android/settings/bluetooth/BluetoothPinRequest.java +++ b/src/com/android/settings/bluetooth/BluetoothPairingRequest.java @@ -21,6 +21,7 @@ import com.android.settings.R; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; +import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothIntent; import android.content.BroadcastReceiver; @@ -30,35 +31,41 @@ import android.content.res.Resources; import android.text.TextUtils; /** - * BluetoothPinRequest is a receiver for any Bluetooth pairing PIN request. It - * checks if the Bluetooth Settings is currently visible and brings up the PIN - * entry dialog. Otherwise it puts a Notification in the status bar, which can - * be clicked to bring up the PIN entry dialog. + * BluetoothPairingRequest is a receiver for any Bluetooth pairing request. It + * checks if the Bluetooth Settings is currently visible and brings up the PIN, the passkey or a + * confirmation entry dialog. Otherwise it puts a Notification in the status bar, which can + * be clicked to bring up the Pairing entry dialog. */ -public class BluetoothPinRequest extends BroadcastReceiver { +public class BluetoothPairingRequest extends BroadcastReceiver { public static final int NOTIFICATION_ID = android.R.drawable.stat_sys_data_bluetooth; - + @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(BluetoothIntent.PAIRING_REQUEST_ACTION)) { - LocalBluetoothManager localManager = LocalBluetoothManager.getInstance(context); - + LocalBluetoothManager localManager = LocalBluetoothManager.getInstance(context); + String address = intent.getStringExtra(BluetoothIntent.ADDRESS); - Intent pinIntent = new Intent(); - pinIntent.setClass(context, BluetoothPinDialog.class); - pinIntent.putExtra(BluetoothIntent.ADDRESS, address); - pinIntent.setAction(BluetoothIntent.PAIRING_REQUEST_ACTION); - pinIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - + int type = intent.getIntExtra(BluetoothIntent.PAIRING_VARIANT, BluetoothClass.ERROR); + Intent pairingIntent = new Intent(); + pairingIntent.setClass(context, BluetoothPairingDialog.class); + pairingIntent.putExtra(BluetoothIntent.ADDRESS, address); + pairingIntent.putExtra(BluetoothIntent.PAIRING_VARIANT, type); + if (type == BluetoothDevice.PAIRING_VARIANT_CONFIRMATION) { + int passkey = intent.getIntExtra(BluetoothIntent.PASSKEY, BluetoothClass.ERROR); + pairingIntent.putExtra(BluetoothIntent.PASSKEY, passkey); + } + pairingIntent.setAction(BluetoothIntent.PAIRING_REQUEST_ACTION); + pairingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + if (localManager.getForegroundActivity() != null) { // Since the BT-related activity is in the foreground, just open the dialog - context.startActivity(pinIntent); - + context.startActivity(pairingIntent); + } else { - + // Put up a notification that leads to the dialog Resources res = context.getResources(); Notification notification = new Notification( @@ -66,27 +73,27 @@ public class BluetoothPinRequest extends BroadcastReceiver { res.getString(R.string.bluetooth_notif_ticker), System.currentTimeMillis()); - PendingIntent pending = PendingIntent.getActivity(context, 0, - pinIntent, PendingIntent.FLAG_ONE_SHOT); - + PendingIntent pending = PendingIntent.getActivity(context, 0, + pairingIntent, PendingIntent.FLAG_ONE_SHOT); + String name = intent.getStringExtra(BluetoothIntent.NAME); if (TextUtils.isEmpty(name)) { name = localManager.getLocalDeviceManager().getName(address); } - - notification.setLatestEventInfo(context, - res.getString(R.string.bluetooth_notif_title), - res.getString(R.string.bluetooth_notif_message) + name, + + notification.setLatestEventInfo(context, + res.getString(R.string.bluetooth_notif_title), + res.getString(R.string.bluetooth_notif_message) + name, pending); notification.flags |= Notification.FLAG_AUTO_CANCEL; - - NotificationManager manager = (NotificationManager) + + NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(NOTIFICATION_ID, notification); } - + } else if (action.equals(BluetoothIntent.PAIRING_CANCEL_ACTION)) { - + // Remove the notification NotificationManager manager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); diff --git a/src/com/android/settings/bluetooth/LocalBluetoothDevice.java b/src/com/android/settings/bluetooth/LocalBluetoothDevice.java index 5259d7b..cb2973f 100644 --- a/src/com/android/settings/bluetooth/LocalBluetoothDevice.java +++ b/src/com/android/settings/bluetooth/LocalBluetoothDevice.java @@ -82,7 +82,7 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> { CONNECT, DISCONNECT, } - class BluetoothJob { + static class BluetoothJob { final BluetoothCommand command; // CONNECT, DISCONNECT final LocalBluetoothDevice device; final Profile profile; // HEADSET, A2DP, etc @@ -96,7 +96,7 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> { this.profile = profile; this.timeSent = 0; } - + @Override public String toString() { StringBuilder sb = new StringBuilder(); @@ -147,7 +147,7 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> { } } } - + private boolean pruneQueue(BluetoothJob job) { boolean removedStaleItems = false; long now = System.currentTimeMillis(); @@ -186,7 +186,7 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> { private boolean processCommand(BluetoothJob job) { boolean successful = false; if (job.timeSent == 0) { - job.timeSent = System.currentTimeMillis(); + job.timeSent = System.currentTimeMillis(); switch (job.command) { case CONNECT: successful = connectInt(job.device, job.profile); @@ -349,7 +349,7 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> { } }; - AlertDialog ad = new AlertDialog.Builder(context) + new AlertDialog.Builder(context) .setTitle(getName()) .setMessage(message) .setPositiveButton(android.R.string.ok, disconnectListener) @@ -363,7 +363,6 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> { // Reset the only-show-one-error-dialog tracking variable mIsConnectingErrorPossible = true; - Context context = mLocalManager.getContext(); boolean hasAtLeastOnePreferredProfile = false; for (Profile profile : mProfiles) { LocalBluetoothProfileManager profileManager = @@ -385,7 +384,6 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> { // Reset the only-show-one-error-dialog tracking variable mIsConnectingErrorPossible = true; - Context context = mLocalManager.getContext(); for (Profile profile : mProfiles) { LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager.getProfileManager(mLocalManager, profile); @@ -450,7 +448,7 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> { public void unpair() { synchronized (workQueue) { // Remove any pending commands for this device - boolean processNow = false; + boolean processNow = false; Iterator<BluetoothJob> it = workQueue.iterator(); while (it.hasNext()) { BluetoothJob job = it.next(); @@ -480,8 +478,6 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> { } private void fillData() { - BluetoothDevice manager = mLocalManager.getBluetoothManager(); - fetchName(); fetchBtClass(); @@ -498,6 +494,17 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> { return mName; } + public void setName(String name) { + if (!mName.equals(name)) { + if (TextUtils.isEmpty(name)) { + mName = mAddress; + } else { + mName = name; + } + dispatchAttributesChanged(); + } + } + public void refreshName() { fetchName(); dispatchAttributesChanged(); @@ -571,23 +578,19 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> { } public int getBtClassDrawable() { - - // First try looking at profiles - if (mProfiles.contains(Profile.A2DP)) { - return R.drawable.ic_bt_headphones_a2dp; - } else if (mProfiles.contains(Profile.HEADSET)) { - return R.drawable.ic_bt_headset_hfp; - } - - // Fallback on class switch (BluetoothClass.Device.Major.getDeviceMajor(mBtClass)) { case BluetoothClass.Device.Major.COMPUTER: return R.drawable.ic_bt_laptop; case BluetoothClass.Device.Major.PHONE: return R.drawable.ic_bt_cellphone; + } - default: + if (mProfiles.contains(Profile.A2DP)) { + return R.drawable.ic_bt_headphones_a2dp; + } else if (mProfiles.contains(Profile.HEADSET)) { + return R.drawable.ic_bt_headset_hfp; + } else { return 0; } } @@ -611,6 +614,14 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> { dispatchAttributesChanged(); } + public void setBtClass(int btClass) { + if (mBtClass != btClass && btClass != BluetoothClass.ERROR) { + mBtClass = btClass; + LocalBluetoothProfileManager.fill(mBtClass, mProfiles); + dispatchAttributesChanged(); + } + } + public int getSummary() { // TODO: clean up int oneOffSummary = getOneOffSummary(); @@ -679,7 +690,9 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> { public void onCreateContextMenu(ContextMenu menu) { // No context menu if it is busy (none of these items are applicable if busy) - if (isBusy()) return; + if (mLocalManager.getBluetoothState() != BluetoothDevice.BLUETOOTH_STATE_ON || isBusy()) { + return; + } int bondState = getBondState(); boolean isConnected = isConnected(); @@ -726,7 +739,6 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> { break; case CONTEXT_ITEM_UNPAIR: - mLocalManager.getBluetoothManager().disconnectRemoteDeviceAcl(mAddress); unpair(); break; diff --git a/src/com/android/settings/bluetooth/LocalBluetoothDeviceManager.java b/src/com/android/settings/bluetooth/LocalBluetoothDeviceManager.java index 2c70fd2..819d482 100644 --- a/src/com/android/settings/bluetooth/LocalBluetoothDeviceManager.java +++ b/src/com/android/settings/bluetooth/LocalBluetoothDeviceManager.java @@ -34,7 +34,7 @@ public class LocalBluetoothDeviceManager { final LocalBluetoothManager mLocalManager; final List<Callback> mCallbacks; - + final List<LocalBluetoothDevice> mDevices = new ArrayList<LocalBluetoothDevice>(); public LocalBluetoothDeviceManager(LocalBluetoothManager localManager) { @@ -47,7 +47,7 @@ public class LocalBluetoothDeviceManager { BluetoothDevice manager = mLocalManager.getBluetoothManager(); String[] bondedAddresses = manager.listBonds(); if (bondedAddresses == null) return false; - + boolean deviceAdded = false; for (String address : bondedAddresses) { LocalBluetoothDevice device = findDevice(address); @@ -58,55 +58,58 @@ public class LocalBluetoothDeviceManager { deviceAdded = true; } } - + return deviceAdded; } - + public synchronized List<LocalBluetoothDevice> getDevicesCopy() { return new ArrayList<LocalBluetoothDevice>(mDevices); } - + void onBluetoothStateChanged(boolean enabled) { if (enabled) { readPairedDevices(); } } - public synchronized void onDeviceAppeared(String address, short rssi) { + public synchronized void onDeviceAppeared(String address, short rssi, int btClass, + String name) { boolean deviceAdded = false; - + LocalBluetoothDevice device = findDevice(address); if (device == null) { device = new LocalBluetoothDevice(mLocalManager.getContext(), address); mDevices.add(device); deviceAdded = true; } - + device.setRssi(rssi); + device.setBtClass(btClass); + device.setName(name); device.setVisible(true); - + if (deviceAdded) { dispatchDeviceAdded(device); } } - + public synchronized void onDeviceDisappeared(String address) { LocalBluetoothDevice device = findDevice(address); if (device == null) return; - + device.setVisible(false); checkForDeviceRemoval(device); } - + private void checkForDeviceRemoval(LocalBluetoothDevice device) { if (device.getBondState() == BluetoothDevice.BOND_NOT_BONDED && !device.isVisible()) { // If device isn't paired, remove it altogether mDevices.remove(device); dispatchDeviceDeleted(device); - } + } } - + public synchronized void onDeviceNameUpdated(String address) { LocalBluetoothDevice device = findDevice(address); if (device != null) { @@ -115,21 +118,21 @@ public class LocalBluetoothDeviceManager { } public synchronized LocalBluetoothDevice findDevice(String address) { - + for (int i = mDevices.size() - 1; i >= 0; i--) { LocalBluetoothDevice device = mDevices.get(i); - + if (device.getAddress().equals(address)) { return device; } } - + return null; } - + /** * Attempts to get the name of a remote device, otherwise returns the address. - * + * * @param address The address. * @return The name, or if unavailable, the address. */ @@ -137,17 +140,17 @@ public class LocalBluetoothDeviceManager { LocalBluetoothDevice device = findDevice(address); return device != null ? device.getName() : address; } - + private void dispatchDeviceAdded(LocalBluetoothDevice device) { synchronized (mCallbacks) { for (Callback callback : mCallbacks) { callback.onDeviceAdded(device); } } - + // TODO: divider between prev paired/connected and scanned } - + private void dispatchDeviceDeleted(LocalBluetoothDevice device) { synchronized (mCallbacks) { for (Callback callback : mCallbacks) { @@ -176,7 +179,7 @@ public class LocalBluetoothDeviceManager { /** * Called when there is a bonding error. - * + * * @param address The address of the remote device. * @param reason The reason, one of the error reasons from * BluetoothDevice.UNBOND_REASON_* @@ -199,7 +202,7 @@ public class LocalBluetoothDeviceManager { } mLocalManager.showError(address, R.string.bluetooth_error_title, errorMsg); } - + public synchronized void onProfileStateChanged(String address, Profile profile, int newProfileState) { LocalBluetoothDevice device = findDevice(address); @@ -208,11 +211,11 @@ public class LocalBluetoothDeviceManager { device.onProfileStateChanged(profile, newProfileState); device.refresh(); } - + public synchronized void onConnectingError(String address) { LocalBluetoothDevice device = findDevice(address); if (device == null) return; - + /* * Go through the device's delegate so we don't spam the user with * errors connecting to different profiles, and instead make sure the @@ -220,10 +223,10 @@ public class LocalBluetoothDeviceManager { */ device.showConnectingError(); } - + public synchronized void onScanningStateChanged(boolean started) { if (!started) return; - + // If starting a new scan, clear old visibility for (int i = mDevices.size() - 1; i >= 0; i--) { LocalBluetoothDevice device = mDevices.get(i); @@ -231,7 +234,7 @@ public class LocalBluetoothDeviceManager { checkForDeviceRemoval(device); } } - + public synchronized void onBtClassChanged(String address) { LocalBluetoothDevice device = findDevice(address); if (device != null) { diff --git a/src/com/android/settings/bluetooth/LocalBluetoothManager.java b/src/com/android/settings/bluetooth/LocalBluetoothManager.java index 2e84338..a6e9d50 100644 --- a/src/com/android/settings/bluetooth/LocalBluetoothManager.java +++ b/src/com/android/settings/bluetooth/LocalBluetoothManager.java @@ -42,15 +42,15 @@ import android.widget.Toast; public class LocalBluetoothManager { private static final String TAG = "LocalBluetoothManager"; static final boolean V = Config.LOGV; - static final boolean D = Config.LOGD && false; - + static final boolean D = Config.LOGD; + private static final String SHARED_PREFERENCES_NAME = "bluetooth_settings"; - + private static LocalBluetoothManager INSTANCE; /** Used when obtaining a reference to the singleton instance. */ private static Object INSTANCE_LOCK = new Object(); private boolean mInitialized; - + private Context mContext; /** If a BT-related activity is in the foreground, this will be it. */ private Activity mForegroundActivity; @@ -61,24 +61,24 @@ public class LocalBluetoothManager { private LocalBluetoothDeviceManager mLocalDeviceManager; private BluetoothEventRedirector mEventRedirector; private BluetoothA2dp mBluetoothA2dp; - + private int mState = BluetoothError.ERROR; private List<Callback> mCallbacks = new ArrayList<Callback>(); - + private static final int SCAN_EXPIRATION_MS = 5 * 60 * 1000; // 5 mins private long mLastScan; - + public static LocalBluetoothManager getInstance(Context context) { synchronized (INSTANCE_LOCK) { if (INSTANCE == null) { INSTANCE = new LocalBluetoothManager(); } - + if (!INSTANCE.init(context)) { return null; } - + return INSTANCE; } } @@ -86,15 +86,15 @@ public class LocalBluetoothManager { private boolean init(Context context) { if (mInitialized) return true; mInitialized = true; - + // This will be around as long as this process is mContext = context.getApplicationContext(); - + mManager = (BluetoothDevice) context.getSystemService(Context.BLUETOOTH_SERVICE); if (mManager == null) { return false; } - + mLocalDeviceManager = new LocalBluetoothDeviceManager(this); mEventRedirector = new BluetoothEventRedirector(this); @@ -104,11 +104,11 @@ public class LocalBluetoothManager { return true; } - + public BluetoothDevice getBluetoothManager() { return mManager; } - + public Context getContext() { return mContext; } @@ -116,7 +116,7 @@ public class LocalBluetoothManager { public Activity getForegroundActivity() { return mForegroundActivity; } - + public void setForegroundActivity(Activity activity) { if (mErrorDialog != null) { mErrorDialog.dismiss(); @@ -124,31 +124,31 @@ public class LocalBluetoothManager { } mForegroundActivity = activity; } - + public SharedPreferences getSharedPreferences() { return mContext.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); } - + public LocalBluetoothDeviceManager getLocalDeviceManager() { return mLocalDeviceManager; } - + List<Callback> getCallbacks() { return mCallbacks; } - + public void registerCallback(Callback callback) { synchronized (mCallbacks) { mCallbacks.add(callback); } } - + public void unregisterCallback(Callback callback) { synchronized (mCallbacks) { mCallbacks.remove(callback); } } - + public void startScanning(boolean force) { if (mManager.isDiscovering()) { /* @@ -156,7 +156,7 @@ public class LocalBluetoothManager { * Note: we only call the callbacks, not the same path as if the * scanning state had really changed (in that case the device * manager would clear its list of unpaired scanned devices). - */ + */ dispatchScanningStateChanged(true); } else { if (!force) { @@ -176,22 +176,22 @@ public class LocalBluetoothManager { } } } - - if (mManager.startDiscovery(true)) { + + if (mManager.startDiscovery()) { mLastScan = System.currentTimeMillis(); } } } - + public int getBluetoothState() { - + if (mState == BluetoothError.ERROR) { syncBluetoothState(); } - + return mState; } - + void setBluetoothStateInt(int state) { mState = state; if (state == BluetoothDevice.BLUETOOTH_STATE_ON || @@ -199,7 +199,7 @@ public class LocalBluetoothManager { mLocalDeviceManager.onBluetoothStateChanged(state == BluetoothDevice.BLUETOOTH_STATE_ON); } } - + private void syncBluetoothState() { int bluetoothState; @@ -218,7 +218,7 @@ public class LocalBluetoothManager { boolean wasSetStateSuccessful = enabled ? mManager.enable() : mManager.disable(); - + if (wasSetStateSuccessful) { setBluetoothStateInt(enabled ? BluetoothDevice.BLUETOOTH_STATE_TURNING_ON @@ -229,11 +229,11 @@ public class LocalBluetoothManager { "setBluetoothEnabled call, manager didn't return success for enabled: " + enabled); } - + syncBluetoothState(); } } - + /** * @param started True if scanning started, false if scanning finished. */ @@ -242,7 +242,7 @@ public class LocalBluetoothManager { mLocalDeviceManager.onScanningStateChanged(started); dispatchScanningStateChanged(started); } - + private void dispatchScanningStateChanged(boolean started) { synchronized (mCallbacks) { for (Callback callback : mCallbacks) { @@ -267,7 +267,7 @@ public class LocalBluetoothManager { .setPositiveButton(android.R.string.ok, null) .show(); } else { - // Fallback on a toast + // Fallback on a toast Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show(); } } @@ -277,5 +277,5 @@ public class LocalBluetoothManager { void onDeviceAdded(LocalBluetoothDevice device); void onDeviceDeleted(LocalBluetoothDevice device); } - + } diff --git a/src/com/android/settings/deviceinfo/Status.java b/src/com/android/settings/deviceinfo/Status.java index 7d22d91..1341989 100644 --- a/src/com/android/settings/deviceinfo/Status.java +++ b/src/com/android/settings/deviceinfo/Status.java @@ -393,7 +393,6 @@ public class Status extends PreferenceActivity { void updateTimes() { long at = SystemClock.uptimeMillis() / 1000; long ut = SystemClock.elapsedRealtime() / 1000; - long st = ut - at; if (ut == 0) { ut = 1; diff --git a/src/com/android/settings/quicklaunch/QuickLaunchSettings.java b/src/com/android/settings/quicklaunch/QuickLaunchSettings.java index 40316b5..fb9fbcd 100644 --- a/src/com/android/settings/quicklaunch/QuickLaunchSettings.java +++ b/src/com/android/settings/quicklaunch/QuickLaunchSettings.java @@ -226,8 +226,7 @@ public class QuickLaunchSettings extends PreferenceActivity implements Log.w(TAG, "Result from bookmark picker does not have an intent."); return; } - - String title = data.getStringExtra(BookmarkPicker.EXTRA_TITLE); + char shortcut = data.getCharExtra(BookmarkPicker.EXTRA_SHORTCUT, (char) 0); updateShortcut(shortcut, data); diff --git a/src/com/android/settings/widget/SettingsAppWidgetProvider.java b/src/com/android/settings/widget/SettingsAppWidgetProvider.java index d8747c9..caffea2 100644 --- a/src/com/android/settings/widget/SettingsAppWidgetProvider.java +++ b/src/com/android/settings/widget/SettingsAppWidgetProvider.java @@ -36,6 +36,7 @@ import android.os.ServiceManager; import android.provider.Settings; import android.util.Log; import android.widget.RemoteViews; +import android.widget.Toast; import com.android.settings.R; import com.android.settings.bluetooth.LocalBluetoothManager; @@ -175,7 +176,8 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider { views.setImageViewResource(R.id.btn_bluetooth, R.drawable.widget_btn_bluetooth); break; case STATE_INTERMEDIATE: - views.setImageViewResource(R.id.btn_bluetooth, R.drawable.widget_btn_bluetooth_gray); + views.setImageViewResource(R.id.btn_bluetooth, + R.drawable.widget_btn_bluetooth_gray); break; } } @@ -187,7 +189,8 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider { * @param appWidgetId * @return */ - private static PendingIntent getLaunchPendingIntent(Context context, int appWidgetId, int buttonId) { + private static PendingIntent getLaunchPendingIntent(Context context, int appWidgetId, + int buttonId) { Intent launchIntent = new Intent(); launchIntent.setClass(context, SettingsAppWidgetProvider.class); launchIntent.addCategory(Intent.CATEGORY_ALTERNATIVE); @@ -256,6 +259,7 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider { } else if (wifiState == STATE_DISABLED) { wifiManager.setWifiEnabled(true); } + Toast.makeText(context, R.string.gadget_toggle_wifi, Toast.LENGTH_SHORT).show(); } /** @@ -265,7 +269,8 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider { * @return true if enabled */ private static boolean getBackgroundDataState(Context context) { - ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + ConnectivityManager connManager = + (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); return connManager.getBackgroundDataSetting(); } @@ -275,16 +280,11 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider { * @param context */ private void toggleBackgroundData(Context context) { - ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + ConnectivityManager connManager = + (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); boolean sync = getBackgroundDataState(context); connManager.setBackgroundDataSetting(!sync); - - IContentService contentService = ContentResolver.getContentService(); - try { - contentService.setListenForNetworkTickles(!sync); - } catch (RemoteException e) { - Log.d(TAG, "toggleBackgroundData: " + e); - } + ContentResolver.setMasterSyncAutomatically(!sync); } /** @@ -306,7 +306,8 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider { private void toggleGps(Context context) { ContentResolver resolver = context.getContentResolver(); boolean enabled = getGpsState(context); - Settings.Secure.setLocationProviderEnabled(resolver, LocationManager.GPS_PROVIDER, !enabled); + Settings.Secure.setLocationProviderEnabled(resolver, LocationManager.GPS_PROVIDER, + !enabled); } /** @@ -399,5 +400,6 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider { } else if (state == STATE_DISABLED) { mLocalBluetoothManager.setBluetoothEnabled(true); } + Toast.makeText(context, R.string.gadget_toggle_bluetooth, Toast.LENGTH_SHORT).show(); } } diff --git a/src/com/android/settings/wifi/AccessPointDialog.java b/src/com/android/settings/wifi/AccessPointDialog.java index 5851a18..c4984cd 100644 --- a/src/com/android/settings/wifi/AccessPointDialog.java +++ b/src/com/android/settings/wifi/AccessPointDialog.java @@ -455,12 +455,12 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On } private void updatePasswordCaption(String security) { - - if (mPasswordText != null && security != null - && security.equals(AccessPointState.WEP)) { - mPasswordText.setText(R.string.please_type_hex_key); - } else { - mPasswordText.setText(R.string.please_type_passphrase); + if (mPasswordText != null) { + if (security != null && security.equals(AccessPointState.WEP)) { + mPasswordText.setText(R.string.please_type_hex_key); + } else { + mPasswordText.setText(R.string.please_type_passphrase); + } } } diff --git a/src/com/android/settings/wifi/AccessPointPreference.java b/src/com/android/settings/wifi/AccessPointPreference.java index 10e0947..6dd5492 100644 --- a/src/com/android/settings/wifi/AccessPointPreference.java +++ b/src/com/android/settings/wifi/AccessPointPreference.java @@ -33,14 +33,11 @@ public class AccessPointPreference extends Preference implements // Signal strength indicator private static final int UI_SIGNAL_LEVELS = 4; - private WifiSettings mWifiSettings; - private AccessPointState mState; public AccessPointPreference(WifiSettings wifiSettings, AccessPointState state) { super(wifiSettings, null); - mWifiSettings = wifiSettings; mState = state; setWidgetLayoutResource(R.layout.preference_widget_wifi_signal); diff --git a/src/com/android/settings/wifi/AdvancedSettings.java b/src/com/android/settings/wifi/AdvancedSettings.java index 323d5c7..2adf072 100644 --- a/src/com/android/settings/wifi/AdvancedSettings.java +++ b/src/com/android/settings/wifi/AdvancedSettings.java @@ -69,6 +69,13 @@ public class AdvancedSettings extends PreferenceActivity Preference preference = findPreference(mPreferenceKeys[i]); preference.setOnPreferenceChangeListener(this); } + + /* + * Fix the Run-time IllegalStateException that ListPreference requires an entries + * array and an entryValues array, this exception occurs when user open/close the + * slider in the Regulatory domain dialog. + */ + initNumChannelsPreference(); } @Override @@ -141,7 +148,7 @@ public class AdvancedSettings extends PreferenceActivity try { int numChannels = Integer.parseInt((String) newValue); WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); - if (!wifiManager.setNumAllowedChannels(numChannels)) { + if (!wifiManager.setNumAllowedChannels(numChannels, true)) { Toast.makeText(this, R.string.wifi_setting_num_channels_error, Toast.LENGTH_SHORT).show(); } diff --git a/src/com/android/settings/wifi/WifiEnabler.java b/src/com/android/settings/wifi/WifiEnabler.java index 88cfe06..10a672b 100644 --- a/src/com/android/settings/wifi/WifiEnabler.java +++ b/src/com/android/settings/wifi/WifiEnabler.java @@ -23,6 +23,7 @@ import static android.net.wifi.WifiManager.WIFI_STATE_ENABLING; import static android.net.wifi.WifiManager.WIFI_STATE_UNKNOWN; import com.android.settings.R; +import com.android.settings.AirplaneModeEnabler; import android.content.BroadcastReceiver; import android.content.Context; @@ -32,6 +33,7 @@ import android.net.NetworkInfo; import android.net.wifi.WifiManager; import android.preference.Preference; import android.preference.CheckBoxPreference; +import android.provider.Settings; import android.text.TextUtils; import android.util.Config; import android.util.Log; @@ -121,7 +123,7 @@ public class WifiEnabler implements Preference.OnPreferenceChangeListener { mWifiCheckBoxPref .setSummary(wifiState == WIFI_STATE_DISABLED ? mOriginalSummary : null); - mWifiCheckBoxPref.setEnabled(isEnabledByDependency()); + mWifiCheckBoxPref.setEnabled(isWifiAllowed(mContext)); } else if (wifiState == WIFI_STATE_DISABLING || wifiState == WIFI_STATE_ENABLING) { mWifiCheckBoxPref.setSummary(wifiState == WIFI_STATE_ENABLING ? R.string.wifi_starting @@ -151,24 +153,23 @@ public class WifiEnabler implements Preference.OnPreferenceChangeListener { } } - private boolean isEnabledByDependency() { - Preference dep = getDependencyPreference(); - if (dep == null) { + private static boolean isWifiAllowed(Context context) { + // allowed if we are not in airplane mode + if (!AirplaneModeEnabler.isAirplaneModeOn(context)) { return true; } - - return !dep.shouldDisableDependents(); - } - - private Preference getDependencyPreference() { - String depKey = mWifiCheckBoxPref.getDependency(); - if (TextUtils.isEmpty(depKey)) { - return null; + // allowed if wifi is not in AIRPLANE_MODE_RADIOS + String radios = Settings.System.getString(context.getContentResolver(), + Settings.System.AIRPLANE_MODE_RADIOS); + if (radios == null || !radios.contains(Settings.System.RADIO_WIFI)) { + return true; } - - return mWifiCheckBoxPref.getPreferenceManager().findPreference(depKey); + // allowed if wifi is in AIRPLANE_MODE_TOGGLEABLE_RADIOS + radios = Settings.System.getString(context.getContentResolver(), + Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS); + return (radios != null && radios.contains(Settings.System.RADIO_WIFI)); } - + private static String getHumanReadableWifiState(int wifiState) { switch (wifiState) { case WIFI_STATE_DISABLED: diff --git a/src/com/android/settings/wifi/WifiLayer.java b/src/com/android/settings/wifi/WifiLayer.java index 5d896aa..ce518e1 100644 --- a/src/com/android/settings/wifi/WifiLayer.java +++ b/src/com/android/settings/wifi/WifiLayer.java @@ -774,7 +774,9 @@ public class WifiLayer { * We pass null for security since we have a network ID (i.e., it's * not a wildcard), and rely on it matching. */ - return findApLocked(wifiInfo.getNetworkId(), wifiInfo.getBSSID(), ssid, null); + synchronized (this) { + return findApLocked(wifiInfo.getNetworkId(), wifiInfo.getBSSID(), ssid, null); + } } else { return null; } @@ -1013,8 +1015,10 @@ public class WifiLayer { * We pass null for security since we have a network ID (i.e., it's * not a wildcard), and rely on it matching. */ - ap = findApLocked(wifiInfo.getNetworkId(), wifiInfo.getBSSID(), wifiInfo - .getSSID(), null); + synchronized (this) { + ap = findApLocked(wifiInfo.getNetworkId(), wifiInfo.getBSSID(), wifiInfo + .getSSID(), null); + } } if (ap != null) { diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java index f18992a..adf4519 100644 --- a/src/com/android/settings/wifi/WifiSettings.java +++ b/src/com/android/settings/wifi/WifiSettings.java @@ -394,8 +394,8 @@ public class WifiSettings extends PreferenceActivity implements WifiLayer.Callba } mDialog = dialog; - dialog.setOnDismissListener(this); if (dialog != null) { + dialog.setOnDismissListener(this); dialog.show(); } } |