Add padlock to usb modes when disabled by admin.
Change-Id: I8504febd78f083eb3ff88926fe29d69edc62b6ef
This commit is contained in:
@@ -134,13 +134,16 @@ public class UsbBackend {
|
|||||||
? UsbPort.POWER_ROLE_SOURCE : UsbPort.POWER_ROLE_SINK;
|
? UsbPort.POWER_ROLE_SOURCE : UsbPort.POWER_ROLE_SINK;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isModeSupported(int mode) {
|
public boolean isModeDisallowedByAdmin(int mode) {
|
||||||
if (mRestricted && (mode & MODE_DATA_MASK) != MODE_DATA_NONE
|
if (mRestricted && (mode & MODE_DATA_MASK) != MODE_DATA_NONE
|
||||||
&& (mode & MODE_DATA_MASK) != MODE_DATA_MIDI) {
|
&& (mode & MODE_DATA_MASK) != MODE_DATA_MIDI) {
|
||||||
// No USB data modes are supported.
|
// No USB data modes are supported.
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isModeSupported(int mode) {
|
||||||
if (!mMidi && (mode & MODE_DATA_MASK) == MODE_DATA_MIDI) {
|
if (!mMidi && (mode & MODE_DATA_MASK) == MODE_DATA_MIDI) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -25,8 +25,12 @@ import android.content.Context;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.graphics.PorterDuff;
|
||||||
import android.hardware.usb.UsbManager;
|
import android.hardware.usb.UsbManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.os.UserManager;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
@@ -35,6 +39,9 @@ import android.widget.LinearLayout;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
|
|
||||||
|
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UI for the USB chooser dialog.
|
* UI for the USB chooser dialog.
|
||||||
@@ -53,6 +60,7 @@ public class UsbModeChooserActivity extends Activity {
|
|||||||
private UsbBackend mBackend;
|
private UsbBackend mBackend;
|
||||||
private AlertDialog mDialog;
|
private AlertDialog mDialog;
|
||||||
private LayoutInflater mLayoutInflater;
|
private LayoutInflater mLayoutInflater;
|
||||||
|
private EnforcedAdmin mEnforcedAdmin;
|
||||||
|
|
||||||
private BroadcastReceiver mDisconnectedReceiver = new BroadcastReceiver() {
|
private BroadcastReceiver mDisconnectedReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
@@ -93,11 +101,14 @@ public class UsbModeChooserActivity extends Activity {
|
|||||||
|
|
||||||
LinearLayout container = (LinearLayout) mDialog.findViewById(R.id.container);
|
LinearLayout container = (LinearLayout) mDialog.findViewById(R.id.container);
|
||||||
|
|
||||||
|
mEnforcedAdmin = RestrictedLockUtils.checkIfRestrictionEnforced(this,
|
||||||
|
UserManager.DISALLOW_USB_FILE_TRANSFER, UserHandle.myUserId());
|
||||||
mBackend = new UsbBackend(this);
|
mBackend = new UsbBackend(this);
|
||||||
int current = mBackend.getCurrentMode();
|
int current = mBackend.getCurrentMode();
|
||||||
for (int i = 0; i < DEFAULT_MODES.length; i++) {
|
for (int i = 0; i < DEFAULT_MODES.length; i++) {
|
||||||
if (mBackend.isModeSupported(DEFAULT_MODES[i])) {
|
if (mBackend.isModeSupported(DEFAULT_MODES[i])) {
|
||||||
inflateOption(DEFAULT_MODES[i], current == DEFAULT_MODES[i], container);
|
inflateOption(DEFAULT_MODES[i], current == DEFAULT_MODES[i], container,
|
||||||
|
mBackend.isModeDisallowedByAdmin(DEFAULT_MODES[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -116,15 +127,31 @@ public class UsbModeChooserActivity extends Activity {
|
|||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void inflateOption(final int mode, boolean selected, LinearLayout container) {
|
private void inflateOption(final int mode, boolean selected, LinearLayout container,
|
||||||
|
final boolean disallowedByAdmin) {
|
||||||
View v = mLayoutInflater.inflate(R.layout.radio_with_summary, container, false);
|
View v = mLayoutInflater.inflate(R.layout.radio_with_summary, container, false);
|
||||||
|
|
||||||
((TextView) v.findViewById(android.R.id.title)).setText(getTitle(mode));
|
TextView titleView = (TextView) v.findViewById(android.R.id.title);
|
||||||
((TextView) v.findViewById(android.R.id.summary)).setText(getSummary(mode));
|
titleView.setText(getTitle(mode));
|
||||||
|
TextView summaryView = (TextView) v.findViewById(android.R.id.summary);
|
||||||
|
summaryView.setText(getSummary(mode));
|
||||||
|
|
||||||
|
if (disallowedByAdmin) {
|
||||||
|
if (mEnforcedAdmin != null) {
|
||||||
|
setDisabledByAdmin(titleView, summaryView);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
v.setOnClickListener(new OnClickListener() {
|
v.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
if (disallowedByAdmin && mEnforcedAdmin != null) {
|
||||||
|
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(
|
||||||
|
UsbModeChooserActivity.this, mEnforcedAdmin);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!ActivityManager.isUserAMonkey()) {
|
if (!ActivityManager.isUserAMonkey()) {
|
||||||
mBackend.setMode(mode);
|
mBackend.setMode(mode);
|
||||||
}
|
}
|
||||||
@@ -136,6 +163,18 @@ public class UsbModeChooserActivity extends Activity {
|
|||||||
container.addView(v);
|
container.addView(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setDisabledByAdmin(TextView titleView, TextView summaryView) {
|
||||||
|
if (mEnforcedAdmin != null) {
|
||||||
|
titleView.setEnabled(false);
|
||||||
|
summaryView.setEnabled(false);
|
||||||
|
RestrictedLockUtils.setTextViewPadlock(this,
|
||||||
|
titleView, true /* showPadlock */);
|
||||||
|
Drawable[] compoundDrawables = titleView.getCompoundDrawablesRelative();
|
||||||
|
compoundDrawables[0 /* start */].mutate().setColorFilter(
|
||||||
|
getColor(R.color.disabled_text_color), PorterDuff.Mode.MULTIPLY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static int getSummary(int mode) {
|
private static int getSummary(int mode) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case UsbBackend.MODE_POWER_SINK | UsbBackend.MODE_DATA_NONE:
|
case UsbBackend.MODE_POWER_SINK | UsbBackend.MODE_DATA_NONE:
|
||||||
|
Reference in New Issue
Block a user