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