Apply policy transparency to HotspotCondition and WiFi settings...
...when there is an active hotspot and user restriction for disallowing tether config is in effect. This is to avoid getting security exceptions from WifiManager when engaging with HotspotCondition or Wifi enable switch. Bug:27936528 Change-Id: Ib3324e853277c177966b55668758d349ffe6ecf5
This commit is contained in:
@@ -85,11 +85,13 @@
|
||||
|
||||
<!-- TODO: Better background -->
|
||||
<View
|
||||
android:id="@+id/divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height=".25dp"
|
||||
android:background="@android:color/white" />
|
||||
|
||||
<com.android.internal.widget.ButtonBarLayout
|
||||
android:id="@+id/buttonBar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="8dp"
|
||||
|
@@ -74,13 +74,13 @@ public class ConditionAdapterUtils {
|
||||
expand.setOnClickListener(onExpandListener);
|
||||
|
||||
View detailGroup = view.itemView.findViewById(R.id.detail_group);
|
||||
CharSequence[] actions = condition.getActions();
|
||||
if (isExpanded != (detailGroup.getVisibility() == View.VISIBLE)) {
|
||||
animateChange(view.itemView, view.itemView.findViewById(R.id.content),
|
||||
detailGroup, isExpanded);
|
||||
detailGroup, isExpanded, actions.length > 0);
|
||||
}
|
||||
if (isExpanded) {
|
||||
view.summary.setText(condition.getSummary());
|
||||
CharSequence[] actions = condition.getActions();
|
||||
for (int i = 0; i < 2; i++) {
|
||||
Button button = (Button) detailGroup.findViewById(i == 0
|
||||
? R.id.first_action : R.id.second_action);
|
||||
@@ -105,7 +105,9 @@ public class ConditionAdapterUtils {
|
||||
}
|
||||
|
||||
private static void animateChange(final View view, final View content,
|
||||
final View detailGroup, final boolean visible) {
|
||||
final View detailGroup, final boolean visible, final boolean hasButtons) {
|
||||
setViewVisibility(detailGroup, R.id.divider, hasButtons);
|
||||
setViewVisibility(detailGroup, R.id.buttonBar, hasButtons);
|
||||
final int beforeBottom = content.getBottom();
|
||||
setHeight(detailGroup, visible ? LayoutParams.WRAP_CONTENT : 0);
|
||||
detailGroup.setVisibility(View.VISIBLE);
|
||||
@@ -138,4 +140,11 @@ public class ConditionAdapterUtils {
|
||||
params.height = height;
|
||||
detailGroup.setLayoutParams(params);
|
||||
}
|
||||
|
||||
private static void setViewVisibility(View containerView, int viewId, boolean visible) {
|
||||
View view = containerView.findViewById(viewId);
|
||||
if (view != null) {
|
||||
view.setVisibility(visible ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -21,10 +21,15 @@ import android.content.Intent;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TetherSettings;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
import com.android.settingslib.TetherUtil;
|
||||
|
||||
public class HotspotCondition extends Condition {
|
||||
@@ -74,7 +79,12 @@ public class HotspotCondition extends Condition {
|
||||
|
||||
@Override
|
||||
public CharSequence[] getActions() {
|
||||
return new CharSequence[] { mManager.getContext().getString(R.string.condition_turn_off) };
|
||||
final Context context = mManager.getContext();
|
||||
if (RestrictedLockUtils.hasBaseUserRestriction(context,
|
||||
UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId())) {
|
||||
return new CharSequence[0];
|
||||
}
|
||||
return new CharSequence[] { context.getString(R.string.condition_turn_off) };
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,8 +96,15 @@ public class HotspotCondition extends Condition {
|
||||
@Override
|
||||
public void onActionClick(int index) {
|
||||
if (index == 0) {
|
||||
TetherUtil.setWifiTethering(false, mManager.getContext());
|
||||
setActive(false);
|
||||
final Context context = mManager.getContext();
|
||||
final EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(context,
|
||||
UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId());
|
||||
if (admin != null) {
|
||||
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(context, admin);
|
||||
} else {
|
||||
TetherUtil.setWifiTethering(false, context);
|
||||
setActive(false);
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unexpected index " + index);
|
||||
}
|
||||
|
@@ -26,6 +26,8 @@ import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.widget.Switch;
|
||||
import android.widget.Toast;
|
||||
@@ -35,6 +37,8 @@ import com.android.internal.logging.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.search.Index;
|
||||
import com.android.settings.widget.SwitchBar;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
import com.android.settingslib.WirelessUtils;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@@ -136,6 +140,9 @@ public class WifiEnabler implements SwitchBar.OnSwitchChangeListener {
|
||||
}
|
||||
|
||||
private void handleWifiStateChanged(int state) {
|
||||
// Clear any previous state
|
||||
mSwitchBar.setDisabledByAdmin(null);
|
||||
|
||||
switch (state) {
|
||||
case WifiManager.WIFI_STATE_ENABLING:
|
||||
mSwitchBar.setEnabled(false);
|
||||
@@ -158,6 +165,16 @@ public class WifiEnabler implements SwitchBar.OnSwitchChangeListener {
|
||||
mSwitchBar.setEnabled(true);
|
||||
updateSearchIndex(false);
|
||||
}
|
||||
if (mayDisableTethering(!mSwitchBar.isChecked())) {
|
||||
if (RestrictedLockUtils.hasBaseUserRestriction(mContext,
|
||||
UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId())) {
|
||||
mSwitchBar.setEnabled(false);
|
||||
} else {
|
||||
final EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(mContext,
|
||||
UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId());
|
||||
mSwitchBar.setDisabledByAdmin(admin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSearchIndex(boolean isWiFiOn) {
|
||||
@@ -206,9 +223,7 @@ public class WifiEnabler implements SwitchBar.OnSwitchChangeListener {
|
||||
}
|
||||
|
||||
// Disable tethering if enabling Wifi
|
||||
int wifiApState = mWifiManager.getWifiApState();
|
||||
if (isChecked && ((wifiApState == WifiManager.WIFI_AP_STATE_ENABLING) ||
|
||||
(wifiApState == WifiManager.WIFI_AP_STATE_ENABLED))) {
|
||||
if (mayDisableTethering(isChecked)) {
|
||||
mWifiManager.setWifiApEnabled(null, false);
|
||||
}
|
||||
MetricsLogger.action(mContext,
|
||||
@@ -219,4 +234,10 @@ public class WifiEnabler implements SwitchBar.OnSwitchChangeListener {
|
||||
Toast.makeText(mContext, R.string.wifi_error, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean mayDisableTethering(boolean isChecked) {
|
||||
final int wifiApState = mWifiManager.getWifiApState();
|
||||
return isChecked && ((wifiApState == WifiManager.WIFI_AP_STATE_ENABLING) ||
|
||||
(wifiApState == WifiManager.WIFI_AP_STATE_ENABLED));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user