Show dialog when user tries to edit a locked down WiFi config
Also, 'FORGET' button is not shown on WifiDialogs of locked down configs. Context menu only shows 'Connect' for them. Bug: 20117316 Change-Id: I3fa986c10b6ff47d1a897794213c225c8c6f579b
This commit is contained in:
@@ -1333,6 +1333,8 @@
|
|||||||
<!-- Wifi Internal 5GHz as an universal itendifier for 5GHz band -->
|
<!-- Wifi Internal 5GHz as an universal itendifier for 5GHz band -->
|
||||||
<string name="wifi_band_5ghz" translatable="false">5GHz</string>
|
<string name="wifi_band_5ghz" translatable="false">5GHz</string>
|
||||||
|
|
||||||
|
<!-- Wifi Alert message when tapping on a preference for a config locked down by device owner. [CHAR LIMIT=200] -->
|
||||||
|
<string name="wifi_alert_lockdown_by_device_owner"><xliff:g id="app_name">%1$s</xliff:g> manages your device and has disabled modifying and deleting this Wi-Fi network. For more information, contact your administrator.</string>
|
||||||
|
|
||||||
<!-- NFC settings -->
|
<!-- NFC settings -->
|
||||||
<!-- Used in the 1st-level settings screen to turn on NFC -->
|
<!-- Used in the 1st-level settings screen to turn on NFC -->
|
||||||
|
@@ -128,8 +128,13 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
|||||||
mAccessPointSavedState = null;
|
mAccessPointSavedState = null;
|
||||||
}
|
}
|
||||||
mSelectedAccessPoint = mDlgAccessPoint;
|
mSelectedAccessPoint = mDlgAccessPoint;
|
||||||
|
|
||||||
|
// Hide forget button if config editing is locked down
|
||||||
|
final boolean hideForgetButton = WifiSettings.isCreatorDeviceOwner(getActivity(),
|
||||||
|
mDlgAccessPoint.getConfig());
|
||||||
mDialog = new WifiDialog(getActivity(), this, mDlgAccessPoint,
|
mDialog = new WifiDialog(getActivity(), this, mDlgAccessPoint,
|
||||||
false /* not editting */, true /* hide the submit button */);
|
false /* not editting */, true /* hide the submit button */,
|
||||||
|
hideForgetButton);
|
||||||
return mDialog;
|
return mDialog;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -315,6 +315,13 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
return (level > -1 && level < mLevels.length) ? mLevels[level] : null;
|
return (level > -1 && level < mLevels.length) ? mLevels[level] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void hideForgetButton() {
|
||||||
|
Button forget = mConfigUi.getForgetButton();
|
||||||
|
if (forget == null) return;
|
||||||
|
|
||||||
|
forget.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
void hideSubmitButton() {
|
void hideSubmitButton() {
|
||||||
Button submit = mConfigUi.getSubmitButton();
|
Button submit = mConfigUi.getSubmitButton();
|
||||||
if (submit == null) return;
|
if (submit == null) return;
|
||||||
|
@@ -37,11 +37,14 @@ class WifiDialog extends AlertDialog implements WifiConfigUiBase {
|
|||||||
private View mView;
|
private View mView;
|
||||||
private WifiConfigController mController;
|
private WifiConfigController mController;
|
||||||
private boolean mHideSubmitButton;
|
private boolean mHideSubmitButton;
|
||||||
|
private boolean mHideForgetButton;
|
||||||
|
|
||||||
public WifiDialog(Context context, DialogInterface.OnClickListener listener,
|
public WifiDialog(Context context, DialogInterface.OnClickListener listener,
|
||||||
AccessPoint accessPoint, boolean edit, boolean hideSubmitButton) {
|
AccessPoint accessPoint, boolean edit, boolean hideSubmitButton,
|
||||||
|
boolean hideForgetButton) {
|
||||||
this(context, listener, accessPoint, edit);
|
this(context, listener, accessPoint, edit);
|
||||||
mHideSubmitButton = hideSubmitButton;
|
mHideSubmitButton = hideSubmitButton;
|
||||||
|
mHideForgetButton = hideForgetButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WifiDialog(Context context, DialogInterface.OnClickListener listener,
|
public WifiDialog(Context context, DialogInterface.OnClickListener listener,
|
||||||
@@ -51,6 +54,7 @@ class WifiDialog extends AlertDialog implements WifiConfigUiBase {
|
|||||||
mListener = listener;
|
mListener = listener;
|
||||||
mAccessPoint = accessPoint;
|
mAccessPoint = accessPoint;
|
||||||
mHideSubmitButton = false;
|
mHideSubmitButton = false;
|
||||||
|
mHideForgetButton = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -73,6 +77,10 @@ class WifiDialog extends AlertDialog implements WifiConfigUiBase {
|
|||||||
* visibility. Right after creation, update button visibility */
|
* visibility. Right after creation, update button visibility */
|
||||||
mController.enableSubmitIfAppropriate();
|
mController.enableSubmitIfAppropriate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mHideForgetButton) {
|
||||||
|
mController.hideForgetButton();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onRestoreInstanceState(Bundle savedInstanceState) {
|
public void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||||
|
@@ -20,10 +20,17 @@ import static android.net.wifi.WifiConfiguration.INVALID_NETWORK_ID;
|
|||||||
import static android.os.UserManager.DISALLOW_CONFIG_WIFI;
|
import static android.os.UserManager.DISALLOW_CONFIG_WIFI;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.app.AppGlobals;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
|
import android.app.admin.DevicePolicyManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.ApplicationInfo;
|
||||||
|
import android.content.pm.IPackageManager;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
@@ -35,6 +42,8 @@ import android.net.wifi.WifiManager;
|
|||||||
import android.net.wifi.WpsInfo;
|
import android.net.wifi.WpsInfo;
|
||||||
import android.nfc.NfcAdapter;
|
import android.nfc.NfcAdapter;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.RemoteException;
|
||||||
|
import android.os.UserHandle;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
@@ -433,6 +442,12 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
menu.add(Menu.NONE, MENU_ID_CONNECT, 0, R.string.wifi_menu_connect);
|
menu.add(Menu.NONE, MENU_ID_CONNECT, 0, R.string.wifi_menu_connect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WifiConfiguration config = mSelectedAccessPoint.getConfig();
|
||||||
|
// Device Owner created configs are uneditable
|
||||||
|
if (isCreatorDeviceOwner(getActivity(), config)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (mSelectedAccessPoint.isSaved() || mSelectedAccessPoint.isEphemeral()) {
|
if (mSelectedAccessPoint.isSaved() || mSelectedAccessPoint.isEphemeral()) {
|
||||||
// Allow forgetting a network if either the network is saved or ephemerally
|
// Allow forgetting a network if either the network is saved or ephemerally
|
||||||
// connected. (In the latter case, "forget" blacklists the network so it won't
|
// connected. (In the latter case, "forget" blacklists the network so it won't
|
||||||
@@ -509,6 +524,31 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void showDialog(AccessPoint accessPoint, boolean edit) {
|
private void showDialog(AccessPoint accessPoint, boolean edit) {
|
||||||
|
WifiConfiguration config = accessPoint.getConfig();
|
||||||
|
if (isCreatorDeviceOwner(getActivity(), config) && accessPoint.isActive()) {
|
||||||
|
final int userId = UserHandle.getUserId(config.creatorUid);
|
||||||
|
final PackageManager pm = getActivity().getPackageManager();
|
||||||
|
final IPackageManager ipm = AppGlobals.getPackageManager();
|
||||||
|
String appName = pm.getNameForUid(config.creatorUid);
|
||||||
|
try {
|
||||||
|
final ApplicationInfo appInfo = ipm.getApplicationInfo(appName, /* flags */ 0,
|
||||||
|
userId);
|
||||||
|
final CharSequence label = pm.getApplicationLabel(appInfo);
|
||||||
|
if (label != null) {
|
||||||
|
appName = label.toString();
|
||||||
|
}
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
// leave appName as packageName
|
||||||
|
}
|
||||||
|
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
|
builder.setTitle(accessPoint.getSsid())
|
||||||
|
.setMessage(getString(R.string.wifi_alert_lockdown_by_device_owner,
|
||||||
|
appName))
|
||||||
|
.setPositiveButton(android.R.string.ok, null)
|
||||||
|
.show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (mDialog != null) {
|
if (mDialog != null) {
|
||||||
removeDialog(WIFI_DIALOG_ID);
|
removeDialog(WIFI_DIALOG_ID);
|
||||||
mDialog = null;
|
mDialog = null;
|
||||||
@@ -537,7 +577,10 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
}
|
}
|
||||||
// If it's null, fine, it's for Add Network
|
// If it's null, fine, it's for Add Network
|
||||||
mSelectedAccessPoint = ap;
|
mSelectedAccessPoint = ap;
|
||||||
mDialog = new WifiDialog(getActivity(), this, ap, mDlgEdit);
|
mDialog = new WifiDialog(getActivity(), this, ap, mDlgEdit,
|
||||||
|
/* no hide submit/connect */ false,
|
||||||
|
/* hide forget if config locked down */ isCreatorDeviceOwner(getActivity(),
|
||||||
|
ap.getConfig()));
|
||||||
return mDialog;
|
return mDialog;
|
||||||
case WPS_PBC_DIALOG_ID:
|
case WPS_PBC_DIALOG_ID:
|
||||||
return new WpsDialog(getActivity(), WpsInfo.PBC);
|
return new WpsDialog(getActivity(), WpsInfo.PBC);
|
||||||
@@ -845,4 +888,29 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the true if the app that created this config is the device owner of the device.
|
||||||
|
* @param config The WiFi config.
|
||||||
|
* @return creator package name or null if creator package is not device owner.
|
||||||
|
*/
|
||||||
|
static boolean isCreatorDeviceOwner(Context context, WifiConfiguration config) {
|
||||||
|
if (config == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(
|
||||||
|
Context.DEVICE_POLICY_SERVICE);
|
||||||
|
final String deviceOwnerPackageName = dpm.getDeviceOwner();
|
||||||
|
if (deviceOwnerPackageName == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final PackageManager pm = context.getPackageManager();
|
||||||
|
try {
|
||||||
|
final int deviceOwnerUid = pm.getPackageUid(deviceOwnerPackageName,
|
||||||
|
UserHandle.getUserId(config.creatorUid));
|
||||||
|
return deviceOwnerUid == config.creatorUid;
|
||||||
|
} catch (NameNotFoundException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user