Implement Settings app UX for when a user has bluetooth config locked down.
When a user has the user restriction DISALLOW_CONFIG_BLUETOOTH - Remove all the menu items for searching and other config - Hide "available" but non-paired devices - Remove settings button from paired devices - Remove ability to make the device visible to others Change-Id: Icaebf29d3cce55d924fdd65449447b5b7a438bbe
This commit is contained in:
@@ -16,22 +16,22 @@
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.bluetooth.BluetoothClass;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.UserManager;
|
||||
import android.preference.Preference;
|
||||
import android.text.Html;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -66,7 +66,10 @@ public final class BluetoothDevicePreference extends Preference implements
|
||||
mCachedDevice = cachedDevice;
|
||||
|
||||
if (cachedDevice.getBondState() == BluetoothDevice.BOND_BONDED) {
|
||||
setWidgetLayoutResource(R.layout.preference_bluetooth);
|
||||
UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
if (! um.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH)) {
|
||||
setWidgetLayoutResource(R.layout.preference_bluetooth);
|
||||
}
|
||||
}
|
||||
|
||||
mCachedDevice.registerCallback(this);
|
||||
|
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.app.Activity;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
@@ -25,6 +27,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserManager;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceCategory;
|
||||
@@ -32,16 +35,13 @@ import android.preference.PreferenceGroup;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.ProgressCategory;
|
||||
import com.android.settings.R;
|
||||
|
||||
/**
|
||||
@@ -74,6 +74,8 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
|
||||
|
||||
private final IntentFilter mIntentFilter;
|
||||
|
||||
private UserManager mUserManager;
|
||||
|
||||
// accessed from inner class (not private to avoid thunks)
|
||||
Preference mMyDevicePreference;
|
||||
|
||||
@@ -100,6 +102,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
mUserManager = (UserManager) getSystemService(Context.USER_SERVICE);
|
||||
mActivityStarted = (savedInstanceState == null); // don't auto start scan after rotation
|
||||
|
||||
mEmptyView = (TextView) getView().findViewById(android.R.id.empty);
|
||||
@@ -167,6 +170,9 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
if (mLocalAdapter == null) return;
|
||||
// If the user is not allowed to configure bluetooth, do not show the menu.
|
||||
if (mUserManager.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH)) return;
|
||||
|
||||
boolean bluetoothIsEnabled = mLocalAdapter.getBluetoothState() == BluetoothAdapter.STATE_ON;
|
||||
boolean isDiscovering = mLocalAdapter.isDiscovering();
|
||||
int textId = isDiscovering ? R.string.bluetooth_searching_for_devices :
|
||||
@@ -213,6 +219,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
|
||||
}
|
||||
|
||||
private void startScanning() {
|
||||
if (mUserManager.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH)) return;
|
||||
if (!mAvailableDevicesCategoryIsPresent) {
|
||||
getPreferenceScreen().addPreference(mAvailableDevicesCategory);
|
||||
}
|
||||
@@ -259,12 +266,14 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
|
||||
mMyDevicePreference.setEnabled(true);
|
||||
preferenceScreen.addPreference(mMyDevicePreference);
|
||||
|
||||
if (mDiscoverableEnabler == null) {
|
||||
mDiscoverableEnabler = new BluetoothDiscoverableEnabler(getActivity(),
|
||||
mLocalAdapter, mMyDevicePreference);
|
||||
mDiscoverableEnabler.resume();
|
||||
LocalBluetoothManager.getInstance(getActivity()).setDiscoverableEnabler(
|
||||
mDiscoverableEnabler);
|
||||
if (! mUserManager.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH)) {
|
||||
if (mDiscoverableEnabler == null) {
|
||||
mDiscoverableEnabler = new BluetoothDiscoverableEnabler(getActivity(),
|
||||
mLocalAdapter, mMyDevicePreference);
|
||||
mDiscoverableEnabler.resume();
|
||||
LocalBluetoothManager.getInstance(getActivity()).setDiscoverableEnabler(
|
||||
mDiscoverableEnabler);
|
||||
}
|
||||
}
|
||||
|
||||
// Paired devices category
|
||||
@@ -278,7 +287,9 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
|
||||
BluetoothDeviceFilter.BONDED_DEVICE_FILTER);
|
||||
int numberOfPairedDevices = mPairedDevicesCategory.getPreferenceCount();
|
||||
|
||||
mDiscoverableEnabler.setNumberOfPairedDevices(numberOfPairedDevices);
|
||||
if (mDiscoverableEnabler != null) {
|
||||
mDiscoverableEnabler.setNumberOfPairedDevices(numberOfPairedDevices);
|
||||
}
|
||||
|
||||
// Available devices category
|
||||
if (mAvailableDevicesCategory == null) {
|
||||
@@ -286,9 +297,11 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
|
||||
} else {
|
||||
mAvailableDevicesCategory.removeAll();
|
||||
}
|
||||
addDeviceCategory(mAvailableDevicesCategory,
|
||||
R.string.bluetooth_preference_found_devices,
|
||||
BluetoothDeviceFilter.UNBONDED_DEVICE_FILTER);
|
||||
if (! mUserManager.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH)) {
|
||||
addDeviceCategory(mAvailableDevicesCategory,
|
||||
R.string.bluetooth_preference_found_devices,
|
||||
BluetoothDeviceFilter.UNBONDED_DEVICE_FILTER);
|
||||
}
|
||||
int numberOfAvailableDevices = mAvailableDevicesCategory.getPreferenceCount();
|
||||
mAvailableDevicesCategoryIsPresent = true;
|
||||
|
||||
@@ -353,6 +366,8 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
|
||||
public void onClick(View v) {
|
||||
// User clicked on advanced options icon for a device in the list
|
||||
if (v.getTag() instanceof CachedBluetoothDevice) {
|
||||
if (mUserManager.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH)) return;
|
||||
|
||||
CachedBluetoothDevice device = (CachedBluetoothDevice) v.getTag();
|
||||
|
||||
Bundle args = new Bundle(1);
|
||||
|
@@ -16,11 +16,15 @@
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothDevicePicker;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
@@ -51,7 +55,9 @@ public final class DevicePickerFragment extends DeviceListPreferenceFragment {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getActivity().setTitle(getString(R.string.device_picker));
|
||||
mStartScanOnResume = (savedInstanceState == null); // don't start scan after rotation
|
||||
UserManager um = (UserManager) getSystemService(Context.USER_SERVICE);
|
||||
mStartScanOnResume = !um.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH)
|
||||
&& (savedInstanceState == null); // don't start scan after rotation
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user