Merge "Fix mvno match data is incorrect for APNs"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 3f8a9d1..62faaa0 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2044,28 +2044,6 @@
</intent-filter>
</activity>
- <receiver
- android:name=".bluetooth.BluetoothDiscoveryReceiver">
- <intent-filter>
- <action android:name="android.bluetooth.adapter.action.DISCOVERY_STARTED" />
- <action android:name="android.bluetooth.adapter.action.DISCOVERY_FINISHED" />
- <category android:name="android.intent.category.DEFAULT" />
- </intent-filter>
- </receiver>
-
- <receiver
- android:name=".bluetooth.DockEventReceiver">
- <intent-filter>
- <action android:name="android.intent.action.DOCK_EVENT" />
- <action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
- <action android:name="android.bluetooth.headset.action.STATE_CHANGED" />
- <action android:name="android.bluetooth.a2dp.action.SINK_STATE_CHANGED" />
- <category android:name="android.intent.category.DEFAULT" />
- </intent-filter>
- </receiver>
-
- <service android:name=".bluetooth.DockService" />
-
<activity android:name=".bluetooth.RequestPermissionActivity"
android:label="@string/bluetooth_permission_request"
android:excludeFromRecents="true"
@@ -2113,11 +2091,11 @@
android:theme="@*android:style/Theme.DeviceDefault.Light.Dialog.Alert">
</activity>
+ <service android:name=".bluetooth.BluetoothPairingService" />
+
<receiver android:name=".bluetooth.BluetoothPairingRequest">
<intent-filter>
<action android:name="android.bluetooth.device.action.PAIRING_REQUEST" />
- <action android:name="android.bluetooth.device.action.PAIRING_CANCEL" />
- <action android:name="android.bluetooth.device.action.BOND_STATE_CHANGED" />
</intent-filter>
</receiver>
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 6827e5b..5a7b42e 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -699,7 +699,7 @@
<!-- Values for the list of long press timeout options. -->
<string-array name="long_press_timeout_selector_values" translatable="false">
- <item>500</item>
+ <item>400</item>
<item>1000</item>
<item>1500</item>
</string-array>
diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml
index b655865..0c6932d 100644
--- a/res/xml/development_prefs.xml
+++ b/res/xml/development_prefs.xml
@@ -198,6 +198,13 @@
android:summary="@string/bluetooth_disable_absolute_volume_summary"/>
<ListPreference
+ android:key="bluetooth_select_avrcp_version"
+ android:title="@string/bluetooth_select_avrcp_version_string"
+ android:dialogTitle="@string/bluetooth_select_avrcp_version_dialog_title"
+ android:entries="@array/bluetooth_avrcp_versions"
+ android:entryValues="@array/bluetooth_avrcp_version_values" />
+
+ <ListPreference
android:key="bluetooth_select_a2dp_codec"
android:title="@string/bluetooth_select_a2dp_codec_type"
android:dialogTitle="@string/bluetooth_select_a2dp_codec_type_dialog_title"
diff --git a/src/com/android/settings/ApnSettings.java b/src/com/android/settings/ApnSettings.java
old mode 100644
new mode 100755
index 3d3f6c5..e9e5226
--- a/src/com/android/settings/ApnSettings.java
+++ b/src/com/android/settings/ApnSettings.java
@@ -339,7 +339,7 @@
if (mAllowAddingApns) {
menu.add(0, MENU_NEW, 0,
getResources().getString(R.string.menu_new))
- .setIcon(android.R.drawable.ic_menu_add)
+ .setIcon(R.drawable.ic_menu_add_white)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
}
menu.add(0, MENU_RESTORE, 0,
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java
index c673676..6c40051 100644
--- a/src/com/android/settings/DevelopmentSettings.java
+++ b/src/com/android/settings/DevelopmentSettings.java
@@ -28,6 +28,7 @@
import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothCodecConfig;
+import android.bluetooth.BluetoothCodecStatus;
import android.bluetooth.BluetoothProfile;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -198,7 +199,10 @@
"bluetooth_disable_absolute_volume";
private static final String BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_PROPERTY =
"persist.bluetooth.disableabsvol";
+ private static final String BLUETOOTH_AVRCP_VERSION_PROPERTY =
+ "persist.bluetooth.avrcpversion";
+ private static final String BLUETOOTH_SELECT_AVRCP_VERSION_KEY = "bluetooth_select_avrcp_version";
private static final String BLUETOOTH_SELECT_A2DP_CODEC_KEY = "bluetooth_select_a2dp_codec";
private static final String BLUETOOTH_SELECT_A2DP_SAMPLE_RATE_KEY = "bluetooth_select_a2dp_sample_rate";
private static final String BLUETOOTH_SELECT_A2DP_BITS_PER_SAMPLE_KEY = "bluetooth_select_a2dp_bits_per_sample";
@@ -277,6 +281,7 @@
private BluetoothA2dp mBluetoothA2dp;
private final Object mBluetoothA2dpLock = new Object();
+ private ListPreference mBluetoothSelectAvrcpVersion;
private ListPreference mBluetoothSelectA2dpCodec;
private ListPreference mBluetoothSelectA2dpSampleRate;
private ListPreference mBluetoothSelectA2dpBitsPerSample;
@@ -470,6 +475,7 @@
mWebViewMultiprocess = findAndInitSwitchPref(WEBVIEW_MULTIPROCESS_KEY);
mBluetoothDisableAbsVolume = findAndInitSwitchPref(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_KEY);
+ mBluetoothSelectAvrcpVersion = addListPreference(BLUETOOTH_SELECT_AVRCP_VERSION_KEY);
mBluetoothSelectA2dpCodec = addListPreference(BLUETOOTH_SELECT_A2DP_CODEC_KEY);
mBluetoothSelectA2dpSampleRate = addListPreference(BLUETOOTH_SELECT_A2DP_SAMPLE_RATE_KEY);
mBluetoothSelectA2dpBitsPerSample = addListPreference(BLUETOOTH_SELECT_A2DP_BITS_PER_SAMPLE_KEY);
@@ -1497,7 +1503,7 @@
private void updateMobileDataAlwaysOnOptions() {
updateSwitchPreference(mMobileDataAlwaysOn, Settings.Global.getInt(
getActivity().getContentResolver(),
- Settings.Global.MOBILE_DATA_ALWAYS_ON, 0) != 0);
+ Settings.Global.MOBILE_DATA_ALWAYS_ON, 1) != 0);
}
private void writeMobileDataAlwaysOnOptions() {
@@ -1763,6 +1769,14 @@
String[] summaries;
int index;
+ // Init the AVRCP Version - Default
+ values = getResources().getStringArray(R.array.bluetooth_avrcp_version_values);
+ summaries = getResources().getStringArray(R.array.bluetooth_avrcp_versions);
+ String value = SystemProperties.get(BLUETOOTH_AVRCP_VERSION_PROPERTY, values[0]);
+ index = mBluetoothSelectAvrcpVersion.findIndexOfValue(value);
+ mBluetoothSelectAvrcpVersion.setValue(values[index]);
+ mBluetoothSelectAvrcpVersion.setSummary(summaries[index]);
+
// Init the Codec Type - Default
values = getResources().getStringArray(R.array.bluetooth_a2dp_codec_values);
summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_summaries);
@@ -1791,50 +1805,80 @@
mBluetoothSelectA2dpChannelMode.setValue(values[index]);
mBluetoothSelectA2dpChannelMode.setSummary(summaries[index]);
- // Init the LDAC Playback Quality - High
+ // Init the LDAC Playback Quality - ABR
values = getResources().getStringArray(R.array.bluetooth_a2dp_codec_ldac_playback_quality_values);
summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_ldac_playback_quality_summaries);
- index = 0;
+ index = 3;
mBluetoothSelectA2dpLdacPlaybackQuality.setValue(values[index]);
mBluetoothSelectA2dpLdacPlaybackQuality.setSummary(summaries[index]);
}
+ private void writeBluetoothAvrcpVersion(Object newValue) {
+ SystemProperties.set(BLUETOOTH_AVRCP_VERSION_PROPERTY, newValue.toString());
+ int index = mBluetoothSelectAvrcpVersion.findIndexOfValue(newValue.toString());
+ if (index >= 0) {
+ String[] titles = getResources().getStringArray(R.array.bluetooth_avrcp_versions);
+ mBluetoothSelectAvrcpVersion.setSummary(titles[index]);
+ }
+ }
+
private void updateBluetoothA2dpConfigurationValues() {
int index;
String[] summaries;
+ BluetoothCodecStatus codecStatus = null;
BluetoothCodecConfig codecConfig = null;
+ BluetoothCodecConfig[] codecsLocalCapabilities = null;
+ BluetoothCodecConfig[] codecsSelectableCapabilities = null;
String streaming;
+ Resources resources = null;
synchronized (mBluetoothA2dpLock) {
if (mBluetoothA2dp != null) {
- codecConfig = mBluetoothA2dp.getCodecConfig();
+ codecStatus = mBluetoothA2dp.getCodecStatus();
+ if (codecStatus != null) {
+ codecConfig = codecStatus.getCodecConfig();
+ codecsLocalCapabilities = codecStatus.getCodecsLocalCapabilities();
+ codecsSelectableCapabilities = codecStatus.getCodecsSelectableCapabilities();
+ }
}
}
if (codecConfig == null)
return;
+ try {
+ resources = getResources();
+ } catch (IllegalStateException e) {
+ return;
+ }
+ if (resources == null) {
+ return;
+ }
+
// Update the Codec Type
index = -1;
switch (codecConfig.getCodecType()) {
case BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC:
index = 1;
break;
- case BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX:
+ case BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC:
index = 2;
break;
- case BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD:
+ case BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX:
index = 3;
break;
- case BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC:
+ case BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD:
index = 4;
break;
+ case BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC:
+ index = 5;
+ break;
case BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID:
default:
break;
}
- if (index >= 0) {
- summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_summaries);
- streaming = getResources().getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]);
+ if (index >= 0 && mBluetoothSelectA2dpCodec != null) {
+ summaries = resources.getStringArray(R.array.bluetooth_a2dp_codec_summaries);
+ streaming = resources.getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]);
mBluetoothSelectA2dpCodec.setSummary(streaming);
}
@@ -1859,9 +1903,9 @@
default:
break;
}
- if (index >= 0) {
- summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_sample_rate_summaries);
- streaming = getResources().getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]);
+ if (index >= 0 && mBluetoothSelectA2dpSampleRate != null) {
+ summaries = resources.getStringArray(R.array.bluetooth_a2dp_codec_sample_rate_summaries);
+ streaming = resources.getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]);
mBluetoothSelectA2dpSampleRate.setSummary(streaming);
}
@@ -1881,9 +1925,9 @@
default:
break;
}
- if (index >= 0) {
- summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_bits_per_sample_summaries);
- streaming = getResources().getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]);
+ if (index >= 0 && mBluetoothSelectA2dpBitsPerSample != null) {
+ summaries = resources.getStringArray(R.array.bluetooth_a2dp_codec_bits_per_sample_summaries);
+ streaming = resources.getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]);
mBluetoothSelectA2dpBitsPerSample.setSummary(streaming);
}
@@ -1900,9 +1944,9 @@
default:
break;
}
- if (index >= 0) {
- summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_channel_mode_summaries);
- streaming = getResources().getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]);
+ if (index >= 0 && mBluetoothSelectA2dpChannelMode != null) {
+ summaries = resources.getStringArray(R.array.bluetooth_a2dp_codec_channel_mode_summaries);
+ streaming = resources.getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]);
mBluetoothSelectA2dpChannelMode.setSummary(streaming);
}
@@ -1921,14 +1965,15 @@
case 0:
case 1:
case 2:
+ case 3:
break;
default:
index = -1;
break;
}
- if (index >= 0) {
- summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_ldac_playback_quality_summaries);
- streaming = getResources().getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]);
+ if (index >= 0 && mBluetoothSelectA2dpLdacPlaybackQuality != null) {
+ summaries = resources.getStringArray(R.array.bluetooth_a2dp_codec_ldac_playback_quality_summaries);
+ streaming = resources.getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]);
mBluetoothSelectA2dpLdacPlaybackQuality.setSummary(streaming);
}
}
@@ -1969,12 +2014,15 @@
codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC;
break;
case 2:
- codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX;
+ codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC;
break;
case 3:
- codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD;
+ codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX;
break;
case 4:
+ codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD;
+ break;
+ case 5:
codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC;
break;
default:
@@ -1986,17 +2034,35 @@
codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
break;
case 2:
- codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX;
+ codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC;
codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
break;
case 3:
- codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD;
+ codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX;
codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
break;
case 4:
+ codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD;
+ codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
+ break;
+ case 5:
codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC;
codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
break;
+ case 6:
+ synchronized (mBluetoothA2dpLock) {
+ if (mBluetoothA2dp != null) {
+ mBluetoothA2dp.enableOptionalCodecs();
+ }
+ }
+ return;
+ case 7:
+ synchronized (mBluetoothA2dpLock) {
+ if (mBluetoothA2dp != null) {
+ mBluetoothA2dp.disableOptionalCodecs();
+ }
+ }
+ return;
default:
break;
}
@@ -2100,6 +2166,7 @@
case 0:
case 1:
case 2:
+ case 3:
codecSpecific1Value = 1000 + index;
break;
default:
@@ -2496,6 +2563,9 @@
toast.show();
}
return false;
+ } else if (preference == mBluetoothSelectAvrcpVersion) {
+ writeBluetoothAvrcpVersion(newValue);
+ return true;
} else if ((preference == mBluetoothSelectA2dpCodec) ||
(preference == mBluetoothSelectA2dpSampleRate) ||
(preference == mBluetoothSelectA2dpBitsPerSample) ||
@@ -2645,7 +2715,15 @@
private BroadcastReceiver mBluetoothA2dpReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
- updateBluetoothA2dpConfigurationValues();
+ Log.d(TAG, "mBluetoothA2dpReceiver.onReceive intent=" + intent);
+ String action = intent.getAction();
+
+ if (BluetoothA2dp.ACTION_CODEC_CONFIG_CHANGED.equals(action)) {
+ BluetoothCodecStatus codecStatus =
+ (BluetoothCodecStatus)intent.getParcelableExtra(BluetoothCodecStatus.EXTRA_CODEC_STATUS);
+ Log.d(TAG, "Received BluetoothCodecStatus=" + codecStatus);
+ updateBluetoothA2dpConfigurationValues();
+ }
}
};
diff --git a/src/com/android/settings/RadioInfo.java b/src/com/android/settings/RadioInfo.java
index 54ff4db..9c9eceb 100644
--- a/src/com/android/settings/RadioInfo.java
+++ b/src/com/android/settings/RadioInfo.java
@@ -493,7 +493,7 @@
log("onPause: unregister phone & data intents");
mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
- phone.setCellInfoListRate(CELL_INFO_LIST_RATE_DISABLED);
+ mTelephonyManager.setCellInfoListRate(CELL_INFO_LIST_RATE_DISABLED);
}
private void restoreFromBundle(Bundle b) {
@@ -1282,7 +1282,7 @@
public void onItemSelected(AdapterView parent, View v, int pos, long id) {
mCellInfoRefreshRateIndex = pos;
- phone.setCellInfoListRate(mCellInfoRefreshRates[pos]);
+ mTelephonyManager.setCellInfoListRate(mCellInfoRefreshRates[pos]);
updateAllCellInfo();
}
diff --git a/src/com/android/settings/WifiCallingSettings.java b/src/com/android/settings/WifiCallingSettings.java
index 3e9da17..5f117f6 100644
--- a/src/com/android/settings/WifiCallingSettings.java
+++ b/src/com/android/settings/WifiCallingSettings.java
@@ -253,15 +253,6 @@
final Context context = getActivity();
- if (ImsManager.isWfcEnabledByPlatform(context)) {
- TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
- tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
-
- mSwitchBar.addOnSwitchChangeListener(this);
-
- mValidListener = true;
- }
-
// NOTE: Buttons will be enabled/disabled in mPhoneStateListener
boolean wfcEnabled = ImsManager.isWfcEnabledByUser(context)
&& ImsManager.isNonTtyOrTtyOnVolteEnabled(context);
@@ -272,6 +263,15 @@
mButtonWfcRoamingMode.setValue(Integer.toString(wfcRoamingMode));
updateButtonWfcMode(context, wfcEnabled, wfcMode, wfcRoamingMode);
+ if (ImsManager.isWfcEnabledByPlatform(context)) {
+ TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
+ tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
+
+ mSwitchBar.addOnSwitchChangeListener(this);
+
+ mValidListener = true;
+ }
+
context.registerReceiver(mIntentReceiver, mIntentFilter);
Intent intent = getActivity().getIntent();
diff --git a/src/com/android/settings/WirelessSettings.java b/src/com/android/settings/WirelessSettings.java
index fc473fc..52b1344 100644
--- a/src/com/android/settings/WirelessSettings.java
+++ b/src/com/android/settings/WirelessSettings.java
@@ -125,7 +125,7 @@
NetworkInfo ni = mCm.getActiveNetworkInfo();
if (mTm.hasIccCard() && (ni != null)) {
// Check for carrier apps that can handle provisioning first
- Intent provisioningIntent = new Intent(TelephonyIntents.ACTION_CARRIER_SETUP);
+ Intent provisioningIntent = new Intent(Intent.ACTION_CARRIER_SETUP);
List<String> carrierPackages =
mTm.getCarrierPackageNamesForIntent(provisioningIntent);
if (carrierPackages != null && !carrierPackages.isEmpty()) {
diff --git a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
index a45e7b4..69e66ae 100644
--- a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
+++ b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
@@ -286,12 +286,12 @@
}
}
if (btClass != null) {
- if (btClass.doesClassMatch(BluetoothClass.PROFILE_A2DP)) {
- return new Pair<Integer, String>(R.drawable.ic_bt_headphones_a2dp, HEADPHONE);
- }
- if (btClass.doesClassMatch(BluetoothClass.PROFILE_HEADSET)) {
+ if (btClass.doesClassMatch(BluetoothClass.PROFILE_HEADSET)) {
return new Pair<Integer, String>(R.drawable.ic_bt_headset_hfp, HEADSET);
}
+ if (btClass.doesClassMatch(BluetoothClass.PROFILE_A2DP)) {
+ return new Pair<Integer, String>(R.drawable.ic_bt_headphones_a2dp, HEADPHONE);
+ }
}
return new Pair<Integer, String>(R.drawable.ic_settings_bluetooth, BLUETOOTH);
}
diff --git a/src/com/android/settings/bluetooth/BluetoothDiscoveryReceiver.java b/src/com/android/settings/bluetooth/BluetoothDiscoveryReceiver.java
deleted file mode 100644
index 1ba9f85..0000000
--- a/src/com/android/settings/bluetooth/BluetoothDiscoveryReceiver.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.bluetooth;
-
-import android.bluetooth.BluetoothAdapter;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.util.Log;
-
-import com.android.settingslib.bluetooth.BluetoothEventManager;
-
-/**
- * BluetoothDiscoveryReceiver updates a timestamp when the
- * Bluetooth adapter starts or finishes discovery mode. This
- * is used to decide whether to open an alert dialog or
- * create a notification when we receive a pairing request.
- *
- * <p>Note that the discovery start/finish intents are also handled
- * by {@link BluetoothEventManager} to update the UI, if visible.
- */
-public final class BluetoothDiscoveryReceiver extends BroadcastReceiver {
- private static final String TAG = "BluetoothDiscoveryReceiver";
-
- @Override
- public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- Log.v(TAG, "Received: " + action);
-
- if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_STARTED) ||
- action.equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)) {
- LocalBluetoothPreferences.persistDiscoveringTimestamp(context);
- }
- }
-}
diff --git a/src/com/android/settings/bluetooth/BluetoothPairingRequest.java b/src/com/android/settings/bluetooth/BluetoothPairingRequest.java
index 1c36bca..96aace9 100644
--- a/src/com/android/settings/bluetooth/BluetoothPairingRequest.java
+++ b/src/com/android/settings/bluetooth/BluetoothPairingRequest.java
@@ -16,110 +16,47 @@
package com.android.settings.bluetooth;
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.PowerManager;
-import android.text.TextUtils;
-
-import com.android.settings.R;
+import android.os.UserHandle;
/**
* 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.
+ * confirmation entry dialog. Otherwise it starts the BluetoothPairingService which
+ * starts a notification in the status bar that can be clicked to bring up the same dialog.
*/
public final class BluetoothPairingRequest extends BroadcastReceiver {
- private 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(BluetoothDevice.ACTION_PAIRING_REQUEST)) {
- // convert broadcast intent into activity intent (same action string)
- BluetoothDevice device =
- intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
- int type = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT,
- BluetoothDevice.ERROR);
- Intent pairingIntent = new Intent();
- pairingIntent.setClass(context, BluetoothPairingDialog.class);
- pairingIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
- pairingIntent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, type);
- if (type == BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION ||
- type == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY ||
- type == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PIN) {
- int pairingKey = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_KEY,
- BluetoothDevice.ERROR);
- pairingIntent.putExtra(BluetoothDevice.EXTRA_PAIRING_KEY, pairingKey);
- }
- pairingIntent.setAction(BluetoothDevice.ACTION_PAIRING_REQUEST);
- pairingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-
- PowerManager powerManager =
- (PowerManager)context.getSystemService(Context.POWER_SERVICE);
- String deviceAddress = device != null ? device.getAddress() : null;
- String deviceName = device != null ? device.getName() : null;
- boolean shouldShowDialog= LocalBluetoothPreferences.shouldShowDialogInForeground(
- context, deviceAddress, deviceName);
- if (powerManager.isInteractive() && shouldShowDialog) {
- // Since the screen is on and the BT-related activity is in the foreground,
- // just open the dialog
- context.startActivity(pairingIntent);
- } else {
- // Put up a notification that leads to the dialog
- Resources res = context.getResources();
- Notification.Builder builder = new Notification.Builder(context)
- .setSmallIcon(android.R.drawable.stat_sys_data_bluetooth)
- .setTicker(res.getString(R.string.bluetooth_notif_ticker));
-
- PendingIntent pending = PendingIntent.getActivity(context, 0,
- pairingIntent, PendingIntent.FLAG_ONE_SHOT);
-
- String name = intent.getStringExtra(BluetoothDevice.EXTRA_NAME);
- if (TextUtils.isEmpty(name)) {
- name = device != null ? device.getAliasName() :
- context.getString(android.R.string.unknownName);
- }
-
- builder.setContentTitle(res.getString(R.string.bluetooth_notif_title))
- .setContentText(res.getString(R.string.bluetooth_notif_message, name))
- .setContentIntent(pending)
- .setAutoCancel(true)
- .setDefaults(Notification.DEFAULT_SOUND)
- .setColor(context.getColor(
- com.android.internal.R.color.system_notification_accent_color));
-
- NotificationManager manager = (NotificationManager)
- context.getSystemService(Context.NOTIFICATION_SERVICE);
- manager.notify(NOTIFICATION_ID, builder.getNotification());
- }
-
- } else if (action.equals(BluetoothDevice.ACTION_PAIRING_CANCEL)) {
-
- // Remove the notification
- NotificationManager manager = (NotificationManager) context
- .getSystemService(Context.NOTIFICATION_SERVICE);
- manager.cancel(NOTIFICATION_ID);
-
- } else if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)) {
- int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE,
- BluetoothDevice.ERROR);
- int oldState = intent.getIntExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE,
- BluetoothDevice.ERROR);
- if((oldState == BluetoothDevice.BOND_BONDING) &&
- (bondState == BluetoothDevice.BOND_NONE)) {
- // Remove the notification
- NotificationManager manager = (NotificationManager) context
- .getSystemService(Context.NOTIFICATION_SERVICE);
- manager.cancel(NOTIFICATION_ID);
- }
- }
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (!action.equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) {
+ return;
}
+ // convert broadcast intent into activity intent (same action string)
+ Intent pairingIntent = BluetoothPairingService.getPairingDialogIntent(context, intent);
+
+ PowerManager powerManager =
+ (PowerManager)context.getSystemService(Context.POWER_SERVICE);
+ BluetoothDevice device =
+ intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+ String deviceAddress = device != null ? device.getAddress() : null;
+ String deviceName = device != null ? device.getName() : null;
+ boolean shouldShowDialog = LocalBluetoothPreferences.shouldShowDialogInForeground(
+ context, deviceAddress, deviceName);
+ if (powerManager.isInteractive() && shouldShowDialog) {
+ // Since the screen is on and the BT-related activity is in the foreground,
+ // just open the dialog
+ context.startActivity(pairingIntent);
+ } else {
+ // Put up a notification that leads to the dialog
+ intent.setClass(context, BluetoothPairingService.class);
+ context.startServiceAsUser(intent, UserHandle.CURRENT);
+ }
+ }
}
diff --git a/src/com/android/settings/bluetooth/BluetoothPairingService.java b/src/com/android/settings/bluetooth/BluetoothPairingService.java
new file mode 100644
index 0000000..5dfd283
--- /dev/null
+++ b/src/com/android/settings/bluetooth/BluetoothPairingService.java
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.bluetooth;
+
+import android.app.Notification;
+import android.app.PendingIntent;
+import android.app.Service;
+import android.bluetooth.BluetoothDevice;
+import android.content.IntentFilter;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.Resources;
+import android.os.IBinder;
+import android.text.TextUtils;
+import android.util.Log;
+
+import com.android.settings.R;
+
+/**
+ * BluetoothPairingService shows a notification if there is a pending bond request
+ * which can launch the appropriate pairing dialog when tapped.
+ */
+public final class BluetoothPairingService extends Service {
+
+ private static final int NOTIFICATION_ID = android.R.drawable.stat_sys_data_bluetooth;
+
+ private static final String TAG = "BluetoothPairingService";
+
+ private BluetoothDevice mDevice;
+
+ public static Intent getPairingDialogIntent(Context context, Intent intent) {
+
+ BluetoothDevice device =
+ intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+ int type = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT,
+ BluetoothDevice.ERROR);
+ Intent pairingIntent = new Intent();
+ pairingIntent.setClass(context, BluetoothPairingDialog.class);
+ pairingIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
+ pairingIntent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, type);
+ if (type == BluetoothDevice.PAIRING_VARIANT_PASSKEY_CONFIRMATION ||
+ type == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PASSKEY ||
+ type == BluetoothDevice.PAIRING_VARIANT_DISPLAY_PIN) {
+ int pairingKey = intent.getIntExtra(BluetoothDevice.EXTRA_PAIRING_KEY,
+ BluetoothDevice.ERROR);
+ pairingIntent.putExtra(BluetoothDevice.EXTRA_PAIRING_KEY, pairingKey);
+ }
+ pairingIntent.setAction(BluetoothDevice.ACTION_PAIRING_REQUEST);
+ pairingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ return pairingIntent;
+ }
+
+ private final BroadcastReceiver mCancelReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (action.equals(BluetoothDevice.ACTION_BOND_STATE_CHANGED)) {
+ int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE,
+ BluetoothDevice.ERROR);
+ if ((bondState != BluetoothDevice.BOND_NONE) && (bondState != BluetoothDevice.BOND_BONDED)) {
+ return;
+ }
+ Log.d(TAG, "Dismiss pairing for " + mDevice.getAddress() + " (" + mDevice.getName() + "), BondState: " + bondState);
+ } else {
+ Log.d(TAG, "Dismiss pairing for " + mDevice.getAddress() + " (" + mDevice.getName() + "), Cancelled.");
+ }
+ stopForeground(true);
+ stopSelf();
+ }
+ };
+
+ @Override
+ public void onCreate() {
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ if (intent == null) {
+ Log.e(TAG, "Can't start: null intent!");
+ stopSelf();
+ return START_NOT_STICKY;
+ }
+
+ Resources res = getResources();
+ Notification.Builder builder = new Notification.Builder(this)
+ .setSmallIcon(android.R.drawable.stat_sys_data_bluetooth)
+ .setTicker(res.getString(R.string.bluetooth_notif_ticker));
+
+ PendingIntent pending = PendingIntent.getActivity(this, 0,
+ getPairingDialogIntent(this, intent), PendingIntent.FLAG_ONE_SHOT);
+
+ mDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+
+ if (mDevice.getBondState() != BluetoothDevice.BOND_BONDING) {
+ Log.w(TAG, "Device " + mDevice + " not bonding: " + mDevice.getBondState());
+ stopSelf();
+ return START_NOT_STICKY;
+ }
+
+ String name = intent.getStringExtra(BluetoothDevice.EXTRA_NAME);
+ if (TextUtils.isEmpty(name)) {
+ BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+ name = device != null ? device.getAliasName() : getString(android.R.string.unknownName);
+ }
+
+ Log.d(TAG, "Show pairing notification for " + mDevice.getAddress() + " (" + name + ")");
+
+ builder.setContentTitle(res.getString(R.string.bluetooth_notif_title))
+ .setContentText(res.getString(R.string.bluetooth_notif_message, name))
+ .setContentIntent(pending)
+ .setDefaults(Notification.DEFAULT_SOUND)
+ .setColor(getColor(com.android.internal.R.color.system_notification_accent_color));
+
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
+ filter.addAction(BluetoothDevice.ACTION_PAIRING_CANCEL);
+ registerReceiver(mCancelReceiver, filter);
+
+ startForeground(NOTIFICATION_ID, builder.getNotification());
+ return START_REDELIVER_INTENT;
+ }
+
+ @Override
+ public void onDestroy() {
+ unregisterReceiver(mCancelReceiver);
+ stopForeground(true);
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ // No binding.
+ return null;
+ }
+
+}
diff --git a/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java b/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java
index fc6b876..e909afd 100644
--- a/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java
+++ b/src/com/android/settings/bluetooth/BluetoothPermissionRequest.java
@@ -118,13 +118,6 @@
context, deviceAddress, deviceName)) {
context.startActivity(connectionAccessIntent);
} else {
- // Acquire wakelock so that LCD comes up since screen is off
- PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK |
- PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
- "ConnectionAccessActivity");
- wakeLock.setReferenceCounted(false);
- wakeLock.acquire();
-
// Put up a notification that leads to the dialog
// Create an intent triggered by clicking on the
@@ -181,7 +174,6 @@
notificationManager.notify(getNotificationTag(mRequestType), NOTIFICATION_ID,
notification);
- wakeLock.release();
}
} else if (action.equals(BluetoothDevice.ACTION_CONNECTION_ACCESS_CANCEL)) {
// Remove the notification
diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java
index 71ebcb5..c352e47 100644
--- a/src/com/android/settings/bluetooth/BluetoothSettings.java
+++ b/src/com/android/settings/bluetooth/BluetoothSettings.java
@@ -77,6 +77,8 @@
/* Private intent to show the list of received files */
private static final String BTOPP_ACTION_OPEN_RECEIVED_FILES =
"android.btopp.intent.action.OPEN_RECEIVED_FILES";
+ private static final String BTOPP_PACKAGE =
+ "com.android.bluetooth";
private static final String KEY_PAIRED_DEVICES = "paired_devices";
@@ -180,13 +182,13 @@
}
@Override
- public void onResume() {
- // resume BluetoothEnabler before calling super.onResume() so we don't get
+ public void onStart() {
+ // resume BluetoothEnabler before calling super.onStart() so we don't get
// any onDeviceAdded() callbacks before setting up view in updateContent()
if (mBluetoothEnabler != null) {
mBluetoothEnabler.resume(getActivity());
}
- super.onResume();
+ super.onStart();
mInitiateDiscoverable = true;
@@ -206,8 +208,8 @@
}
@Override
- public void onPause() {
- super.onPause();
+ public void onStop() {
+ super.onStop();
if (mBluetoothEnabler != null) {
mBluetoothEnabler.pause();
}
@@ -262,6 +264,7 @@
case MENU_ID_SHOW_RECEIVED:
MetricsLogger.action(getActivity(), MetricsEvent.ACTION_BLUETOOTH_FILES);
Intent intent = new Intent(BTOPP_ACTION_OPEN_RECEIVED_FILES);
+ intent.setPackage(BTOPP_PACKAGE);
getActivity().sendBroadcast(intent);
return true;
}
diff --git a/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java b/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
index e6fcbcb..c132163 100644
--- a/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
+++ b/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
@@ -98,8 +98,8 @@
abstract void addPreferencesForActivity();
@Override
- public void onResume() {
- super.onResume();
+ public void onStart() {
+ super.onStart();
if (mLocalManager == null || isUiRestricted()) return;
mLocalManager.setForegroundActivity(getActivity());
@@ -109,8 +109,8 @@
}
@Override
- public void onPause() {
- super.onPause();
+ public void onStop() {
+ super.onStop();
if (mLocalManager == null || isUiRestricted()) {
return;
}
diff --git a/src/com/android/settings/bluetooth/DevicePickerFragment.java b/src/com/android/settings/bluetooth/DevicePickerFragment.java
index 09481ce..00c7316 100644
--- a/src/com/android/settings/bluetooth/DevicePickerFragment.java
+++ b/src/com/android/settings/bluetooth/DevicePickerFragment.java
@@ -47,7 +47,7 @@
private boolean mNeedAuth;
private String mLaunchPackage;
private String mLaunchClass;
- private boolean mStartScanOnResume;
+ private boolean mStartScanOnStart;
@Override
void addPreferencesForActivity() {
@@ -94,18 +94,18 @@
super.onCreate(savedInstanceState);
getActivity().setTitle(getString(R.string.device_picker));
UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
- mStartScanOnResume = !um.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH)
+ mStartScanOnStart = !um.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH)
&& (savedInstanceState == null); // don't start scan after rotation
setHasOptionsMenu(true);
}
@Override
- public void onResume() {
- super.onResume();
+ public void onStart() {
+ super.onStart();
addCachedDevices();
- if (mStartScanOnResume) {
+ if (mStartScanOnStart) {
mLocalAdapter.startScanning(true);
- mStartScanOnResume = false;
+ mStartScanOnStart = false;
}
}
diff --git a/src/com/android/settings/bluetooth/DockEventReceiver.java b/src/com/android/settings/bluetooth/DockEventReceiver.java
deleted file mode 100644
index 048b098..0000000
--- a/src/com/android/settings/bluetooth/DockEventReceiver.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * 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.bluetooth;
-
-import android.app.Service;
-import android.bluetooth.BluetoothA2dp;
-import android.bluetooth.BluetoothAdapter;
-import android.bluetooth.BluetoothDevice;
-import android.bluetooth.BluetoothHeadset;
-import android.bluetooth.BluetoothProfile;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.os.PowerManager;
-import android.util.Log;
-
-public final class DockEventReceiver extends BroadcastReceiver {
-
- private static final boolean DEBUG = DockService.DEBUG;
-
- private static final String TAG = "DockEventReceiver";
-
- public static final String ACTION_DOCK_SHOW_UI =
- "com.android.settings.bluetooth.action.DOCK_SHOW_UI";
-
- private static final int EXTRA_INVALID = -1234;
-
- private static final Object sStartingServiceSync = new Object();
-
- private static PowerManager.WakeLock sStartingService;
-
- @Override
- public void onReceive(Context context, Intent intent) {
- if (intent == null)
- return;
-
- int state = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, intent.getIntExtra(
- BluetoothAdapter.EXTRA_STATE, EXTRA_INVALID));
- BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
-
- if (DEBUG) {
- Log.d(TAG, "Action: " + intent.getAction() + " State:" + state + " Device: "
- + (device == null ? "null" : device.getAliasName()));
- }
-
- if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())
- || ACTION_DOCK_SHOW_UI.endsWith(intent.getAction())) {
- if ((device == null) && (ACTION_DOCK_SHOW_UI.endsWith(intent.getAction()) ||
- ((state != Intent.EXTRA_DOCK_STATE_UNDOCKED) &&
- (state != Intent.EXTRA_DOCK_STATE_LE_DESK)))) {
- if (DEBUG) Log.d(TAG,
- "Wrong state: "+state+" or intent: "+intent.toString()+" with null device");
- return;
- }
-
- switch (state) {
- case Intent.EXTRA_DOCK_STATE_UNDOCKED:
- case Intent.EXTRA_DOCK_STATE_CAR:
- case Intent.EXTRA_DOCK_STATE_DESK:
- case Intent.EXTRA_DOCK_STATE_LE_DESK:
- case Intent.EXTRA_DOCK_STATE_HE_DESK:
- Intent i = new Intent(intent);
- i.setClass(context, DockService.class);
- beginStartingService(context, i);
- break;
- default:
- Log.e(TAG, "Unknown state: " + state);
- break;
- }
- } else if (BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED.equals(intent.getAction()) ||
- BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED.equals(intent.getAction())) {
- int newState = intent.getIntExtra(BluetoothProfile.EXTRA_STATE,
- BluetoothProfile.STATE_CONNECTED);
- int oldState = intent.getIntExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, 0);
-
- /*
- * Reconnect to the dock if:
- * 1) it is a dock
- * 2) it is disconnected
- * 3) the disconnect is initiated remotely
- * 4) the dock is still docked (check can only be done in the Service)
- */
- if (device == null) {
- if (DEBUG) Log.d(TAG, "Device is missing");
- return;
- }
-
- if (newState == BluetoothProfile.STATE_DISCONNECTED &&
- oldState != BluetoothProfile.STATE_DISCONNECTING) {
- // Too bad, the dock state can't be checked from a BroadcastReceiver.
- Intent i = new Intent(intent);
- i.setClass(context, DockService.class);
- beginStartingService(context, i);
- }
-
- } else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(intent.getAction())) {
- int btState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
- if (btState != BluetoothAdapter.STATE_TURNING_ON) {
- Intent i = new Intent(intent);
- i.setClass(context, DockService.class);
- beginStartingService(context, i);
- }
- }
- }
-
- /**
- * Start the service to process the current event notifications, acquiring
- * the wake lock before returning to ensure that the service will run.
- */
- private static void beginStartingService(Context context, Intent intent) {
- synchronized (sStartingServiceSync) {
- if (sStartingService == null) {
- PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
- sStartingService = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
- "StartingDockService");
- }
-
- sStartingService.acquire();
-
- if (context.startService(intent) == null) {
- Log.e(TAG, "Can't start DockService");
- }
- }
- }
-
- /**
- * Called back by the service when it has finished processing notifications,
- * releasing the wake lock if the service is now stopping.
- */
- public static void finishStartingService(Service service, int startId) {
- synchronized (sStartingServiceSync) {
- if (sStartingService != null) {
- if (DEBUG) Log.d(TAG, "stopSelf id = " + startId);
- if (service.stopSelfResult(startId)) {
- Log.d(TAG, "finishStartingService: stopping service");
- sStartingService.release();
- }
- }
- }
- }
-}
diff --git a/src/com/android/settings/bluetooth/DockService.java b/src/com/android/settings/bluetooth/DockService.java
deleted file mode 100644
index 020ca0c..0000000
--- a/src/com/android/settings/bluetooth/DockService.java
+++ /dev/null
@@ -1,982 +0,0 @@
-/*
- * 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.bluetooth;
-
-import android.app.AlertDialog;
-import android.app.Notification;
-import android.app.Service;
-import android.bluetooth.BluetoothA2dp;
-import android.bluetooth.BluetoothAdapter;
-import android.bluetooth.BluetoothDevice;
-import android.bluetooth.BluetoothHeadset;
-import android.bluetooth.BluetoothProfile;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.SharedPreferences;
-import android.os.Handler;
-import android.os.HandlerThread;
-import android.os.IBinder;
-import android.os.Looper;
-import android.os.Message;
-import android.provider.Settings;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.WindowManager;
-import android.widget.CheckBox;
-import android.widget.CompoundButton;
-
-import com.android.settings.R;
-import com.android.settingslib.bluetooth.BluetoothCallback;
-import com.android.settingslib.bluetooth.CachedBluetoothDevice;
-import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
-import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
-import com.android.settingslib.bluetooth.LocalBluetoothManager;
-import com.android.settingslib.bluetooth.LocalBluetoothProfile;
-import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
-import com.android.settingslib.bluetooth.LocalBluetoothProfileManager.ServiceListener;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-
-public final class DockService extends Service implements ServiceListener {
-
- private static final String TAG = "DockService";
-
- static final boolean DEBUG = false;
-
- // Time allowed for the device to be undocked and redocked without severing
- // the bluetooth connection
- private static final long UNDOCKED_GRACE_PERIOD = 1000;
-
- // Time allowed for the device to be undocked and redocked without turning
- // off Bluetooth
- private static final long DISABLE_BT_GRACE_PERIOD = 2000;
-
- // Msg for user wanting the UI to setup the dock
- private static final int MSG_TYPE_SHOW_UI = 111;
-
- // Msg for device docked event
- private static final int MSG_TYPE_DOCKED = 222;
-
- // Msg for device undocked event
- private static final int MSG_TYPE_UNDOCKED_TEMPORARY = 333;
-
- // Msg for undocked command to be process after UNDOCKED_GRACE_PERIOD millis
- // since MSG_TYPE_UNDOCKED_TEMPORARY
- private static final int MSG_TYPE_UNDOCKED_PERMANENT = 444;
-
- // Msg for disabling bt after DISABLE_BT_GRACE_PERIOD millis since
- // MSG_TYPE_UNDOCKED_PERMANENT
- private static final int MSG_TYPE_DISABLE_BT = 555;
-
- private static final String SHARED_PREFERENCES_NAME = "dock_settings";
-
- private static final String KEY_DISABLE_BT_WHEN_UNDOCKED = "disable_bt_when_undock";
-
- private static final String KEY_DISABLE_BT = "disable_bt";
-
- private static final String KEY_CONNECT_RETRY_COUNT = "connect_retry_count";
-
- /*
- * If disconnected unexpectedly, reconnect up to 6 times. Each profile counts
- * as one time so it's only 3 times for both profiles on the car dock.
- */
- private static final int MAX_CONNECT_RETRY = 6;
-
- private static final int INVALID_STARTID = -100;
-
- // Created in OnCreate()
- private volatile Looper mServiceLooper;
- private volatile ServiceHandler mServiceHandler;
- private Runnable mRunnable;
- private LocalBluetoothAdapter mLocalAdapter;
- private CachedBluetoothDeviceManager mDeviceManager;
- private LocalBluetoothProfileManager mProfileManager;
-
- // Normally set after getting a docked event and unset when the connection
- // is severed. One exception is that mDevice could be null if the service
- // was started after the docked event.
- private BluetoothDevice mDevice;
-
- // Created and used for the duration of the dialog
- private AlertDialog mDialog;
- private LocalBluetoothProfile[] mProfiles;
- private boolean[] mCheckedItems;
- private int mStartIdAssociatedWithDialog;
-
- // Set while BT is being enabled.
- private BluetoothDevice mPendingDevice;
- private int mPendingStartId;
- private int mPendingTurnOnStartId = INVALID_STARTID;
- private int mPendingTurnOffStartId = INVALID_STARTID;
-
- private CheckBox mAudioMediaCheckbox;
-
- @Override
- public void onCreate() {
- if (DEBUG) Log.d(TAG, "onCreate");
-
- LocalBluetoothManager manager = Utils.getLocalBtManager(this);
- if (manager == null) {
- Log.e(TAG, "Can't get LocalBluetoothManager: exiting");
- return;
- }
-
- mLocalAdapter = manager.getBluetoothAdapter();
- mDeviceManager = manager.getCachedDeviceManager();
- mProfileManager = manager.getProfileManager();
- if (mProfileManager == null) {
- Log.e(TAG, "Can't get LocalBluetoothProfileManager: exiting");
- return;
- }
-
- HandlerThread thread = new HandlerThread("DockService");
- thread.start();
-
- mServiceLooper = thread.getLooper();
- mServiceHandler = new ServiceHandler(mServiceLooper);
- }
-
- @Override
- public void onDestroy() {
- if (DEBUG) Log.d(TAG, "onDestroy");
- mRunnable = null;
- if (mDialog != null) {
- mDialog.dismiss();
- mDialog = null;
- }
- if (mProfileManager != null) {
- mProfileManager.removeServiceListener(this);
- }
- if (mServiceLooper != null) {
- mServiceLooper.quit();
- }
-
- mLocalAdapter = null;
- mDeviceManager = null;
- mProfileManager = null;
- mServiceLooper = null;
- mServiceHandler = null;
- }
-
- @Override
- public IBinder onBind(Intent intent) {
- // not supported
- return null;
- }
-
- private SharedPreferences getPrefs() {
- return getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE);
- }
-
- @Override
- public int onStartCommand(Intent intent, int flags, int startId) {
- if (DEBUG) Log.d(TAG, "onStartCommand startId: " + startId + " flags: " + flags);
-
- if (intent == null) {
- // Nothing to process, stop.
- if (DEBUG) Log.d(TAG, "START_NOT_STICKY - intent is null.");
-
- // NOTE: We MUST not call stopSelf() directly, since we need to
- // make sure the wake lock acquired by the Receiver is released.
- DockEventReceiver.finishStartingService(this, startId);
- return START_NOT_STICKY;
- }
-
- if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(intent.getAction())) {
- handleBtStateChange(intent, startId);
- return START_NOT_STICKY;
- }
-
- /*
- * This assumes that the intent sender has checked that this is a dock
- * and that the intent is for a disconnect
- */
- final SharedPreferences prefs = getPrefs();
- if (BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED.equals(intent.getAction())) {
- BluetoothDevice disconnectedDevice = intent
- .getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
- int retryCount = prefs.getInt(KEY_CONNECT_RETRY_COUNT, 0);
- if (retryCount < MAX_CONNECT_RETRY) {
- prefs.edit().putInt(KEY_CONNECT_RETRY_COUNT, retryCount + 1).apply();
- handleUnexpectedDisconnect(disconnectedDevice, mProfileManager.getHeadsetProfile(), startId);
- }
- return START_NOT_STICKY;
- } else if (BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED.equals(intent.getAction())) {
- BluetoothDevice disconnectedDevice = intent
- .getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
-
- int retryCount = prefs.getInt(KEY_CONNECT_RETRY_COUNT, 0);
- if (retryCount < MAX_CONNECT_RETRY) {
- prefs.edit().putInt(KEY_CONNECT_RETRY_COUNT, retryCount + 1).apply();
- handleUnexpectedDisconnect(disconnectedDevice, mProfileManager.getA2dpProfile(), startId);
- }
- return START_NOT_STICKY;
- }
-
- Message msg = parseIntent(intent);
- if (msg == null) {
- // Bad intent
- if (DEBUG) Log.d(TAG, "START_NOT_STICKY - Bad intent.");
- DockEventReceiver.finishStartingService(this, startId);
- return START_NOT_STICKY;
- }
-
- if (msg.what == MSG_TYPE_DOCKED) {
- prefs.edit().remove(KEY_CONNECT_RETRY_COUNT).apply();
- }
-
- msg.arg2 = startId;
- processMessage(msg);
-
- return START_NOT_STICKY;
- }
-
- private final class ServiceHandler extends Handler {
- private ServiceHandler(Looper looper) {
- super(looper);
- }
-
- @Override
- public void handleMessage(Message msg) {
- processMessage(msg);
- }
- }
-
- // This method gets messages from both onStartCommand and mServiceHandler/mServiceLooper
- private synchronized void processMessage(Message msg) {
- int msgType = msg.what;
- final int state = msg.arg1;
- final int startId = msg.arg2;
- BluetoothDevice device = null;
- if (msg.obj != null) {
- device = (BluetoothDevice) msg.obj;
- }
-
- if(DEBUG) Log.d(TAG, "processMessage: " + msgType + " state: " + state + " device = "
- + (device == null ? "null" : device.toString()));
-
- boolean deferFinishCall = false;
-
- switch (msgType) {
- case MSG_TYPE_SHOW_UI:
- if (device != null) {
- createDialog(device, state, startId);
- }
- break;
-
- case MSG_TYPE_DOCKED:
- deferFinishCall = msgTypeDocked(device, state, startId);
- break;
-
- case MSG_TYPE_UNDOCKED_PERMANENT:
- deferFinishCall = msgTypeUndockedPermanent(device, startId);
- break;
-
- case MSG_TYPE_UNDOCKED_TEMPORARY:
- msgTypeUndockedTemporary(device, state, startId);
- break;
-
- case MSG_TYPE_DISABLE_BT:
- deferFinishCall = msgTypeDisableBluetooth(startId);
- break;
- }
-
- if (mDialog == null && mPendingDevice == null && msgType != MSG_TYPE_UNDOCKED_TEMPORARY
- && !deferFinishCall) {
- // NOTE: We MUST not call stopSelf() directly, since we need to
- // make sure the wake lock acquired by the Receiver is released.
- DockEventReceiver.finishStartingService(this, startId);
- }
- }
-
- private boolean msgTypeDisableBluetooth(int startId) {
- if (DEBUG) {
- Log.d(TAG, "BT DISABLE");
- }
- final SharedPreferences prefs = getPrefs();
- if (mLocalAdapter.disable()) {
- prefs.edit().remove(KEY_DISABLE_BT_WHEN_UNDOCKED).apply();
- return false;
- } else {
- // disable() returned an error. Persist a flag to disable BT later
- prefs.edit().putBoolean(KEY_DISABLE_BT, true).apply();
- mPendingTurnOffStartId = startId;
- if(DEBUG) {
- Log.d(TAG, "disable failed. try again later " + startId);
- }
- return true;
- }
- }
-
- private void msgTypeUndockedTemporary(BluetoothDevice device, int state,
- int startId) {
- // Undocked event received. Queue a delayed msg to sever connection
- Message newMsg = mServiceHandler.obtainMessage(MSG_TYPE_UNDOCKED_PERMANENT, state,
- startId, device);
- mServiceHandler.sendMessageDelayed(newMsg, UNDOCKED_GRACE_PERIOD);
- }
-
- private boolean msgTypeUndockedPermanent(BluetoothDevice device, int startId) {
- // Grace period passed. Disconnect.
- handleUndocked(device);
- if (device != null) {
- final SharedPreferences prefs = getPrefs();
-
- if (DEBUG) {
- Log.d(TAG, "DISABLE_BT_WHEN_UNDOCKED = "
- + prefs.getBoolean(KEY_DISABLE_BT_WHEN_UNDOCKED, false));
- }
-
- if (prefs.getBoolean(KEY_DISABLE_BT_WHEN_UNDOCKED, false)) {
- if (hasOtherConnectedDevices(device)) {
- // Don't disable BT if something is connected
- prefs.edit().remove(KEY_DISABLE_BT_WHEN_UNDOCKED).apply();
- } else {
- // BT was disabled when we first docked
- if (DEBUG) {
- Log.d(TAG, "QUEUED BT DISABLE");
- }
- // Queue a delayed msg to disable BT
- Message newMsg = mServiceHandler.obtainMessage(
- MSG_TYPE_DISABLE_BT, 0, startId, null);
- mServiceHandler.sendMessageDelayed(newMsg,
- DISABLE_BT_GRACE_PERIOD);
- return true;
- }
- }
- }
- return false;
- }
-
- private boolean msgTypeDocked(BluetoothDevice device, final int state,
- final int startId) {
- if (DEBUG) {
- // TODO figure out why hasMsg always returns false if device
- // is supplied
- Log.d(TAG, "1 Has undock perm msg = "
- + mServiceHandler.hasMessages(MSG_TYPE_UNDOCKED_PERMANENT, mDevice));
- Log.d(TAG, "2 Has undock perm msg = "
- + mServiceHandler.hasMessages(MSG_TYPE_UNDOCKED_PERMANENT, device));
- }
-
- mServiceHandler.removeMessages(MSG_TYPE_UNDOCKED_PERMANENT);
- mServiceHandler.removeMessages(MSG_TYPE_DISABLE_BT);
- getPrefs().edit().remove(KEY_DISABLE_BT).apply();
-
- if (device != null) {
- if (!device.equals(mDevice)) {
- if (mDevice != null) {
- // Not expected. Cleanup/undock existing
- handleUndocked(mDevice);
- }
-
- mDevice = device;
-
- // Register first in case LocalBluetoothProfileManager
- // becomes ready after isManagerReady is called and it
- // would be too late to register a service listener.
- mProfileManager.addServiceListener(this);
- if (mProfileManager.isManagerReady()) {
- handleDocked(device, state, startId);
- // Not needed after all
- mProfileManager.removeServiceListener(this);
- } else {
- final BluetoothDevice d = device;
- mRunnable = new Runnable() {
- public void run() {
- handleDocked(d, state, startId); // FIXME: WTF runnable here?
- }
- };
- return true;
- }
- }
- } else {
- // display dialog to enable dock for media audio only in the case of low end docks and
- // if not already selected by user
- int dockAudioMediaEnabled = Settings.Global.getInt(getContentResolver(),
- Settings.Global.DOCK_AUDIO_MEDIA_ENABLED, -1);
- if (dockAudioMediaEnabled == -1 &&
- state == Intent.EXTRA_DOCK_STATE_LE_DESK) {
- handleDocked(null, state, startId);
- return true;
- }
- }
- return false;
- }
-
- synchronized boolean hasOtherConnectedDevices(BluetoothDevice dock) {
- Collection<CachedBluetoothDevice> cachedDevices = mDeviceManager.getCachedDevicesCopy();
- Set<BluetoothDevice> btDevices = mLocalAdapter.getBondedDevices();
- if (btDevices == null || cachedDevices == null || btDevices.isEmpty()) {
- return false;
- }
- if(DEBUG) {
- Log.d(TAG, "btDevices = " + btDevices.size());
- Log.d(TAG, "cachedDeviceUIs = " + cachedDevices.size());
- }
-
- for (CachedBluetoothDevice deviceUI : cachedDevices) {
- BluetoothDevice btDevice = deviceUI.getDevice();
- if (!btDevice.equals(dock) && btDevices.contains(btDevice) && deviceUI
- .isConnected()) {
- if(DEBUG) Log.d(TAG, "connected deviceUI = " + deviceUI.getName());
- return true;
- }
- }
- return false;
- }
-
- private Message parseIntent(Intent intent) {
- BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
- int state = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, -1234);
-
- if (DEBUG) {
- Log.d(TAG, "Action: " + intent.getAction() + " State:" + state
- + " Device: " + (device == null ? "null" : device.getAliasName()));
- }
-
- int msgType;
- switch (state) {
- case Intent.EXTRA_DOCK_STATE_UNDOCKED:
- msgType = MSG_TYPE_UNDOCKED_TEMPORARY;
- break;
- case Intent.EXTRA_DOCK_STATE_DESK:
- case Intent.EXTRA_DOCK_STATE_HE_DESK:
- case Intent.EXTRA_DOCK_STATE_CAR:
- if (device == null) {
- Log.w(TAG, "device is null");
- return null;
- }
- /// Fall Through ///
- case Intent.EXTRA_DOCK_STATE_LE_DESK:
- if (DockEventReceiver.ACTION_DOCK_SHOW_UI.equals(intent.getAction())) {
- if (device == null) {
- Log.w(TAG, "device is null");
- return null;
- }
- msgType = MSG_TYPE_SHOW_UI;
- } else {
- msgType = MSG_TYPE_DOCKED;
- }
- break;
- default:
- return null;
- }
-
- return mServiceHandler.obtainMessage(msgType, state, 0, device);
- }
-
- private void createDialog(BluetoothDevice device,
- int state, int startId) {
- if (mDialog != null) {
- // Shouldn't normally happen
- mDialog.dismiss();
- mDialog = null;
- }
- mDevice = device;
- switch (state) {
- case Intent.EXTRA_DOCK_STATE_CAR:
- case Intent.EXTRA_DOCK_STATE_DESK:
- case Intent.EXTRA_DOCK_STATE_LE_DESK:
- case Intent.EXTRA_DOCK_STATE_HE_DESK:
- break;
- default:
- return;
- }
-
- startForeground(0, new Notification());
-
- final AlertDialog.Builder ab = new AlertDialog.Builder(this);
- View view;
- LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
-
- mAudioMediaCheckbox = null;
-
- if (device != null) {
- // Device in a new dock.
- boolean firstTime =
- !LocalBluetoothPreferences.hasDockAutoConnectSetting(this, device.getAddress());
-
- CharSequence[] items = initBtSettings(device, state, firstTime);
-
- ab.setTitle(getString(R.string.bluetooth_dock_settings_title));
-
- // Profiles
- ab.setMultiChoiceItems(items, mCheckedItems, mMultiClickListener);
-
- // Remember this settings
- view = inflater.inflate(R.layout.remember_dock_setting, null);
- CheckBox rememberCheckbox = (CheckBox) view.findViewById(R.id.remember);
-
- // check "Remember setting" by default if no value was saved
- boolean checked = firstTime ||
- LocalBluetoothPreferences.getDockAutoConnectSetting(this, device.getAddress());
- rememberCheckbox.setChecked(checked);
- rememberCheckbox.setOnCheckedChangeListener(mCheckedChangeListener);
- if (DEBUG) {
- Log.d(TAG, "Auto connect = "
- + LocalBluetoothPreferences.getDockAutoConnectSetting(this, device.getAddress()));
- }
- } else {
- ab.setTitle(getString(R.string.bluetooth_dock_settings_title));
-
- view = inflater.inflate(R.layout.dock_audio_media_enable_dialog, null);
- mAudioMediaCheckbox =
- (CheckBox) view.findViewById(R.id.dock_audio_media_enable_cb);
-
- boolean checked = Settings.Global.getInt(getContentResolver(),
- Settings.Global.DOCK_AUDIO_MEDIA_ENABLED, 0) == 1;
-
- mAudioMediaCheckbox.setChecked(checked);
- mAudioMediaCheckbox.setOnCheckedChangeListener(mCheckedChangeListener);
- }
-
- float pixelScaleFactor = getResources().getDisplayMetrics().density;
- int viewSpacingLeft = (int) (14 * pixelScaleFactor);
- int viewSpacingRight = (int) (14 * pixelScaleFactor);
- ab.setView(view, viewSpacingLeft, 0 /* top */, viewSpacingRight, 0 /* bottom */);
-
- // Ok Button
- ab.setPositiveButton(getString(android.R.string.ok), mClickListener);
-
- mStartIdAssociatedWithDialog = startId;
- mDialog = ab.create();
- mDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
- mDialog.setOnDismissListener(mDismissListener);
- mDialog.show();
- }
-
- // Called when the individual bt profiles are clicked.
- private final DialogInterface.OnMultiChoiceClickListener mMultiClickListener =
- new DialogInterface.OnMultiChoiceClickListener() {
- public void onClick(DialogInterface dialog, int which, boolean isChecked) {
- if (DEBUG) {
- Log.d(TAG, "Item " + which + " changed to " + isChecked);
- }
- mCheckedItems[which] = isChecked;
- }
- };
-
-
- // Called when the "Remember" Checkbox is clicked
- private final CompoundButton.OnCheckedChangeListener mCheckedChangeListener =
- new CompoundButton.OnCheckedChangeListener() {
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if (DEBUG) {
- Log.d(TAG, "onCheckedChanged: Remember Settings = " + isChecked);
- }
- if (mDevice != null) {
- LocalBluetoothPreferences.saveDockAutoConnectSetting(
- DockService.this, mDevice.getAddress(), isChecked);
- } else {
- Settings.Global.putInt(getContentResolver(),
- Settings.Global.DOCK_AUDIO_MEDIA_ENABLED, isChecked ? 1 : 0);
- }
- }
- };
-
-
- // Called when the dialog is dismissed
- private final DialogInterface.OnDismissListener mDismissListener =
- new DialogInterface.OnDismissListener() {
- public void onDismiss(DialogInterface dialog) {
- // NOTE: We MUST not call stopSelf() directly, since we need to
- // make sure the wake lock acquired by the Receiver is released.
- if (mPendingDevice == null) {
- DockEventReceiver.finishStartingService(
- DockService.this, mStartIdAssociatedWithDialog);
- }
- stopForeground(true);
- }
- };
-
- // Called when clicked on the OK button
- private final DialogInterface.OnClickListener mClickListener =
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- if (which == DialogInterface.BUTTON_POSITIVE) {
- if (mDevice != null) {
- if (!LocalBluetoothPreferences
- .hasDockAutoConnectSetting(
- DockService.this,
- mDevice.getAddress())) {
- LocalBluetoothPreferences
- .saveDockAutoConnectSetting(
- DockService.this,
- mDevice.getAddress(), true);
- }
-
- applyBtSettings(mDevice, mStartIdAssociatedWithDialog);
- } else if (mAudioMediaCheckbox != null) {
- Settings.Global.putInt(getContentResolver(),
- Settings.Global.DOCK_AUDIO_MEDIA_ENABLED,
- mAudioMediaCheckbox.isChecked() ? 1 : 0);
- }
- }
- }
- };
-
- private CharSequence[] initBtSettings(BluetoothDevice device,
- int state, boolean firstTime) {
- // TODO Avoid hardcoding dock and profiles. Read from system properties
- int numOfProfiles;
- switch (state) {
- case Intent.EXTRA_DOCK_STATE_DESK:
- case Intent.EXTRA_DOCK_STATE_LE_DESK:
- case Intent.EXTRA_DOCK_STATE_HE_DESK:
- numOfProfiles = 1;
- break;
- case Intent.EXTRA_DOCK_STATE_CAR:
- numOfProfiles = 2;
- break;
- default:
- return null;
- }
-
- mProfiles = new LocalBluetoothProfile[numOfProfiles];
- mCheckedItems = new boolean[numOfProfiles];
- CharSequence[] items = new CharSequence[numOfProfiles];
-
- // FIXME: convert switch to something else
- switch (state) {
- case Intent.EXTRA_DOCK_STATE_CAR:
- items[0] = getString(R.string.bluetooth_dock_settings_headset);
- items[1] = getString(R.string.bluetooth_dock_settings_a2dp);
- mProfiles[0] = mProfileManager.getHeadsetProfile();
- mProfiles[1] = mProfileManager.getA2dpProfile();
- if (firstTime) {
- // Enable by default for car dock
- mCheckedItems[0] = true;
- mCheckedItems[1] = true;
- } else {
- mCheckedItems[0] = mProfiles[0].isPreferred(device);
- mCheckedItems[1] = mProfiles[1].isPreferred(device);
- }
- break;
-
- case Intent.EXTRA_DOCK_STATE_DESK:
- case Intent.EXTRA_DOCK_STATE_LE_DESK:
- case Intent.EXTRA_DOCK_STATE_HE_DESK:
- items[0] = getString(R.string.bluetooth_dock_settings_a2dp);
- mProfiles[0] = mProfileManager.getA2dpProfile();
- if (firstTime) {
- // Disable by default for desk dock
- mCheckedItems[0] = false;
- } else {
- mCheckedItems[0] = mProfiles[0].isPreferred(device);
- }
- break;
- }
- return items;
- }
-
- // TODO: move to background thread to fix strict mode warnings
- private void handleBtStateChange(Intent intent, int startId) {
- int btState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
- synchronized (this) {
- if(DEBUG) Log.d(TAG, "BtState = " + btState + " mPendingDevice = " + mPendingDevice);
- if (btState == BluetoothAdapter.STATE_ON) {
- handleBluetoothStateOn(startId);
- } else if (btState == BluetoothAdapter.STATE_TURNING_OFF) {
- // Remove the flag to disable BT if someone is turning off bt.
- // The rational is that:
- // a) if BT is off at undock time, no work needs to be done
- // b) if BT is on at undock time, the user wants it on.
- getPrefs().edit().remove(KEY_DISABLE_BT_WHEN_UNDOCKED).apply();
- DockEventReceiver.finishStartingService(this, startId);
- } else if (btState == BluetoothAdapter.STATE_OFF) {
- // Bluetooth was turning off as we were trying to turn it on.
- // Let's try again
- if(DEBUG) Log.d(TAG, "Bluetooth = OFF mPendingDevice = " + mPendingDevice);
-
- if (mPendingTurnOffStartId != INVALID_STARTID) {
- DockEventReceiver.finishStartingService(this, mPendingTurnOffStartId);
- getPrefs().edit().remove(KEY_DISABLE_BT).apply();
- mPendingTurnOffStartId = INVALID_STARTID;
- }
-
- if (mPendingDevice != null) {
- mLocalAdapter.enable();
- mPendingTurnOnStartId = startId;
- } else {
- DockEventReceiver.finishStartingService(this, startId);
- }
- }
- }
- }
-
- private void handleBluetoothStateOn(int startId) {
- if (mPendingDevice != null) {
- if (mPendingDevice.equals(mDevice)) {
- if(DEBUG) {
- Log.d(TAG, "applying settings");
- }
- applyBtSettings(mPendingDevice, mPendingStartId);
- } else if(DEBUG) {
- Log.d(TAG, "mPendingDevice (" + mPendingDevice + ") != mDevice ("
- + mDevice + ')');
- }
-
- mPendingDevice = null;
- DockEventReceiver.finishStartingService(this, mPendingStartId);
- } else {
- final SharedPreferences prefs = getPrefs();
- if (DEBUG) {
- Log.d(TAG, "A DISABLE_BT_WHEN_UNDOCKED = "
- + prefs.getBoolean(KEY_DISABLE_BT_WHEN_UNDOCKED, false));
- }
- // Reconnect if docked and bluetooth was enabled by user.
- Intent i = registerReceiver(null, new IntentFilter(Intent.ACTION_DOCK_EVENT));
- if (i != null) {
- int state = i.getIntExtra(Intent.EXTRA_DOCK_STATE,
- Intent.EXTRA_DOCK_STATE_UNDOCKED);
- if (state != Intent.EXTRA_DOCK_STATE_UNDOCKED) {
- BluetoothDevice device = i
- .getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
- if (device != null) {
- connectIfEnabled(device);
- }
- } else if (prefs.getBoolean(KEY_DISABLE_BT, false)
- && mLocalAdapter.disable()) {
- mPendingTurnOffStartId = startId;
- prefs.edit().remove(KEY_DISABLE_BT).apply();
- return;
- }
- }
- }
-
- if (mPendingTurnOnStartId != INVALID_STARTID) {
- DockEventReceiver.finishStartingService(this, mPendingTurnOnStartId);
- mPendingTurnOnStartId = INVALID_STARTID;
- }
-
- DockEventReceiver.finishStartingService(this, startId);
- }
-
- private synchronized void handleUnexpectedDisconnect(BluetoothDevice disconnectedDevice,
- LocalBluetoothProfile profile, int startId) {
- if (DEBUG) {
- Log.d(TAG, "handling failed connect for " + disconnectedDevice);
- }
-
- // Reconnect if docked.
- if (disconnectedDevice != null) {
- // registerReceiver can't be called from a BroadcastReceiver
- Intent intent = registerReceiver(null, new IntentFilter(Intent.ACTION_DOCK_EVENT));
- if (intent != null) {
- int state = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
- Intent.EXTRA_DOCK_STATE_UNDOCKED);
- if (state != Intent.EXTRA_DOCK_STATE_UNDOCKED) {
- BluetoothDevice dockedDevice = intent
- .getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
- if (dockedDevice != null && dockedDevice.equals(disconnectedDevice)) {
- CachedBluetoothDevice cachedDevice = getCachedBluetoothDevice(
- dockedDevice);
- cachedDevice.connectProfile(profile);
- }
- }
- }
- }
-
- DockEventReceiver.finishStartingService(this, startId);
- }
-
- private synchronized void connectIfEnabled(BluetoothDevice device) {
- CachedBluetoothDevice cachedDevice = getCachedBluetoothDevice(
- device);
- List<LocalBluetoothProfile> profiles = cachedDevice.getConnectableProfiles();
- for (LocalBluetoothProfile profile : profiles) {
- if (profile.getPreferred(device) == BluetoothProfile.PRIORITY_AUTO_CONNECT) {
- cachedDevice.connect(false);
- return;
- }
- }
- }
-
- private synchronized void applyBtSettings(BluetoothDevice device, int startId) {
- if (device == null || mProfiles == null || mCheckedItems == null
- || mLocalAdapter == null) {
- return;
- }
-
- // Turn on BT if something is enabled
- for (boolean enable : mCheckedItems) {
- if (enable) {
- int btState = mLocalAdapter.getBluetoothState();
- if (DEBUG) {
- Log.d(TAG, "BtState = " + btState);
- }
- // May have race condition as the phone comes in and out and in the dock.
- // Always turn on BT
- mLocalAdapter.enable();
-
- // if adapter was previously OFF, TURNING_OFF, or TURNING_ON
- if (btState != BluetoothAdapter.STATE_ON) {
- if (mPendingDevice != null && mPendingDevice.equals(mDevice)) {
- return;
- }
-
- mPendingDevice = device;
- mPendingStartId = startId;
- if (btState != BluetoothAdapter.STATE_TURNING_ON) {
- getPrefs().edit().putBoolean(
- KEY_DISABLE_BT_WHEN_UNDOCKED, true).apply();
- }
- return;
- }
- }
- }
-
- mPendingDevice = null;
-
- boolean callConnect = false;
- CachedBluetoothDevice cachedDevice = getCachedBluetoothDevice(
- device);
- for (int i = 0; i < mProfiles.length; i++) {
- LocalBluetoothProfile profile = mProfiles[i];
- if (DEBUG) Log.d(TAG, profile.toString() + " = " + mCheckedItems[i]);
-
- if (mCheckedItems[i]) {
- // Checked but not connected
- callConnect = true;
- } else if (!mCheckedItems[i]) {
- // Unchecked, may or may not be connected.
- int status = profile.getConnectionStatus(cachedDevice.getDevice());
- if (status == BluetoothProfile.STATE_CONNECTED) {
- if (DEBUG) Log.d(TAG, "applyBtSettings - Disconnecting");
- cachedDevice.disconnect(mProfiles[i]);
- }
- }
- profile.setPreferred(device, mCheckedItems[i]);
- if (DEBUG) {
- if (mCheckedItems[i] != profile.isPreferred(device)) {
- Log.e(TAG, "Can't save preferred value");
- }
- }
- }
-
- if (callConnect) {
- if (DEBUG) Log.d(TAG, "applyBtSettings - Connecting");
- cachedDevice.connect(false);
- }
- }
-
- private synchronized void handleDocked(BluetoothDevice device, int state,
- int startId) {
- if (device != null &&
- LocalBluetoothPreferences.getDockAutoConnectSetting(this, device.getAddress())) {
- // Setting == auto connect
- initBtSettings(device, state, false);
- applyBtSettings(mDevice, startId);
- } else {
- createDialog(device, state, startId);
- }
- }
-
- private synchronized void handleUndocked(BluetoothDevice device) {
- mRunnable = null;
- mProfileManager.removeServiceListener(this);
- if (mDialog != null) {
- mDialog.dismiss();
- mDialog = null;
- }
- mDevice = null;
- mPendingDevice = null;
- if (device != null) {
- CachedBluetoothDevice cachedDevice = getCachedBluetoothDevice(device);
- cachedDevice.disconnect();
- }
- }
-
- private CachedBluetoothDevice getCachedBluetoothDevice(BluetoothDevice device) {
- CachedBluetoothDevice cachedDevice = mDeviceManager.findDevice(device);
- if (cachedDevice == null) {
- cachedDevice = mDeviceManager.addDevice(mLocalAdapter, mProfileManager, device);
- }
- return cachedDevice;
- }
-
- public synchronized void onServiceConnected() {
- if (mRunnable != null) {
- mRunnable.run();
- mRunnable = null;
- mProfileManager.removeServiceListener(this);
- }
- }
-
- public void onServiceDisconnected() {
- // FIXME: shouldn't I do something on service disconnected too?
- }
-
- public static class DockBluetoothCallback implements BluetoothCallback {
- private final Context mContext;
-
- public DockBluetoothCallback(Context context) {
- mContext = context;
- }
-
- public void onBluetoothStateChanged(int bluetoothState) { }
- public void onDeviceAdded(CachedBluetoothDevice cachedDevice) { }
- public void onDeviceDeleted(CachedBluetoothDevice cachedDevice) { }
- public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) { }
-
- @Override
- public void onScanningStateChanged(boolean started) {
- // TODO: Find a more unified place for a persistent BluetoothCallback to live
- // as this is not exactly dock related.
- LocalBluetoothPreferences.persistDiscoveringTimestamp(mContext);
- }
-
- @Override
- public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
- BluetoothDevice device = cachedDevice.getDevice();
- if (bondState == BluetoothDevice.BOND_NONE) {
- if (device.isBluetoothDock()) {
- // After a dock is unpaired, we will forget the settings
- LocalBluetoothPreferences
- .removeDockAutoConnectSetting(mContext, device.getAddress());
-
- // if the device is undocked, remove it from the list as well
- if (!device.getAddress().equals(getDockedDeviceAddress(mContext))) {
- cachedDevice.setVisible(false);
- }
- }
- }
- }
-
- // This can't be called from a broadcast receiver where the filter is set in the Manifest.
- private static String getDockedDeviceAddress(Context context) {
- // This works only because these broadcast intents are "sticky"
- Intent i = context.registerReceiver(null, new IntentFilter(Intent.ACTION_DOCK_EVENT));
- if (i != null) {
- int state = i.getIntExtra(Intent.EXTRA_DOCK_STATE, Intent.EXTRA_DOCK_STATE_UNDOCKED);
- if (state != Intent.EXTRA_DOCK_STATE_UNDOCKED) {
- BluetoothDevice device = i.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
- if (device != null) {
- return device.getAddress();
- }
- }
- }
- return null;
- }
- }
-}
diff --git a/src/com/android/settings/bluetooth/LocalBluetoothPreferences.java b/src/com/android/settings/bluetooth/LocalBluetoothPreferences.java
index 401b13c..19eb200 100644
--- a/src/com/android/settings/bluetooth/LocalBluetoothPreferences.java
+++ b/src/com/android/settings/bluetooth/LocalBluetoothPreferences.java
@@ -40,14 +40,10 @@
// of raising notifications
private static final int GRACE_PERIOD_TO_SHOW_DIALOGS_IN_FOREGROUND = 60 * 1000;
- private static final String KEY_DISCOVERING_TIMESTAMP = "last_discovering_time";
-
private static final String KEY_LAST_SELECTED_DEVICE = "last_selected_device";
private static final String KEY_LAST_SELECTED_DEVICE_TIME = "last_selected_device_time";
- private static final String KEY_DOCK_AUTO_CONNECT = "auto_connect_to_dock";
-
private static final String KEY_DISCOVERABLE_END_TIMESTAMP = "discoverable_end_timestamp";
private LocalBluetoothPreferences() {
@@ -95,11 +91,14 @@
// If the device was discoverING recently
LocalBluetoothAdapter adapter = manager.getBluetoothAdapter();
- if (adapter != null && adapter.isDiscovering()) {
- return true;
- } else if ((sharedPreferences.getLong(KEY_DISCOVERING_TIMESTAMP, 0) +
+ if (adapter != null) {
+ if (adapter.isDiscovering()) {
+ return true;
+ }
+ if ((adapter.getDiscoveryEndMillis() +
GRACE_PERIOD_TO_SHOW_DIALOGS_IN_FOREGROUND) > currentTimeMillis) {
- return true;
+ return true;
+ }
}
// If the device was picked in the device picker recently
@@ -146,39 +145,4 @@
editor.putLong(KEY_DISCOVERABLE_END_TIMESTAMP, endTimestamp);
editor.apply();
}
-
- static void persistDiscoveringTimestamp(final Context context) {
- // Load the shared preferences and edit it on a background
- // thread (but serialized!).
- QueuedWork.singleThreadExecutor().submit(new Runnable() {
- public void run() {
- SharedPreferences.Editor editor = getSharedPreferences(context).edit();
- editor.putLong(
- KEY_DISCOVERING_TIMESTAMP,
- System.currentTimeMillis());
- editor.apply();
- }
- });
- }
-
- static boolean hasDockAutoConnectSetting(Context context, String addr) {
- return getSharedPreferences(context).contains(KEY_DOCK_AUTO_CONNECT + addr);
- }
-
- static boolean getDockAutoConnectSetting(Context context, String addr) {
- return getSharedPreferences(context).getBoolean(KEY_DOCK_AUTO_CONNECT + addr,
- false);
- }
-
- static void saveDockAutoConnectSetting(Context context, String addr, boolean autoConnect) {
- SharedPreferences.Editor editor = getSharedPreferences(context).edit();
- editor.putBoolean(KEY_DOCK_AUTO_CONNECT + addr, autoConnect);
- editor.apply();
- }
-
- static void removeDockAutoConnectSetting(Context context, String addr) {
- SharedPreferences.Editor editor = getSharedPreferences(context).edit();
- editor.remove(KEY_DOCK_AUTO_CONNECT + addr);
- editor.apply();
- }
}
diff --git a/src/com/android/settings/bluetooth/Utils.java b/src/com/android/settings/bluetooth/Utils.java
index 2cbe473..b74191e 100755
--- a/src/com/android/settings/bluetooth/Utils.java
+++ b/src/com/android/settings/bluetooth/Utils.java
@@ -23,7 +23,6 @@
import android.widget.Toast;
import com.android.settings.R;
-import com.android.settings.bluetooth.DockService.DockBluetoothCallback;
import com.android.settings.search.Index;
import com.android.settings.search.SearchIndexableRaw;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -84,11 +83,6 @@
// TODO: wire this up to show connection errors...
static void showConnectingError(Context context, String name) {
- // if (!mIsConnectingErrorPossible) {
- // return;
- // }
- // mIsConnectingErrorPossible = false;
-
showError(context, name, R.string.bluetooth_connecting_error_message);
}
@@ -137,8 +131,6 @@
@Override
public void onBluetoothManagerInitialized(Context appContext,
LocalBluetoothManager bluetoothManager) {
- bluetoothManager.getEventManager().registerCallback(
- new DockBluetoothCallback(appContext));
com.android.settingslib.bluetooth.Utils.setErrorListener(mErrorListener);
}
};
diff --git a/src/com/android/settings/datausage/AppDataUsage.java b/src/com/android/settings/datausage/AppDataUsage.java
index 45fdc1d..6400b53 100644
--- a/src/com/android/settings/datausage/AppDataUsage.java
+++ b/src/com/android/settings/datausage/AppDataUsage.java
@@ -49,6 +49,7 @@
import com.android.settingslib.Utils;
import com.android.settingslib.net.ChartData;
import com.android.settingslib.net.ChartDataLoader;
+import com.android.settingslib.net.UidDetail;
import com.android.settingslib.net.UidDetailProvider;
import java.util.concurrent.BlockingQueue;
@@ -207,19 +208,12 @@
removePreference(KEY_APP_LIST);
}
} else {
- if (mAppItem.key == TrafficStats.UID_REMOVED) {
- mLabel = getContext().getString(R.string.data_usage_uninstalled_apps_users);
- } else if (mAppItem.key == TrafficStats.UID_TETHERING) {
- mLabel = getContext().getString(R.string.tether_settings_title_all);
- } else {
- final int userId = UidDetailProvider.getUserIdForKey(mAppItem.key);
- final UserManager um = UserManager.get(getActivity());
- final UserInfo info = um.getUserInfo(userId);
- final PackageManager pm = getPackageManager();
- mIcon = Utils.getUserIcon(getActivity(), um, info);
- mLabel = Utils.getUserLabel(getActivity(), info);
- mPackageName = getActivity().getPackageName();
- }
+ final Context context = getActivity();
+ UidDetail uidDetail = new UidDetailProvider(context).getUidDetail(mAppItem.key, true);
+ mIcon = uidDetail.icon;
+ mLabel = uidDetail.label;
+ mPackageName = context.getPackageName();
+
removePreference(KEY_UNRESTRICTED_DATA);
removePreference(KEY_APP_SETTINGS);
removePreference(KEY_RESTRICT_BACKGROUND);
diff --git a/src/com/android/settings/datausage/DataUsageList.java b/src/com/android/settings/datausage/DataUsageList.java
index 7ac81f5..eda78a9 100644
--- a/src/com/android/settings/datausage/DataUsageList.java
+++ b/src/com/android/settings/datausage/DataUsageList.java
@@ -476,7 +476,7 @@
final ConnectivityManager conn = ConnectivityManager.from(context);
final TelephonyManager tele = TelephonyManager.from(context);
- final int slotId = SubscriptionManager.getSlotId(subId);
+ final int slotId = SubscriptionManager.getSlotIndex(subId);
final boolean isReady = tele.getSimState(slotId) == SIM_STATE_READY;
boolean retVal = conn.isNetworkSupported(TYPE_MOBILE) && isReady;
diff --git a/src/com/android/settings/datausage/DataUsageMeteredSettings.java b/src/com/android/settings/datausage/DataUsageMeteredSettings.java
index eb43d47..7a397ad 100644
--- a/src/com/android/settings/datausage/DataUsageMeteredSettings.java
+++ b/src/com/android/settings/datausage/DataUsageMeteredSettings.java
@@ -114,7 +114,8 @@
}
private Preference buildWifiPref(Context context, WifiConfiguration config) {
- final String networkId = config.SSID;
+ final String networkId = config.isPasspoint() ?
+ config.providerFriendlyName : config.SSID;
final NetworkTemplate template = NetworkTemplate.buildTemplateWifi(networkId);
final MeteredPreference pref = new MeteredPreference(context, template);
pref.setTitle(removeDoubleQuotes(networkId));
diff --git a/src/com/android/settings/search/Index.java b/src/com/android/settings/search/Index.java
index 084f9c3..fe89d4f 100644
--- a/src/com/android/settings/search/Index.java
+++ b/src/com/android/settings/search/Index.java
@@ -707,7 +707,7 @@
}
private String buildSearchMatchStringForColumns(String query, String[] columnNames) {
- final String value = query + "*";
+ final String value = (query != null ? query.trim() : "") + "*";
StringBuilder sb = new StringBuilder();
final int count = columnNames.length;
for (int n = 0; n < count; n++) {
diff --git a/src/com/android/settings/sim/SimDialogActivity.java b/src/com/android/settings/sim/SimDialogActivity.java
index dccba13..853f80d 100644
--- a/src/com/android/settings/sim/SimDialogActivity.java
+++ b/src/com/android/settings/sim/SimDialogActivity.java
@@ -59,8 +59,7 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- final Bundle extras = getIntent().getExtras();
- final int dialogType = extras.getInt(DIALOG_TYPE_KEY, INVALID_PICK);
+ final int dialogType = getIntent().getIntExtra(DIALOG_TYPE_KEY, INVALID_PICK);
switch (dialogType) {
case DATA_PICK:
@@ -69,7 +68,7 @@
createDialog(this, dialogType).show();
break;
case PREFERRED_PICK:
- displayPreferredDialog(extras.getInt(PREFERRED_SIM));
+ displayPreferredDialog(getIntent().getIntExtra(PREFERRED_SIM, 0));
break;
default:
throw new IllegalArgumentException("Invalid dialog type " + dialogType + " sent.");
diff --git a/src/com/android/settings/vpn2/VpnSettings.java b/src/com/android/settings/vpn2/VpnSettings.java
index 0d968ab..29a67ab 100644
--- a/src/com/android/settings/vpn2/VpnSettings.java
+++ b/src/com/android/settings/vpn2/VpnSettings.java
@@ -19,6 +19,7 @@
import android.annotation.UiThread;
import android.annotation.WorkerThread;
import android.app.AppOpsManager;
+import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
@@ -208,9 +209,16 @@
public boolean handleMessage(Message message) {
mUpdater.removeMessages(RESCAN_MESSAGE);
+ //Return if activity has been recycled
+ final Activity activity = getActivity();
+ if (activity == null) {
+ return true;
+ }
+ final Context context = activity.getApplicationContext();
+
// Run heavy RPCs before switching to UI thread
final List<VpnProfile> vpnProfiles = loadVpnProfiles(mKeyStore);
- final List<AppVpnInfo> vpnApps = getVpnApps(getActivity(), /* includeProfiles */ true);
+ final List<AppVpnInfo> vpnApps = getVpnApps(context, /* includeProfiles */ true);
final Map<String, LegacyVpnInfo> connectedLegacyVpns = getConnectedLegacyVpns();
final Set<AppVpnInfo> connectedAppVpns = getConnectedAppVpns();
@@ -219,7 +227,7 @@
final String lockdownVpnKey = VpnUtils.getLockdownVpn();
// Refresh list of VPNs
- getActivity().runOnUiThread(new Runnable() {
+ activity.runOnUiThread(new Runnable() {
@Override
public void run() {
// Can't do anything useful if the context has gone away
@@ -271,7 +279,6 @@
}
}
});
-
mUpdater.sendEmptyMessageDelayed(RESCAN_MESSAGE, RESCAN_INTERVAL_MS);
return true;
}
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 7007d19..aef5416 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -168,6 +168,7 @@
final Activity activity = getActivity();
if (activity != null) {
mProgressHeader = (ProgressBar) setPinnedHeaderView(R.layout.wifi_progress_header);
+ setProgressBarVisible(false);
}
}
@@ -298,6 +299,8 @@
// On/off switch is hidden for Setup Wizard (returns null)
mWifiEnabler = createWifiEnabler();
+
+ mWifiTracker.startTracking();
}
/**
@@ -317,7 +320,6 @@
mWifiEnabler.resume(activity);
}
- mWifiTracker.startTracking();
activity.invalidateOptionsMenu();
}
@@ -327,7 +329,11 @@
if (mWifiEnabler != null) {
mWifiEnabler.pause();
}
+ }
+ @Override
+ public void onStop() {
+ super.onStop();
mWifiTracker.stopTracking();
}
@@ -602,14 +608,19 @@
public void onAccessPointsChanged() {
// Safeguard from some delayed event handling
if (getActivity() == null) return;
+ final int wifiState = mWifiManager.getWifiState();
if (isUiRestricted()) {
if (!isUiRestrictedByOnlyAdmin()) {
- addMessagePreference(R.string.wifi_empty_list_user_restricted);
+ if (WifiManager.WIFI_STATE_DISABLED == wifiState) {
+ addMessagePreference(R.string.wifi_empty_list_wifi_off);
+ }
+ else {
+ addMessagePreference(R.string.wifi_empty_list_user_restricted);
+ }
}
getPreferenceScreen().removeAll();
return;
}
- final int wifiState = mWifiManager.getWifiState();
switch (wifiState) {
case WifiManager.WIFI_STATE_ENABLED:
@@ -702,7 +713,7 @@
private void setOffMessage() {
if (isUiRestricted()) {
if (!isUiRestrictedByOnlyAdmin()) {
- addMessagePreference(R.string.wifi_empty_list_user_restricted);
+ addMessagePreference(R.string.wifi_empty_list_wifi_off);
}
getPreferenceScreen().removeAll();
return;
@@ -758,7 +769,7 @@
protected void setProgressBarVisible(boolean visible) {
if (mProgressHeader != null) {
- mProgressHeader.setVisibility(visible ? View.VISIBLE : View.GONE);
+ mProgressHeader.setVisibility(visible && !isUiRestricted() ? View.VISIBLE : View.GONE);
}
}
@@ -840,6 +851,8 @@
Log.e(TAG, "Failed to forget invalid network " + mSelectedAccessPoint.getConfig());
return;
}
+ } else if (mSelectedAccessPoint.getConfig().isPasspoint()) {
+ mWifiManager.removePasspointConfiguration(mSelectedAccessPoint.getConfig().FQDN);
} else {
mWifiManager.forget(mSelectedAccessPoint.getConfig().networkId, mForgetListener);
}