Restrict WifiScanModeActivity when user restriction applies
Bug: 299633613 Change-Id: If8cfb7047c0131da451a7af0d2b5108080876b85
This commit is contained in:
@@ -39,26 +39,24 @@ import com.android.settings.Utils;
|
|||||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||||
import com.android.settingslib.wifi.WifiPermissionChecker;
|
import com.android.settingslib.wifi.WifiPermissionChecker;
|
||||||
|
|
||||||
/**
|
/** This activity requests users permission to allow scanning even when Wi-Fi is turned off */
|
||||||
* This activity requests users permission to allow scanning even when Wi-Fi is turned off
|
|
||||||
*/
|
|
||||||
public class WifiScanModeActivity extends FragmentActivity {
|
public class WifiScanModeActivity extends FragmentActivity {
|
||||||
private static final String TAG = "WifiScanModeActivity";
|
private static final String TAG = "WifiScanModeActivity";
|
||||||
private DialogFragment mDialog;
|
private DialogFragment mDialog;
|
||||||
@VisibleForTesting
|
@VisibleForTesting String mApp;
|
||||||
String mApp;
|
@VisibleForTesting WifiPermissionChecker mWifiPermissionChecker;
|
||||||
@VisibleForTesting
|
|
||||||
WifiPermissionChecker mWifiPermissionChecker;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
getWindow().addSystemFlags(
|
getWindow()
|
||||||
WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
|
.addSystemFlags(
|
||||||
|
WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
if (intent != null && WifiManager.ACTION_REQUEST_SCAN_ALWAYS_AVAILABLE
|
if (intent != null
|
||||||
.equals(intent.getAction())) {
|
&& WifiManager.ACTION_REQUEST_SCAN_ALWAYS_AVAILABLE.equals(
|
||||||
|
intent.getAction())) {
|
||||||
refreshAppLabel();
|
refreshAppLabel();
|
||||||
} else {
|
} else {
|
||||||
finish();
|
finish();
|
||||||
@@ -92,6 +90,12 @@ public class WifiScanModeActivity extends FragmentActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isWifiScanModeConfigAllowed(getApplicationContext())) {
|
||||||
|
Log.e(TAG, "This user is not allowed to configure Wi-Fi Scan Mode!");
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (mDialog == null) {
|
if (mDialog == null) {
|
||||||
mDialog = AlertDialogFragment.newInstance(mApp);
|
mDialog = AlertDialogFragment.newInstance(mApp);
|
||||||
mDialog.show(getSupportFragmentManager(), "dialog");
|
mDialog.show(getSupportFragmentManager(), "dialog");
|
||||||
@@ -140,6 +144,7 @@ public class WifiScanModeActivity extends FragmentActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final String mApp;
|
private final String mApp;
|
||||||
|
|
||||||
public AlertDialogFragment(String app) {
|
public AlertDialogFragment(String app) {
|
||||||
super();
|
super();
|
||||||
mApp = app;
|
mApp = app;
|
||||||
@@ -158,25 +163,27 @@ public class WifiScanModeActivity extends FragmentActivity {
|
|||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
return new AlertDialog.Builder(getActivity())
|
return new AlertDialog.Builder(getActivity())
|
||||||
.setMessage(TextUtils.isEmpty(mApp) ?
|
.setMessage(
|
||||||
getString(R.string.wifi_scan_always_turn_on_message_unknown) :
|
TextUtils.isEmpty(mApp)
|
||||||
getString(R.string.wifi_scan_always_turnon_message, mApp))
|
? getString(R.string.wifi_scan_always_turn_on_message_unknown)
|
||||||
.setPositiveButton(R.string.wifi_scan_always_confirm_allow,
|
: getString(R.string.wifi_scan_always_turnon_message, mApp))
|
||||||
|
.setPositiveButton(
|
||||||
|
R.string.wifi_scan_always_confirm_allow,
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int whichButton) {
|
public void onClick(DialogInterface dialog, int whichButton) {
|
||||||
((WifiScanModeActivity) getActivity()).doPositiveClick();
|
((WifiScanModeActivity) getActivity()).doPositiveClick();
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
)
|
.setNegativeButton(
|
||||||
.setNegativeButton(R.string.wifi_scan_always_confirm_deny,
|
R.string.wifi_scan_always_confirm_deny,
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int whichButton) {
|
public void onClick(DialogInterface dialog, int whichButton) {
|
||||||
((WifiScanModeActivity) getActivity()).doNegativeClick();
|
((WifiScanModeActivity) getActivity()).doNegativeClick();
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
)
|
|
||||||
.create();
|
.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCancel(DialogInterface dialog) {
|
public void onCancel(DialogInterface dialog) {
|
||||||
((WifiScanModeActivity) getActivity()).doNegativeClick();
|
((WifiScanModeActivity) getActivity()).doNegativeClick();
|
||||||
@@ -184,9 +191,14 @@ public class WifiScanModeActivity extends FragmentActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isGuestUser(Context context) {
|
private static boolean isGuestUser(Context context) {
|
||||||
if (context == null) return false;
|
|
||||||
final UserManager userManager = context.getSystemService(UserManager.class);
|
final UserManager userManager = context.getSystemService(UserManager.class);
|
||||||
if (userManager == null) return false;
|
if (userManager == null) return false;
|
||||||
return userManager.isGuestUser();
|
return userManager.isGuestUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isWifiScanModeConfigAllowed(Context context) {
|
||||||
|
final UserManager userManager = context.getSystemService(UserManager.class);
|
||||||
|
if (userManager == null) return true;
|
||||||
|
return !userManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_LOCATION);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user