Remove unused classes and tests.
Old usb pages have been replaced by UsbDetailsFragment and UsbDefaultFragment. Old connected devices has been replaced by new connected devices. Bug: 70848054 Test: Passes Change-Id: I538cbb88d4f878449a83da9a4a0381e74e840c6a
This commit is contained in:
@@ -212,33 +212,6 @@
|
|||||||
android:value="true" />
|
android:value="true" />
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
|
||||||
android:name=".Settings$ConnectedDeviceDashboardActivityOld"
|
|
||||||
android:enabled="false"
|
|
||||||
android:label="@string/connected_devices_dashboard_title"
|
|
||||||
android:icon="@drawable/ic_homepage_connected_device"
|
|
||||||
android:taskAffinity="com.android.settings"
|
|
||||||
android:parentActivityName="Settings">
|
|
||||||
<intent-filter android:priority="1">
|
|
||||||
<action android:name="android.settings.NFC_SETTINGS" />
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
</intent-filter>
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.MAIN" />
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
<category android:name="android.intent.category.VOICE_LAUNCH" />
|
|
||||||
</intent-filter>
|
|
||||||
<intent-filter android:priority="10">
|
|
||||||
<action android:name="com.android.settings.action.SETTINGS"/>
|
|
||||||
</intent-filter>
|
|
||||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
|
||||||
android:value="com.android.settings.connecteddevice.ConnectedDeviceDashboardFragmentOld"/>
|
|
||||||
<meta-data android:name="com.android.settings.category"
|
|
||||||
android:value="com.android.settings.category.ia.homepage"/>
|
|
||||||
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
|
|
||||||
android:value="true" />
|
|
||||||
</activity>
|
|
||||||
|
|
||||||
<activity android:name="AirplaneModeVoiceActivity"
|
<activity android:name="AirplaneModeVoiceActivity"
|
||||||
android:label="@string/wireless_networks_settings_title"
|
android:label="@string/wireless_networks_settings_title"
|
||||||
android:theme="@*android:style/Theme.DeviceDefault.Light.Voice"
|
android:theme="@*android:style/Theme.DeviceDefault.Light.Voice"
|
||||||
|
@@ -1,56 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- Copyright (C) 2016 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<PreferenceScreen
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:key="connected_devices_screen"
|
|
||||||
android:title="@string/connected_devices_dashboard_title">
|
|
||||||
|
|
||||||
<com.android.settings.widget.MasterSwitchPreference
|
|
||||||
android:key="toggle_bluetooth"
|
|
||||||
android:title="@string/bluetooth_settings_title"
|
|
||||||
android:icon="@drawable/ic_settings_bluetooth"
|
|
||||||
android:order="-7"/>
|
|
||||||
|
|
||||||
<SwitchPreference
|
|
||||||
android:key="toggle_nfc"
|
|
||||||
android:title="@string/nfc_quick_toggle_title"
|
|
||||||
android:icon="@drawable/ic_nfc"
|
|
||||||
android:summary="@string/nfc_quick_toggle_summary"
|
|
||||||
android:order="-5"/>
|
|
||||||
|
|
||||||
<com.android.settingslib.RestrictedPreference
|
|
||||||
android:fragment="com.android.settings.nfc.AndroidBeam"
|
|
||||||
android:key="android_beam_settings"
|
|
||||||
android:title="@string/android_beam_settings_title"
|
|
||||||
android:icon="@drawable/ic_android"
|
|
||||||
android:order="-4"/>
|
|
||||||
|
|
||||||
<Preference
|
|
||||||
android:key="usb_mode"
|
|
||||||
android:title="@string/usb_pref"
|
|
||||||
android:icon="@drawable/ic_usb"
|
|
||||||
android:order="-2">
|
|
||||||
<intent android:action="android.intent.action.MAIN"
|
|
||||||
android:targetPackage="com.android.settings"
|
|
||||||
android:targetClass="com.android.settings.connecteddevice.usb.UsbModeChooserActivity"/>
|
|
||||||
</Preference>
|
|
||||||
|
|
||||||
<PreferenceCategory
|
|
||||||
android:key="dashboard_tile_placeholder"
|
|
||||||
android:order="50"/>
|
|
||||||
|
|
||||||
</PreferenceScreen>
|
|
@@ -1,41 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:title="@string/storage_title_usb">
|
|
||||||
|
|
||||||
<PreferenceCategory
|
|
||||||
android:title="@string/usb_connection_category" />
|
|
||||||
|
|
||||||
<CheckBoxPreference
|
|
||||||
android:key="usb_mtp"
|
|
||||||
android:title="@string/usb_mtp_title"
|
|
||||||
android:summary="@string/usb_mtp_summary"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<CheckBoxPreference
|
|
||||||
android:key="usb_ptp"
|
|
||||||
android:title="@string/usb_ptp_title"
|
|
||||||
android:summary="@string/usb_ptp_summary"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<CheckBoxPreference
|
|
||||||
android:key="usb_midi"
|
|
||||||
android:title="@string/usb_midi_title"
|
|
||||||
android:summary="@string/usb_midi_summary"
|
|
||||||
/>
|
|
||||||
|
|
||||||
</PreferenceScreen>
|
|
@@ -16,10 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings;
|
package com.android.settings;
|
||||||
|
|
||||||
import static com.android.settings.core.FeatureFlags.CONNECTED_DEVICE_V2;
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.FeatureFlagUtils;
|
|
||||||
|
|
||||||
import com.android.settings.enterprise.EnterprisePrivacySettings;
|
import com.android.settings.enterprise.EnterprisePrivacySettings;
|
||||||
|
|
||||||
@@ -157,11 +154,7 @@ public class Settings extends SettingsActivity {
|
|||||||
|
|
||||||
// Top level categories for new IA
|
// Top level categories for new IA
|
||||||
public static class NetworkDashboardActivity extends SettingsActivity {}
|
public static class NetworkDashboardActivity extends SettingsActivity {}
|
||||||
public static class ConnectedDeviceDashboardActivity extends SettingsActivity {
|
public static class ConnectedDeviceDashboardActivity extends SettingsActivity {}
|
||||||
public static final boolean isEnabled() {
|
|
||||||
return FeatureFlagUtils.isEnabled(null /* context */, CONNECTED_DEVICE_V2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static class ConnectedDeviceDashboardActivityOld extends SettingsActivity {}
|
public static class ConnectedDeviceDashboardActivityOld extends SettingsActivity {}
|
||||||
public static class PowerUsageSummaryActivity extends SettingsActivity { /* empty */ }
|
public static class PowerUsageSummaryActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class PowerUsageSummaryLegacyActivity extends SettingsActivity { /* empty */ }
|
public static class PowerUsageSummaryLegacyActivity extends SettingsActivity { /* empty */ }
|
||||||
@@ -169,10 +162,6 @@ public class Settings extends SettingsActivity {
|
|||||||
public static class StorageDashboardActivity extends SettingsActivity {}
|
public static class StorageDashboardActivity extends SettingsActivity {}
|
||||||
public static class AccountDashboardActivity extends SettingsActivity {}
|
public static class AccountDashboardActivity extends SettingsActivity {}
|
||||||
public static class SystemDashboardActivity extends SettingsActivity {}
|
public static class SystemDashboardActivity extends SettingsActivity {}
|
||||||
public static class AdvancedConnectedDeviceActivity extends SettingsActivity {
|
public static class AdvancedConnectedDeviceActivity extends SettingsActivity {}
|
||||||
public static final boolean isEnabled() {
|
|
||||||
return FeatureFlagUtils.isEnabled(null /* context */, CONNECTED_DEVICE_V2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -631,19 +631,10 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
Utils.isBandwidthControlEnabled() /* enabled */,
|
Utils.isBandwidthControlEnabled() /* enabled */,
|
||||||
isAdmin) || somethingChanged;
|
isAdmin) || somethingChanged;
|
||||||
|
|
||||||
final boolean isConnectedDeviceV2Enabled =
|
|
||||||
Settings.ConnectedDeviceDashboardActivity.isEnabled();
|
|
||||||
// Enable new connected page if v2 enabled
|
|
||||||
somethingChanged = setTileEnabled(
|
somethingChanged = setTileEnabled(
|
||||||
new ComponentName(packageName,
|
new ComponentName(packageName,
|
||||||
Settings.ConnectedDeviceDashboardActivity.class.getName()),
|
Settings.ConnectedDeviceDashboardActivity.class.getName()),
|
||||||
isConnectedDeviceV2Enabled && !UserManager.isDeviceInDemoMode(this) /* enabled */,
|
!UserManager.isDeviceInDemoMode(this) /* enabled */,
|
||||||
isAdmin) || somethingChanged;
|
|
||||||
// Enable old connected page if v2 disabled
|
|
||||||
somethingChanged = setTileEnabled(
|
|
||||||
new ComponentName(packageName,
|
|
||||||
Settings.ConnectedDeviceDashboardActivityOld.class.getName()),
|
|
||||||
!isConnectedDeviceV2Enabled && !UserManager.isDeviceInDemoMode(this) /* enabled */,
|
|
||||||
isAdmin) || somethingChanged;
|
isAdmin) || somethingChanged;
|
||||||
|
|
||||||
somethingChanged = setTileEnabled(new ComponentName(packageName,
|
somethingChanged = setTileEnabled(new ComponentName(packageName,
|
||||||
|
@@ -24,8 +24,6 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.bluetooth.BluetoothFilesPreferenceController;
|
import com.android.settings.bluetooth.BluetoothFilesPreferenceController;
|
||||||
import com.android.settings.bluetooth.BluetoothMasterSwitchPreferenceController;
|
import com.android.settings.bluetooth.BluetoothMasterSwitchPreferenceController;
|
||||||
import com.android.settings.bluetooth.BluetoothSwitchPreferenceController;
|
import com.android.settings.bluetooth.BluetoothSwitchPreferenceController;
|
||||||
import com.android.settings.connecteddevice.usb.UsbBackend;
|
|
||||||
import com.android.settings.connecteddevice.usb.UsbModePreferenceController;
|
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.nfc.NfcPreferenceController;
|
import com.android.settings.nfc.NfcPreferenceController;
|
||||||
import com.android.settings.print.PrintSettingPreferenceController;
|
import com.android.settings.print.PrintSettingPreferenceController;
|
||||||
@@ -75,8 +73,6 @@ public class AdvancedConnectedDeviceDashboardFragment extends DashboardFragment
|
|||||||
final NfcPreferenceController nfcPreferenceController =
|
final NfcPreferenceController nfcPreferenceController =
|
||||||
new NfcPreferenceController(context);
|
new NfcPreferenceController(context);
|
||||||
controllers.add(nfcPreferenceController);
|
controllers.add(nfcPreferenceController);
|
||||||
controllers.add(new UsbModePreferenceController(
|
|
||||||
context, new UsbBackend(context), lifecycle));
|
|
||||||
final BluetoothSwitchPreferenceController bluetoothPreferenceController =
|
final BluetoothSwitchPreferenceController bluetoothPreferenceController =
|
||||||
new BluetoothSwitchPreferenceController(context);
|
new BluetoothSwitchPreferenceController(context);
|
||||||
controllers.add(bluetoothPreferenceController);
|
controllers.add(bluetoothPreferenceController);
|
||||||
|
@@ -1,155 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 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.connecteddevice;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.provider.SearchIndexableResource;
|
|
||||||
import android.support.annotation.VisibleForTesting;
|
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto;
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.bluetooth.BluetoothMasterSwitchPreferenceController;
|
|
||||||
import com.android.settings.bluetooth.Utils;
|
|
||||||
import com.android.settings.connecteddevice.usb.UsbBackend;
|
|
||||||
import com.android.settings.connecteddevice.usb.UsbModePreferenceController;
|
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
|
||||||
import com.android.settings.dashboard.SummaryLoader;
|
|
||||||
import com.android.settings.nfc.NfcPreferenceController;
|
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the previous {@link ConnectedDeviceDashboardFragment} in Android O, in Android P the
|
|
||||||
* main entry will be {@link ConnectedDeviceDashboardFragment}
|
|
||||||
*
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class ConnectedDeviceDashboardFragmentOld extends DashboardFragment {
|
|
||||||
|
|
||||||
private static final String TAG = "ConnectedDeviceFrag2";
|
|
||||||
private UsbModePreferenceController mUsbPrefController;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMetricsCategory() {
|
|
||||||
return MetricsProto.MetricsEvent.SETTINGS_CONNECTED_DEVICE_CATEGORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getLogTag() {
|
|
||||||
return TAG;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getHelpResource() {
|
|
||||||
return R.string.help_url_connected_devices;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getPreferenceScreenResId() {
|
|
||||||
return R.xml.connected_devices_old;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
|
||||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
|
||||||
final Lifecycle lifecycle = getLifecycle();
|
|
||||||
final NfcPreferenceController nfcPreferenceController =
|
|
||||||
new NfcPreferenceController(context);
|
|
||||||
lifecycle.addObserver(nfcPreferenceController);
|
|
||||||
controllers.add(nfcPreferenceController);
|
|
||||||
mUsbPrefController = new UsbModePreferenceController(context, new UsbBackend(context),
|
|
||||||
lifecycle);
|
|
||||||
controllers.add(mUsbPrefController);
|
|
||||||
final BluetoothMasterSwitchPreferenceController bluetoothPreferenceController =
|
|
||||||
new BluetoothMasterSwitchPreferenceController(
|
|
||||||
context, Utils.getLocalBtManager(context), this);
|
|
||||||
lifecycle.addObserver(bluetoothPreferenceController);
|
|
||||||
controllers.add(bluetoothPreferenceController);
|
|
||||||
|
|
||||||
return controllers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
static class SummaryProvider implements SummaryLoader.SummaryProvider {
|
|
||||||
|
|
||||||
private final Context mContext;
|
|
||||||
private final SummaryLoader mSummaryLoader;
|
|
||||||
private final NfcPreferenceController mNfcPreferenceController;
|
|
||||||
|
|
||||||
public SummaryProvider(Context context, SummaryLoader summaryLoader) {
|
|
||||||
mContext = context;
|
|
||||||
mSummaryLoader = summaryLoader;
|
|
||||||
mNfcPreferenceController = new NfcPreferenceController(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setListening(boolean listening) {
|
|
||||||
if (listening) {
|
|
||||||
if (mNfcPreferenceController.isAvailable()) {
|
|
||||||
mSummaryLoader.setSummary(this,
|
|
||||||
mContext.getString(R.string.connected_devices_dashboard_summary));
|
|
||||||
} else {
|
|
||||||
mSummaryLoader.setSummary(this, mContext.getString(
|
|
||||||
R.string.connected_devices_dashboard_no_nfc_summary));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
|
|
||||||
= new SummaryLoader.SummaryProviderFactory() {
|
|
||||||
@Override
|
|
||||||
public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
|
|
||||||
SummaryLoader summaryLoader) {
|
|
||||||
return new SummaryProvider(activity, summaryLoader);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* For Search.
|
|
||||||
*/
|
|
||||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
|
||||||
new BaseSearchIndexProvider() {
|
|
||||||
@Override
|
|
||||||
public List<SearchIndexableResource> getXmlResourcesToIndex(
|
|
||||||
Context context, boolean enabled) {
|
|
||||||
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
|
||||||
sir.xmlResId = R.xml.connected_devices_old;
|
|
||||||
return Arrays.asList(sir);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getNonIndexableKeys(Context context) {
|
|
||||||
final List<String> keys = super.getNonIndexableKeys(context);
|
|
||||||
PackageManager pm = context.getPackageManager();
|
|
||||||
if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC)) {
|
|
||||||
keys.add(NfcPreferenceController.KEY_TOGGLE_NFC);
|
|
||||||
keys.add(NfcPreferenceController.KEY_ANDROID_BEAM_SETTINGS);
|
|
||||||
}
|
|
||||||
keys.add(BluetoothMasterSwitchPreferenceController.KEY_TOGGLE_BLUETOOTH);
|
|
||||||
|
|
||||||
return keys;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
@@ -40,8 +40,7 @@ public class ConnectedUsbDeviceUpdater {
|
|||||||
UsbConnectionBroadcastReceiver.UsbConnectionListener mUsbConnectionListener =
|
UsbConnectionBroadcastReceiver.UsbConnectionListener mUsbConnectionListener =
|
||||||
(connected, newMode) -> {
|
(connected, newMode) -> {
|
||||||
if (connected) {
|
if (connected) {
|
||||||
mUsbPreference.setSummary(
|
mUsbPreference.setSummary(getSummary(mUsbBackend.getCurrentMode()));
|
||||||
UsbModePreferenceController.getSummary(mUsbBackend.getCurrentMode()));
|
|
||||||
mDevicePreferenceCallback.onDeviceAdded(mUsbPreference);
|
mDevicePreferenceCallback.onDeviceAdded(mUsbPreference);
|
||||||
} else {
|
} else {
|
||||||
mDevicePreferenceCallback.onDeviceRemoved(mUsbPreference);
|
mDevicePreferenceCallback.onDeviceRemoved(mUsbPreference);
|
||||||
@@ -94,4 +93,31 @@ public class ConnectedUsbDeviceUpdater {
|
|||||||
//TODO(b/70336520): Use an API to get data instead of sticky intent
|
//TODO(b/70336520): Use an API to get data instead of sticky intent
|
||||||
mUsbReceiver.register();
|
mUsbReceiver.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getSummary(int mode) {
|
||||||
|
switch (mode) {
|
||||||
|
case UsbBackend.MODE_POWER_SINK | UsbBackend.MODE_DATA_NONE:
|
||||||
|
return R.string.usb_summary_charging_only;
|
||||||
|
case UsbBackend.MODE_POWER_SOURCE | UsbBackend.MODE_DATA_NONE:
|
||||||
|
return R.string.usb_summary_power_only;
|
||||||
|
case UsbBackend.MODE_POWER_SINK | UsbBackend.MODE_DATA_MTP:
|
||||||
|
return R.string.usb_summary_file_transfers;
|
||||||
|
case UsbBackend.MODE_POWER_SINK | UsbBackend.MODE_DATA_PTP:
|
||||||
|
return R.string.usb_summary_photo_transfers;
|
||||||
|
case UsbBackend.MODE_POWER_SINK | UsbBackend.MODE_DATA_MIDI:
|
||||||
|
return R.string.usb_summary_MIDI;
|
||||||
|
case UsbBackend.MODE_POWER_SINK | UsbBackend.MODE_DATA_TETHER:
|
||||||
|
return R.string.usb_summary_tether;
|
||||||
|
case UsbBackend.MODE_POWER_SOURCE | UsbBackend.MODE_DATA_MTP:
|
||||||
|
return R.string.usb_summary_file_transfers_power;
|
||||||
|
case UsbBackend.MODE_POWER_SOURCE | UsbBackend.MODE_DATA_PTP:
|
||||||
|
return R.string.usb_summary_photo_transfers_power;
|
||||||
|
case UsbBackend.MODE_POWER_SOURCE | UsbBackend.MODE_DATA_MIDI:
|
||||||
|
return R.string.usb_summary_MIDI_power;
|
||||||
|
case UsbBackend.MODE_POWER_SOURCE | UsbBackend.MODE_DATA_TETHER:
|
||||||
|
return R.string.usb_summary_tether_power;
|
||||||
|
default:
|
||||||
|
return R.string.usb_summary_charging_only;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -53,7 +53,7 @@ public class UsbDetailsHeaderController extends UsbDetailsController {
|
|||||||
mHeaderController.setLabel(mContext.getString(R.string.usb_pref));
|
mHeaderController.setLabel(mContext.getString(R.string.usb_pref));
|
||||||
mHeaderController.setIcon(mContext.getDrawable(R.drawable.ic_usb));
|
mHeaderController.setIcon(mContext.getDrawable(R.drawable.ic_usb));
|
||||||
mHeaderController.setSummary(
|
mHeaderController.setSummary(
|
||||||
mContext.getString(UsbModePreferenceController.getSummary(newMode)));
|
mContext.getString(ConnectedUsbDeviceUpdater.getSummary(newMode)));
|
||||||
mHeaderController.done(mFragment.getActivity(), true /* rebindActions */);
|
mHeaderController.done(mFragment.getActivity(), true /* rebindActions */);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,204 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.connecteddevice.usb;
|
|
||||||
|
|
||||||
import android.annotation.Nullable;
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.ActivityManager;
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.graphics.PorterDuff;
|
|
||||||
import android.hardware.usb.UsbManager;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.UserHandle;
|
|
||||||
import android.os.UserManager;
|
|
||||||
import android.support.annotation.VisibleForTesting;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.View.OnClickListener;
|
|
||||||
import android.widget.Checkable;
|
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
|
||||||
|
|
||||||
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* UI for the USB chooser dialog.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class UsbModeChooserActivity extends Activity {
|
|
||||||
|
|
||||||
public static final int[] DEFAULT_MODES = {
|
|
||||||
UsbBackend.MODE_POWER_SINK | UsbBackend.MODE_DATA_NONE,
|
|
||||||
UsbBackend.MODE_POWER_SOURCE | UsbBackend.MODE_DATA_NONE,
|
|
||||||
UsbBackend.MODE_POWER_SINK | UsbBackend.MODE_DATA_MTP,
|
|
||||||
UsbBackend.MODE_POWER_SINK | UsbBackend.MODE_DATA_PTP,
|
|
||||||
UsbBackend.MODE_POWER_SINK | UsbBackend.MODE_DATA_MIDI
|
|
||||||
};
|
|
||||||
|
|
||||||
private UsbBackend mBackend;
|
|
||||||
private AlertDialog mDialog;
|
|
||||||
private LayoutInflater mLayoutInflater;
|
|
||||||
private EnforcedAdmin mEnforcedAdmin;
|
|
||||||
|
|
||||||
private BroadcastReceiver mDisconnectedReceiver = new BroadcastReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
String action = intent.getAction();
|
|
||||||
if (UsbManager.ACTION_USB_STATE.equals(action)) {
|
|
||||||
boolean connected = intent.getBooleanExtra(UsbManager.USB_CONNECTED, false);
|
|
||||||
boolean hostConnected =
|
|
||||||
intent.getBooleanExtra(UsbManager.USB_HOST_CONNECTED, false);
|
|
||||||
if (!connected && !hostConnected) {
|
|
||||||
mDialog.dismiss();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
mLayoutInflater = LayoutInflater.from(this);
|
|
||||||
|
|
||||||
mDialog = new AlertDialog.Builder(this)
|
|
||||||
.setTitle(R.string.usb_use)
|
|
||||||
.setView(R.layout.usb_dialog_container)
|
|
||||||
.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
|
||||||
@Override
|
|
||||||
public void onDismiss(DialogInterface dialog) {
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}).create();
|
|
||||||
mDialog.show();
|
|
||||||
|
|
||||||
LinearLayout container = (LinearLayout) mDialog.findViewById(R.id.container);
|
|
||||||
|
|
||||||
mEnforcedAdmin = RestrictedLockUtils.checkIfRestrictionEnforced(this,
|
|
||||||
UserManager.DISALLOW_USB_FILE_TRANSFER, UserHandle.myUserId());
|
|
||||||
mBackend = new UsbBackend(this);
|
|
||||||
int current = mBackend.getCurrentMode();
|
|
||||||
for (int i = 0; i < DEFAULT_MODES.length; i++) {
|
|
||||||
if (mBackend.isModeSupported(DEFAULT_MODES[i])
|
|
||||||
&& !mBackend.isModeDisallowedBySystem(DEFAULT_MODES[i])) {
|
|
||||||
inflateOption(DEFAULT_MODES[i], current == DEFAULT_MODES[i], container,
|
|
||||||
mBackend.isModeDisallowed(DEFAULT_MODES[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStart() {
|
|
||||||
super.onStart();
|
|
||||||
|
|
||||||
IntentFilter filter = new IntentFilter(UsbManager.ACTION_USB_STATE);
|
|
||||||
registerReceiver(mDisconnectedReceiver, filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStop() {
|
|
||||||
unregisterReceiver(mDisconnectedReceiver);
|
|
||||||
super.onStop();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void inflateOption(final int mode, boolean selected, LinearLayout container,
|
|
||||||
final boolean disallowedByAdmin) {
|
|
||||||
View v = mLayoutInflater.inflate(R.layout.restricted_radio_with_summary, container, false);
|
|
||||||
|
|
||||||
TextView titleView = (TextView) v.findViewById(android.R.id.title);
|
|
||||||
titleView.setText(getTitle(mode));
|
|
||||||
TextView summaryView = (TextView) v.findViewById(android.R.id.summary);
|
|
||||||
updateSummary(summaryView, mode);
|
|
||||||
|
|
||||||
if (disallowedByAdmin) {
|
|
||||||
if (mEnforcedAdmin != null) {
|
|
||||||
setDisabledByAdmin(v, titleView, summaryView);
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
v.setOnClickListener(new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (disallowedByAdmin && mEnforcedAdmin != null) {
|
|
||||||
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(
|
|
||||||
UsbModeChooserActivity.this, mEnforcedAdmin);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!ActivityManager.isUserAMonkey()) {
|
|
||||||
mBackend.setMode(mode);
|
|
||||||
}
|
|
||||||
mDialog.dismiss();
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
((Checkable) v).setChecked(selected);
|
|
||||||
container.addView(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setDisabledByAdmin(View rootView, TextView titleView, TextView summaryView) {
|
|
||||||
if (mEnforcedAdmin != null) {
|
|
||||||
titleView.setEnabled(false);
|
|
||||||
summaryView.setEnabled(false);
|
|
||||||
rootView.findViewById(R.id.restricted_icon).setVisibility(View.VISIBLE);
|
|
||||||
Drawable[] compoundDrawables = titleView.getCompoundDrawablesRelative();
|
|
||||||
compoundDrawables[0 /* start */].mutate().setColorFilter(
|
|
||||||
getColor(R.color.disabled_text_color), PorterDuff.Mode.MULTIPLY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
static void updateSummary(TextView summaryView, int mode) {
|
|
||||||
if (mode == (UsbBackend.MODE_POWER_SOURCE | UsbBackend.MODE_DATA_NONE)) {
|
|
||||||
summaryView.setText(R.string.usb_use_power_only_desc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
static int getTitle(int mode) {
|
|
||||||
switch (mode) {
|
|
||||||
case UsbBackend.MODE_POWER_SINK | UsbBackend.MODE_DATA_NONE:
|
|
||||||
return R.string.usb_use_charging_only;
|
|
||||||
case UsbBackend.MODE_POWER_SOURCE | UsbBackend.MODE_DATA_NONE:
|
|
||||||
return R.string.usb_use_power_only;
|
|
||||||
case UsbBackend.MODE_POWER_SINK | UsbBackend.MODE_DATA_MTP:
|
|
||||||
return R.string.usb_use_file_transfers;
|
|
||||||
case UsbBackend.MODE_POWER_SINK | UsbBackend.MODE_DATA_PTP:
|
|
||||||
return R.string.usb_use_photo_transfers;
|
|
||||||
case UsbBackend.MODE_POWER_SINK | UsbBackend.MODE_DATA_MIDI:
|
|
||||||
return R.string.usb_use_MIDI;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,122 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 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.connecteddevice.usb;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.support.v7.preference.Preference;
|
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
|
||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
|
||||||
import com.android.settingslib.core.lifecycle.events.OnPause;
|
|
||||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
|
||||||
|
|
||||||
public class UsbModePreferenceController extends AbstractPreferenceController
|
|
||||||
implements PreferenceControllerMixin, LifecycleObserver, OnResume, OnPause {
|
|
||||||
|
|
||||||
private static final String KEY_USB_MODE = "usb_mode";
|
|
||||||
|
|
||||||
private UsbBackend mUsbBackend;
|
|
||||||
@VisibleForTesting
|
|
||||||
UsbConnectionBroadcastReceiver mUsbReceiver;
|
|
||||||
private Preference mUsbPreference;
|
|
||||||
|
|
||||||
public UsbModePreferenceController(Context context, UsbBackend usbBackend,
|
|
||||||
Lifecycle lifecycle) {
|
|
||||||
super(context);
|
|
||||||
mUsbBackend = usbBackend;
|
|
||||||
mUsbReceiver = new UsbConnectionBroadcastReceiver(mContext, (connected, newMode) -> {
|
|
||||||
updateSummary(mUsbPreference, connected, newMode);
|
|
||||||
}, mUsbBackend);
|
|
||||||
if (lifecycle != null) {
|
|
||||||
lifecycle.addObserver(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void displayPreference(PreferenceScreen screen) {
|
|
||||||
super.displayPreference(screen);
|
|
||||||
mUsbPreference = screen.findPreference(KEY_USB_MODE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateState(Preference preference) {
|
|
||||||
updateSummary(preference, mUsbReceiver.isConnected(), mUsbBackend.getCurrentMode());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAvailable() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPreferenceKey() {
|
|
||||||
return KEY_USB_MODE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPause() {
|
|
||||||
mUsbReceiver.unregister();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
mUsbReceiver.register();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getSummary(int mode) {
|
|
||||||
switch (mode) {
|
|
||||||
case UsbBackend.MODE_POWER_SINK | UsbBackend.MODE_DATA_NONE:
|
|
||||||
return R.string.usb_summary_charging_only;
|
|
||||||
case UsbBackend.MODE_POWER_SOURCE | UsbBackend.MODE_DATA_NONE:
|
|
||||||
return R.string.usb_summary_power_only;
|
|
||||||
case UsbBackend.MODE_POWER_SINK | UsbBackend.MODE_DATA_MTP:
|
|
||||||
return R.string.usb_summary_file_transfers;
|
|
||||||
case UsbBackend.MODE_POWER_SINK | UsbBackend.MODE_DATA_PTP:
|
|
||||||
return R.string.usb_summary_photo_transfers;
|
|
||||||
case UsbBackend.MODE_POWER_SINK | UsbBackend.MODE_DATA_MIDI:
|
|
||||||
return R.string.usb_summary_MIDI;
|
|
||||||
case UsbBackend.MODE_POWER_SINK | UsbBackend.MODE_DATA_TETHER:
|
|
||||||
return R.string.usb_summary_tether;
|
|
||||||
case UsbBackend.MODE_POWER_SOURCE | UsbBackend.MODE_DATA_MTP:
|
|
||||||
return R.string.usb_summary_file_transfers_power;
|
|
||||||
case UsbBackend.MODE_POWER_SOURCE | UsbBackend.MODE_DATA_PTP:
|
|
||||||
return R.string.usb_summary_photo_transfers_power;
|
|
||||||
case UsbBackend.MODE_POWER_SOURCE | UsbBackend.MODE_DATA_MIDI:
|
|
||||||
return R.string.usb_summary_MIDI_power;
|
|
||||||
case UsbBackend.MODE_POWER_SOURCE | UsbBackend.MODE_DATA_TETHER:
|
|
||||||
return R.string.usb_summary_tether_power;
|
|
||||||
default:
|
|
||||||
return R.string.usb_summary_charging_only;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateSummary(Preference preference, boolean connected, int mode) {
|
|
||||||
if (preference != null) {
|
|
||||||
if (connected) {
|
|
||||||
preference.setEnabled(true);
|
|
||||||
preference.setSummary(getSummary(mode));
|
|
||||||
} else {
|
|
||||||
preference.setSummary(R.string.disconnected);
|
|
||||||
preference.setEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -20,7 +20,6 @@ package com.android.settings.core;
|
|||||||
* This class keeps track of all feature flags in Settings.
|
* This class keeps track of all feature flags in Settings.
|
||||||
*/
|
*/
|
||||||
public class FeatureFlags {
|
public class FeatureFlags {
|
||||||
public static final String CONNECTED_DEVICE_V2 = "settings_connected_device_v2";
|
|
||||||
public static final String BATTERY_SETTINGS_V2 = "settings_battery_v2";
|
public static final String BATTERY_SETTINGS_V2 = "settings_battery_v2";
|
||||||
public static final String BATTERY_DISPLAY_APP_LIST = "settings_battery_display_app_list";
|
public static final String BATTERY_DISPLAY_APP_LIST = "settings_battery_display_app_list";
|
||||||
public static final String ZONE_PICKER_V2 = "settings_zone_picker_v2";
|
public static final String ZONE_PICKER_V2 = "settings_zone_picker_v2";
|
||||||
|
@@ -55,9 +55,7 @@ import com.android.settings.applications.assist.ManageAssist;
|
|||||||
import com.android.settings.applications.manageapplications.ManageApplications;
|
import com.android.settings.applications.manageapplications.ManageApplications;
|
||||||
import com.android.settings.bluetooth.BluetoothDeviceDetailsFragment;
|
import com.android.settings.bluetooth.BluetoothDeviceDetailsFragment;
|
||||||
import com.android.settings.bluetooth.BluetoothSettings;
|
import com.android.settings.bluetooth.BluetoothSettings;
|
||||||
import com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment;
|
|
||||||
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
|
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
|
||||||
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragmentOld;
|
|
||||||
import com.android.settings.connecteddevice.usb.UsbDetailsFragment;
|
import com.android.settings.connecteddevice.usb.UsbDetailsFragment;
|
||||||
import com.android.settings.datausage.DataUsageList;
|
import com.android.settings.datausage.DataUsageList;
|
||||||
import com.android.settings.datausage.DataUsageSummary;
|
import com.android.settings.datausage.DataUsageSummary;
|
||||||
@@ -242,7 +240,6 @@ public class SettingsGateway {
|
|||||||
SystemDashboardFragment.class.getName(),
|
SystemDashboardFragment.class.getName(),
|
||||||
NetworkDashboardFragment.class.getName(),
|
NetworkDashboardFragment.class.getName(),
|
||||||
ConnectedDeviceDashboardFragment.class.getName(),
|
ConnectedDeviceDashboardFragment.class.getName(),
|
||||||
ConnectedDeviceDashboardFragmentOld.class.getName(),
|
|
||||||
UsbDetailsFragment.class.getName(),
|
UsbDetailsFragment.class.getName(),
|
||||||
AppAndNotificationDashboardFragment.class.getName(),
|
AppAndNotificationDashboardFragment.class.getName(),
|
||||||
AccountDashboardFragment.class.getName(),
|
AccountDashboardFragment.class.getName(),
|
||||||
@@ -252,7 +249,6 @@ public class SettingsGateway {
|
|||||||
BluetoothDeviceDetailsFragment.class.getName(),
|
BluetoothDeviceDetailsFragment.class.getName(),
|
||||||
DataUsageList.class.getName(),
|
DataUsageList.class.getName(),
|
||||||
DirectoryAccessDetails.class.getName(),
|
DirectoryAccessDetails.class.getName(),
|
||||||
AdvancedConnectedDeviceDashboardFragment.class.getName()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public static final String[] SETTINGS_FOR_RESTRICTED = {
|
public static final String[] SETTINGS_FOR_RESTRICTED = {
|
||||||
|
@@ -1,156 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 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.development;
|
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.hardware.usb.UsbManager;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.support.annotation.VisibleForTesting;
|
|
||||||
import android.support.v7.preference.ListPreference;
|
|
||||||
import android.support.v7.preference.Preference;
|
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.Utils;
|
|
||||||
import com.android.settings.wrapper.UsbManagerWrapper;
|
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
|
||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
|
||||||
import com.android.settingslib.core.lifecycle.events.OnCreate;
|
|
||||||
import com.android.settingslib.core.lifecycle.events.OnDestroy;
|
|
||||||
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
|
|
||||||
|
|
||||||
public class SelectUsbConfigPreferenceController extends
|
|
||||||
DeveloperOptionsPreferenceController implements
|
|
||||||
Preference.OnPreferenceChangeListener, LifecycleObserver, OnCreate, OnDestroy,
|
|
||||||
PreferenceControllerMixin {
|
|
||||||
|
|
||||||
private static final String USB_CONFIGURATION_KEY = "select_usb_configuration";
|
|
||||||
|
|
||||||
private final String[] mListValues;
|
|
||||||
private final String[] mListSummaries;
|
|
||||||
private final UsbManager mUsbManager;
|
|
||||||
@VisibleForTesting
|
|
||||||
UsbManagerWrapper mUsbManagerWrapper;
|
|
||||||
private BroadcastReceiver mUsbReceiver;
|
|
||||||
private ListPreference mPreference;
|
|
||||||
|
|
||||||
public SelectUsbConfigPreferenceController(Context context, Lifecycle lifecycle) {
|
|
||||||
super(context);
|
|
||||||
|
|
||||||
mListValues = context.getResources().getStringArray(R.array.usb_configuration_values);
|
|
||||||
mListSummaries = context.getResources().getStringArray(R.array.usb_configuration_titles);
|
|
||||||
mUsbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
|
|
||||||
mUsbManagerWrapper = new UsbManagerWrapper(mUsbManager);
|
|
||||||
mUsbReceiver = new BroadcastReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
if (mPreference != null) {
|
|
||||||
updateUsbConfigurationValues();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if (lifecycle != null) {
|
|
||||||
lifecycle.addObserver(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
IntentFilter filter = new IntentFilter();
|
|
||||||
filter.addAction(UsbManager.ACTION_USB_STATE);
|
|
||||||
mContext.registerReceiver(mUsbReceiver, filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPreferenceKey() {
|
|
||||||
return USB_CONFIGURATION_KEY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void displayPreference(PreferenceScreen screen) {
|
|
||||||
super.displayPreference(screen);
|
|
||||||
|
|
||||||
mPreference = (ListPreference) screen.findPreference(getPreferenceKey());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
||||||
if (Utils.isMonkeyRunning()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
writeUsbConfigurationOption(mUsbManagerWrapper
|
|
||||||
.usbFunctionsFromString(newValue.toString()));
|
|
||||||
updateUsbConfigurationValues();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateState(Preference preference) {
|
|
||||||
updateUsbConfigurationValues();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
mContext.unregisterReceiver(mUsbReceiver);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAvailable() {
|
|
||||||
final PackageManager packageManager = mContext.getPackageManager();
|
|
||||||
|
|
||||||
return packageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST)
|
|
||||||
|| packageManager.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDeveloperOptionsSwitchEnabled() {
|
|
||||||
mPreference.setEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDeveloperOptionsSwitchDisabled() {
|
|
||||||
mPreference.setEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
void setCurrentFunctions(long functions) {
|
|
||||||
mUsbManager.setCurrentFunctions(functions);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateUsbConfigurationValues() {
|
|
||||||
long functions = mUsbManagerWrapper.getCurrentFunctions();
|
|
||||||
int index = 0;
|
|
||||||
for (int i = 0; i < mListValues.length; i++) {
|
|
||||||
if (functions == mUsbManagerWrapper.usbFunctionsFromString(mListValues[i])) {
|
|
||||||
index = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mPreference.setValue(mListValues[index]);
|
|
||||||
mPreference.setSummary(mListSummaries[index]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void writeUsbConfigurationOption(long newValue) {
|
|
||||||
setCurrentFunctions(newValue);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -21,7 +21,7 @@ import android.support.annotation.VisibleForTesting;
|
|||||||
import com.android.settings.DateTimeSettings;
|
import com.android.settings.DateTimeSettings;
|
||||||
import com.android.settings.DisplaySettings;
|
import com.android.settings.DisplaySettings;
|
||||||
import com.android.settings.LegalSettings;
|
import com.android.settings.LegalSettings;
|
||||||
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragmentOld;
|
import com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment;
|
||||||
import com.android.settings.datausage.DataUsageSummaryLegacy;
|
import com.android.settings.datausage.DataUsageSummaryLegacy;
|
||||||
import com.android.settings.deviceinfo.aboutphone.MyDeviceInfoFragment;
|
import com.android.settings.deviceinfo.aboutphone.MyDeviceInfoFragment;
|
||||||
import com.android.settings.accessibility.AccessibilitySettings;
|
import com.android.settings.accessibility.AccessibilitySettings;
|
||||||
@@ -36,7 +36,6 @@ import com.android.settings.applications.assist.ManageAssist;
|
|||||||
import com.android.settings.backup.BackupSettingsActivity;
|
import com.android.settings.backup.BackupSettingsActivity;
|
||||||
import com.android.settings.backup.BackupSettingsFragment;
|
import com.android.settings.backup.BackupSettingsFragment;
|
||||||
import com.android.settings.bluetooth.BluetoothSettings;
|
import com.android.settings.bluetooth.BluetoothSettings;
|
||||||
import com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment;
|
|
||||||
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
|
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
|
||||||
import com.android.settings.connecteddevice.usb.UsbDetailsFragment;
|
import com.android.settings.connecteddevice.usb.UsbDetailsFragment;
|
||||||
import com.android.settings.datausage.DataUsageSummary;
|
import com.android.settings.datausage.DataUsageSummary;
|
||||||
@@ -45,7 +44,6 @@ import com.android.settings.development.DevelopmentSettingsDashboardFragment;
|
|||||||
import com.android.settings.deviceinfo.DeviceInfoSettings;
|
import com.android.settings.deviceinfo.DeviceInfoSettings;
|
||||||
import com.android.settings.deviceinfo.StorageDashboardFragment;
|
import com.android.settings.deviceinfo.StorageDashboardFragment;
|
||||||
import com.android.settings.deviceinfo.StorageSettings;
|
import com.android.settings.deviceinfo.StorageSettings;
|
||||||
import com.android.settings.deviceinfo.aboutphone.MyDeviceInfoFragment;
|
|
||||||
import com.android.settings.display.AmbientDisplaySettings;
|
import com.android.settings.display.AmbientDisplaySettings;
|
||||||
import com.android.settings.display.NightDisplaySettings;
|
import com.android.settings.display.NightDisplaySettings;
|
||||||
import com.android.settings.display.ScreenZoomSettings;
|
import com.android.settings.display.ScreenZoomSettings;
|
||||||
@@ -157,7 +155,6 @@ public class SearchIndexableResourcesImpl implements SearchIndexableResources {
|
|||||||
addIndex(ResetDashboardFragment.class);
|
addIndex(ResetDashboardFragment.class);
|
||||||
addIndex(StorageDashboardFragment.class);
|
addIndex(StorageDashboardFragment.class);
|
||||||
addIndex(ConnectedDeviceDashboardFragment.class);
|
addIndex(ConnectedDeviceDashboardFragment.class);
|
||||||
addIndex(ConnectedDeviceDashboardFragmentOld.class);
|
|
||||||
addIndex(AdvancedConnectedDeviceDashboardFragment.class);
|
addIndex(AdvancedConnectedDeviceDashboardFragment.class);
|
||||||
addIndex(EnterprisePrivacySettings.class);
|
addIndex(EnterprisePrivacySettings.class);
|
||||||
addIndex(PaymentSettings.class);
|
addIndex(PaymentSettings.class);
|
||||||
|
@@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 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.connecteddevice.usb;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
import static org.mockito.Matchers.anyInt;
|
|
||||||
import static org.mockito.Mockito.never;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
|
|
||||||
import android.widget.TextView;
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.connecteddevice.usb.UsbModeChooserActivity;
|
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
|
||||||
import com.android.settings.TestConfig;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.robolectric.annotation.Config;
|
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
|
||||||
public class UsbModeChooserActivityTest {
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private TextView mTextView;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateSummary_chargeDevice_shouldNotSetSummary() {
|
|
||||||
UsbModeChooserActivity.updateSummary(mTextView, UsbModeChooserActivity.DEFAULT_MODES[0]);
|
|
||||||
verify(mTextView, never()).setText(anyInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateSummary_supplyPower_shouldSetSummary() {
|
|
||||||
UsbModeChooserActivity.updateSummary(mTextView, UsbModeChooserActivity.DEFAULT_MODES[1]);
|
|
||||||
verify(mTextView).setText(R.string.usb_use_power_only_desc);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateSummary_transferFiles_shouldNotSetSummary() {
|
|
||||||
UsbModeChooserActivity.updateSummary(mTextView, UsbModeChooserActivity.DEFAULT_MODES[2]);
|
|
||||||
verify(mTextView, never()).setText(anyInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateSummary_transferPhoto_shouldNotSetSummary() {
|
|
||||||
UsbModeChooserActivity.updateSummary(mTextView, UsbModeChooserActivity.DEFAULT_MODES[3]);
|
|
||||||
verify(mTextView, never()).setText(anyInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateSummary_MIDI_shouldNotSetSummary() {
|
|
||||||
UsbModeChooserActivity.updateSummary(mTextView, UsbModeChooserActivity.DEFAULT_MODES[4]);
|
|
||||||
verify(mTextView, never()).setText(anyInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getTitle_shouldReturnCorrectTitle() {
|
|
||||||
assertThat(UsbModeChooserActivity.getTitle(UsbModeChooserActivity.DEFAULT_MODES[0]))
|
|
||||||
.isEqualTo(R.string.usb_use_charging_only);
|
|
||||||
|
|
||||||
assertThat(UsbModeChooserActivity.getTitle(UsbModeChooserActivity.DEFAULT_MODES[1]))
|
|
||||||
.isEqualTo(R.string.usb_use_power_only);
|
|
||||||
|
|
||||||
assertThat(UsbModeChooserActivity.getTitle(UsbModeChooserActivity.DEFAULT_MODES[2]))
|
|
||||||
.isEqualTo(R.string.usb_use_file_transfers);
|
|
||||||
|
|
||||||
assertThat(UsbModeChooserActivity.getTitle(UsbModeChooserActivity.DEFAULT_MODES[3]))
|
|
||||||
.isEqualTo(R.string.usb_use_photo_transfers);
|
|
||||||
|
|
||||||
assertThat(UsbModeChooserActivity.getTitle(UsbModeChooserActivity.DEFAULT_MODES[4]))
|
|
||||||
.isEqualTo(R.string.usb_use_MIDI);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,105 +0,0 @@
|
|||||||
package com.android.settings.connecteddevice.usb;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.support.v7.preference.Preference;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.TestConfig;
|
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.robolectric.annotation.Config;
|
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
|
||||||
public class UsbModePreferenceControllerTest {
|
|
||||||
|
|
||||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
|
||||||
private UsbBackend mUsbBackend;
|
|
||||||
@Mock
|
|
||||||
private UsbConnectionBroadcastReceiver mUsbConnectionBroadcastReceiver;
|
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
private UsbModePreferenceController mController;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
mContext = ShadowApplication.getInstance().getApplicationContext();
|
|
||||||
mController = new UsbModePreferenceController(mContext, mUsbBackend, null /* lifecycle */);
|
|
||||||
mController.mUsbReceiver = mUsbConnectionBroadcastReceiver;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetSummary_chargeDevice() {
|
|
||||||
assertThat(mController.getSummary(0))
|
|
||||||
.isEqualTo(R.string.usb_summary_charging_only);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetSummary_supplyPower() {
|
|
||||||
assertThat(mController.getSummary(UsbBackend.MODE_POWER_SOURCE))
|
|
||||||
.isEqualTo(R.string.usb_summary_power_only);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetSummary_TransferFiles() {
|
|
||||||
assertThat(mController.getSummary(UsbBackend.MODE_DATA_MTP))
|
|
||||||
.isEqualTo(R.string.usb_summary_file_transfers);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetSummary_TransferPhoto() {
|
|
||||||
assertThat(mController.getSummary(UsbBackend.MODE_DATA_PTP))
|
|
||||||
.isEqualTo(R.string.usb_summary_photo_transfers);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetSummary_MIDI() {
|
|
||||||
assertThat(mController.getSummary(UsbBackend.MODE_DATA_MIDI))
|
|
||||||
.isEqualTo(R.string.usb_summary_MIDI);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetSummary_Tethering() {
|
|
||||||
assertThat(mController.getSummary(UsbBackend.MODE_DATA_TETHER))
|
|
||||||
.isEqualTo(R.string.usb_summary_tether);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testPreferenceSummary_usbDisconnected() {
|
|
||||||
final Preference preference = new Preference(mContext);
|
|
||||||
preference.setKey("usb_mode");
|
|
||||||
preference.setEnabled(true);
|
|
||||||
when(mUsbBackend.getCurrentMode()).thenReturn(UsbBackend.MODE_POWER_SINK);
|
|
||||||
when(mUsbConnectionBroadcastReceiver.isConnected()).thenReturn(false);
|
|
||||||
mController.updateState(preference);
|
|
||||||
|
|
||||||
assertThat(preference.getKey()).isEqualTo("usb_mode");
|
|
||||||
assertThat(preference.getSummary()).isEqualTo(
|
|
||||||
mContext.getString(R.string.disconnected));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUsbBroadcastReceiver_usbConnected_shouldUpdateSummary() {
|
|
||||||
final Preference preference = new Preference(mContext);
|
|
||||||
preference.setKey("usb_mode");
|
|
||||||
preference.setEnabled(true);
|
|
||||||
when(mUsbBackend.getCurrentMode()).thenReturn(UsbBackend.MODE_POWER_SINK);
|
|
||||||
when(mUsbConnectionBroadcastReceiver.isConnected()).thenReturn(true);
|
|
||||||
mController.updateState(preference);
|
|
||||||
|
|
||||||
assertThat(preference.getSummary()).isEqualTo(
|
|
||||||
mContext.getString(R.string.usb_summary_charging_only));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,244 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 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.development;
|
|
||||||
|
|
||||||
import static android.arch.lifecycle.Lifecycle.Event.ON_CREATE;
|
|
||||||
import static android.arch.lifecycle.Lifecycle.Event.ON_DESTROY;
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertFalse;
|
|
||||||
import static junit.framework.Assert.assertTrue;
|
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyLong;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
|
||||||
import static org.mockito.Mockito.doNothing;
|
|
||||||
import static org.mockito.Mockito.doReturn;
|
|
||||||
import static org.mockito.Mockito.never;
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.arch.lifecycle.LifecycleOwner;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.hardware.usb.UsbManager;
|
|
||||||
import android.hardware.usb.UsbManagerExtras;
|
|
||||||
import android.support.v7.preference.ListPreference;
|
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.TestConfig;
|
|
||||||
import com.android.settings.wrapper.UsbManagerWrapper;
|
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
|
||||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
import org.robolectric.annotation.Config;
|
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH,
|
|
||||||
sdk = TestConfig.SDK_VERSION,
|
|
||||||
shadows = {ShadowUtils.class})
|
|
||||||
public class SelectUsbConfigPreferenceControllerTest {
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private ListPreference mPreference;
|
|
||||||
@Mock
|
|
||||||
private PreferenceScreen mScreen;
|
|
||||||
@Mock
|
|
||||||
private UsbManager mUsbManager;
|
|
||||||
@Mock
|
|
||||||
private PackageManager mPackageManager;
|
|
||||||
@Mock
|
|
||||||
private UsbManagerWrapper mUsbManagerWrapper;
|
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
private LifecycleOwner mLifecycleOwner;
|
|
||||||
private Lifecycle mLifecycle;
|
|
||||||
private SelectUsbConfigPreferenceController mController;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Array Values Key
|
|
||||||
*
|
|
||||||
* 0: Charging
|
|
||||||
* 1: MTP
|
|
||||||
* 2: PTP
|
|
||||||
* 3: RNDIS
|
|
||||||
* 4: Audio Source
|
|
||||||
* 5: MIDI
|
|
||||||
*/
|
|
||||||
private String[] mValues;
|
|
||||||
private String[] mSummaries;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setup() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
mLifecycleOwner = () -> mLifecycle;
|
|
||||||
mLifecycle = new Lifecycle(mLifecycleOwner);
|
|
||||||
mContext = spy(RuntimeEnvironment.application);
|
|
||||||
doReturn(mUsbManager).when(mContext).getSystemService(Context.USB_SERVICE);
|
|
||||||
doReturn(mPackageManager).when(mContext).getPackageManager();
|
|
||||||
mValues = mContext.getResources().getStringArray(R.array.usb_configuration_values);
|
|
||||||
mSummaries = mContext.getResources().getStringArray(R.array.usb_configuration_titles);
|
|
||||||
mController = spy(new SelectUsbConfigPreferenceController(mContext, mLifecycle));
|
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
|
||||||
mController.displayPreference(mScreen);
|
|
||||||
mController.mUsbManagerWrapper = mUsbManagerWrapper;
|
|
||||||
|
|
||||||
when(mUsbManagerWrapper.usbFunctionsFromString("mtp")).thenReturn(UsbManagerExtras.MTP);
|
|
||||||
when(mUsbManagerWrapper.usbFunctionsFromString("rndis"))
|
|
||||||
.thenReturn(UsbManagerExtras.RNDIS);
|
|
||||||
when(mUsbManagerWrapper.usbFunctionsFromString("none"))
|
|
||||||
.thenReturn(UsbManagerExtras.NONE);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void teardown() {
|
|
||||||
ShadowUtils.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onPreferenceChange_setCharging_shouldEnableCharging() {
|
|
||||||
when(mUsbManagerWrapper.getCurrentFunctions()).thenReturn(
|
|
||||||
UsbManagerExtras.usbFunctionsFromString(mValues[0]));
|
|
||||||
doNothing().when(mController).setCurrentFunctions(anyLong());
|
|
||||||
mController.onPreferenceChange(mPreference, mValues[0]);
|
|
||||||
|
|
||||||
verify(mController).setCurrentFunctions(
|
|
||||||
UsbManagerExtras.usbFunctionsFromString(mValues[0]));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onUsbAccessoryAndHostDisabled_shouldNotBeAvailable() {
|
|
||||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST)).thenReturn(false);
|
|
||||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY)).thenReturn(
|
|
||||||
false);
|
|
||||||
assertFalse(mController.isAvailable());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onUsbHostEnabled_shouldBeAvailable() {
|
|
||||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST)).thenReturn(true);
|
|
||||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY)).thenReturn(
|
|
||||||
false);
|
|
||||||
assertTrue(mController.isAvailable());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onUsbAccessoryEnabled_shouldBeAvailable() {
|
|
||||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST)).thenReturn(false);
|
|
||||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY)).thenReturn(
|
|
||||||
true);
|
|
||||||
assertTrue(mController.isAvailable());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onPreferenceChange_setMtp_shouldEnableMtp() {
|
|
||||||
when(mUsbManagerWrapper.getCurrentFunctions())
|
|
||||||
.thenReturn(UsbManagerExtras.usbFunctionsFromString(mValues[1]));
|
|
||||||
doNothing().when(mController).setCurrentFunctions(anyLong());
|
|
||||||
mController.onPreferenceChange(mPreference, mValues[1]);
|
|
||||||
|
|
||||||
verify(mController).setCurrentFunctions(
|
|
||||||
UsbManagerExtras.usbFunctionsFromString(mValues[1]));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onPreferenceChange_monkeyUser_shouldReturnFalse() {
|
|
||||||
when(mUsbManagerWrapper.getCurrentFunctions())
|
|
||||||
.thenReturn(UsbManagerExtras.usbFunctionsFromString(mValues[1]));
|
|
||||||
ShadowUtils.setIsUserAMonkey(true);
|
|
||||||
doNothing().when(mController).setCurrentFunctions(anyLong());
|
|
||||||
|
|
||||||
final boolean isHandled = mController.onPreferenceChange(mPreference, mValues[1]);
|
|
||||||
|
|
||||||
assertThat(isHandled).isFalse();
|
|
||||||
verify(mController, never()).setCurrentFunctions(anyLong());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateState_chargingEnabled_shouldSetPreferenceToCharging() {
|
|
||||||
when(mUsbManagerWrapper.getCurrentFunctions())
|
|
||||||
.thenReturn(UsbManagerExtras.usbFunctionsFromString(mValues[0]));
|
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
|
||||||
|
|
||||||
verify(mPreference).setValue(mValues[0]);
|
|
||||||
verify(mPreference).setSummary(mSummaries[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateState_RndisEnabled_shouldEnableRndis() {
|
|
||||||
when(mUsbManagerWrapper.getCurrentFunctions())
|
|
||||||
.thenReturn(UsbManagerExtras.usbFunctionsFromString(mValues[3]));
|
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
|
||||||
|
|
||||||
verify(mPreference).setValue(mValues[3]);
|
|
||||||
verify(mPreference).setSummary(mSummaries[3]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateState_noValueSet_shouldEnableChargingAsDefault() {
|
|
||||||
when(mUsbManagerWrapper.getCurrentFunctions()).thenReturn(UsbManagerExtras.NONE);
|
|
||||||
mController.updateState(mPreference);
|
|
||||||
|
|
||||||
verify(mPreference).setValue(mValues[0]);
|
|
||||||
verify(mPreference).setSummary(mSummaries[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onDeveloperOptionsSwitchDisabled_shouldDisablePreference() {
|
|
||||||
mController.onDeveloperOptionsSwitchDisabled();
|
|
||||||
|
|
||||||
verify(mPreference).setEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onDeveloperOptionsSwitchEnabled_shouldEnablePreference() {
|
|
||||||
mController.onDeveloperOptionsSwitchEnabled();
|
|
||||||
|
|
||||||
verify(mPreference).setEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onCreate_shouldRegisterReceiver() {
|
|
||||||
mLifecycle.onCreate(null /* bundle */);
|
|
||||||
mLifecycle.handleLifecycleEvent(ON_CREATE);
|
|
||||||
|
|
||||||
verify(mContext).registerReceiver(any(), any());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onDestroy_shouldUnregisterReceiver() {
|
|
||||||
doNothing().when(mContext).unregisterReceiver(any());
|
|
||||||
mLifecycle.handleLifecycleEvent(ON_CREATE);
|
|
||||||
mLifecycle.handleLifecycleEvent(ON_DESTROY);
|
|
||||||
|
|
||||||
verify(mContext).unregisterReceiver(any());
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user