Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3c3fa0cc authored by Maggie Benthall's avatar Maggie Benthall Committed by Android (Google) Code Review
Browse files

Merge "Implement Settings app UX for when a user has bluetooth config locked down." into jb-mr2-dev

parents d81a3f73 11b69bf8
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -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,8 +66,11 @@ public final class BluetoothDevicePreference extends Preference implements
        mCachedDevice = cachedDevice;

        if (cachedDevice.getBondState() == BluetoothDevice.BOND_BONDED) {
            UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
            if (! um.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH)) {
                setWidgetLayoutResource(R.layout.preference_bluetooth);
            }
        }

        mCachedDevice.registerCallback(this);

+28 −13
Original line number Diff line number Diff line
@@ -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,6 +266,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
                mMyDevicePreference.setEnabled(true);
                preferenceScreen.addPreference(mMyDevicePreference);

                if (! mUserManager.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH)) {
                    if (mDiscoverableEnabler == null) {
                        mDiscoverableEnabler = new BluetoothDiscoverableEnabler(getActivity(),
                                mLocalAdapter, mMyDevicePreference);
@@ -266,6 +274,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
                        LocalBluetoothManager.getInstance(getActivity()).setDiscoverableEnabler(
                                mDiscoverableEnabler);
                    }
                }

                // Paired devices category
                if (mPairedDevicesCategory == null) {
@@ -278,7 +287,9 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
                        BluetoothDeviceFilter.BONDED_DEVICE_FILTER);
                int numberOfPairedDevices = mPairedDevicesCategory.getPreferenceCount();

                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();
                }
                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);
+7 −1
Original line number Diff line number Diff line
@@ -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