Merge "Import translations. DO NOT MERGE" into mnc-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index c006ce3..2bba142 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1786,6 +1786,13 @@
</intent-filter>
</activity>
+ <activity android:name=".deviceinfo.UsbModeChooserActivity"
+ android:excludeFromRecents="true"
+ android:exported="true"
+ android:permission="android.permission.MANAGE_USB"
+ android:theme="@style/Transparent">
+ </activity>
+
<activity android:name=".bluetooth.RequestPermissionHelperActivity"
android:label="@string/bluetooth_pairing_request"
android:excludeFromRecents="true"
diff --git a/res/menu/storage.xml b/res/menu/storage.xml
deleted file mode 100644
index 2e4c660..0000000
--- a/res/menu/storage.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2012 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<menu xmlns:android="http://schemas.android.com/apk/res/android">
- <item
- android:id="@+id/storage_usb"
- android:title="@string/storage_menu_usb" />
-</menu>
diff --git a/res/menu/storage_volume.xml b/res/menu/storage_volume.xml
index b461f46..efa468c 100644
--- a/res/menu/storage_volume.xml
+++ b/res/menu/storage_volume.xml
@@ -30,7 +30,4 @@
<item
android:id="@+id/storage_migrate"
android:title="@string/storage_menu_migrate" />
- <item
- android:id="@+id/storage_usb"
- android:title="@string/storage_menu_usb" />
</menu>
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index d556b1b..1af15f9 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -1365,4 +1365,12 @@
<item>0</item>
</string-array>
+ <!-- These values must match up with the code in UsbModeChooserActivity.java. -->
+ <string-array name="usb_available_functions">
+ <item>@string/usb_use_charging_only</item>
+ <item>@string/usb_use_file_transfers</item>
+ <item>@string/usb_use_photo_transfers</item>
+ <item>@string/usb_use_MIDI</item>
+ </string-array>
+
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 53df0ef..c89aa17 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2293,8 +2293,6 @@
<string name="storage_menu_migrate">Migrate data</string>
<!-- Storage setting. Menu option for forgetting a storage device [CHAR LIMIT=30]-->
<string name="storage_menu_forget">Forget</string>
- <!-- Storage setting. Menu option for USB transfer settings [CHAR LIMIT=30]-->
- <string name="storage_menu_usb">USB computer connection</string>
<!-- Storage setting. Title for USB transfer settings [CHAR LIMIT=30]-->
<string name="storage_title_usb">USB computer connection</string>
@@ -3540,10 +3538,14 @@
<string name="select_logd_size_title">Logger buffer sizes</string>
<!-- UI debug setting: limit size of Android logger buffers [CHAR LIMIT=59] -->
<string name="select_logd_size_dialog_title">Select Logger sizes per log buffer</string>
- <!-- Setting Checkbox title whether to allow mock locations -->
- <string name="allow_mock_location">Allow mock locations</string>
- <!-- setting Checkbox summary whether to allow mock locations -->
- <string name="allow_mock_location_summary">Allow mock locations</string>
+
+ <!-- UI debug setting: select current app to mock location [CHAR LIMIT=50] -->
+ <string name="mock_location_app">Select mock location app</string>
+ <!-- UI debug setting: no mock location app has been set [CHAR LIMIT=50] -->
+ <string name="mock_location_app_not_set">No mock location app set</string>
+ <!-- UI debug setting: mock location app has been set [CHAR LIMIT=50] -->
+ <string name="mock_location_app_set">Mock location app: <xliff:g id="app_name">%1$s</xliff:g></string>
+
<!-- Setting Checkbox title whether to enable view attribute inspection -->
<string name="debug_view_attributes">Enable view attribute inspection</string>
<!-- Title of warning dialog about the implications of enabling USB debugging -->
@@ -6601,4 +6603,25 @@
<!-- Description of how many more permissions to view on next page [CHAR LIMIT=30] -->
<string name="additional_permissions_more"><xliff:g id="count" example="2">%1$d</xliff:g> more</string>
+ <!-- One of the choices in a dialog (with title defined in usb_use) that lets the user
+ select what the USB connection for this device should be used for. This choice
+ is for charging only. -->
+ <string name="usb_use_charging_only">Charging only</string>
+ <!-- One of the choices in a dialog (with title defined in usb_use) that lets the user
+ select what the USB connection for this device should be used for. This choice
+ is for transferring files via MTP. -->
+ <string name="usb_use_file_transfers">Transfer files (MTP)</string>
+ <!-- One of the choices in a dialog (with title defined in usb_use) that lets the user
+ select what the USB connection for this device should be used for. This choice
+ is for transferring photos via PTP. -->
+ <string name="usb_use_photo_transfers">Transfer photos (PTP)</string>
+ <!-- One of the choices in a dialog (with title defined in usb_use) that lets the user
+ select what the USB connection for this device should be used for. This choice
+ is for entering MIDI mode. -->
+ <string name="usb_use_MIDI">MIDI</string>
+ <!-- The title used in a dialog which lets the user select what the USB connection
+ for this device should be used for. Choices are usb_use_charging_only,
+ usb_use_file_transfer, use_use_photo_transfer, and usb_use_MIDI -->
+ <string name="usb_use">Use USB for</string>
+
</resources>
diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml
index 39866c9..32c96c1 100644
--- a/res/xml/development_prefs.xml
+++ b/res/xml/development_prefs.xml
@@ -86,10 +86,8 @@
android:title="@string/bugreport_in_power"
android:summary="@string/bugreport_in_power_summary"/>
- <SwitchPreference
- android:key="allow_mock_location"
- android:title="@string/allow_mock_location"
- android:summary="@string/allow_mock_location_summary"/>
+ <PreferenceScreen android:key="mock_location_app"
+ android:title="@string/mock_location_app" />
<SwitchPreference
android:key="debug_view_attributes"
diff --git a/src/com/android/settings/AppPicker.java b/src/com/android/settings/AppPicker.java
index d525427..2447bcb 100644
--- a/src/com/android/settings/AppPicker.java
+++ b/src/com/android/settings/AppPicker.java
@@ -22,6 +22,8 @@
import java.util.Comparator;
import java.util.List;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
import com.android.settings.applications.AppViewHolder;
import android.app.ListActivity;
@@ -40,10 +42,20 @@
public class AppPicker extends ListActivity {
private AppListAdapter mAdapter;
+ public static final String EXTRA_REQUESTIING_PERMISSION
+ = "com.android.settings.extra.REQUESTIING_PERMISSION";
+ public static final String EXTRA_DEBUGGABLE = "com.android.settings.extra.DEBUGGABLE";
+
+ private String mPermissionName;
+ private boolean mDebuggableOnly;
+
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
+ mPermissionName = getIntent().getStringExtra(EXTRA_REQUESTIING_PERMISSION);
+ mDebuggableOnly = getIntent().getBooleanExtra(EXTRA_DEBUGGABLE, false);
+
mAdapter = new AppListAdapter(this);
if (mAdapter.getCount() <= 0) {
finish();
@@ -89,13 +101,41 @@
if (ai.uid == Process.SYSTEM_UID) {
continue;
}
- // On a user build, we only allow debugging of apps that
- // are marked as debuggable. Otherwise (for platform development)
- // we allow all apps.
- if ((ai.flags&ApplicationInfo.FLAG_DEBUGGABLE) == 0
- && "user".equals(Build.TYPE)) {
- continue;
+
+ // Filter out apps that are not debuggable if required.
+ if (mDebuggableOnly) {
+ // On a user build, we only allow debugging of apps that
+ // are marked as debuggable. Otherwise (for platform development)
+ // we allow all apps.
+ if ((ai.flags&ApplicationInfo.FLAG_DEBUGGABLE) == 0
+ && "user".equals(Build.TYPE)) {
+ continue;
+ }
}
+
+ // Filter out apps that do not request the permission if required.
+ if (mPermissionName != null) {
+ boolean requestsPermission = false;
+ try {
+ PackageInfo pi = getPackageManager().getPackageInfo(ai.packageName,
+ PackageManager.GET_PERMISSIONS);
+ if (pi.requestedPermissions == null) {
+ continue;
+ }
+ for (String requestedPermission : pi.requestedPermissions) {
+ if (requestedPermission.equals(mPermissionName)) {
+ requestsPermission = true;
+ break;
+ }
+ }
+ if (!requestsPermission) {
+ continue;
+ }
+ } catch (PackageManager.NameNotFoundException e) {
+ continue;
+ }
+ }
+
MyApplicationInfo info = new MyApplicationInfo();
info.info = ai;
info.label = info.info.loadLabel(getPackageManager()).toString();
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java
index 314e70a..a647dcc 100644
--- a/src/com/android/settings/DevelopmentSettings.java
+++ b/src/com/android/settings/DevelopmentSettings.java
@@ -16,9 +16,12 @@
package com.android.settings;
+import android.Manifest;
import android.app.Activity;
import android.app.ActivityManagerNative;
import android.app.AlertDialog;
+import android.app.AppOpsManager;
+import android.app.AppOpsManager.PackageOps;
import android.app.Dialog;
import android.app.admin.DevicePolicyManager;
import android.app.backup.IBackupManager;
@@ -74,6 +77,7 @@
import com.android.settings.search.Indexable;
import com.android.settings.widget.SwitchBar;
+import java.lang.Process;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
@@ -106,7 +110,6 @@
private static final String KEEP_SCREEN_ON = "keep_screen_on";
private static final String BT_HCI_SNOOP_LOG = "bt_hci_snoop_log";
private static final String ENABLE_OEM_UNLOCK = "oem_unlock_enable";
- private static final String ALLOW_MOCK_LOCATION = "allow_mock_location";
private static final String HDCP_CHECKING_KEY = "hdcp_checking";
private static final String HDCP_CHECKING_PROPERTY = "persist.sys.hdcp_checking";
private static final String LOCAL_BACKUP_PASSWORD = "local_backup_password";
@@ -119,6 +122,7 @@
private static final String DEBUG_APP_KEY = "debug_app";
private static final String WAIT_FOR_DEBUGGER_KEY = "wait_for_debugger";
+ private static final String MOCK_LOCATION_APP_KEY = "mock_location_app";
private static final String VERIFY_APPS_OVER_USB_KEY = "verify_apps_over_usb";
private static final String DEBUG_VIEW_ATTRIBUTES = "debug_view_attributes";
private static final String STRICT_MODE_KEY = "strict_mode";
@@ -174,6 +178,7 @@
private static final String TERMINAL_APP_PACKAGE = "com.android.terminal";
private static final int RESULT_DEBUG_APP = 1000;
+ private static final int RESULT_MOCK_LOCATION_APP = 1001;
private static final String PERSISTENT_DATA_BLOCK_PROP = "ro.frp.pst";
@@ -181,6 +186,8 @@
private static String DEFAULT_LOG_RING_BUFFER_SIZE_IN_BYTES = "262144"; // 256K
+ private static final int[] MOCK_LOCATOIN_APP_OPS = new int[] {AppOpsManager.OP_MOCK_LOCATION};
+
private static final String MULTI_WINDOW_SYSTEM_PROPERTY = "persist.sys.debug.multi_window";
private IWindowManager mWindowManager;
private IBackupManager mBackupManager;
@@ -201,12 +208,15 @@
private SwitchPreference mKeepScreenOn;
private SwitchPreference mBtHciSnoopLog;
private SwitchPreference mEnableOemUnlock;
- private SwitchPreference mAllowMockLocation;
private SwitchPreference mDebugViewAttributes;
private PreferenceScreen mPassword;
private String mDebugApp;
private Preference mDebugAppPref;
+
+ private String mMockLocationApp;
+ private Preference mMockLocationAppPref;
+
private SwitchPreference mWaitForDebugger;
private SwitchPreference mVerifyAppsOverUsb;
private SwitchPreference mWifiDisplayCertification;
@@ -317,7 +327,7 @@
removePreference(mEnableOemUnlock);
mEnableOemUnlock = null;
}
- mAllowMockLocation = findAndInitSwitchPref(ALLOW_MOCK_LOCATION);
+
mDebugViewAttributes = findAndInitSwitchPref(DEBUG_VIEW_ATTRIBUTES);
mPassword = (PreferenceScreen) findPreference(LOCAL_BACKUP_PASSWORD);
mAllPrefs.add(mPassword);
@@ -333,6 +343,10 @@
mDebugAppPref = findPreference(DEBUG_APP_KEY);
mAllPrefs.add(mDebugAppPref);
mWaitForDebugger = findAndInitSwitchPref(WAIT_FOR_DEBUGGER_KEY);
+
+ mMockLocationAppPref = findPreference(MOCK_LOCATION_APP_KEY);
+ mAllPrefs.add(mMockLocationAppPref);
+
mVerifyAppsOverUsb = findAndInitSwitchPref(VERIFY_APPS_OVER_USB_KEY);
if (!showVerifierSetting()) {
if (debugDebuggingCategory != null) {
@@ -558,13 +572,12 @@
if (mEnableOemUnlock != null) {
updateSwitchPreference(mEnableOemUnlock, Utils.isOemUnlockEnabled(getActivity()));
}
- updateSwitchPreference(mAllowMockLocation, Settings.Secure.getInt(cr,
- Settings.Secure.ALLOW_MOCK_LOCATION, 0) != 0);
updateSwitchPreference(mDebugViewAttributes, Settings.Global.getInt(cr,
Settings.Global.DEBUG_VIEW_ATTRIBUTES, 0) != 0);
updateHdcpValues();
updatePasswordSummary();
updateDebuggerOptions();
+ updateMockLocation();
updateStrictModeVisualOptions();
updatePointerLocationOptions();
updateShowTouchesOptions();
@@ -677,6 +690,41 @@
}
}
+ private void writeMockLocation() {
+ AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
+
+ // Disable the app op of the previous mock location app if such.
+ List<PackageOps> packageOps = appOpsManager.getPackagesForOps(MOCK_LOCATOIN_APP_OPS);
+ if (packageOps != null) {
+ // Should be one but in case we are in a bad state due to use of command line tools.
+ for (PackageOps packageOp : packageOps) {
+ if (packageOp.getOps().get(0).getMode() != AppOpsManager.MODE_ERRORED) {
+ String oldMockLocationApp = packageOp.getPackageName();
+ try {
+ ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(
+ oldMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
+ appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid,
+ oldMockLocationApp, AppOpsManager.MODE_ERRORED);
+ } catch (NameNotFoundException e) {
+ /* ignore */
+ }
+ }
+ }
+ }
+
+ // Enable the app op of the new mock location app if such.
+ if (!TextUtils.isEmpty(mMockLocationApp)) {
+ try {
+ ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(
+ mMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
+ appOpsManager.setMode(AppOpsManager.OP_MOCK_LOCATION, ai.uid,
+ mMockLocationApp, AppOpsManager.MODE_ALLOWED);
+ } catch (NameNotFoundException e) {
+ /* ignore */
+ }
+ }
+ }
+
private static void resetDebuggerOptions() {
try {
ActivityManagerNative.getDefault().setDebugApp(
@@ -709,6 +757,39 @@
}
}
+ private void updateMockLocation() {
+ AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
+
+ List<PackageOps> packageOps = appOpsManager.getPackagesForOps(MOCK_LOCATOIN_APP_OPS);
+ if (packageOps != null) {
+ for (PackageOps packageOp : packageOps) {
+ if (packageOp.getOps().get(0).getMode() == AppOpsManager.MODE_ALLOWED) {
+ mMockLocationApp = packageOps.get(0).getPackageName();
+ break;
+ }
+ }
+ }
+
+ if (!TextUtils.isEmpty(mMockLocationApp)) {
+ String label = mMockLocationApp;
+ try {
+ ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo(
+ mMockLocationApp, PackageManager.GET_DISABLED_COMPONENTS);
+ CharSequence appLabel = getPackageManager().getApplicationLabel(ai);
+ if (appLabel != null) {
+ label = appLabel.toString();
+ }
+ } catch (PackageManager.NameNotFoundException e) {
+ /* ignore */
+ }
+
+ mMockLocationAppPref.setSummary(getString(R.string.mock_location_app_set, label));
+ mHaveDebugSettings = true;
+ } else {
+ mMockLocationAppPref.setSummary(getString(R.string.mock_location_app_not_set));
+ }
+ }
+
private void updateVerifyAppsOverUsbOptions() {
updateSwitchPreference(mVerifyAppsOverUsb, Settings.Global.getInt(getActivity().getContentResolver(),
Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1) != 0);
@@ -1274,7 +1355,7 @@
private void writeUsbConfigurationOption(Object newValue) {
UsbManager manager = (UsbManager)getActivity().getSystemService(Context.USB_SERVICE);
- manager.setCurrentFunction(newValue.toString(), false);
+ manager.setCurrentFunction(newValue.toString());
}
private void updateCpuUsageOptions() {
@@ -1506,6 +1587,12 @@
writeDebuggerOptions();
updateDebuggerOptions();
}
+ } else if (requestCode == RESULT_MOCK_LOCATION_APP) {
+ if (resultCode == Activity.RESULT_OK) {
+ mMockLocationApp = data.getAction();
+ writeMockLocation();
+ updateMockLocation();
+ }
} else if (requestCode == REQUEST_CODE_ENABLE_OEM_UNLOCK) {
if (resultCode == Activity.RESULT_OK) {
if (mEnableOemUnlock.isChecked()) {
@@ -1574,16 +1661,19 @@
Utils.setOemUnlockEnabled(getActivity(), false);
}
}
- } else if (preference == mAllowMockLocation) {
- Settings.Secure.putInt(getActivity().getContentResolver(),
- Settings.Secure.ALLOW_MOCK_LOCATION,
- mAllowMockLocation.isChecked() ? 1 : 0);
+ } else if (preference == mMockLocationAppPref) {
+ Intent intent = new Intent(getActivity(), AppPicker.class);
+ intent.putExtra(AppPicker.EXTRA_REQUESTIING_PERMISSION,
+ Manifest.permission.ACCESS_MOCK_LOCATION);
+ startActivityForResult(intent, RESULT_MOCK_LOCATION_APP);
} else if (preference == mDebugViewAttributes) {
Settings.Global.putInt(getActivity().getContentResolver(),
Settings.Global.DEBUG_VIEW_ATTRIBUTES,
mDebugViewAttributes.isChecked() ? 1 : 0);
} else if (preference == mDebugAppPref) {
- startActivityForResult(new Intent(getActivity(), AppPicker.class), RESULT_DEBUG_APP);
+ Intent intent = new Intent(getActivity(), AppPicker.class);
+ intent.putExtra(AppPicker.EXTRA_DEBUGGABLE, true);
+ startActivityForResult(intent, RESULT_DEBUG_APP);
} else if (preference == mWaitForDebugger) {
writeDebuggerOptions();
} else if (preference == mVerifyAppsOverUsb) {
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index aa492f3..7ce581f 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -87,7 +87,6 @@
import com.android.settings.deviceinfo.PrivateVolumeSettings;
import com.android.settings.deviceinfo.PublicVolumeSettings;
import com.android.settings.deviceinfo.StorageSettings;
-import com.android.settings.deviceinfo.UsbSettings;
import com.android.settings.fuelgauge.BatterySaverSettings;
import com.android.settings.fuelgauge.PowerUsageDetail;
import com.android.settings.fuelgauge.PowerUsageSummary;
@@ -318,7 +317,6 @@
PrivateVolumeSettings.class.getName(),
PublicVolumeSettings.class.getName(),
DevelopmentSettings.class.getName(),
- UsbSettings.class.getName(),
AndroidBeam.class.getName(),
WifiDisplaySettings.class.getName(),
PowerUsageSummary.class.getName(),
diff --git a/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java b/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
index e5f50dd..7cefe4a 100644
--- a/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
+++ b/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
@@ -273,7 +273,6 @@
final MenuItem unmount = menu.findItem(R.id.storage_unmount);
final MenuItem format = menu.findItem(R.id.storage_format);
final MenuItem migrate = menu.findItem(R.id.storage_migrate);
- final MenuItem usb = menu.findItem(R.id.storage_usb);
// Actions live in menu for non-internal private volumes; they're shown
// as preference items for public volumes.
@@ -293,9 +292,6 @@
final VolumeInfo privateVol = getActivity().getPackageManager()
.getPrimaryStorageCurrentVolume();
migrate.setVisible(!Objects.equals(mVolume, privateVol));
-
- // TODO: show usb if we jumped past first screen
- usb.setVisible(false);
}
@Override
@@ -324,10 +320,6 @@
intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, mVolume.getId());
startActivity(intent);
return true;
- case R.id.storage_usb:
- startFragment(this, UsbSettings.class.getCanonicalName(),
- R.string.storage_title_usb, 0, null);
- return true;
}
return super.onOptionsItemSelected(item);
}
diff --git a/src/com/android/settings/deviceinfo/StorageSettings.java b/src/com/android/settings/deviceinfo/StorageSettings.java
index 4c03d8f..b5b3841 100644
--- a/src/com/android/settings/deviceinfo/StorageSettings.java
+++ b/src/com/android/settings/deviceinfo/StorageSettings.java
@@ -149,29 +149,6 @@
}
@Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
- inflater.inflate(R.menu.storage, menu);
- }
-
- @Override
- public void onPrepareOptionsMenu(Menu menu) {
- final MenuItem usb = menu.findItem(R.id.storage_usb);
-
- usb.setVisible(!mUserManager.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER));
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.storage_usb:
- startFragment(this, UsbSettings.class.getCanonicalName(),
- R.string.storage_title_usb, 0, null);
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
-
- @Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference pref) {
final String volId = pref.getKey();
final VolumeInfo vol = mStorageManager.findVolumeById(volId);
diff --git a/src/com/android/settings/deviceinfo/UsbModeChooserActivity.java b/src/com/android/settings/deviceinfo/UsbModeChooserActivity.java
new file mode 100644
index 0000000..76b2fd1
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/UsbModeChooserActivity.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.deviceinfo;
+
+import android.annotation.Nullable;
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.hardware.usb.UsbManager;
+import android.os.Bundle;
+import android.util.Log;
+import com.android.settings.R;
+
+/**
+ * UI for the USB chooser dialog.
+ *
+ * TODO: Don't show some UI elements if UserManager.DISALLOW_USB_FILE_TRANSFER is disabled.
+ */
+public class UsbModeChooserActivity extends Activity {
+
+ private UsbManager mUsbManager;
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
+ final AlertDialog levelDialog;
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(R.string.usb_use);
+ builder.setSingleChoiceItems(R.array.usb_available_functions, getCurrentFunction(),
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ setCurrentFunction(which);
+ dialog.dismiss();
+ UsbModeChooserActivity.this.finish();
+ }
+ });
+ builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
+ @Override
+ public void onDismiss(DialogInterface dialog) {
+ UsbModeChooserActivity.this.finish();
+ }
+ });
+ builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ UsbModeChooserActivity.this.finish();
+ }
+ });
+ levelDialog = builder.create();
+ levelDialog.show();
+ }
+
+ /*
+ * If you change the numbers here, you also need to change R.array.usb_available_functions
+ * so that everything matches.
+ */
+ private int getCurrentFunction() {
+ if (mUsbManager.isFunctionEnabled(UsbManager.USB_FUNCTION_MTP)) {
+ return 1;
+ } else if (mUsbManager.isFunctionEnabled(UsbManager.USB_FUNCTION_PTP)) {
+ return 2;
+ } else if (mUsbManager.isFunctionEnabled(UsbManager.USB_FUNCTION_MIDI)) {
+ return 3;
+ }
+ return 0;
+ }
+
+ /*
+ * If you change the numbers here, you also need to change R.array.usb_available_functions
+ * so that everything matches.
+ */
+ private void setCurrentFunction(int which) {
+ switch (which) {
+ case 0:
+ mUsbManager.setCurrentFunction("none");
+ break;
+ case 1:
+ mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_MTP);
+ break;
+ case 2:
+ mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_PTP);
+ break;
+ case 3:
+ mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_MIDI);
+ break;
+ }
+ }
+}
diff --git a/src/com/android/settings/deviceinfo/UsbSettings.java b/src/com/android/settings/deviceinfo/UsbSettings.java
deleted file mode 100644
index d8a675c..0000000
--- a/src/com/android/settings/deviceinfo/UsbSettings.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.deviceinfo;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.hardware.usb.UsbManager;
-import android.os.Bundle;
-import android.os.UserManager;
-import android.preference.CheckBoxPreference;
-import android.preference.Preference;
-import android.preference.PreferenceScreen;
-import android.util.Log;
-
-import com.android.internal.logging.MetricsLogger;
-import com.android.settings.R;
-import com.android.settings.SettingsPreferenceFragment;
-import com.android.settings.Utils;
-
-/**
- * USB storage settings.
- */
-public class UsbSettings extends SettingsPreferenceFragment {
-
- private static final String TAG = "UsbSettings";
-
- private static final String KEY_MTP = "usb_mtp";
- private static final String KEY_PTP = "usb_ptp";
- private static final String KEY_MIDI = "usb_midi";
-
- private UsbManager mUsbManager;
- private CheckBoxPreference mMtp;
- private CheckBoxPreference mPtp;
- private CheckBoxPreference mMidi;
- private boolean mUsbAccessoryMode;
-
- private final BroadcastReceiver mStateReceiver = new BroadcastReceiver() {
- public void onReceive(Context content, Intent intent) {
- String action = intent.getAction();
- if (action.equals(UsbManager.ACTION_USB_STATE)) {
- mUsbAccessoryMode = intent.getBooleanExtra(UsbManager.USB_FUNCTION_ACCESSORY, false);
- Log.e(TAG, "UsbAccessoryMode " + mUsbAccessoryMode);
- }
- updateToggles(mUsbManager.getDefaultFunction());
- }
- };
-
- private PreferenceScreen createPreferenceHierarchy() {
- PreferenceScreen root = getPreferenceScreen();
- if (root != null) {
- root.removeAll();
- }
- addPreferencesFromResource(R.xml.usb_settings);
- root = getPreferenceScreen();
-
- mMtp = (CheckBoxPreference)root.findPreference(KEY_MTP);
- mPtp = (CheckBoxPreference)root.findPreference(KEY_PTP);
- mMidi = (CheckBoxPreference)root.findPreference(KEY_MIDI);
-
- UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
- if (um.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER)) {
- mMtp.setEnabled(false);
- mPtp.setEnabled(false);
- }
-
- return root;
- }
-
- @Override
- protected int getMetricsCategory() {
- return MetricsLogger.DEVICEINFO_USB;
- }
-
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- mUsbManager = (UsbManager)getSystemService(Context.USB_SERVICE);
- }
-
- @Override
- public void onPause() {
- super.onPause();
- getActivity().unregisterReceiver(mStateReceiver);
- }
-
- @Override
- public void onResume() {
- super.onResume();
-
- // Make sure we reload the preference hierarchy since some of these settings
- // depend on others...
- createPreferenceHierarchy();
-
- // ACTION_USB_STATE is sticky so this will call updateToggles
- getActivity().registerReceiver(mStateReceiver,
- new IntentFilter(UsbManager.ACTION_USB_STATE));
- }
-
- private void updateToggles(String function) {
- if (UsbManager.USB_FUNCTION_MTP.equals(function)) {
- mMtp.setChecked(true);
- mPtp.setChecked(false);
- mMidi.setChecked(false);
- } else if (UsbManager.USB_FUNCTION_PTP.equals(function)) {
- mMtp.setChecked(false);
- mPtp.setChecked(true);
- mMidi.setChecked(false);
- } else if (UsbManager.USB_FUNCTION_MIDI.equals(function)) {
- mMtp.setChecked(false);
- mPtp.setChecked(false);
- mMidi.setChecked(true);
- } else {
- mMtp.setChecked(false);
- mPtp.setChecked(false);
- mMidi.setChecked(false);
- }
- UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
- if (um.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER)) {
- Log.e(TAG, "USB is locked down");
- mMtp.setEnabled(false);
- mPtp.setEnabled(false);
- mMidi.setEnabled(true);
- } else if (!mUsbAccessoryMode) {
- //Enable MTP and PTP switch while USB is not in Accessory Mode, otherwise disable it
- Log.e(TAG, "USB Normal Mode");
- mMtp.setEnabled(true);
- mPtp.setEnabled(true);
- mMidi.setEnabled(true);
- } else {
- Log.e(TAG, "USB Accessory Mode");
- mMtp.setEnabled(false);
- mPtp.setEnabled(false);
- mMidi.setEnabled(false);
- }
- }
-
- @Override
- public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
-
- // Don't allow any changes to take effect as the USB host will be disconnected, killing
- // the monkeys
- if (Utils.isMonkeyRunning()) {
- 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";
- if (preference == mMtp && mMtp.isChecked()) {
- function = UsbManager.USB_FUNCTION_MTP;
- } else if (preference == mPtp && mPtp.isChecked()) {
- function = UsbManager.USB_FUNCTION_PTP;
- } else if (preference == mMidi && mMidi.isChecked()) {
- function = UsbManager.USB_FUNCTION_MIDI;
- }
-
- mUsbManager.setCurrentFunction(function, true);
- updateToggles(function);
-
- return true;
- }
-}
diff --git a/src/com/android/settings/search/Ranking.java b/src/com/android/settings/search/Ranking.java
index e1eec5f..93e0948 100644
--- a/src/com/android/settings/search/Ranking.java
+++ b/src/com/android/settings/search/Ranking.java
@@ -34,7 +34,6 @@
import com.android.settings.applications.ManageDefaultApps;
import com.android.settings.bluetooth.BluetoothSettings;
import com.android.settings.deviceinfo.StorageSettings;
-import com.android.settings.deviceinfo.UsbSettings;
import com.android.settings.fuelgauge.BatterySaverSettings;
import com.android.settings.fuelgauge.PowerUsageSummary;
import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
@@ -131,7 +130,6 @@
// Storage
sRankMap.put(StorageSettings.class.getName(), RANK_STORAGE);
- sRankMap.put(UsbSettings.class.getName(), RANK_STORAGE);
// Battery
sRankMap.put(PowerUsageSummary.class.getName(), RANK_POWER_USAGE);
diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java
index a3d2ddc..4d28d4a 100644
--- a/src/com/android/settings/search/SearchIndexableResources.java
+++ b/src/com/android/settings/search/SearchIndexableResources.java
@@ -36,7 +36,6 @@
import com.android.settings.applications.ManageDefaultApps;
import com.android.settings.bluetooth.BluetoothSettings;
import com.android.settings.deviceinfo.StorageSettings;
-import com.android.settings.deviceinfo.UsbSettings;
import com.android.settings.fuelgauge.BatterySaverSettings;
import com.android.settings.fuelgauge.PowerUsageSummary;
import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
@@ -178,13 +177,6 @@
StorageSettings.class.getName(),
R.drawable.ic_settings_storage));
- sResMap.put(UsbSettings.class.getName(),
- new SearchIndexableResource(
- Ranking.getRankForClassName(UsbSettings.class.getName()),
- R.xml.usb_settings,
- UsbSettings.class.getName(),
- R.drawable.ic_settings_storage));
-
sResMap.put(PowerUsageSummary.class.getName(),
new SearchIndexableResource(
Ranking.getRankForClassName(PowerUsageSummary.class.getName()),