summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/com/android/settings/SecuritySettings.java26
-rw-r--r--src/com/android/settings/applications/InstalledAppDetails.java42
-rw-r--r--src/com/android/settings/profiles/AbstractTriggerPreference.java38
-rw-r--r--src/com/android/settings/profiles/BluetoothTriggerPreference.java45
-rw-r--r--src/com/android/settings/profiles/ProfileConfig.java16
-rw-r--r--src/com/android/settings/profiles/TriggersFragment.java229
-rw-r--r--src/com/android/settings/profiles/WifiTriggerAPPreference.java31
-rw-r--r--src/com/android/settings/profiles/WifiTriggerFragment.java139
8 files changed, 393 insertions, 173 deletions
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index e124fa2..b01dc74 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -40,6 +40,7 @@ import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
import android.provider.Settings;
+import android.provider.Settings.SettingNotFoundException;
import android.security.KeyStore;
import android.telephony.TelephonyManager;
import android.util.Log;
@@ -93,6 +94,8 @@ public class SecuritySettings extends SettingsPreferenceFragment
private static final String LOCKSCREEN_QUICK_UNLOCK_CONTROL = "quick_unlock_control";
private static final String KEY_VIBRATE_PREF = "lockscreen_vibrate";
private static final String KEY_SMS_SECURITY_CHECK_PREF = "sms_security_check_limit";
+ private static final String KEY_PRIVACY_GUARD_DEFAULT = "privacy_guard_default";
+ private static final String KEY_APP_SECURITY_CATEGORY = "app_security";
DevicePolicyManager mDPM;
@@ -125,6 +128,7 @@ public class SecuritySettings extends SettingsPreferenceFragment
private CheckBoxPreference mHomeUnlock;
private CheckBoxPreference mQuickUnlockScreen;
private ListPreference mSmsSecurityCheck;
+ private CheckBoxPreference mPrivacyGuardDefault;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -393,13 +397,26 @@ public class SecuritySettings extends SettingsPreferenceFragment
}
}
- boolean isTelephony = pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
- if (isTelephony) {
- addPreferencesFromResource(R.xml.security_settings_app_cyanogenmod);
+ // App security settings
+ addPreferencesFromResource(R.xml.security_settings_app_cyanogenmod);
+ mSmsSecurityCheck = (ListPreference) root.findPreference(KEY_SMS_SECURITY_CHECK_PREF);
+ if (pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
mSmsSecurityCheck = (ListPreference) root.findPreference(KEY_SMS_SECURITY_CHECK_PREF);
mSmsSecurityCheck.setOnPreferenceChangeListener(this);
int smsSecurityCheck = Integer.valueOf(mSmsSecurityCheck.getValue());
updateSmsSecuritySummary(smsSecurityCheck);
+ } else {
+ PreferenceGroup appCategory = (PreferenceGroup)
+ root.findPreference(KEY_APP_SECURITY_CATEGORY);
+ appCategory.removePreference(mSmsSecurityCheck);
+ }
+
+ mPrivacyGuardDefault = (CheckBoxPreference) findPreference(KEY_PRIVACY_GUARD_DEFAULT);
+ try {
+ mPrivacyGuardDefault.setChecked(Settings.Secure.getInt(getContentResolver(),
+ Settings.Secure.PRIVACY_GUARD_DEFAULT) == 1);
+ } catch (SettingNotFoundException e) {
+ mPrivacyGuardDefault.setChecked(false);
}
}
@@ -691,6 +708,9 @@ public class SecuritySettings extends SettingsPreferenceFragment
} else if (KEY_TOGGLE_VERIFY_APPLICATIONS.equals(key)) {
Settings.Global.putInt(getContentResolver(), Settings.Global.PACKAGE_VERIFIER_ENABLE,
mToggleVerifyApps.isChecked() ? 1 : 0);
+ } else if (KEY_PRIVACY_GUARD_DEFAULT.equals(key)) {
+ Settings.Secure.putInt(getContentResolver(), Settings.Secure.PRIVACY_GUARD_DEFAULT,
+ mPrivacyGuardDefault.isChecked() ? 1 : 0);
} else {
// If we didn't handle it, let preferences handle it.
return super.onPreferenceTreeClick(preferenceScreen, preference);
diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java
index be515df..36adae2 100644
--- a/src/com/android/settings/applications/InstalledAppDetails.java
+++ b/src/com/android/settings/applications/InstalledAppDetails.java
@@ -140,6 +140,7 @@ public class InstalledAppDetails extends Fragment
private Button mClearDataButton;
private Button mMoveAppButton;
private CompoundButton mNotificationSwitch;
+ private CompoundButton mPrivacyGuardSwitch;
private PackageMoveObserver mPackageMoveObserver;
@@ -179,6 +180,7 @@ public class InstalledAppDetails extends Fragment
private static final int DLG_DISABLE = DLG_BASE + 7;
private static final int DLG_DISABLE_NOTIFICATIONS = DLG_BASE + 8;
private static final int DLG_SPECIAL_DISABLE = DLG_BASE + 9;
+ private static final int DLG_PRIVACY_GUARD = DLG_BASE + 10;
// Menu identifiers
public static final int UNINSTALL_ALL_USERS_MENU = 1;
@@ -398,6 +400,13 @@ public class InstalledAppDetails extends Fragment
}
}
+ private void initPrivacyGuardButton() {
+ // TODO: We probably want to disable this optional for the built-in apps
+ boolean enabled = mPm.getPrivacyGuardSetting(mAppEntry.info.packageName);
+ mPrivacyGuardSwitch.setChecked(enabled);
+ mPrivacyGuardSwitch.setOnCheckedChangeListener(this);
+ }
+
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
@@ -475,6 +484,8 @@ public class InstalledAppDetails extends Fragment
mNotificationSwitch = (CompoundButton) view.findViewById(R.id.notification_switch);
+ mPrivacyGuardSwitch = (CompoundButton) view.findViewById(R.id.privacy_guard_switch);
+
return view;
}
@@ -981,6 +992,7 @@ public class InstalledAppDetails extends Fragment
initDataButtons();
initMoveButton();
initNotificationButton();
+ initPrivacyGuardButton();
} else {
mMoveAppButton.setText(R.string.moving);
mMoveAppButton.setEnabled(false);
@@ -1184,6 +1196,25 @@ public class InstalledAppDetails extends Fragment
})
.setNegativeButton(R.string.dlg_cancel, null)
.create();
+ case DLG_PRIVACY_GUARD:
+ return new AlertDialog.Builder(getActivity())
+ .setTitle(getActivity().getText(R.string.privacy_guard_dlg_title))
+ .setIconAttribute(android.R.attr.alertDialogIcon)
+ .setMessage(getActivity().getText(R.string.privacy_guard_dlg_text))
+ .setPositiveButton(R.string.dlg_ok,
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ getOwner().setPrivacyGuard(true);
+ }
+ })
+ .setNegativeButton(R.string.dlg_cancel,
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ // Re-enable the checkbox
+ getOwner().mPrivacyGuardSwitch.setChecked(false);
+ }
+ })
+ .create();
}
throw new IllegalArgumentException("unknown id " + id);
}
@@ -1273,6 +1304,11 @@ public class InstalledAppDetails extends Fragment
}
}
+ private void setPrivacyGuard(boolean enabled) {
+ String packageName = mAppEntry.info.packageName;
+ mPm.setPrivacyGuardSetting(packageName, enabled);
+ }
+
private int getPremiumSmsPermission(String packageName) {
try {
if (mSmsManager != null) {
@@ -1370,6 +1406,12 @@ public class InstalledAppDetails extends Fragment
} else {
setNotificationsEnabled(true);
}
+ } else if (buttonView == mPrivacyGuardSwitch) {
+ if (isChecked) {
+ showDialogInner(DLG_PRIVACY_GUARD, 0);
+ } else {
+ setPrivacyGuard(false);
+ }
}
}
}
diff --git a/src/com/android/settings/profiles/AbstractTriggerPreference.java b/src/com/android/settings/profiles/AbstractTriggerPreference.java
new file mode 100644
index 0000000..1bc2ec0
--- /dev/null
+++ b/src/com/android/settings/profiles/AbstractTriggerPreference.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2013 The CyanogenMod 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.profiles;
+
+import android.app.Profile;
+import android.content.Context;
+import android.preference.Preference;
+
+public class AbstractTriggerPreference extends Preference {
+
+ public AbstractTriggerPreference(Context context) {
+ super(context);
+ }
+
+ private int mTriggerState = Profile.TriggerState.DISABLED;
+
+ public void setTriggerState(int trigger) {
+ mTriggerState = trigger;
+ }
+
+ public int getTriggerState() {
+ return mTriggerState;
+ }
+}
diff --git a/src/com/android/settings/profiles/BluetoothTriggerPreference.java b/src/com/android/settings/profiles/BluetoothTriggerPreference.java
new file mode 100644
index 0000000..848fc28
--- /dev/null
+++ b/src/com/android/settings/profiles/BluetoothTriggerPreference.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2013 The CyanogenMod 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.profiles;
+
+import android.bluetooth.BluetoothDevice;
+import android.content.Context;
+
+public class BluetoothTriggerPreference extends AbstractTriggerPreference {
+
+ private String mAddress;
+
+ BluetoothTriggerPreference(Context context, BluetoothDevice device) {
+ super(context);
+ mAddress = device.getAddress();
+ if (device.getAlias() != null) {
+ setTitle(device.getAlias());
+ } else {
+ setTitle(device.getName());
+ }
+ }
+
+ BluetoothTriggerPreference(Context context, String name, String address) {
+ super(context);
+ mAddress = address;
+ setTitle(name);
+ }
+
+ public String getAddress() {
+ return mAddress;
+ }
+}
diff --git a/src/com/android/settings/profiles/ProfileConfig.java b/src/com/android/settings/profiles/ProfileConfig.java
index a27baa7..1a7a53e 100644
--- a/src/com/android/settings/profiles/ProfileConfig.java
+++ b/src/com/android/settings/profiles/ProfileConfig.java
@@ -63,7 +63,7 @@ public class ProfileConfig extends SettingsPreferenceFragment
private static final int MENU_DELETE = Menu.FIRST + 1;
- private static final int MENU_WIFI = Menu.FIRST + 2;
+ private static final int MENU_TRIGGERS = Menu.FIRST + 2;
private Profile mProfile;
@@ -135,9 +135,9 @@ public class ProfileConfig extends SettingsPreferenceFragment
nfc.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |
MenuItem.SHOW_AS_ACTION_WITH_TEXT);
}
- MenuItem wifi = menu.add(0, MENU_WIFI, 0, R.string.profile_trigger_wifi)
+ MenuItem triggers = menu.add(0, MENU_TRIGGERS, 0, R.string.profile_triggers)
.setIcon(R.drawable.ic_location);
- wifi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |
+ triggers.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |
MenuItem.SHOW_AS_ACTION_WITH_TEXT);
MenuItem delete = menu.add(0, MENU_DELETE, 1, R.string.profile_menu_delete)
.setIcon(R.drawable.ic_menu_trash_holo_dark);
@@ -154,8 +154,8 @@ public class ProfileConfig extends SettingsPreferenceFragment
case MENU_NFC_WRITE:
startNFCProfileWriter();
return true;
- case MENU_WIFI:
- startWifiTrigger();
+ case MENU_TRIGGERS:
+ startTriggerFragment();
return true;
default:
return false;
@@ -186,14 +186,12 @@ public class ProfileConfig extends SettingsPreferenceFragment
pa.startActivity(i);
}
- private void startWifiTrigger() {
+ private void startTriggerFragment() {
final PreferenceActivity pa = (PreferenceActivity) getActivity();
- final String title = getResources().getString(R.string.profile_trigger_title_wifi,
- mProfile.getName());
final Bundle args = new Bundle();
args.putParcelable("profile", mProfile);
- pa.startPreferencePanel(WifiTriggerFragment.class.getName(), args, 0, title, null, 0);
+ pa.startPreferencePanel(TriggersFragment.class.getName(), args, 0, "", null, 0);
}
private void fillList() {
diff --git a/src/com/android/settings/profiles/TriggersFragment.java b/src/com/android/settings/profiles/TriggersFragment.java
new file mode 100644
index 0000000..d3d01e9
--- /dev/null
+++ b/src/com/android/settings/profiles/TriggersFragment.java
@@ -0,0 +1,229 @@
+/*
+ * Copyright (C) 2013 The CyanogenMod 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.profiles;
+
+import android.app.ActionBar;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.Profile;
+import android.app.Profile.ProfileTrigger;
+import android.app.Profile.TriggerType;
+import android.app.ProfileManager;
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.res.Resources;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiManager;
+import android.os.Bundle;
+import android.preference.Preference;
+import android.preference.PreferenceScreen;
+import android.util.Log;
+import android.widget.ArrayAdapter;
+
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Settings Preference to configure triggers to switch profiles base on Wi-Fi events
+ */
+public class TriggersFragment extends SettingsPreferenceFragment implements ActionBar.OnNavigationListener {
+ private Profile mProfile;
+ private Preference mSelectedTrigger;
+ private ProfileManager mProfileManager;
+ private WifiManager mWifiManager;
+ private BluetoothAdapter mBluetoothAdapter;
+
+ private int mTriggerFilter = 0;
+ private static final int WIFI_TRIGGER = 1;
+ private static final int BT_TRIGGER = 2;
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ mProfileManager = (ProfileManager) getSystemService(Context.PROFILE_SERVICE);
+ mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
+ mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();;
+ addPreferencesFromResource(R.xml.wifi_settings);
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ loadPreferences();
+ loadActionBar();
+ }
+
+ private void loadActionBar() {
+ final ActionBar actionBar = getActivity().getActionBar();
+ actionBar.setDisplayShowTitleEnabled(true);
+ actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
+ Resources res = getResources();
+
+ String[] navItems = res.getStringArray(R.array.profile_trigger_filters);
+ ArrayAdapter<String> navAdapter = new ArrayAdapter<String>(
+ actionBar.getThemedContext(), android.R.layout.simple_list_item_1, navItems);
+
+ // Set up the dropdown list navigation in the action bar.
+ actionBar.setListNavigationCallbacks(navAdapter, this);
+ actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP
+ | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ Bundle args = getArguments();
+ if (args != null) {
+ mProfile = args.getParcelable("profile");
+ }
+ }
+
+ private void initPreference(AbstractTriggerPreference pref, int state, Resources res, int icon) {
+ String summary = res.getStringArray(R.array.profile_trigger_wifi_options)[state];
+ pref.setSummary(summary);
+ pref.setTriggerState(state);
+ pref.setIcon(icon);
+ }
+
+ private void loadPreferences() {
+ final List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks();
+ final Resources res = getResources();
+ final List<AbstractTriggerPreference> prefs = new ArrayList<AbstractTriggerPreference>();
+
+ getPreferenceScreen().removeAll();
+
+ if (mTriggerFilter == WIFI_TRIGGER || mTriggerFilter == 0) {
+ if (configs != null ) {
+ for (WifiConfiguration config : configs) {
+ WifiTriggerAPPreference accessPoint =
+ new WifiTriggerAPPreference(getActivity(), config);
+ int state = mProfile.getTrigger(Profile.TriggerType.WIFI, accessPoint.getSSID());
+ initPreference(accessPoint, state, res, R.drawable.ic_wifi_signal_4);
+ prefs.add(accessPoint);
+ }
+ } else {
+ final List<ProfileTrigger> triggers = mProfile.getTriggersFromType(TriggerType.WIFI);
+ for (ProfileTrigger trigger : triggers) {
+ WifiTriggerAPPreference accessPoint =
+ new WifiTriggerAPPreference(getActivity(), trigger.getName());
+ initPreference(accessPoint, trigger.getState(), res, R.drawable.ic_wifi_signal_4);
+ prefs.add(accessPoint);
+ }
+ }
+ }
+
+ Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
+ if (mTriggerFilter == BT_TRIGGER || mTriggerFilter == 0) {
+ if (!pairedDevices.isEmpty()) {
+ for (BluetoothDevice device : pairedDevices) {
+ BluetoothTriggerPreference bt =
+ new BluetoothTriggerPreference(getActivity(), device);
+ int state = mProfile.getTrigger(Profile.TriggerType.BLUETOOTH, bt.getAddress());
+ initPreference(bt, state, res, R.drawable.ic_settings_bluetooth2);
+ prefs.add(bt);
+ }
+ } else {
+ final List<ProfileTrigger> triggers = mProfile.getTriggersFromType(TriggerType.BLUETOOTH);
+ for (ProfileTrigger trigger : triggers) {
+ BluetoothTriggerPreference bt = new BluetoothTriggerPreference(getActivity(),
+ trigger.getName(), trigger.getId());
+ initPreference(bt, trigger.getState(), res, R.drawable.ic_settings_bluetooth2);
+ prefs.add(bt);
+ }
+ }
+ }
+
+ Collections.sort(prefs, new Comparator<AbstractTriggerPreference>() {
+ @Override
+ public int compare(AbstractTriggerPreference o1, AbstractTriggerPreference o2) {
+ if (o1.getTriggerState() == o2.getTriggerState()) {
+ return o1.compareTo(o2);
+ }
+ return o1.getTriggerState() < o2.getTriggerState() ? -1 : 1;
+ }
+ });
+ for (Preference pref: prefs) {
+ getPreferenceScreen().addPreference(pref);
+ }
+
+ }
+
+ @Override
+ public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
+ mSelectedTrigger = preference;
+ if (preference instanceof WifiTriggerAPPreference) {
+ showDialog(WIFI_TRIGGER);
+ return true;
+ } else if (preference instanceof BluetoothTriggerPreference) {
+ showDialog(BT_TRIGGER);
+ return true;
+ }
+ return super.onPreferenceTreeClick(screen, preference);
+ }
+
+ @Override
+ public Dialog onCreateDialog(final int dialogId) {
+ final String id;
+ final String triggerName = mSelectedTrigger.getTitle().toString();
+ final int triggerType;
+
+ switch (dialogId) {
+ case WIFI_TRIGGER:
+ WifiTriggerAPPreference pref = (WifiTriggerAPPreference) mSelectedTrigger;
+ id = pref.getSSID();
+ triggerType = Profile.TriggerType.WIFI;
+ break;
+ case BT_TRIGGER:
+ BluetoothTriggerPreference btpref = (BluetoothTriggerPreference) mSelectedTrigger;
+ id = btpref.getAddress();
+ triggerType = Profile.TriggerType.BLUETOOTH;
+ break;
+ default:
+ return super.onCreateDialog(dialogId);
+ }
+
+ return new AlertDialog.Builder(getActivity())
+ .setTitle(R.string.profile_trigger_configure)
+ .setSingleChoiceItems(R.array.profile_trigger_wifi_options,
+ mProfile.getTrigger(triggerType, id),
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ mProfile.setTrigger(triggerType, id, which, triggerName);
+ mProfileManager.updateProfile(mProfile);
+ loadPreferences();
+ dialog.dismiss();
+ }
+ })
+ .create();
+ }
+
+ @Override
+ public boolean onNavigationItemSelected(int itemPosition, long itemId) {
+ mTriggerFilter = itemPosition;
+ loadPreferences();
+ return true;
+ }
+}
diff --git a/src/com/android/settings/profiles/WifiTriggerAPPreference.java b/src/com/android/settings/profiles/WifiTriggerAPPreference.java
index c886bc1..239509a 100644
--- a/src/com/android/settings/profiles/WifiTriggerAPPreference.java
+++ b/src/com/android/settings/profiles/WifiTriggerAPPreference.java
@@ -16,46 +16,33 @@
package com.android.settings.profiles;
-import android.app.Profile;
import android.content.Context;
import android.net.wifi.WifiConfiguration;
-import android.os.Bundle;
-import android.preference.Preference;
-import com.android.settings.R;
+public class WifiTriggerAPPreference extends AbstractTriggerPreference {
-public class WifiTriggerAPPreference extends Preference {
-
- private String mSsid;
- private int mTriggerType = Profile.TriggerState.DISABLED;
+ private String mSSID;
private WifiConfiguration mConfig;
WifiTriggerAPPreference(Context context, WifiConfiguration config) {
super(context);
- setWidgetLayoutResource(R.layout.preference_widget_wifi_signal);
loadConfig(config);
- setTitle(mSsid);
- }
-
- public void setTriggerType(int trigger) {
- mTriggerType = trigger;
+ setTitle(mSSID);
}
- public int getTriggerType() {
- return mTriggerType;
+ WifiTriggerAPPreference(Context context, String ssid) {
+ super(context);
+ mSSID = ssid;
+ setTitle(mSSID);
}
private void loadConfig(WifiConfiguration config) {
- mSsid = (config.SSID == null ? "" : removeDoubleQuotes(config.SSID));
+ mSSID = (config.SSID == null ? "" : removeDoubleQuotes(config.SSID));
mConfig = config;
}
- public WifiConfiguration getConfig() {
- return mConfig;
- }
-
public String getSSID() {
- return mSsid;
+ return mSSID;
}
public static String removeDoubleQuotes(String string) {
diff --git a/src/com/android/settings/profiles/WifiTriggerFragment.java b/src/com/android/settings/profiles/WifiTriggerFragment.java
deleted file mode 100644
index 73d40a2..0000000
--- a/src/com/android/settings/profiles/WifiTriggerFragment.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright (C) 2013 The CyanogenMod 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.profiles;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.app.Profile;
-import android.app.ProfileManager;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.res.Resources;
-import android.net.wifi.WifiConfiguration;
-import android.net.wifi.WifiManager;
-import android.os.Bundle;
-import android.preference.Preference;
-import android.preference.PreferenceScreen;
-
-import com.android.settings.R;
-import com.android.settings.SettingsPreferenceFragment;
-
-/**
- * Settings Preference to configure triggers to switch profiles base on Wi-Fi events
- */
-public class WifiTriggerFragment extends SettingsPreferenceFragment {
- private Profile mProfile;
- private WifiTriggerAPPreference mSelectedAccessPoint;
- private ProfileManager mProfileManager;
- private WifiManager mWifiManager;
-
- private static final int WIFI_TRIGGER = 1;
-
- @Override
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
- mProfileManager = (ProfileManager) getSystemService(Context.PROFILE_SERVICE);
- mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
- addPreferencesFromResource(R.xml.wifi_settings);
- }
-
- @Override
- public void onResume() {
- super.onResume();
- loadWifiConfiguration();
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- Bundle args = getArguments();
- if (args != null) {
- mProfile = args.getParcelable("profile");
- }
- }
-
- private void loadWifiConfiguration() {
- final List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks();
- final Resources res = getResources();
- final List<WifiTriggerAPPreference> aps = new ArrayList<WifiTriggerAPPreference>();
-
- getPreferenceScreen().removeAll();
-
- if (configs != null) {
- for (WifiConfiguration config : configs) {
- WifiTriggerAPPreference accessPoint = new WifiTriggerAPPreference(getActivity(), config);
- int state = mProfile.getWifiTrigger(accessPoint.getSSID());
- String summary = res.getStringArray(R.array.profile_trigger_wifi_options)[state];
-
- accessPoint.setSummary(summary);
- accessPoint.setTriggerType(state);
- aps.add(accessPoint);
- }
- }
-
- Collections.sort(aps, new Comparator<WifiTriggerAPPreference>() {
- @Override
- public int compare(WifiTriggerAPPreference o1, WifiTriggerAPPreference o2) {
- if (o1.getTriggerType() == o2.getTriggerType()) {
- return o1.getSSID().compareTo(o2.getSSID());
- }
- return o1.getTriggerType() < o2.getTriggerType() ? -1 : 1;
- }
- });
- for (WifiTriggerAPPreference ap: aps) {
- getPreferenceScreen().addPreference(ap);
- }
- }
-
- @Override
- public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
- if (preference instanceof WifiTriggerAPPreference) {
- mSelectedAccessPoint = (WifiTriggerAPPreference) preference;
- showDialog(WIFI_TRIGGER);
- return true;
- }
- return super.onPreferenceTreeClick(screen, preference);
- }
-
- @Override
- public Dialog onCreateDialog(int dialogId) {
- switch (dialogId) {
- case WIFI_TRIGGER:
- final String ssid = mSelectedAccessPoint.getSSID();
- int currentTriggerType = mProfile.getWifiTrigger(ssid);
-
- return new AlertDialog.Builder(getActivity())
- .setTitle(R.string.profile_trigger_configure)
- .setSingleChoiceItems(R.array.profile_trigger_wifi_options, currentTriggerType,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- mProfile.setWifiTrigger(ssid, which);
- mProfileManager.updateProfile(mProfile);
- loadWifiConfiguration();
- dialog.dismiss();
- }
- })
- .create();
- }
- return super.onCreateDialog(dialogId);
- }
-}