Use restrictionsprovider framework in Settings.
Bug: 15305103 Change-Id: Ib0147e366fe90de3512d0cc06e2a47ee16012dff
This commit is contained in:
@@ -268,6 +268,8 @@
|
|||||||
<string name="bluetooth_disconnect_title">Disconnect?</string>
|
<string name="bluetooth_disconnect_title">Disconnect?</string>
|
||||||
<!-- Bluetooth settings. Message for disconnecting from all profiles of a bluetooth device. [CHAR LIMIT=NONE] -->
|
<!-- Bluetooth settings. Message for disconnecting from all profiles of a bluetooth device. [CHAR LIMIT=NONE] -->
|
||||||
<string name="bluetooth_disconnect_all_profiles">This will end your connection with:<br><b><xliff:g id="device_name">%1$s</xliff:g></b></string>
|
<string name="bluetooth_disconnect_all_profiles">This will end your connection with:<br><b><xliff:g id="device_name">%1$s</xliff:g></b></string>
|
||||||
|
<!-- Bluetooth Settings. text displayed when user has restriction DISALLOW_CONFIG_BLUETOOTH [CHAR LIMIT=NONE]-->
|
||||||
|
<string name="bluetooth_empty_list_user_restricted">You don\'t have permission to change Bluetooth settings.</string>
|
||||||
|
|
||||||
<!-- Bluetooth Visibility message. This message informs the user that their device is now visible to other bluetooth devices. [CHAR LIMIT=50] -->
|
<!-- Bluetooth Visibility message. This message informs the user that their device is now visible to other bluetooth devices. [CHAR LIMIT=50] -->
|
||||||
<string name="bluetooth_is_visible_message"><xliff:g id="device_name">%1$s</xliff:g> is now visible to nearby devices.</string>
|
<string name="bluetooth_is_visible_message"><xliff:g id="device_name">%1$s</xliff:g> is now visible to nearby devices.</string>
|
||||||
@@ -5792,6 +5794,9 @@
|
|||||||
<!-- Full package name of OEM preferred device feedback reporter [DO NOT TRANSLATE] -->
|
<!-- Full package name of OEM preferred device feedback reporter [DO NOT TRANSLATE] -->
|
||||||
<string name="oem_preferred_feedback_reporter" translatable="false"></string>
|
<string name="oem_preferred_feedback_reporter" translatable="false"></string>
|
||||||
|
|
||||||
|
<!-- PIN entry dialog title for entering the administrator PIN [CHAR LIMIT=none] -->
|
||||||
|
<string name="restr_pin_enter_admin_pin">Enter administrator PIN</string>
|
||||||
|
|
||||||
<!-- Switch On/Off -->
|
<!-- Switch On/Off -->
|
||||||
<string name="switch_on_text">On</string>
|
<string name="switch_on_text">On</string>
|
||||||
<string name="switch_off_text">Off</string>
|
<string name="switch_off_text">Off</string>
|
||||||
|
@@ -23,62 +23,61 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.content.RestrictionsManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.PersistableBundle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for settings activities that should be pin protected when in restricted mode.
|
* Base class for settings screens that should be pin protected when in restricted mode.
|
||||||
* The constructor for this class will take the restriction key that this screen should be
|
* The constructor for this class will take the restriction key that this screen should be
|
||||||
* locked by. If {@link UserManager.hasRestrictionsPin()} and
|
* locked by. If {@link RestrictionsManager.hasRestrictionsProvider()} and
|
||||||
* {@link UserManager.hasUserRestriction(String)} returns true for the restriction key, then
|
* {@link UserManager.hasUserRestriction()}, then the user will have to enter the restrictions
|
||||||
* the user will have to enter the restrictions pin before seeing the Settings screen.
|
* pin before seeing the Settings screen.
|
||||||
*
|
*
|
||||||
* If this settings screen should be pin protected whenever
|
* If this settings screen should be pin protected whenever
|
||||||
* {@link UserManager.hasUserRestriction(String)} returns true, pass in
|
* {@link RestrictionsManager.hasRestrictionsProvider()} returns true, pass in
|
||||||
* {@link RESTRICTIONS_PIN_SET} to the constructor instead of a restrictions key.
|
* {@link RESTRICT_IF_OVERRIDABLE} to the constructor instead of a restrictions key.
|
||||||
*/
|
*/
|
||||||
public class RestrictedSettingsFragment extends SettingsPreferenceFragment {
|
public class RestrictedSettingsFragment extends SettingsPreferenceFragment {
|
||||||
|
|
||||||
protected static final String RESTRICTIONS_PIN_SET = "restrictions_pin_set";
|
protected static final String RESTRICT_IF_OVERRIDABLE = "restrict_if_overridable";
|
||||||
|
|
||||||
private static final String EXTRA_PREFERENCE = "pref";
|
// No RestrictedSettingsFragment screens should use this number in startActivityForResult.
|
||||||
private static final String EXTRA_CHECKBOX_STATE = "isChecked";
|
|
||||||
// Should be unique across all settings screens that use this.
|
|
||||||
private static final int REQUEST_PIN_CHALLENGE = 12309;
|
private static final int REQUEST_PIN_CHALLENGE = 12309;
|
||||||
|
|
||||||
private static final String KEY_CHALLENGE_SUCCEEDED = "chsc";
|
private static final String KEY_CHALLENGE_SUCCEEDED = "chsc";
|
||||||
private static final String KEY_CHALLENGE_REQUESTED = "chrq";
|
private static final String KEY_CHALLENGE_REQUESTED = "chrq";
|
||||||
private static final String KEY_RESUME_ACTION_BUNDLE = "rsmb";
|
|
||||||
|
|
||||||
// If the restriction PIN is entered correctly.
|
// If the restriction PIN is entered correctly.
|
||||||
private boolean mChallengeSucceeded;
|
private boolean mChallengeSucceeded;
|
||||||
private boolean mChallengeRequested;
|
private boolean mChallengeRequested;
|
||||||
private Bundle mResumeActionBundle;
|
private boolean mScreenToggledOff;
|
||||||
|
|
||||||
private UserManager mUserManager;
|
private UserManager mUserManager;
|
||||||
|
private RestrictionsManager mRestrictionsManager;
|
||||||
|
|
||||||
private final String mRestrictionKey;
|
private final String mRestrictionKey;
|
||||||
|
|
||||||
private final HashSet<Preference> mProtectedByRestictionsPrefs = new HashSet<Preference>();
|
|
||||||
|
|
||||||
// Receiver to clear pin status when the screen is turned off.
|
// Receiver to clear pin status when the screen is turned off.
|
||||||
private BroadcastReceiver mScreenOffReceiver = new BroadcastReceiver() {
|
private BroadcastReceiver mScreenOffReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
mChallengeSucceeded = false;
|
if (!mChallengeRequested) {
|
||||||
if (shouldBePinProtected(mRestrictionKey)) {
|
mChallengeSucceeded = false;
|
||||||
ensurePin(null);
|
mChallengeRequested = false;
|
||||||
|
mScreenToggledOff = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param restrictionKey The restriction key to check before pin protecting
|
* @param restrictionKey The restriction key to check before pin protecting
|
||||||
* this settings page. Pass in {@link RESTRICTIONS_PIN_SET} if it should
|
* this settings page. Pass in {@link RESTRICT_IF_OVERRIDABLE} if it should
|
||||||
* be PIN protected whenever a restrictions pin is set. Pass in
|
* be protected whenever a restrictions provider is set. Pass in
|
||||||
* null if it should never be PIN protected.
|
* null if it should never be protected.
|
||||||
*/
|
*/
|
||||||
public RestrictedSettingsFragment(String restrictionKey) {
|
public RestrictedSettingsFragment(String restrictionKey) {
|
||||||
mRestrictionKey = restrictionKey;
|
mRestrictionKey = restrictionKey;
|
||||||
@@ -88,12 +87,24 @@ public class RestrictedSettingsFragment extends SettingsPreferenceFragment {
|
|||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
|
|
||||||
|
mRestrictionsManager = (RestrictionsManager) getSystemService(Context.RESTRICTIONS_SERVICE);
|
||||||
mUserManager = (UserManager) getSystemService(Context.USER_SERVICE);
|
mUserManager = (UserManager) getSystemService(Context.USER_SERVICE);
|
||||||
|
|
||||||
if (icicle != null) {
|
if (icicle != null) {
|
||||||
mChallengeSucceeded = icicle.getBoolean(KEY_CHALLENGE_SUCCEEDED, false);
|
mChallengeSucceeded = icicle.getBoolean(KEY_CHALLENGE_SUCCEEDED, false);
|
||||||
mChallengeRequested = icicle.getBoolean(KEY_CHALLENGE_REQUESTED, false);
|
mChallengeRequested = icicle.getBoolean(KEY_CHALLENGE_REQUESTED, false);
|
||||||
mResumeActionBundle = icicle.getBundle(KEY_RESUME_ACTION_BUNDLE);
|
} else {
|
||||||
|
mChallengeSucceeded = false;
|
||||||
|
mChallengeRequested = false;
|
||||||
|
}
|
||||||
|
mScreenToggledOff = false;
|
||||||
|
|
||||||
|
IntentFilter offFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
|
||||||
|
offFilter.addAction(Intent.ACTION_USER_PRESENT);
|
||||||
|
getActivity().registerReceiver(mScreenOffReceiver, offFilter);
|
||||||
|
|
||||||
|
if (shouldBeProviderProtected(mRestrictionKey)) {
|
||||||
|
ensurePin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,11 +112,8 @@ public class RestrictedSettingsFragment extends SettingsPreferenceFragment {
|
|||||||
public void onSaveInstanceState(Bundle outState) {
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
|
|
||||||
outState.putBoolean(KEY_CHALLENGE_REQUESTED, mChallengeRequested);
|
|
||||||
if (mResumeActionBundle != null) {
|
|
||||||
outState.putBundle(KEY_RESUME_ACTION_BUNDLE, mResumeActionBundle);
|
|
||||||
}
|
|
||||||
if (getActivity().isChangingConfigurations()) {
|
if (getActivity().isChangingConfigurations()) {
|
||||||
|
outState.putBoolean(KEY_CHALLENGE_REQUESTED, mChallengeRequested);
|
||||||
outState.putBoolean(KEY_CHALLENGE_SUCCEEDED, mChallengeSucceeded);
|
outState.putBoolean(KEY_CHALLENGE_SUCCEEDED, mChallengeSucceeded);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -113,55 +121,28 @@ public class RestrictedSettingsFragment extends SettingsPreferenceFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if (shouldBePinProtected(mRestrictionKey)) {
|
if (mScreenToggledOff) {
|
||||||
ensurePin(null);
|
mScreenToggledOff = false;
|
||||||
} else {
|
if(shouldBeProviderProtected(mRestrictionKey)) {
|
||||||
// If the whole screen is not pin protected, reset mChallengeSucceeded so next
|
ensurePin();
|
||||||
// time user uses a protected preference, they are prompted for pin again.
|
}
|
||||||
mChallengeSucceeded = false;
|
|
||||||
}
|
}
|
||||||
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
|
|
||||||
filter.addAction(Intent.ACTION_USER_PRESENT);
|
|
||||||
getActivity().registerReceiver(mScreenOffReceiver, filter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onDestroy() {
|
||||||
super.onPause();
|
|
||||||
getActivity().unregisterReceiver(mScreenOffReceiver);
|
getActivity().unregisterReceiver(mScreenOffReceiver);
|
||||||
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (requestCode == REQUEST_PIN_CHALLENGE) {
|
if (requestCode == REQUEST_PIN_CHALLENGE) {
|
||||||
Bundle resumeActionBundle = mResumeActionBundle;
|
|
||||||
mResumeActionBundle = null;
|
|
||||||
mChallengeRequested = false;
|
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
mChallengeSucceeded = true;
|
mChallengeSucceeded = true;
|
||||||
String prefKey = resumeActionBundle == null ?
|
mChallengeRequested = false;
|
||||||
null : resumeActionBundle.getString(EXTRA_PREFERENCE);
|
} else {
|
||||||
if (prefKey != null) {
|
mChallengeSucceeded = false;
|
||||||
Preference pref = findPreference(prefKey);
|
|
||||||
if (pref != null) {
|
|
||||||
// Make sure the checkbox state is the same as it was when we launched the
|
|
||||||
// pin challenge.
|
|
||||||
if (pref instanceof CheckBoxPreference
|
|
||||||
&& resumeActionBundle.containsKey(EXTRA_CHECKBOX_STATE)) {
|
|
||||||
boolean isChecked =
|
|
||||||
resumeActionBundle.getBoolean(EXTRA_CHECKBOX_STATE, false);
|
|
||||||
((CheckBoxPreference)pref).setChecked(isChecked);
|
|
||||||
}
|
|
||||||
if (!onPreferenceTreeClick(getPreferenceScreen(), pref)) {
|
|
||||||
Intent prefIntent = pref.getIntent();
|
|
||||||
if (prefIntent != null) {
|
|
||||||
pref.getContext().startActivity(prefIntent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (!isDetached()) {
|
|
||||||
finishFragment();
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -169,93 +150,54 @@ public class RestrictedSettingsFragment extends SettingsPreferenceFragment {
|
|||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ensurePin(Preference preference) {
|
private void ensurePin() {
|
||||||
if (!mChallengeSucceeded) {
|
if (!mChallengeSucceeded && !mChallengeRequested
|
||||||
final UserManager um = UserManager.get(getActivity());
|
&& mRestrictionsManager.hasRestrictionsProvider()) {
|
||||||
if (!mChallengeRequested) {
|
Intent intent = mRestrictionsManager.getLocalApprovalIntent();
|
||||||
if (um.hasRestrictionsChallenge()) {
|
if (intent != null) {
|
||||||
mResumeActionBundle = new Bundle();
|
mChallengeRequested = true;
|
||||||
if (preference != null) {
|
mChallengeSucceeded = false;
|
||||||
mResumeActionBundle.putString(EXTRA_PREFERENCE, preference.getKey());
|
PersistableBundle request = new PersistableBundle();
|
||||||
if (preference instanceof CheckBoxPreference) {
|
request.putString(RestrictionsManager.REQUEST_KEY_MESSAGE,
|
||||||
mResumeActionBundle.putBoolean(EXTRA_CHECKBOX_STATE,
|
getResources().getString(R.string.restr_pin_enter_admin_pin));
|
||||||
((CheckBoxPreference)preference).isChecked());
|
intent.putExtra(RestrictionsManager.EXTRA_REQUEST_BUNDLE, request);
|
||||||
}
|
startActivityForResult(intent, REQUEST_PIN_CHALLENGE);
|
||||||
}
|
|
||||||
Intent requestPin = new Intent(Intent.ACTION_RESTRICTIONS_CHALLENGE);
|
|
||||||
startActivityForResult(requestPin, REQUEST_PIN_CHALLENGE);
|
|
||||||
mChallengeRequested = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mChallengeSucceeded = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if this activity is restricted, but no restriction pin has been set.
|
* Returns true if this activity is restricted, but no restrictions provider has been set.
|
||||||
* Used to determine if the settings UI should disable UI.
|
* Used to determine if the settings UI should disable UI.
|
||||||
*/
|
*/
|
||||||
protected boolean isRestrictedAndNotPinProtected() {
|
protected boolean isRestrictedAndNotProviderProtected() {
|
||||||
if (mRestrictionKey == null || RESTRICTIONS_PIN_SET.equals(mRestrictionKey)) {
|
if (mRestrictionKey == null || RESTRICT_IF_OVERRIDABLE.equals(mRestrictionKey)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return mUserManager.hasUserRestriction(mRestrictionKey)
|
return mUserManager.hasUserRestriction(mRestrictionKey)
|
||||||
&& !mUserManager.hasRestrictionsChallenge();
|
&& !mRestrictionsManager.hasRestrictionsProvider();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean hasChallengeSucceeded() {
|
||||||
|
return (mChallengeRequested && mChallengeSucceeded) || !mChallengeRequested;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called to trigger the pin entry if the given restriction key is locked down.
|
* Returns true if this restrictions key is locked down.
|
||||||
* @param restrictionsKey The restriction key or {@link RESTRICTIONS_PIN_SET} if
|
|
||||||
* pin entry should get triggered if there is a pin set.
|
|
||||||
*/
|
*/
|
||||||
protected boolean restrictionsPinCheck(String restrictionsKey, Preference preference) {
|
protected boolean shouldBeProviderProtected(String restrictionKey) {
|
||||||
if (shouldBePinProtected(restrictionsKey) && !mChallengeSucceeded) {
|
if (restrictionKey == null) {
|
||||||
ensurePin(preference);
|
return false;
|
||||||
return false;
|
}
|
||||||
} else {
|
boolean restricted = RESTRICT_IF_OVERRIDABLE.equals(restrictionKey)
|
||||||
return true;
|
|| mUserManager.hasUserRestriction(mRestrictionKey);
|
||||||
}
|
return restricted && mRestrictionsManager.hasRestrictionsProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean hasChallengeSucceeded() {
|
|
||||||
return mChallengeSucceeded;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if this restrictions key is locked down.
|
|
||||||
*/
|
|
||||||
protected boolean shouldBePinProtected(String restrictionKey) {
|
|
||||||
if (restrictionKey == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
boolean restricted = RESTRICTIONS_PIN_SET.equals(restrictionKey)
|
|
||||||
|| mUserManager.hasUserRestriction(restrictionKey);
|
|
||||||
return restricted && mUserManager.hasRestrictionsChallenge();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If the preference is one that was added by protectByRestrictions(), then it will
|
|
||||||
* prompt the user for the restrictions pin if they haven't entered it already.
|
|
||||||
* Intended to be called at the top of onPreferenceTreeClick. If this function returns
|
|
||||||
* true, then onPreferenceTreeClick should return true.
|
|
||||||
*/
|
|
||||||
boolean ensurePinRestrictedPreference(Preference preference) {
|
|
||||||
return mProtectedByRestictionsPrefs.contains(preference)
|
|
||||||
&& !restrictionsPinCheck(RESTRICTIONS_PIN_SET, preference);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call this with any preferences that should require the PIN to be entered
|
* Returns whether restricted or actionable UI elements should be removed or disabled.
|
||||||
* before they are accessible.
|
|
||||||
*/
|
*/
|
||||||
protected void protectByRestrictions(Preference pref) {
|
protected boolean isUiRestricted() {
|
||||||
if (pref != null) {
|
return isRestrictedAndNotProviderProtected() || !hasChallengeSucceeded();
|
||||||
mProtectedByRestictionsPrefs.add(pref);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void protectByRestrictions(String key) {
|
|
||||||
Preference pref = findPreference(key);
|
|
||||||
protectByRestrictions(pref);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -140,6 +140,13 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
|
|||||||
}
|
}
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
|
if (isUiRestricted()) {
|
||||||
|
setDeviceListGroup(getPreferenceScreen());
|
||||||
|
removeAllDevices();
|
||||||
|
mEmptyView.setText(R.string.bluetooth_empty_list_user_restricted);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
getActivity().registerReceiver(mReceiver, mIntentFilter);
|
getActivity().registerReceiver(mReceiver, mIntentFilter);
|
||||||
if (mLocalAdapter != null) {
|
if (mLocalAdapter != null) {
|
||||||
updateContent(mLocalAdapter.getBluetoothState(), mActivityStarted);
|
updateContent(mLocalAdapter.getBluetoothState(), mActivityStarted);
|
||||||
@@ -155,6 +162,11 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
|
|||||||
if (mBluetoothEnabler != null) {
|
if (mBluetoothEnabler != null) {
|
||||||
mBluetoothEnabler.pause();
|
mBluetoothEnabler.pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isUiRestricted()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
getActivity().unregisterReceiver(mReceiver);
|
getActivity().unregisterReceiver(mReceiver);
|
||||||
|
|
||||||
// Make the device only visible to connected devices.
|
// Make the device only visible to connected devices.
|
||||||
@@ -165,7 +177,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
|
|||||||
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 the user is not allowed to configure bluetooth, do not show the menu.
|
||||||
if (isRestrictedAndNotPinProtected()) return;
|
if (isUiRestricted()) return;
|
||||||
|
|
||||||
boolean bluetoothIsEnabled = mLocalAdapter.getBluetoothState() == BluetoothAdapter.STATE_ON;
|
boolean bluetoothIsEnabled = mLocalAdapter.getBluetoothState() == BluetoothAdapter.STATE_ON;
|
||||||
boolean isDiscovering = mLocalAdapter.isDiscovering();
|
boolean isDiscovering = mLocalAdapter.isDiscovering();
|
||||||
@@ -219,7 +231,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void startScanning() {
|
private void startScanning() {
|
||||||
if (isRestrictedAndNotPinProtected()) return;
|
if (isUiRestricted()) return;
|
||||||
if (!mAvailableDevicesCategoryIsPresent) {
|
if (!mAvailableDevicesCategoryIsPresent) {
|
||||||
getPreferenceScreen().addPreference(mAvailableDevicesCategory);
|
getPreferenceScreen().addPreference(mAvailableDevicesCategory);
|
||||||
}
|
}
|
||||||
@@ -252,6 +264,11 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
|
|||||||
preferenceScreen.setOrderingAsAdded(true);
|
preferenceScreen.setOrderingAsAdded(true);
|
||||||
mDevicePreferenceMap.clear();
|
mDevicePreferenceMap.clear();
|
||||||
|
|
||||||
|
if (isUiRestricted()) {
|
||||||
|
messageId = R.string.bluetooth_empty_list_user_restricted;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Paired devices category
|
// Paired devices category
|
||||||
if (mPairedDevicesCategory == null) {
|
if (mPairedDevicesCategory == null) {
|
||||||
mPairedDevicesCategory = new PreferenceCategory(getActivity());
|
mPairedDevicesCategory = new PreferenceCategory(getActivity());
|
||||||
@@ -270,11 +287,9 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
|
|||||||
} else {
|
} else {
|
||||||
mAvailableDevicesCategory.removeAll();
|
mAvailableDevicesCategory.removeAll();
|
||||||
}
|
}
|
||||||
if (!isRestrictedAndNotPinProtected()) {
|
addDeviceCategory(mAvailableDevicesCategory,
|
||||||
addDeviceCategory(mAvailableDevicesCategory,
|
R.string.bluetooth_preference_found_devices,
|
||||||
R.string.bluetooth_preference_found_devices,
|
BluetoothDeviceFilter.UNBONDED_DEVICE_FILTER);
|
||||||
BluetoothDeviceFilter.UNBONDED_DEVICE_FILTER);
|
|
||||||
}
|
|
||||||
int numberOfAvailableDevices = mAvailableDevicesCategory.getPreferenceCount();
|
int numberOfAvailableDevices = mAvailableDevicesCategory.getPreferenceCount();
|
||||||
mAvailableDevicesCategoryIsPresent = true;
|
mAvailableDevicesCategoryIsPresent = true;
|
||||||
|
|
||||||
@@ -313,6 +328,9 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
|
|||||||
|
|
||||||
case BluetoothAdapter.STATE_OFF:
|
case BluetoothAdapter.STATE_OFF:
|
||||||
messageId = R.string.bluetooth_empty_list_bluetooth_off;
|
messageId = R.string.bluetooth_empty_list_bluetooth_off;
|
||||||
|
if (isUiRestricted()) {
|
||||||
|
messageId = R.string.bluetooth_empty_list_user_restricted;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BluetoothAdapter.STATE_TURNING_ON:
|
case BluetoothAdapter.STATE_TURNING_ON:
|
||||||
@@ -323,7 +341,9 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
|
|||||||
setDeviceListGroup(preferenceScreen);
|
setDeviceListGroup(preferenceScreen);
|
||||||
removeAllDevices();
|
removeAllDevices();
|
||||||
mEmptyView.setText(messageId);
|
mEmptyView.setText(messageId);
|
||||||
getActivity().invalidateOptionsMenu();
|
if (!isUiRestricted()) {
|
||||||
|
getActivity().invalidateOptionsMenu();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -336,7 +356,9 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
|
|||||||
public void onScanningStateChanged(boolean started) {
|
public void onScanningStateChanged(boolean started) {
|
||||||
super.onScanningStateChanged(started);
|
super.onScanningStateChanged(started);
|
||||||
// Update options' enabled state
|
// Update options' enabled state
|
||||||
getActivity().invalidateOptionsMenu();
|
if (getActivity() != null) {
|
||||||
|
getActivity().invalidateOptionsMenu();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -350,7 +372,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
|
|||||||
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 (isRestrictedAndNotPinProtected()) return;
|
if (isUiRestricted()) return;
|
||||||
|
|
||||||
CachedBluetoothDevice device = (CachedBluetoothDevice) v.getTag();
|
CachedBluetoothDevice device = (CachedBluetoothDevice) v.getTag();
|
||||||
|
|
||||||
|
@@ -96,7 +96,7 @@ public abstract class DeviceListPreferenceFragment extends
|
|||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if (mLocalManager == null) return;
|
if (mLocalManager == null || isUiRestricted()) return;
|
||||||
|
|
||||||
mLocalManager.setForegroundActivity(getActivity());
|
mLocalManager.setForegroundActivity(getActivity());
|
||||||
mLocalManager.getEventManager().registerCallback(this);
|
mLocalManager.getEventManager().registerCallback(this);
|
||||||
@@ -107,7 +107,9 @@ public abstract class DeviceListPreferenceFragment extends
|
|||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
if (mLocalManager == null) return;
|
if (mLocalManager == null || isUiRestricted()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
removeAllDevices();
|
removeAllDevices();
|
||||||
mLocalManager.setForegroundActivity(null);
|
mLocalManager.setForegroundActivity(null);
|
||||||
|
@@ -442,7 +442,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
// If the user is not allowed to configure wifi, do not show the menu.
|
// If the user is not allowed to configure wifi, do not show the menu.
|
||||||
if (isRestrictedAndNotPinProtected()) return;
|
if (isUiRestricted()) return;
|
||||||
|
|
||||||
addOptionsMenuItems(menu);
|
addOptionsMenuItems(menu);
|
||||||
super.onCreateOptionsMenu(menu, inflater);
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
@@ -491,7 +491,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
// If the user is not allowed to configure wifi, do not handle menu selections.
|
// If the user is not allowed to configure wifi, do not handle menu selections.
|
||||||
if (isRestrictedAndNotPinProtected()) return false;
|
if (isUiRestricted()) return false;
|
||||||
|
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case MENU_ID_WPS_PBC:
|
case MENU_ID_WPS_PBC:
|
||||||
@@ -686,7 +686,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
// Safeguard from some delayed event handling
|
// Safeguard from some delayed event handling
|
||||||
if (getActivity() == null) return;
|
if (getActivity() == null) return;
|
||||||
|
|
||||||
if (isRestrictedAndNotPinProtected()) {
|
if (isUiRestricted()) {
|
||||||
addMessagePreference(R.string.wifi_empty_list_user_restricted);
|
addMessagePreference(R.string.wifi_empty_list_user_restricted);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user