When user has DISALLOW_USB_FILE_TRANSFER set, disable settings controls.
Under Settings > Storage, remove the "USB computer connection" menu item. In case someone launches the UsbSettings screen instead, also disable those checkboxes. Change-Id: I59ec8b16bed4670beeac8d359e5368e4a659061b
This commit is contained in:
@@ -33,6 +33,7 @@ import android.os.Environment;
|
|||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
|
import android.os.UserManager;
|
||||||
import android.os.storage.IMountService;
|
import android.os.storage.IMountService;
|
||||||
import android.os.storage.StorageEventListener;
|
import android.os.storage.StorageEventListener;
|
||||||
import android.os.storage.StorageManager;
|
import android.os.storage.StorageManager;
|
||||||
@@ -174,7 +175,10 @@ public class Memory extends SettingsPreferenceFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onPrepareOptionsMenu(Menu menu) {
|
public void onPrepareOptionsMenu(Menu menu) {
|
||||||
final MenuItem usb = menu.findItem(R.id.storage_usb);
|
final MenuItem usb = menu.findItem(R.id.storage_usb);
|
||||||
usb.setVisible(!isMassStorageEnabled());
|
UserManager um = (UserManager)getActivity().getSystemService(Context.USER_SERVICE);
|
||||||
|
boolean usbItemVisible = !isMassStorageEnabled()
|
||||||
|
&& !um.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER);
|
||||||
|
usb.setVisible(usbItemVisible);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -16,20 +16,16 @@
|
|||||||
|
|
||||||
package com.android.settings.deviceinfo;
|
package com.android.settings.deviceinfo;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.app.Dialog;
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ContentQueryMap;
|
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.hardware.usb.UsbManager;
|
import android.hardware.usb.UsbManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.UserManager;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
import android.provider.Settings;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -73,6 +69,12 @@ public class UsbSettings extends SettingsPreferenceFragment {
|
|||||||
mMtp = (CheckBoxPreference)root.findPreference(KEY_MTP);
|
mMtp = (CheckBoxPreference)root.findPreference(KEY_MTP);
|
||||||
mPtp = (CheckBoxPreference)root.findPreference(KEY_PTP);
|
mPtp = (CheckBoxPreference)root.findPreference(KEY_PTP);
|
||||||
|
|
||||||
|
UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
|
||||||
|
if (um.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER)) {
|
||||||
|
mMtp.setEnabled(false);
|
||||||
|
mPtp.setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,8 +114,12 @@ public class UsbSettings extends SettingsPreferenceFragment {
|
|||||||
mMtp.setChecked(false);
|
mMtp.setChecked(false);
|
||||||
mPtp.setChecked(false);
|
mPtp.setChecked(false);
|
||||||
}
|
}
|
||||||
|
UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
|
||||||
if (!mUsbAccessoryMode) {
|
if (um.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER)) {
|
||||||
|
Log.e(TAG, "USB is locked down");
|
||||||
|
mMtp.setEnabled(false);
|
||||||
|
mPtp.setEnabled(false);
|
||||||
|
} else if (!mUsbAccessoryMode) {
|
||||||
//Enable MTP and PTP switch while USB is not in Accessory Mode, otherwise disable it
|
//Enable MTP and PTP switch while USB is not in Accessory Mode, otherwise disable it
|
||||||
Log.e(TAG, "USB Normal Mode");
|
Log.e(TAG, "USB Normal Mode");
|
||||||
mMtp.setEnabled(true);
|
mMtp.setEnabled(true);
|
||||||
@@ -133,6 +139,12 @@ public class UsbSettings extends SettingsPreferenceFragment {
|
|||||||
if (Utils.isMonkeyRunning()) {
|
if (Utils.isMonkeyRunning()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// If this user is disallowed from using USB, don't handle their attempts to change the
|
||||||
|
// setting.
|
||||||
|
UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
|
||||||
|
if (um.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
String function = "none";
|
String function = "none";
|
||||||
if (preference == mMtp && mMtp.isChecked()) {
|
if (preference == mMtp && mMtp.isChecked()) {
|
||||||
|
Reference in New Issue
Block a user