Merge "Apply policy transparency to HotspotCondition and WiFi settings..." into nyc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
295f1060e9
@@ -85,11 +85,13 @@
|
|||||||
|
|
||||||
<!-- TODO: Better background -->
|
<!-- TODO: Better background -->
|
||||||
<View
|
<View
|
||||||
|
android:id="@+id/divider"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height=".25dp"
|
android:layout_height=".25dp"
|
||||||
android:background="@android:color/white" />
|
android:background="@android:color/white" />
|
||||||
|
|
||||||
<com.android.internal.widget.ButtonBarLayout
|
<com.android.internal.widget.ButtonBarLayout
|
||||||
|
android:id="@+id/buttonBar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingTop="8dp"
|
android:paddingTop="8dp"
|
||||||
|
@@ -74,13 +74,13 @@ public class ConditionAdapterUtils {
|
|||||||
expand.setOnClickListener(onExpandListener);
|
expand.setOnClickListener(onExpandListener);
|
||||||
|
|
||||||
View detailGroup = view.itemView.findViewById(R.id.detail_group);
|
View detailGroup = view.itemView.findViewById(R.id.detail_group);
|
||||||
|
CharSequence[] actions = condition.getActions();
|
||||||
if (isExpanded != (detailGroup.getVisibility() == View.VISIBLE)) {
|
if (isExpanded != (detailGroup.getVisibility() == View.VISIBLE)) {
|
||||||
animateChange(view.itemView, view.itemView.findViewById(R.id.content),
|
animateChange(view.itemView, view.itemView.findViewById(R.id.content),
|
||||||
detailGroup, isExpanded);
|
detailGroup, isExpanded, actions.length > 0);
|
||||||
}
|
}
|
||||||
if (isExpanded) {
|
if (isExpanded) {
|
||||||
view.summary.setText(condition.getSummary());
|
view.summary.setText(condition.getSummary());
|
||||||
CharSequence[] actions = condition.getActions();
|
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
Button button = (Button) detailGroup.findViewById(i == 0
|
Button button = (Button) detailGroup.findViewById(i == 0
|
||||||
? R.id.first_action : R.id.second_action);
|
? 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,
|
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();
|
final int beforeBottom = content.getBottom();
|
||||||
setHeight(detailGroup, visible ? LayoutParams.WRAP_CONTENT : 0);
|
setHeight(detailGroup, visible ? LayoutParams.WRAP_CONTENT : 0);
|
||||||
detailGroup.setVisibility(View.VISIBLE);
|
detailGroup.setVisibility(View.VISIBLE);
|
||||||
@@ -138,4 +140,11 @@ public class ConditionAdapterUtils {
|
|||||||
params.height = height;
|
params.height = height;
|
||||||
detailGroup.setLayoutParams(params);
|
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.graphics.drawable.Icon;
|
||||||
import android.net.wifi.WifiConfiguration;
|
import android.net.wifi.WifiConfiguration;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.os.UserManager;
|
||||||
|
|
||||||
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.TetherSettings;
|
import com.android.settings.TetherSettings;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
|
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||||
import com.android.settingslib.TetherUtil;
|
import com.android.settingslib.TetherUtil;
|
||||||
|
|
||||||
public class HotspotCondition extends Condition {
|
public class HotspotCondition extends Condition {
|
||||||
@@ -74,7 +79,12 @@ public class HotspotCondition extends Condition {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence[] getActions() {
|
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
|
@Override
|
||||||
@@ -86,8 +96,15 @@ public class HotspotCondition extends Condition {
|
|||||||
@Override
|
@Override
|
||||||
public void onActionClick(int index) {
|
public void onActionClick(int index) {
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
TetherUtil.setWifiTethering(false, mManager.getContext());
|
final Context context = mManager.getContext();
|
||||||
setActive(false);
|
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 {
|
} else {
|
||||||
throw new IllegalArgumentException("Unexpected index " + index);
|
throw new IllegalArgumentException("Unexpected index " + index);
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,8 @@ import android.net.wifi.WifiInfo;
|
|||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.os.UserManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.widget.Switch;
|
import android.widget.Switch;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@@ -35,6 +37,8 @@ import com.android.internal.logging.MetricsProto.MetricsEvent;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.search.Index;
|
import com.android.settings.search.Index;
|
||||||
import com.android.settings.widget.SwitchBar;
|
import com.android.settings.widget.SwitchBar;
|
||||||
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
|
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||||
import com.android.settingslib.WirelessUtils;
|
import com.android.settingslib.WirelessUtils;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
@@ -136,6 +140,9 @@ public class WifiEnabler implements SwitchBar.OnSwitchChangeListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleWifiStateChanged(int state) {
|
private void handleWifiStateChanged(int state) {
|
||||||
|
// Clear any previous state
|
||||||
|
mSwitchBar.setDisabledByAdmin(null);
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case WifiManager.WIFI_STATE_ENABLING:
|
case WifiManager.WIFI_STATE_ENABLING:
|
||||||
mSwitchBar.setEnabled(false);
|
mSwitchBar.setEnabled(false);
|
||||||
@@ -158,6 +165,16 @@ public class WifiEnabler implements SwitchBar.OnSwitchChangeListener {
|
|||||||
mSwitchBar.setEnabled(true);
|
mSwitchBar.setEnabled(true);
|
||||||
updateSearchIndex(false);
|
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) {
|
private void updateSearchIndex(boolean isWiFiOn) {
|
||||||
@@ -206,9 +223,7 @@ public class WifiEnabler implements SwitchBar.OnSwitchChangeListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Disable tethering if enabling Wifi
|
// Disable tethering if enabling Wifi
|
||||||
int wifiApState = mWifiManager.getWifiApState();
|
if (mayDisableTethering(isChecked)) {
|
||||||
if (isChecked && ((wifiApState == WifiManager.WIFI_AP_STATE_ENABLING) ||
|
|
||||||
(wifiApState == WifiManager.WIFI_AP_STATE_ENABLED))) {
|
|
||||||
mWifiManager.setWifiApEnabled(null, false);
|
mWifiManager.setWifiApEnabled(null, false);
|
||||||
}
|
}
|
||||||
MetricsLogger.action(mContext,
|
MetricsLogger.action(mContext,
|
||||||
@@ -219,4 +234,10 @@ public class WifiEnabler implements SwitchBar.OnSwitchChangeListener {
|
|||||||
Toast.makeText(mContext, R.string.wifi_error, Toast.LENGTH_SHORT).show();
|
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