summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeoffrey Borggaard <geoffreyb@google.com>2013-08-02 15:03:22 -0400
committerGeoffrey Borggaard <geoffreyb@google.com>2013-08-02 17:07:21 -0400
commite38ea38002290da8ed16f07ea45f0ebfb41b38cd (patch)
treef14fd120a61adeef202ab5febe267644e98072ac
parent040ce605826af509f6391e3536204c07476dc28a (diff)
downloadpackages_apps_Settings-e38ea38002290da8ed16f07ea45f0ebfb41b38cd.zip
packages_apps_Settings-e38ea38002290da8ed16f07ea45f0ebfb41b38cd.tar.gz
packages_apps_Settings-e38ea38002290da8ed16f07ea45f0ebfb41b38cd.tar.bz2
Adds a base class for restricted settings
Creates an easy way to ask for the restriction pin before allowing access to a settings page. Does this to the WiFiSettings. Change-Id: I49734f66e09b6449596412ecf6fc1113bf57ce7f
-rw-r--r--src/com/android/settings/RestrictedSettingsFragment.java127
-rw-r--r--src/com/android/settings/wifi/WifiSettings.java31
2 files changed, 140 insertions, 18 deletions
diff --git a/src/com/android/settings/RestrictedSettingsFragment.java b/src/com/android/settings/RestrictedSettingsFragment.java
new file mode 100644
index 0000000..55c264c
--- /dev/null
+++ b/src/com/android/settings/RestrictedSettingsFragment.java
@@ -0,0 +1,127 @@
+/*
+ * 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;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.UserManager;
+
+/**
+ * Base class for settings activities that should be pin protected when in restricted mode.
+ * The constructor for this class will take the restriction key that this screen should be
+ * locked by. If {@link UserManager.hasRestrictionsPin()} and {@link UserManager.hasUserRestriction(String)} returns true for the
+ * restriction key, then the user will hav
+ *
+ */
+public class RestrictedSettingsFragment extends SettingsPreferenceFragment {
+
+ // Should be unique across all settings screens that use this.
+ private static final int REQUEST_PIN_CHALLENGE = 12309;
+
+ private static final String KEY_CHALLENGE_SUCCEEDED = "chsc";
+ private static final String KEY_CHALLENGE_REQUESTED = "chrq";
+
+ // If the restriction PIN is entered correctly.
+ private boolean mChallengeSucceeded;
+ private boolean mChallengeRequested;
+
+ private UserManager mUserManager;
+
+ private final String mRestrictionKey;
+
+ public RestrictedSettingsFragment(String restrictedFlag) {
+ mRestrictionKey = restrictedFlag;
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+
+ mUserManager = (UserManager) getSystemService(Context.USER_SERVICE);
+ }
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+
+ if (icicle != null) {
+ mChallengeSucceeded = icicle.getBoolean(KEY_CHALLENGE_SUCCEEDED, false);
+ mChallengeRequested = icicle.getBoolean(KEY_CHALLENGE_REQUESTED, false);
+ }
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+
+ outState.putBoolean(KEY_CHALLENGE_REQUESTED, mChallengeRequested);
+ if (getActivity().isChangingConfigurations()) {
+ outState.putBoolean(KEY_CHALLENGE_SUCCEEDED, mChallengeSucceeded);
+ }
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ if (mUserManager.hasUserRestriction(mRestrictionKey)
+ && mUserManager.hasRestrictionsPin()) {
+ ensurePin();
+ }
+ }
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == REQUEST_PIN_CHALLENGE) {
+ mChallengeRequested = false;
+ if (resultCode == Activity.RESULT_OK) {
+
+ mChallengeSucceeded = true;
+ } else if (!isDetached()) {
+ finishFragment();
+ }
+ return;
+ }
+
+ super.onActivityResult(requestCode, resultCode, data);
+ }
+
+ private void ensurePin() {
+ if (!mChallengeSucceeded) {
+ final UserManager um = UserManager.get(getActivity());
+ if (!mChallengeRequested) {
+ if (um.hasRestrictionsPin()) {
+ Intent requestPin =
+ new Intent(Intent.ACTION_RESTRICTIONS_PIN_CHALLENGE);
+ startActivityForResult(requestPin, REQUEST_PIN_CHALLENGE);
+ mChallengeRequested = true;
+ }
+ }
+ }
+ mChallengeSucceeded = false;
+ }
+
+ /**
+ * Returns true if this activity is restricted, but no restriction pin has been set.
+ * Used to determine if the settings UI should disable UI.
+ */
+ protected boolean isRestrictedAndNotPinProtected() {
+ return mUserManager.hasUserRestriction(mRestrictionKey)
+ && !mUserManager.hasRestrictionsPin();
+ }
+}
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 24f56c1..9fc1010 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -19,6 +19,13 @@ package com.android.settings.wifi;
import static android.net.wifi.WifiConfiguration.INVALID_NETWORK_ID;
import static android.os.UserManager.DISALLOW_CONFIG_WIFI;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+
import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
@@ -43,12 +50,10 @@ import android.net.wifi.WpsInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
-import android.os.UserManager;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.provider.Settings;
-import android.telephony.TelephonyManager;
import android.util.AttributeSet;
import android.util.Log;
import android.view.ContextMenu;
@@ -72,16 +77,9 @@ import android.widget.TextView;
import android.widget.Toast;
import com.android.settings.R;
-import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.RestrictedSettingsFragment;
import com.android.settings.wifi.p2p.WifiP2pSettings;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicBoolean;
-
/**
* Two types of UI are provided here.
*
@@ -90,7 +88,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
* The second is for Setup Wizard, with a simplified interface that hides the action bar
* and menus.
*/
-public class WifiSettings extends SettingsPreferenceFragment
+public class WifiSettings extends RestrictedSettingsFragment
implements DialogInterface.OnClickListener {
private static final String TAG = "WifiSettings";
private static final int MENU_ID_WPS_PBC = Menu.FIRST;
@@ -129,9 +127,6 @@ public class WifiSettings extends SettingsPreferenceFragment
private WifiManager.ActionListener mForgetListener;
private boolean mP2pSupported;
-
- private UserManager mUserManager;
-
private WifiEnabler mWifiEnabler;
// An access point being editted is stored here.
private AccessPoint mSelectedAccessPoint;
@@ -179,6 +174,7 @@ public class WifiSettings extends SettingsPreferenceFragment
/* End of "used in Wifi Setup context" */
public WifiSettings() {
+ super(DISALLOW_CONFIG_WIFI);
mFilter = new IntentFilter();
mFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
mFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
@@ -292,7 +288,6 @@ public class WifiSettings extends SettingsPreferenceFragment
mP2pSupported = getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT);
mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
- mUserManager = (UserManager) getSystemService(Context.USER_SERVICE);
mConnectListener = new WifiManager.ActionListener() {
@Override
@@ -449,7 +444,7 @@ public class WifiSettings extends SettingsPreferenceFragment
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// If the user is not allowed to configure wifi, do not show the menu.
- if (mUserManager.hasUserRestriction(DISALLOW_CONFIG_WIFI)) return;
+ if (isRestrictedAndNotPinProtected()) return;
final boolean wifiIsEnabled = mWifiManager.isWifiEnabled();
if (mSetupWizardMode) {
@@ -507,7 +502,7 @@ public class WifiSettings extends SettingsPreferenceFragment
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// If the user is not allowed to configure wifi, do not handle menu selections.
- if (mUserManager.hasUserRestriction(DISALLOW_CONFIG_WIFI)) return false;
+ if (isRestrictedAndNotPinProtected()) return false;
switch (item.getItemId()) {
case MENU_ID_WPS_PBC:
@@ -709,7 +704,7 @@ public class WifiSettings extends SettingsPreferenceFragment
// Safeguard from some delayed event handling
if (getActivity() == null) return;
- if (mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_WIFI)) {
+ if (isRestrictedAndNotPinProtected()) {
addMessagePreference(R.string.wifi_empty_list_user_restricted);
return;
}