summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorWei Wang <weiwa@google.com>2014-02-27 16:28:34 -0800
committerWei Wang <weiwa@google.com>2014-03-03 11:18:21 -0800
commit17d2124c1ccb1bd46393f70252d06d866646e97d (patch)
tree02ee33a24498ca758cdcc8a7ca89057c649771a3 /src/com
parentee4f84b0fb9e837cb54cb69e475cece68a90491e (diff)
downloadpackages_apps_Settings-17d2124c1ccb1bd46393f70252d06d866646e97d.zip
packages_apps_Settings-17d2124c1ccb1bd46393f70252d06d866646e97d.tar.gz
packages_apps_Settings-17d2124c1ccb1bd46393f70252d06d866646e97d.tar.bz2
Revert "BLE peripheral mode (4/4): Settings change for advertising preference."
This reverts commit eb56b9ccb8fa70a6c567d0bcd02f821e4de4bf7b. Conflicts: src/com/android/settings/bluetooth/BluetoothDiscoverableEnabler.java src/com/android/settings/bluetooth/BluetoothSettings.java src/com/android/settings/bluetooth/LocalDeviceProfilesSettings.java Change-Id: I2ce6b9eb0e335ba1b9aa4e1cb61a041f00d9aa87
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/settings/bluetooth/BluetoothAdvertisingEnabler.java50
-rw-r--r--src/com/android/settings/bluetooth/BluetoothAdvertisingFragment.java103
-rwxr-xr-xsrc/com/android/settings/bluetooth/BluetoothDiscoverableEnabler.java32
-rw-r--r--src/com/android/settings/bluetooth/BluetoothLocalDevicePreference.java46
-rwxr-xr-xsrc/com/android/settings/bluetooth/BluetoothSettings.java35
-rw-r--r--src/com/android/settings/bluetooth/LocalBluetoothAdapter.java11
-rw-r--r--src/com/android/settings/bluetooth/LocalBluetoothManager.java9
-rw-r--r--src/com/android/settings/bluetooth/LocalBluetoothPreferences.java17
-rw-r--r--src/com/android/settings/bluetooth/LocalDeviceProfilesSettings.java99
-rw-r--r--src/com/android/settings/bluetooth/RequestPermissionActivity.java86
-rw-r--r--src/com/android/settings/bluetooth/RequestPermissionHelperActivity.java16
-rwxr-xr-xsrc/com/android/settings/bluetooth/Utils.java18
12 files changed, 38 insertions, 484 deletions
diff --git a/src/com/android/settings/bluetooth/BluetoothAdvertisingEnabler.java b/src/com/android/settings/bluetooth/BluetoothAdvertisingEnabler.java
deleted file mode 100644
index a6b0838..0000000
--- a/src/com/android/settings/bluetooth/BluetoothAdvertisingEnabler.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2013 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.content.Context;
-import android.preference.PreferenceScreen;
-
-import com.android.settings.R;
-
-/**
- * BluetoothAdvertisingEnabler helps manager change of bluetooth advertising preferences.
- */
-final class BluetoothAdvertisingEnabler {
-
- private Context mContext;
- private final PreferenceScreen mBluetoothAdvertisingPreference;
-
- public BluetoothAdvertisingEnabler(Context context, PreferenceScreen bluetoothBroadcast) {
- mContext = context;
- mBluetoothAdvertisingPreference = bluetoothBroadcast;
- }
-
- public void resume(Context context) {
- if (mContext != context) {
- mContext = context;
- }
- boolean isBroadcastingEnable = LocalBluetoothPreferences.isAdvertisingEnabled(mContext);
- handleAdvertisingStateChange(isBroadcastingEnable);
- }
-
- private void handleAdvertisingStateChange(boolean isBroadcastingEnable) {
- mBluetoothAdvertisingPreference.setSummary(isBroadcastingEnable ?
- R.string.bluetooth_broadcasting_state_on :
- R.string.bluetooth_broadcasting_state_off);
- }
-}
diff --git a/src/com/android/settings/bluetooth/BluetoothAdvertisingFragment.java b/src/com/android/settings/bluetooth/BluetoothAdvertisingFragment.java
deleted file mode 100644
index ea6adb0..0000000
--- a/src/com/android/settings/bluetooth/BluetoothAdvertisingFragment.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright (C) 2013 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.ActionBar;
-import android.app.Activity;
-import android.app.Fragment;
-import android.bluetooth.BluetoothAdapter;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Bundle;
-import android.preference.PreferenceActivity;
-import android.view.Gravity;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.CompoundButton;
-import android.widget.Switch;
-
-import com.android.settings.R;
-
-/**
- * Fragment to display and let the user change advertising preference.
- */
-public class BluetoothAdvertisingFragment extends Fragment
- implements CompoundButton.OnCheckedChangeListener {
-
- private static final String TAG = "BluetoothAdvertisingFragment";
- private View mView;
- private Switch mActionBarSwitch;
- private Activity mActivity;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- mActivity = getActivity();
- mActionBarSwitch = new Switch(mActivity);
- if (mActivity instanceof PreferenceActivity) {
- final int padding = mActivity.getResources().getDimensionPixelSize(
- R.dimen.action_bar_switch_padding);
- mActionBarSwitch.setPaddingRelative(0, 0, padding, 0);
- mActivity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
- ActionBar.DISPLAY_SHOW_CUSTOM);
- mActivity.getActionBar().setCustomView(mActionBarSwitch, new ActionBar.LayoutParams(
- ActionBar.LayoutParams.WRAP_CONTENT,
- ActionBar.LayoutParams.WRAP_CONTENT,
- Gravity.CENTER_VERTICAL | Gravity.END));
- mActivity.getActionBar().setTitle(R.string.bluetooth_broadcasting);
- }
- mActionBarSwitch.setChecked(
- LocalBluetoothPreferences.isAdvertisingEnabled(mActivity.getApplicationContext()));
-
- mActionBarSwitch.setOnCheckedChangeListener(this);
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- mView = inflater.inflate(R.layout.bluetooth_advertising, container, false);
- initView(mView);
- return mView;
- }
-
- @Override
- public void onDestroyView() {
- super.onDestroyView();
- getActivity().getActionBar().setCustomView(null);
- }
-
- private void initView(View view) {
- mActionBarSwitch.setOnCheckedChangeListener(this);
- }
-
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean desiredState) {
- mActionBarSwitch.setChecked(desiredState);
- Context context = getActivity();
- LocalBluetoothPreferences.setAdvertisingEnabled(context, desiredState);
- if (!desiredState) {
- LocalBluetoothAdapter adapter =
- LocalBluetoothManager.getInstance(context).getBluetoothAdapter();
- // Stop advertising if advertising is in process.
- if (adapter.isAdvertising()) {
- Intent intent = new Intent(BluetoothAdapter.ACTION_STOP_ADVERTISING);
- getActivity().startActivity(intent);
- }
- }
- }
-}
diff --git a/src/com/android/settings/bluetooth/BluetoothDiscoverableEnabler.java b/src/com/android/settings/bluetooth/BluetoothDiscoverableEnabler.java
index f47fecc..17da0a7 100755
--- a/src/com/android/settings/bluetooth/BluetoothDiscoverableEnabler.java
+++ b/src/com/android/settings/bluetooth/BluetoothDiscoverableEnabler.java
@@ -25,10 +25,13 @@ import android.content.SharedPreferences;
import android.os.Handler;
import android.os.SystemProperties;
import android.preference.Preference;
-import android.util.Log;
+import android.text.format.DateUtils;
import com.android.settings.R;
+import android.text.format.Time;
+import android.util.Log;
+
/**
* BluetoothDiscoverableEnabler is a helper to manage the "Discoverable"
* checkbox. It sets/unsets discoverability and keeps track of how much time
@@ -60,8 +63,6 @@ final class BluetoothDiscoverableEnabler implements Preference.OnPreferenceClick
private Context mContext;
private final Handler mUiHandler;
private final Preference mDiscoveryPreference;
- // Preference for visibility time out. Not final as it needs to be set through setter.
- private Preference mVisibilityTimeoutPreference;
private final LocalBluetoothAdapter mLocalAdapter;
@@ -100,10 +101,6 @@ final class BluetoothDiscoverableEnabler implements Preference.OnPreferenceClick
discoveryPreference.setPersistent(false);
}
- public void setVisibilityPreference(Preference visibilityPreference) {
- mVisibilityTimeoutPreference = visibilityPreference;
- }
-
public void resume(Context context) {
if (mLocalAdapter == null) {
return;
@@ -117,7 +114,6 @@ final class BluetoothDiscoverableEnabler implements Preference.OnPreferenceClick
mContext.registerReceiver(mReceiver, filter);
mDiscoveryPreference.setOnPreferenceClickListener(this);
handleModeChanged(mLocalAdapter.getScanMode());
- updateVisibilityTimeoutDisplay();
}
public void pause() {
@@ -128,9 +124,6 @@ final class BluetoothDiscoverableEnabler implements Preference.OnPreferenceClick
mUiHandler.removeCallbacks(mUpdateCountdownSummaryRunnable);
mContext.unregisterReceiver(mReceiver);
mDiscoveryPreference.setOnPreferenceClickListener(null);
- if (mVisibilityTimeoutPreference != null) {
- mVisibilityTimeoutPreference.setOnPreferenceClickListener(null);
- }
}
public boolean onPreferenceClick(Preference preference) {
@@ -161,23 +154,6 @@ final class BluetoothDiscoverableEnabler implements Preference.OnPreferenceClick
mLocalAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE);
BluetoothDiscoverableTimeoutReceiver.cancelDiscoverableAlarm(mContext);
}
- updateVisibilityTimeoutDisplay();
- }
-
- // Update visibility timeout preference.
- private void updateVisibilityTimeoutDisplay() {
- if (mVisibilityTimeoutPreference == null) {
- return;
- }
- int index = getDiscoverableTimeoutIndex();
-
- String visibilitySummary = "";
- CharSequence[] timeoutChoices =
- mContext.getResources().getTextArray(R.array.bluetooth_visibility_timeout_entries);
- if (index >= 0 && index < timeoutChoices.length) {
- visibilitySummary = timeoutChoices[index].toString();
- }
- mVisibilityTimeoutPreference.setSummary(visibilitySummary);
}
private void updateTimerDisplay(int timeout) {
diff --git a/src/com/android/settings/bluetooth/BluetoothLocalDevicePreference.java b/src/com/android/settings/bluetooth/BluetoothLocalDevicePreference.java
deleted file mode 100644
index 403c3b4..0000000
--- a/src/com/android/settings/bluetooth/BluetoothLocalDevicePreference.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2013 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.content.Context;
-import android.preference.Preference;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.ImageView;
-
-import com.android.settings.R;
-
-/**
- * A preference screen to show information for local device.
- */
-public class BluetoothLocalDevicePreference extends Preference {
- private static OnClickListener mSettingsListener;
-
- public BluetoothLocalDevicePreference(Context context, OnClickListener settingsListener) {
- super(context);
- mSettingsListener = settingsListener;
- setWidgetLayoutResource(R.layout.preference_bluetooth);
- }
-
- @Override
- protected void onBindView(View view) {
- ImageView deviceDetails = (ImageView) view.findViewById(
- R.id.deviceDetails);
- deviceDetails.setOnClickListener(mSettingsListener);
- super.onBindView(view);
- }
-}
diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java
index c6b560f..acd9dad 100755
--- a/src/com/android/settings/bluetooth/BluetoothSettings.java
+++ b/src/com/android/settings/bluetooth/BluetoothSettings.java
@@ -51,7 +51,9 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
private static final String TAG = "BluetoothSettings";
private static final int MENU_ID_SCAN = Menu.FIRST;
- private static final int MENU_ID_SHOW_RECEIVED = Menu.FIRST + 1;
+ private static final int MENU_ID_RENAME_DEVICE = Menu.FIRST + 1;
+ private static final int MENU_ID_VISIBILITY_TIMEOUT = Menu.FIRST + 2;
+ private static final int MENU_ID_SHOW_RECEIVED = Menu.FIRST + 3;
/* Private intent to show the list of received files */
private static final String BTOPP_ACTION_OPEN_RECEIVED_FILES =
@@ -189,6 +191,12 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
menu.add(Menu.NONE, MENU_ID_SCAN, 0, textId)
.setEnabled(bluetoothIsEnabled && !isDiscovering)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
+ menu.add(Menu.NONE, MENU_ID_RENAME_DEVICE, 0, R.string.bluetooth_rename_device)
+ .setEnabled(bluetoothIsEnabled)
+ .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
+ menu.add(Menu.NONE, MENU_ID_VISIBILITY_TIMEOUT, 0, R.string.bluetooth_visibility_timeout)
+ .setEnabled(bluetoothIsEnabled)
+ .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
menu.add(Menu.NONE, MENU_ID_SHOW_RECEIVED, 0, R.string.bluetooth_show_received_files)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
super.onCreateOptionsMenu(menu, inflater);
@@ -203,6 +211,16 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
}
return true;
+ case MENU_ID_RENAME_DEVICE:
+ new BluetoothNameDialogFragment().show(
+ getFragmentManager(), "rename device");
+ return true;
+
+ case MENU_ID_VISIBILITY_TIMEOUT:
+ new BluetoothVisibilityTimeoutFragment().show(
+ getFragmentManager(), "visibility timeout");
+ return true;
+
case MENU_ID_SHOW_RECEIVED:
Intent intent = new Intent(BTOPP_ACTION_OPEN_RECEIVED_FILES);
getActivity().sendBroadcast(intent);
@@ -247,8 +265,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
// This device
if (mMyDevicePreference == null) {
- mMyDevicePreference = new BluetoothLocalDevicePreference(
- getActivity(), mLocalDeviceProfilesListener);
+ mMyDevicePreference = new Preference(getActivity());
}
mMyDevicePreference.setTitle(mLocalAdapter.getName());
if (getResources().getBoolean(com.android.internal.R.bool.config_voice_capable)) {
@@ -356,18 +373,6 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
updateContent(mLocalAdapter.getBluetoothState(), false);
}
- // Listener for local device profile fragment.
- private final View.OnClickListener mLocalDeviceProfilesListener = new View.OnClickListener() {
- public void onClick(View v) {
- if (isRestrictedAndNotPinProtected()) return;
-
- ((SettingsActivity) getActivity()).startPreferencePanel(
- LocalDeviceProfilesSettings.class.getName(), null,
- 0, mLocalAdapter.getName(), null, 0);
- }
- };
-
-
private final View.OnClickListener mDeviceProfilesListener = new View.OnClickListener() {
public void onClick(View v) {
// User clicked on advanced options icon for a device in the list
diff --git a/src/com/android/settings/bluetooth/LocalBluetoothAdapter.java b/src/com/android/settings/bluetooth/LocalBluetoothAdapter.java
index 041ecb7..013171c 100644
--- a/src/com/android/settings/bluetooth/LocalBluetoothAdapter.java
+++ b/src/com/android/settings/bluetooth/LocalBluetoothAdapter.java
@@ -118,9 +118,6 @@ public final class LocalBluetoothAdapter {
return mAdapter.isDiscovering();
}
- boolean isAdvertising() {
- return mAdapter.isAdvertising();
- }
boolean isEnabled() {
return mAdapter.isEnabled();
}
@@ -129,14 +126,6 @@ public final class LocalBluetoothAdapter {
mAdapter.setDiscoverableTimeout(timeout);
}
- boolean startAdvertising() {
- return mAdapter.startAdvertising();
- }
-
- boolean stopAdvertising() {
- return mAdapter.stopAdvertisting();
- }
-
void setName(String name) {
mAdapter.setName(name);
}
diff --git a/src/com/android/settings/bluetooth/LocalBluetoothManager.java b/src/com/android/settings/bluetooth/LocalBluetoothManager.java
index 265cabb..ae8dec2 100644
--- a/src/com/android/settings/bluetooth/LocalBluetoothManager.java
+++ b/src/com/android/settings/bluetooth/LocalBluetoothManager.java
@@ -37,7 +37,6 @@ public final class LocalBluetoothManager {
private Context mForegroundActivity;
private BluetoothDiscoverableEnabler mDiscoverableEnabler;
- private BluetoothAdvertisingEnabler mAdvertisingEnabler;
private final LocalBluetoothAdapter mLocalAdapter;
@@ -71,14 +70,6 @@ public final class LocalBluetoothManager {
return mDiscoverableEnabler;
}
- public void setBluetoothAdvertisingEnabler(BluetoothAdvertisingEnabler advertisingEnabler) {
- this.mAdvertisingEnabler = advertisingEnabler;
- }
-
- public BluetoothAdvertisingEnabler getAdvertisingEnabler() {
- return mAdvertisingEnabler;
- }
-
private LocalBluetoothManager(LocalBluetoothAdapter adapter, Context context) {
mContext = context;
mLocalAdapter = adapter;
diff --git a/src/com/android/settings/bluetooth/LocalBluetoothPreferences.java b/src/com/android/settings/bluetooth/LocalBluetoothPreferences.java
index f862f72..f00b801 100644
--- a/src/com/android/settings/bluetooth/LocalBluetoothPreferences.java
+++ b/src/com/android/settings/bluetooth/LocalBluetoothPreferences.java
@@ -17,10 +17,8 @@
package com.android.settings.bluetooth;
import android.app.QueuedWork;
-import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.SharedPreferences;
-import android.content.SharedPreferences.Editor;
import android.content.res.Configuration;
import android.util.Log;
@@ -48,10 +46,6 @@ final class LocalBluetoothPreferences {
private static final String KEY_DISCOVERABLE_END_TIMESTAMP = "discoverable_end_timestamp";
- private static final String KEY_ADVERTISEMENT_PREFERENCE = "bt_advertisement_perference";
-
- private static final boolean DEFAULT_ADVERTISING_ENABLED = false;
-
private LocalBluetoothPreferences() {
}
@@ -64,17 +58,6 @@ final class LocalBluetoothPreferences {
KEY_DISCOVERABLE_END_TIMESTAMP, 0);
}
- static boolean isAdvertisingEnabled(Context context) {
- return getSharedPreferences(context).getBoolean(
- KEY_ADVERTISEMENT_PREFERENCE, DEFAULT_ADVERTISING_ENABLED);
- }
-
- static void setAdvertisingEnabled(Context context, boolean advertisingEnabled) {
- Editor preferenceEditor = getSharedPreferences(context).edit();
- preferenceEditor.putBoolean(KEY_ADVERTISEMENT_PREFERENCE, advertisingEnabled);
- preferenceEditor.apply();
- }
-
static boolean shouldShowDialogInForeground(Context context,
String deviceAddress) {
LocalBluetoothManager manager = LocalBluetoothManager.getInstance(context);
diff --git a/src/com/android/settings/bluetooth/LocalDeviceProfilesSettings.java b/src/com/android/settings/bluetooth/LocalDeviceProfilesSettings.java
deleted file mode 100644
index 47b1476..0000000
--- a/src/com/android/settings/bluetooth/LocalDeviceProfilesSettings.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (C) 2013 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.Activity;
-import android.os.Bundle;
-import android.preference.Preference;
-import android.preference.Preference.OnPreferenceClickListener;
-import android.preference.PreferenceScreen;
-
-import com.android.settings.R;
-import com.android.settings.SettingsPreferenceFragment;
-
-/**
- * This preference fragment presents the user with the profiles of the local devices and allow them
- * to be modified.
- */
-public final class LocalDeviceProfilesSettings extends SettingsPreferenceFragment {
- private static final String TAG = "LocalDeviceProfilesSettings";
-
- private static final String KEY_RENAME_DEVICE = "rename_device";
- private static final String KEY_BROADCASTING = "broadcasting";
- private static final String KEY_VISIBILITY_TIMEOUT = "visibility_timeout";
-
- private LocalBluetoothManager mManager;
- private BluetoothDiscoverableEnabler mDiscoverableEnabler;
- private BluetoothAdvertisingEnabler mAdvertisingEnabler;
-
- private Preference mDeviceNamePref;
- private Preference mVisibilityPref;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.bluetooth_local_device_profile);
- getPreferenceScreen().setOrderingAsAdded(true);
- mDeviceNamePref = findPreference(KEY_RENAME_DEVICE);
- mDeviceNamePref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- new BluetoothNameDialogFragment().show(getFragmentManager(), "rename device");
- return true;
- }
- });
-
- mVisibilityPref = findPreference(KEY_VISIBILITY_TIMEOUT);
- mVisibilityPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- new BluetoothVisibilityTimeoutFragment().show(
- getFragmentManager(), "visibility timeout");
- return true;
- }
- });
-
- mManager = LocalBluetoothManager.getInstance(getActivity());
- mDiscoverableEnabler = mManager.getDiscoverableEnabler();
- // Set the visibility timeout preference to the enabler so the visibility timeout
- // preference can be updated when the timeout changes.
- mDiscoverableEnabler.setVisibilityPreference(mVisibilityPref);
-
- PreferenceScreen bluetoothBroadcast = (PreferenceScreen)findPreference(KEY_BROADCASTING);
- mAdvertisingEnabler = new BluetoothAdvertisingEnabler(getActivity(), bluetoothBroadcast);
- mManager.setBluetoothAdvertisingEnabler(mAdvertisingEnabler);
- }
-
- @Override
- public void onResume() {
- super.onResume();
- final Activity activity = getActivity();
- mManager.setForegroundActivity(activity);
- mAdvertisingEnabler.resume(activity);
- mDiscoverableEnabler.resume(activity);
- }
-
- @Override
- public void onPause() {
- super.onPause();
- mManager.setForegroundActivity(null);
- if (mDiscoverableEnabler != null) {
- mDiscoverableEnabler.pause();
- }
- }
-
-}
diff --git a/src/com/android/settings/bluetooth/RequestPermissionActivity.java b/src/com/android/settings/bluetooth/RequestPermissionActivity.java
index 1b105de..9f266a5 100644
--- a/src/com/android/settings/bluetooth/RequestPermissionActivity.java
+++ b/src/com/android/settings/bluetooth/RequestPermissionActivity.java
@@ -16,6 +16,8 @@
package com.android.settings.bluetooth;
+import com.android.settings.R;
+
import android.app.Activity;
import android.app.AlertDialog;
import android.bluetooth.BluetoothAdapter;
@@ -26,22 +28,17 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
-import android.os.UserHandle;
import android.util.Log;
-import com.android.settings.R;
-
/**
- * RequestPermissionActivity asks the user whether to enable bluetooth, discovery or advertisement.
- * This is usually started by an application wanted to start bluetooth, discovery or advertisement.
+ * RequestPermissionActivity asks the user whether to enable discovery. This is
+ * usually started by an application wanted to start bluetooth and or discovery
*/
public class RequestPermissionActivity extends Activity implements
DialogInterface.OnClickListener {
// Command line to test this
// adb shell am start -a android.bluetooth.adapter.action.REQUEST_ENABLE
// adb shell am start -a android.bluetooth.adapter.action.REQUEST_DISCOVERABLE
- // adb shell am start -a android.bluetooth.adapter.action.START_ADVERTISING
- // adb shell am start -a android.bluetooth.adapter.action.STOP_ADVERTISING
private static final String TAG = "RequestPermissionActivity";
@@ -53,11 +50,6 @@ public class RequestPermissionActivity extends Activity implements
private static final int REQUEST_CODE_START_BT = 1;
- private static final int EXTRA_INTENT_NONE = 0;
- private static final int EXTRA_INTENT_DISCOVERY = 1;
- private static final int EXTRA_INTENT_START_ADVERTISING = 2;
- private static final int EXTRA_INTENT_STOP_ADVERTISING = 3;
-
private LocalBluetoothAdapter mLocalAdapter;
private int mTimeout = BluetoothDiscoverableEnabler.DEFAULT_DISCOVERABLE_TIMEOUT;
@@ -75,14 +67,10 @@ public class RequestPermissionActivity extends Activity implements
// False if requesting BT to be turned on + discoverable mode
private boolean mEnableOnly;
- private int mExtraIntent = EXTRA_INTENT_NONE;
-
private boolean mUserConfirmed;
private AlertDialog mDialog;
- private Context mContext;
-
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
@@ -106,8 +94,6 @@ public class RequestPermissionActivity extends Activity implements
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- mContext = getApplicationContext();
-
// Note: initializes mLocalAdapter and returns true on error
if (parseIntent()) {
finish();
@@ -139,27 +125,21 @@ public class RequestPermissionActivity extends Activity implements
intent.setClass(this, RequestPermissionHelperActivity.class);
if (mEnableOnly) {
intent.setAction(RequestPermissionHelperActivity.ACTION_INTERNAL_REQUEST_BT_ON);
- } else if (mExtraIntent == EXTRA_INTENT_DISCOVERY) {
+ } else {
intent.setAction(RequestPermissionHelperActivity.
ACTION_INTERNAL_REQUEST_BT_ON_AND_DISCOVERABLE);
intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, mTimeout);
- } else if (mExtraIntent == EXTRA_INTENT_START_ADVERTISING) {
- intent.setAction(RequestPermissionHelperActivity.
- ACTION_INTERNAL_REQUEST_BT_ON_AND_START_ADVERTISE);
- } else if (mExtraIntent == EXTRA_INTENT_STOP_ADVERTISING) {
- // Nothing to do. Advertising cannot be in process with bluetooth disabled.
}
-
startActivityForResult(intent, REQUEST_CODE_START_BT);
mNeededToEnableBluetooth = true;
break;
case BluetoothAdapter.STATE_ON:
- if (needAskUserPermission()) {
- // Ask the user for permissions of bluetooth operations.
- createDialog();
- } else {
- // No need to ask for permission, just proceed.
+ if (mEnableOnly) {
+ // Nothing to do. Already enabled.
proceedAndFinish();
+ } else {
+ // Ask the user about enabling discovery mode
+ createDialog();
}
break;
default:
@@ -167,19 +147,6 @@ public class RequestPermissionActivity extends Activity implements
}
}
- private boolean needAskUserPermission() {
- if (mEnableOnly) {
- return false;
- }
- if (mExtraIntent == EXTRA_INTENT_STOP_ADVERTISING) {
- return false;
- }
- if (mExtraIntent == EXTRA_INTENT_START_ADVERTISING) {
- return !LocalBluetoothPreferences.isAdvertisingEnabled(mContext);
- }
- return true;
- }
-
private void createDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
@@ -188,7 +155,7 @@ public class RequestPermissionActivity extends Activity implements
// to turn on BT
builder.setMessage(getString(R.string.bluetooth_turning_on));
builder.setCancelable(false);
- } else if (mExtraIntent == EXTRA_INTENT_DISCOVERY) {
+ } else {
// Ask the user whether to turn on discovery mode or not
// For lasting discoverable mode there is a different message
if (mTimeout == BluetoothDiscoverableEnabler.DISCOVERABLE_TIMEOUT_NEVER) {
@@ -200,11 +167,6 @@ public class RequestPermissionActivity extends Activity implements
}
builder.setPositiveButton(getString(R.string.allow), this);
builder.setNegativeButton(getString(R.string.deny), this);
- } else if (mExtraIntent == EXTRA_INTENT_START_ADVERTISING) {
- builder.setMessage(getString(R.string.bluetooth_ask_start_broadcast,
- Utils.getCallingApp(this)));
- builder.setPositiveButton(getString(R.string.allow), this);
- builder.setNegativeButton(getString(R.string.deny), this);
}
mDialog = builder.create();
@@ -261,8 +223,7 @@ public class RequestPermissionActivity extends Activity implements
if (mEnableOnly) {
// BT enabled. Done
returnCode = RESULT_OK;
- } else if (mExtraIntent == EXTRA_INTENT_DISCOVERY
- && mLocalAdapter.setScanMode(
+ } else if (mLocalAdapter.setScanMode(
BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE, mTimeout)) {
// If already in discoverable mode, this will extend the timeout.
long endTime = System.currentTimeMillis() + (long) mTimeout * 1000;
@@ -276,22 +237,6 @@ public class RequestPermissionActivity extends Activity implements
if (returnCode < RESULT_FIRST_USER) {
returnCode = RESULT_FIRST_USER;
}
- } else if (mExtraIntent == EXTRA_INTENT_START_ADVERTISING) {
- // Advertise allowed as user said yes.
- LocalBluetoothPreferences.setAdvertisingEnabled(mContext, true);
- if (mLocalAdapter.startAdvertising()) {
- returnCode = RESULT_OK;
- Intent intent = new Intent(BluetoothAdapter.ACTION_BLUETOOTH_ADVERTISING_STARTED);
- mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
- } else {
- returnCode = RESULT_CANCELED;
- }
- } else if (mExtraIntent == EXTRA_INTENT_STOP_ADVERTISING
- && mLocalAdapter.isAdvertising()
- && mLocalAdapter.stopAdvertising()) {
- Intent intent = new Intent(BluetoothAdapter.ACTION_BLUETOOTH_ADVERTISING_STOPPED);
- mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
- returnCode = RESULT_OK;
} else {
returnCode = RESULT_CANCELED;
}
@@ -314,7 +259,6 @@ public class RequestPermissionActivity extends Activity implements
mEnableOnly = true;
} else if (intent != null
&& intent.getAction().equals(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE)) {
- mExtraIntent = EXTRA_INTENT_DISCOVERY;
mTimeout = intent.getIntExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION,
BluetoothDiscoverableEnabler.DEFAULT_DISCOVERABLE_TIMEOUT);
@@ -323,12 +267,6 @@ public class RequestPermissionActivity extends Activity implements
if (mTimeout < 0 || mTimeout > MAX_DISCOVERABLE_TIMEOUT) {
mTimeout = BluetoothDiscoverableEnabler.DEFAULT_DISCOVERABLE_TIMEOUT;
}
- } else if (intent != null
- && intent.getAction().equals(BluetoothAdapter.ACTION_START_ADVERTISING)) {
- mExtraIntent = EXTRA_INTENT_START_ADVERTISING;
- } else if (intent != null
- && intent.getAction().equals(BluetoothAdapter.ACTION_STOP_ADVERTISING)) {
- mExtraIntent = EXTRA_INTENT_STOP_ADVERTISING;
} else {
Log.e(TAG, "Error: this activity may be started only with intent "
+ BluetoothAdapter.ACTION_REQUEST_ENABLE + " or "
diff --git a/src/com/android/settings/bluetooth/RequestPermissionHelperActivity.java b/src/com/android/settings/bluetooth/RequestPermissionHelperActivity.java
index 34874b3..f108513 100644
--- a/src/com/android/settings/bluetooth/RequestPermissionHelperActivity.java
+++ b/src/com/android/settings/bluetooth/RequestPermissionHelperActivity.java
@@ -30,7 +30,7 @@ import android.view.View;
import android.widget.TextView;
/**
- * RequestPermissionHelperActivity asks the user whether to enable discovery or advertisement.
+ * RequestPermissionHelperActivity asks the user whether to enable discovery.
* This is usually started by RequestPermissionActivity.
*/
public class RequestPermissionHelperActivity extends AlertActivity implements
@@ -43,9 +43,6 @@ public class RequestPermissionHelperActivity extends AlertActivity implements
public static final String ACTION_INTERNAL_REQUEST_BT_ON_AND_DISCOVERABLE =
"com.android.settings.bluetooth.ACTION_INTERNAL_REQUEST_BT_ON_AND_DISCOVERABLE";
- public static final String ACTION_INTERNAL_REQUEST_BT_ON_AND_START_ADVERTISE =
- "com.android.settings.bluetooth.ACTION_INTERNAL_REQUEST_BT_ON_AND_ADVERTISE";
-
private LocalBluetoothAdapter mLocalAdapter;
private int mTimeout;
@@ -53,7 +50,6 @@ public class RequestPermissionHelperActivity extends AlertActivity implements
// True if requesting BT to be turned on
// False if requesting BT to be turned on + discoverable mode
private boolean mEnableOnly;
- private boolean mDiscovery;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -79,15 +75,12 @@ public class RequestPermissionHelperActivity extends AlertActivity implements
if (mEnableOnly) {
p.mMessage = getString(R.string.bluetooth_ask_enablement);
- } else if (mDiscovery) {
+ } else {
if (mTimeout == BluetoothDiscoverableEnabler.DISCOVERABLE_TIMEOUT_NEVER) {
p.mMessage = getString(R.string.bluetooth_ask_enablement_and_lasting_discovery);
} else {
p.mMessage = getString(R.string.bluetooth_ask_enablement_and_discovery, mTimeout);
}
- } else {
- p.mMessage = getString(R.string.bluetooth_ask_enablement_and_start_broadcast,
- Utils.getCallingApp(this));
}
p.mPositiveButtonText = getString(R.string.allow);
@@ -145,14 +138,9 @@ public class RequestPermissionHelperActivity extends AlertActivity implements
} else if (intent != null
&& intent.getAction().equals(ACTION_INTERNAL_REQUEST_BT_ON_AND_DISCOVERABLE)) {
mEnableOnly = false;
- mDiscovery = true;
// Value used for display purposes. Not range checking.
mTimeout = intent.getIntExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION,
BluetoothDiscoverableEnabler.DEFAULT_DISCOVERABLE_TIMEOUT);
- } else if (intent != null
- && intent.getAction().equals(ACTION_INTERNAL_REQUEST_BT_ON_AND_START_ADVERTISE)) {
- mEnableOnly = false;
- mDiscovery = false;
} else {
setResult(RESULT_CANCELED);
return true;
diff --git a/src/com/android/settings/bluetooth/Utils.java b/src/com/android/settings/bluetooth/Utils.java
index 6590b06..fb44d5a 100755
--- a/src/com/android/settings/bluetooth/Utils.java
+++ b/src/com/android/settings/bluetooth/Utils.java
@@ -16,15 +16,11 @@
package com.android.settings.bluetooth;
-import android.app.Activity;
import android.app.AlertDialog;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.content.DialogInterface;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
import android.widget.Toast;
import com.android.settings.R;
@@ -106,18 +102,4 @@ final class Utils {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}
}
-
- /**
- * Get application name of the calling activity. Returns empty string on errors.
- */
- static String getCallingApp(Activity activity) {
- final PackageManager pm = activity.getApplicationContext().getPackageManager();
- ApplicationInfo applicationInfo;
- try {
- applicationInfo = pm.getApplicationInfo(activity.getCallingPackage(), 0);
- } catch (final NameNotFoundException e) {
- applicationInfo = null;
- }
- return (applicationInfo == null) ? "" : pm.getApplicationLabel(applicationInfo).toString();
- }
}