Snap for 4625912 from f6cba5d9b5 to pi-release
Change-Id: If17ee88a62ee7b5420c09580a1eb989c4802fdd9
This commit is contained in:
@@ -212,33 +212,6 @@
|
||||
android:value="true" />
|
||||
</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"
|
||||
android:label="@string/wireless_networks_settings_title"
|
||||
android:theme="@*android:style/Theme.DeviceDefault.Light.Voice"
|
||||
@@ -3296,7 +3269,7 @@
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<service android:name=".fuelgauge.batterytip.AnomalyCleanUpJobService"
|
||||
<service android:name=".fuelgauge.batterytip.AnomalyCleanupJobService"
|
||||
android:permission="android.permission.BIND_JOB_SERVICE" />
|
||||
|
||||
<service android:name=".fuelgauge.batterytip.AnomalyDetectionJobService"
|
||||
|
||||
@@ -2113,38 +2113,6 @@
|
||||
column="17"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
message="Avoid using hardcoded color"
|
||||
category="Correctness"
|
||||
priority="4"
|
||||
summary="Using hardcoded color"
|
||||
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
|
||||
errorLine1=" android:background="#00ffffff""
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/layout/preference_importance_slider.xml"
|
||||
line="59"
|
||||
column="17"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
message="Avoid using hardcoded color"
|
||||
category="Correctness"
|
||||
priority="4"
|
||||
summary="Using hardcoded color"
|
||||
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
|
||||
errorLine1=" android:progressBackgroundTint="@color/importance_secondary_slider_color""
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/layout/preference_importance_slider.xml"
|
||||
line="60"
|
||||
column="17"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="8dp"
|
||||
android:orientation="vertical"
|
||||
android:clickable="false"
|
||||
android:focusable="false" >
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Subhead"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:ellipsize="marquee"
|
||||
android:fadingEdge="horizontal" />
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/auto_importance"
|
||||
android:src="@drawable/notification_auto_importance"
|
||||
android:layout_gravity="center_vertical|start"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@*android:id/seekbar"
|
||||
android:layout_marginStart="56dp"
|
||||
android:layout_marginEnd="32dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:focusable="true"
|
||||
android:background="#00ffffff"
|
||||
android:progressBackgroundTint="@color/importance_secondary_slider_color"
|
||||
android:thumbTint="?android:attr/colorAccent"
|
||||
android:progressTint="?android:attr/colorAccent"
|
||||
style="@android:style/Widget.Material.SeekBar.Discrete"
|
||||
android:tickMarkTint="@android:color/black" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/summary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignStart="@android:id/title"
|
||||
android:textAlignment="viewStart"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Body1"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:maxLines="10"
|
||||
android:minLines="3" />
|
||||
</LinearLayout>
|
||||
@@ -94,9 +94,6 @@
|
||||
<color name="message_icon_background_outgoing">#4285f4</color>
|
||||
<color name="message_icon_text_outgoing">#ffffffff</color>
|
||||
|
||||
<color name="importance_disabled_slider_color">@*android:color/material_grey_300</color>
|
||||
<color name="importance_secondary_slider_color">#858383</color>
|
||||
|
||||
<color name="usage_graph_dots">#B0BEC5</color>
|
||||
|
||||
<!-- Gestures settings -->
|
||||
|
||||
@@ -5410,7 +5410,7 @@
|
||||
<string name="usage_access_title">Apps with usage access</string>
|
||||
|
||||
<!-- Sound settings screen, setting check box label -->
|
||||
<string name="emergency_tone_title">Emergency tone</string>
|
||||
<string name="emergency_tone_title">Emergency dialing signal</string>
|
||||
<!-- Sound settings screen, setting option summary text -->
|
||||
<string name="emergency_tone_summary">Set behavior when an emergency call is placed</string>
|
||||
|
||||
@@ -6868,14 +6868,14 @@
|
||||
<!-- Sound: Other sounds: Value for the dock audio media with value 1: enabled. [CHAR LIMIT=30] -->
|
||||
<string name="dock_audio_media_enabled">Media audio only</string>
|
||||
|
||||
<!-- Sound: Other sounds: Value for the emergency tone option with value 0: silent. [CHAR LIMIT=30] -->
|
||||
<string name="emergency_tone_silent">Silent</string>
|
||||
<!-- Sound: Other sounds: Value for the emergency dialing signal option with value 0: silence. [CHAR LIMIT=30] -->
|
||||
<string name="emergency_tone_silent">Silence</string>
|
||||
|
||||
<!-- Sound: Other sounds: Value for the emergency tone option with value 1: alert. [CHAR LIMIT=30] -->
|
||||
<string name="emergency_tone_alert">Alert</string>
|
||||
<!-- Sound: Other sounds: Value for the emergency dialing signal option with value 1: tones. [CHAR LIMIT=30] -->
|
||||
<string name="emergency_tone_alert">Tones</string>
|
||||
|
||||
<!-- Sound: Other sounds: Value for the emergency tone option with value 2: vibrate. [CHAR LIMIT=30] -->
|
||||
<string name="emergency_tone_vibrate">Vibrate</string>
|
||||
<!-- Sound: Other sounds: Value for the emergency dialing signal option with value 2: vibrations. [CHAR LIMIT=30] -->
|
||||
<string name="emergency_tone_vibrate">Vibrations</string>
|
||||
|
||||
<!-- Sound: Other sounds: Title for the option enabling boot sounds. [CHAR LIMIT=30] -->
|
||||
<string name="boot_sounds_title">Power on sounds</string>
|
||||
|
||||
@@ -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,13 +16,11 @@
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import static android.provider.Telephony.Carriers.CONTENT_URI;
|
||||
import static android.provider.Telephony.Carriers.FILTERED_URI;
|
||||
|
||||
import android.content.ContentUris;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.provider.Telephony;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.telephony.SubscriptionManager;
|
||||
@@ -37,7 +35,6 @@ import android.widget.RelativeLayout;
|
||||
public class ApnPreference extends Preference implements
|
||||
CompoundButton.OnCheckedChangeListener, OnClickListener {
|
||||
final static String TAG = "ApnPreference";
|
||||
private boolean mDpcEnforced = false;
|
||||
|
||||
private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
|
||||
@@ -121,8 +118,7 @@ public class ApnPreference extends Preference implements
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
int pos = Integer.parseInt(getKey());
|
||||
Uri url = ContentUris.withAppendedId(
|
||||
mDpcEnforced ? FILTERED_URI : CONTENT_URI, pos);
|
||||
Uri url = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI, pos);
|
||||
Intent editIntent = new Intent(Intent.ACTION_EDIT, url);
|
||||
editIntent.putExtra(ApnSettings.SUB_ID, mSubId);
|
||||
context.startActivity(editIntent);
|
||||
@@ -141,8 +137,4 @@ public class ApnPreference extends Preference implements
|
||||
public void setSubId(int subId) {
|
||||
mSubId = subId;
|
||||
}
|
||||
|
||||
public void setDpcEnforced(boolean enforced) {
|
||||
mDpcEnforced = enforced;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,6 @@
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import static android.provider.Telephony.Carriers.CONTENT_URI;
|
||||
import static android.provider.Telephony.Carriers.ENFORCE_MANAGED_URI;
|
||||
import static android.provider.Telephony.Carriers.FILTERED_URI;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.app.ProgressDialog;
|
||||
@@ -43,6 +39,7 @@ import android.os.UserManager;
|
||||
import android.provider.Telephony;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceGroup;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
@@ -53,6 +50,7 @@ import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
@@ -248,17 +246,6 @@ public class ApnSettings extends RestrictedSettingsFragment implements
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isDpcApnEnforced() {
|
||||
try (Cursor enforceCursor = getContentResolver().query(ENFORCE_MANAGED_URI,
|
||||
null, null, null, null)) {
|
||||
if (enforceCursor == null || enforceCursor.getCount() != 1) {
|
||||
return false;
|
||||
}
|
||||
enforceCursor.moveToFirst();
|
||||
return enforceCursor.getInt(0) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void fillList() {
|
||||
final TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
||||
final int subId = mSubscriptionInfo != null ? mSubscriptionInfo.getSubscriptionId()
|
||||
@@ -272,9 +259,9 @@ public class ApnSettings extends RestrictedSettingsFragment implements
|
||||
where.append(" AND NOT (type='ims')");
|
||||
}
|
||||
|
||||
Cursor cursor = getContentResolver().query(FILTERED_URI,
|
||||
new String[] {"_id", "name", "apn", "type", "mvno_type", "mvno_match_data"},
|
||||
where.toString(), null, Telephony.Carriers.DEFAULT_SORT_ORDER);
|
||||
Cursor cursor = getContentResolver().query(Telephony.Carriers.CONTENT_URI, new String[] {
|
||||
"_id", "name", "apn", "type", "mvno_type", "mvno_match_data"}, where.toString(),
|
||||
null, Telephony.Carriers.DEFAULT_SORT_ORDER);
|
||||
|
||||
if (cursor != null) {
|
||||
IccRecords r = null;
|
||||
@@ -292,7 +279,6 @@ public class ApnSettings extends RestrictedSettingsFragment implements
|
||||
|
||||
mSelectedKey = getSelectedApnKey();
|
||||
cursor.moveToFirst();
|
||||
boolean enforced = isDpcApnEnforced();
|
||||
while (!cursor.isAfterLast()) {
|
||||
String name = cursor.getString(NAME_INDEX);
|
||||
String apn = cursor.getString(APN_INDEX);
|
||||
@@ -309,7 +295,6 @@ public class ApnSettings extends RestrictedSettingsFragment implements
|
||||
pref.setPersistent(false);
|
||||
pref.setOnPreferenceChangeListener(this);
|
||||
pref.setSubId(subId);
|
||||
pref.setDpcEnforced(enforced);
|
||||
|
||||
boolean selectable = ((type == null) || !type.equals("mms"));
|
||||
pref.setSelectable(selectable);
|
||||
@@ -358,14 +343,15 @@ public class ApnSettings extends RestrictedSettingsFragment implements
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
if (!mUnavailable && !isDpcApnEnforced()) {
|
||||
if (!mUnavailable) {
|
||||
if (mAllowAddingApns) {
|
||||
menu.add(0, MENU_NEW, 0,
|
||||
getResources().getString(R.string.menu_new))
|
||||
.setIcon(R.drawable.ic_menu_add_white)
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
}
|
||||
menu.add(0, MENU_RESTORE, 0, getResources().getString(R.string.menu_restore))
|
||||
menu.add(0, MENU_RESTORE, 0,
|
||||
getResources().getString(R.string.menu_restore))
|
||||
.setIcon(android.R.drawable.ic_menu_upload);
|
||||
}
|
||||
|
||||
@@ -401,7 +387,7 @@ public class ApnSettings extends RestrictedSettingsFragment implements
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(Preference preference) {
|
||||
int pos = Integer.parseInt(preference.getKey());
|
||||
Uri url = ContentUris.withAppendedId(isDpcApnEnforced() ? FILTERED_URI : CONTENT_URI, pos);
|
||||
Uri url = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI, pos);
|
||||
startActivity(new Intent(Intent.ACTION_EDIT, url));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -16,10 +16,7 @@
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import static com.android.settings.core.FeatureFlags.CONNECTED_DEVICE_V2;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
import com.android.settings.enterprise.EnterprisePrivacySettings;
|
||||
|
||||
@@ -157,11 +154,7 @@ public class Settings extends SettingsActivity {
|
||||
|
||||
// Top level categories for new IA
|
||||
public static class NetworkDashboardActivity extends SettingsActivity {}
|
||||
public static class ConnectedDeviceDashboardActivity extends SettingsActivity {
|
||||
public static final boolean isEnabled() {
|
||||
return FeatureFlagUtils.isEnabled(null /* context */, CONNECTED_DEVICE_V2);
|
||||
}
|
||||
}
|
||||
public static class ConnectedDeviceDashboardActivity extends SettingsActivity {}
|
||||
public static class ConnectedDeviceDashboardActivityOld extends SettingsActivity {}
|
||||
public static class PowerUsageSummaryActivity 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 AccountDashboardActivity extends SettingsActivity {}
|
||||
public static class SystemDashboardActivity extends SettingsActivity {}
|
||||
public static class AdvancedConnectedDeviceActivity extends SettingsActivity {
|
||||
public static final boolean isEnabled() {
|
||||
return FeatureFlagUtils.isEnabled(null /* context */, CONNECTED_DEVICE_V2);
|
||||
}
|
||||
}
|
||||
public static class AdvancedConnectedDeviceActivity extends SettingsActivity {}
|
||||
|
||||
}
|
||||
|
||||
@@ -631,19 +631,10 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
Utils.isBandwidthControlEnabled() /* enabled */,
|
||||
isAdmin) || somethingChanged;
|
||||
|
||||
final boolean isConnectedDeviceV2Enabled =
|
||||
Settings.ConnectedDeviceDashboardActivity.isEnabled();
|
||||
// Enable new connected page if v2 enabled
|
||||
somethingChanged = setTileEnabled(
|
||||
new ComponentName(packageName,
|
||||
Settings.ConnectedDeviceDashboardActivity.class.getName()),
|
||||
isConnectedDeviceV2Enabled && !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 */,
|
||||
!UserManager.isDeviceInDemoMode(this) /* enabled */,
|
||||
isAdmin) || somethingChanged;
|
||||
|
||||
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.BluetoothMasterSwitchPreferenceController;
|
||||
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.nfc.NfcPreferenceController;
|
||||
import com.android.settings.print.PrintSettingPreferenceController;
|
||||
@@ -75,8 +73,6 @@ public class AdvancedConnectedDeviceDashboardFragment extends DashboardFragment
|
||||
final NfcPreferenceController nfcPreferenceController =
|
||||
new NfcPreferenceController(context);
|
||||
controllers.add(nfcPreferenceController);
|
||||
controllers.add(new UsbModePreferenceController(
|
||||
context, new UsbBackend(context), lifecycle));
|
||||
final BluetoothSwitchPreferenceController bluetoothPreferenceController =
|
||||
new BluetoothSwitchPreferenceController(context);
|
||||
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 =
|
||||
(connected, newMode) -> {
|
||||
if (connected) {
|
||||
mUsbPreference.setSummary(
|
||||
UsbModePreferenceController.getSummary(mUsbBackend.getCurrentMode()));
|
||||
mUsbPreference.setSummary(getSummary(mUsbBackend.getCurrentMode()));
|
||||
mDevicePreferenceCallback.onDeviceAdded(mUsbPreference);
|
||||
} else {
|
||||
mDevicePreferenceCallback.onDeviceRemoved(mUsbPreference);
|
||||
@@ -94,4 +93,31 @@ public class ConnectedUsbDeviceUpdater {
|
||||
//TODO(b/70336520): Use an API to get data instead of sticky intent
|
||||
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.setIcon(mContext.getDrawable(R.drawable.ic_usb));
|
||||
mHeaderController.setSummary(
|
||||
mContext.getString(UsbModePreferenceController.getSummary(newMode)));
|
||||
mContext.getString(ConnectedUsbDeviceUpdater.getSummary(newMode)));
|
||||
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.
|
||||
*/
|
||||
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_DISPLAY_APP_LIST = "settings_battery_display_app_list";
|
||||
public static final String ZONE_PICKER_V2 = "settings_zone_picker_v2";
|
||||
|
||||
@@ -67,14 +67,20 @@ public class PreferenceControllerListHelper {
|
||||
try {
|
||||
controller = BasePreferenceController.createInstance(context, controllerName);
|
||||
} catch (IllegalStateException e) {
|
||||
Log.d(TAG, "Could not find Context-only controller for pref: " + controllerName);
|
||||
final String key = metadata.getString(METADATA_KEY);
|
||||
if (TextUtils.isEmpty(key)) {
|
||||
Log.w(TAG, "Controller requires key but it's not defined in xml: "
|
||||
+ controllerName);
|
||||
continue;
|
||||
}
|
||||
Log.d(TAG, "Could not find Context-only controller for pref: " + key);
|
||||
controller = BasePreferenceController.createInstance(context, controllerName, key);
|
||||
try {
|
||||
controller = BasePreferenceController.createInstance(context, controllerName,
|
||||
key);
|
||||
} catch (IllegalStateException e2) {
|
||||
Log.w(TAG, "Cannot instantiate controller from reflection: " + controllerName);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
controllers.add(controller);
|
||||
}
|
||||
|
||||
@@ -55,9 +55,7 @@ import com.android.settings.applications.assist.ManageAssist;
|
||||
import com.android.settings.applications.manageapplications.ManageApplications;
|
||||
import com.android.settings.bluetooth.BluetoothDeviceDetailsFragment;
|
||||
import com.android.settings.bluetooth.BluetoothSettings;
|
||||
import com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment;
|
||||
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
|
||||
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragmentOld;
|
||||
import com.android.settings.connecteddevice.usb.UsbDetailsFragment;
|
||||
import com.android.settings.datausage.DataUsageList;
|
||||
import com.android.settings.datausage.DataUsageSummary;
|
||||
@@ -242,7 +240,6 @@ public class SettingsGateway {
|
||||
SystemDashboardFragment.class.getName(),
|
||||
NetworkDashboardFragment.class.getName(),
|
||||
ConnectedDeviceDashboardFragment.class.getName(),
|
||||
ConnectedDeviceDashboardFragmentOld.class.getName(),
|
||||
UsbDetailsFragment.class.getName(),
|
||||
AppAndNotificationDashboardFragment.class.getName(),
|
||||
AccountDashboardFragment.class.getName(),
|
||||
@@ -252,7 +249,6 @@ public class SettingsGateway {
|
||||
BluetoothDeviceDetailsFragment.class.getName(),
|
||||
DataUsageList.class.getName(),
|
||||
DirectoryAccessDetails.class.getName(),
|
||||
AdvancedConnectedDeviceDashboardFragment.class.getName()
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package com.android.settings.fuelgauge;
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
@@ -119,7 +120,8 @@ public class BatterySaverController extends TogglePreferenceController
|
||||
mBatterySaverPref.setSummary(getSummary());
|
||||
}
|
||||
|
||||
private final ContentObserver mObserver = new ContentObserver(new Handler()) {
|
||||
private final ContentObserver mObserver = new ContentObserver(
|
||||
new Handler(Looper.getMainLooper())) {
|
||||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
updateSummary();
|
||||
|
||||
@@ -25,7 +25,6 @@ import android.os.BatteryStats;
|
||||
import android.os.Bundle;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceGroup;
|
||||
import android.text.format.Formatter;
|
||||
import android.util.SparseArray;
|
||||
@@ -33,17 +32,14 @@ import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.View.OnLongClickListener;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Settings.HighPowerApplicationsActivity;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.applications.LayoutPreference;
|
||||
import com.android.settings.applications.manageapplications.ManageApplications;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.display.BatteryPercentagePreferenceController;
|
||||
import com.android.settings.fuelgauge.anomaly.Anomaly;
|
||||
@@ -56,7 +52,6 @@ import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import com.android.settingslib.utils.PowerUtil;
|
||||
import com.android.settingslib.utils.StringUtil;
|
||||
|
||||
@@ -242,11 +237,7 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
|
||||
KEY_BATTERY_TIP, (SettingsActivity) getActivity(), this /* fragment */, this /*
|
||||
BatteryTipListener */);
|
||||
controllers.add(mBatteryTipPreferenceController);
|
||||
BatterySaverController batterySaverController = new BatterySaverController(context);
|
||||
controllers.add(batterySaverController);
|
||||
controllers.add(new BatteryPercentagePreferenceController(context));
|
||||
|
||||
lifecycle.addObserver(batterySaverController);
|
||||
return controllers;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import android.app.job.JobScheduler;
|
||||
import android.app.job.JobService;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -32,7 +31,7 @@ import com.android.settingslib.utils.ThreadUtils;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/** A JobService to clean up obsolete data in anomaly database */
|
||||
public class AnomalyCleanUpJobService extends JobService {
|
||||
public class AnomalyCleanupJobService extends JobService {
|
||||
private static final String TAG = "AnomalyCleanUpJobService";
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -41,12 +40,13 @@ public class AnomalyCleanUpJobService extends JobService {
|
||||
public static void scheduleCleanUp(Context context) {
|
||||
final JobScheduler jobScheduler = context.getSystemService(JobScheduler.class);
|
||||
|
||||
final ComponentName component = new ComponentName(context, AnomalyCleanUpJobService.class);
|
||||
final ComponentName component = new ComponentName(context, AnomalyCleanupJobService.class);
|
||||
final JobInfo.Builder jobBuilder =
|
||||
new JobInfo.Builder(R.id.job_anomaly_clean_up, component)
|
||||
.setMinimumLatency(CLEAN_UP_FREQUENCY_MS)
|
||||
.setRequiresDeviceIdle(true)
|
||||
.setPersisted(true);
|
||||
.setPeriodic(CLEAN_UP_FREQUENCY_MS)
|
||||
.setRequiresDeviceIdle(true)
|
||||
.setRequiresCharging(true)
|
||||
.setPersisted(true);
|
||||
|
||||
if (jobScheduler.schedule(jobBuilder.build()) != JobScheduler.RESULT_SUCCESS) {
|
||||
Log.i(TAG, "Anomaly clean up job service schedule failed.");
|
||||
@@ -61,7 +61,7 @@ public class AnomalyCleanUpJobService extends JobService {
|
||||
ThreadUtils.postOnBackgroundThread(() -> {
|
||||
batteryDatabaseManager.deleteAllAnomaliesBeforeTimeStamp(
|
||||
System.currentTimeMillis() - TimeUnit.HOURS.toMillis(
|
||||
policy.dataHistoryRetainHour));
|
||||
policy.dataHistoryRetainDay));
|
||||
jobFinished(params, false /* wantsReschedule */);
|
||||
});
|
||||
|
||||
@@ -70,6 +70,6 @@ public class AnomalyCleanUpJobService extends JobService {
|
||||
|
||||
@Override
|
||||
public boolean onStopJob(JobParameters jobParameters) {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,10 @@ public class AnomalyConfigReceiver extends BroadcastReceiver {
|
||||
extraIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
uploadPendingIntent(statsManager, pendingIntent);
|
||||
|
||||
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
|
||||
AnomalyCleanupJobService.scheduleCleanUp(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,5 @@ public class AnomalyDetectionReceiver extends BroadcastReceiver {
|
||||
bundle.putLong(KEY_ANOMALY_TIMESTAMP, System.currentTimeMillis());
|
||||
|
||||
AnomalyDetectionJobService.scheduleAnomalyDetection(context, intent);
|
||||
AnomalyCleanUpJobService.scheduleCleanUp(context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.Utils;
|
||||
@@ -131,8 +132,7 @@ public class BatteryTipDialogFragment extends InstrumentedDialogFragment impleme
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
//TODO(b/70570352): add correct metric id
|
||||
return 0;
|
||||
return MetricsProto.MetricsEvent.FUELGAUGE_BATTERY_TIP_DIALOG;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.util.KeyValueListParser;
|
||||
import android.util.Log;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Class to store the policy for battery tips, which comes from
|
||||
@@ -43,7 +44,7 @@ public class BatteryTipPolicy {
|
||||
private static final String KEY_REDUCED_BATTERY_PERCENT = "reduced_battery_percent";
|
||||
private static final String KEY_LOW_BATTERY_ENABLED = "low_battery_enabled";
|
||||
private static final String KEY_LOW_BATTERY_HOUR = "low_battery_hour";
|
||||
private static final String KEY_DATA_HISTORY_RETAIN_HOUR = "data_history_retain_hour";
|
||||
private static final String KEY_DATA_HISTORY_RETAIN_DAY = "data_history_retain_day";
|
||||
private static final String KEY_EXCESSIVE_BG_DRAIN_PERCENTAGE = "excessive_bg_drain_percentage";
|
||||
|
||||
/**
|
||||
@@ -145,18 +146,19 @@ public class BatteryTipPolicy {
|
||||
public final int lowBatteryHour;
|
||||
|
||||
/**
|
||||
* TTL hour for anomaly data stored in database
|
||||
* TTL day for anomaly data stored in database
|
||||
*
|
||||
* @see Settings.Global#BATTERY_TIP_CONSTANTS
|
||||
* @see #KEY_DATA_HISTORY_RETAIN_HOUR
|
||||
* @see #KEY_DATA_HISTORY_RETAIN_DAY
|
||||
*/
|
||||
public final int dataHistoryRetainHour;
|
||||
public final int dataHistoryRetainDay;
|
||||
|
||||
/**
|
||||
* Battery drain percentage threshold for excessive background anomaly(i.e. 10%)
|
||||
*
|
||||
* This is an additional check for excessive background, to check whether battery drain
|
||||
* for an app is larger than x%
|
||||
*
|
||||
* @see Settings.Global#BATTERY_TIP_CONSTANTS
|
||||
* @see #KEY_EXCESSIVE_BG_DRAIN_PERCENTAGE
|
||||
*/
|
||||
@@ -193,7 +195,7 @@ public class BatteryTipPolicy {
|
||||
reducedBatteryPercent = mParser.getInt(KEY_REDUCED_BATTERY_PERCENT, 50);
|
||||
lowBatteryEnabled = mParser.getBoolean(KEY_LOW_BATTERY_ENABLED, false);
|
||||
lowBatteryHour = mParser.getInt(KEY_LOW_BATTERY_HOUR, 16);
|
||||
dataHistoryRetainHour = mParser.getInt(KEY_DATA_HISTORY_RETAIN_HOUR, 72);
|
||||
dataHistoryRetainDay = mParser.getInt(KEY_DATA_HISTORY_RETAIN_DAY, 30);
|
||||
excessiveBgDrainPercentage = mParser.getInt(KEY_EXCESSIVE_BG_DRAIN_PERCENTAGE, 10);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,12 +23,15 @@ import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceGroup;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
import com.android.settings.fuelgauge.batterytip.actions.BatteryTipAction;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.SummaryTip;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -45,6 +48,7 @@ public class BatteryTipPreferenceController extends BasePreferenceController {
|
||||
private List<BatteryTip> mBatteryTips;
|
||||
private Map<String, BatteryTip> mBatteryTipMap;
|
||||
private SettingsActivity mSettingsActivity;
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
@VisibleForTesting
|
||||
PreferenceGroup mPreferenceGroup;
|
||||
@VisibleForTesting
|
||||
@@ -63,6 +67,7 @@ public class BatteryTipPreferenceController extends BasePreferenceController {
|
||||
mBatteryTipMap = new HashMap<>();
|
||||
mFragment = fragment;
|
||||
mSettingsActivity = settingsActivity;
|
||||
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,6 +104,9 @@ public class BatteryTipPreferenceController extends BasePreferenceController {
|
||||
final Preference preference = batteryTip.buildPreference(mPrefContext);
|
||||
mBatteryTipMap.put(preference.getKey(), batteryTip);
|
||||
mPreferenceGroup.addPreference(preference);
|
||||
mMetricsFeatureProvider.action(mContext,
|
||||
MetricsProto.MetricsEvent.ACTION_BATTERY_TIP_SHOWN,
|
||||
batteryTip.getType());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,8 +78,10 @@ public class BaseSearchIndexProvider implements Indexable.SearchIndexProvider {
|
||||
((BasePreferenceController) controller).updateNonIndexableKeys(
|
||||
nonIndexableKeys);
|
||||
} else {
|
||||
throw new IllegalStateException(controller.getClass().getName()
|
||||
+ " must implement " + PreferenceControllerMixin.class.getName());
|
||||
Log.e(TAG, controller.getClass().getName()
|
||||
+ " must implement " + PreferenceControllerMixin.class.getName()
|
||||
+ " treating the key non-indexable");
|
||||
nonIndexableKeys.add(controller.getPreferenceKey());
|
||||
}
|
||||
}
|
||||
return nonIndexableKeys;
|
||||
|
||||
@@ -21,7 +21,7 @@ import android.support.annotation.VisibleForTesting;
|
||||
import com.android.settings.DateTimeSettings;
|
||||
import com.android.settings.DisplaySettings;
|
||||
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.deviceinfo.aboutphone.MyDeviceInfoFragment;
|
||||
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.BackupSettingsFragment;
|
||||
import com.android.settings.bluetooth.BluetoothSettings;
|
||||
import com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment;
|
||||
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
|
||||
import com.android.settings.connecteddevice.usb.UsbDetailsFragment;
|
||||
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.StorageDashboardFragment;
|
||||
import com.android.settings.deviceinfo.StorageSettings;
|
||||
import com.android.settings.deviceinfo.aboutphone.MyDeviceInfoFragment;
|
||||
import com.android.settings.display.AmbientDisplaySettings;
|
||||
import com.android.settings.display.NightDisplaySettings;
|
||||
import com.android.settings.display.ScreenZoomSettings;
|
||||
@@ -157,7 +155,6 @@ public class SearchIndexableResourcesImpl implements SearchIndexableResources {
|
||||
addIndex(ResetDashboardFragment.class);
|
||||
addIndex(StorageDashboardFragment.class);
|
||||
addIndex(ConnectedDeviceDashboardFragment.class);
|
||||
addIndex(ConnectedDeviceDashboardFragmentOld.class);
|
||||
addIndex(AdvancedConnectedDeviceDashboardFragment.class);
|
||||
addIndex(EnterprisePrivacySettings.class);
|
||||
addIndex(PaymentSettings.class);
|
||||
|
||||
31
tests/robotests/res/xml-mcc998/location_settings.xml
Normal file
31
tests/robotests/res/xml-mcc998/location_settings.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2018 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"
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||
android:key="fake_title_key"
|
||||
android:title="screen_title"
|
||||
settings:controller="com.android.settings.slices.FakePreferenceController">
|
||||
|
||||
<Preference
|
||||
android:key="key"
|
||||
android:title="title"
|
||||
android:icon="@drawable/ic_android"
|
||||
android:summary="summary"
|
||||
settings:controller="com.android.settings.core.BadPreferenceController"/>
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.core;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public class BadPreferenceController extends BasePreferenceController {
|
||||
|
||||
public BadPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
throw new IllegalArgumentException("error");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
}
|
||||
@@ -59,6 +59,17 @@ public class PreferenceControllerListHelperTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(qualifiers = "mcc998")
|
||||
public void getControllers_partialFailure_shouldReturnTheRest() {
|
||||
final List<BasePreferenceController> controllers =
|
||||
PreferenceControllerListHelper.getPreferenceControllersFromXml(mContext,
|
||||
R.xml.location_settings);
|
||||
|
||||
assertThat(controllers).hasSize(1);
|
||||
assertThat(controllers.get(0)).isInstanceOf(FakePreferenceController.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterControllers_noFilter_shouldReturnSameList() {
|
||||
final List<BasePreferenceController> controllers = new ArrayList<>();
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class AnomalyCleanUpJobServiceTest {
|
||||
public class AnomalyCleanupJobServiceTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
@@ -49,7 +49,7 @@ public class AnomalyCleanUpJobServiceTest {
|
||||
|
||||
@Test
|
||||
public void testScheduleCleanUp() {
|
||||
AnomalyCleanUpJobService.scheduleCleanUp(application);
|
||||
AnomalyCleanupJobService.scheduleCleanUp(application);
|
||||
|
||||
ShadowJobScheduler shadowJobScheduler = Shadows.shadowOf(
|
||||
application.getSystemService(JobScheduler.class));
|
||||
@@ -57,7 +57,8 @@ public class AnomalyCleanUpJobServiceTest {
|
||||
assertEquals(1, pendingJobs.size());
|
||||
JobInfo pendingJob = pendingJobs.get(0);
|
||||
assertThat(pendingJob.getId()).isEqualTo(R.id.job_anomaly_clean_up);
|
||||
assertThat(pendingJob.getMinLatencyMillis()).isEqualTo(TimeUnit.DAYS.toMillis(1));
|
||||
assertThat(pendingJob.getIntervalMillis()).isEqualTo(TimeUnit.DAYS.toMillis(1));
|
||||
assertThat(pendingJob.isRequireDeviceIdle()).isTrue();
|
||||
assertThat(pendingJob.isRequireCharging()).isTrue();
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ public class BatteryTipPolicyTest {
|
||||
+ ",reduced_battery_percent=30"
|
||||
+ ",low_battery_enabled=false"
|
||||
+ ",low_battery_hour=10"
|
||||
+ ",data_history_retain_hour=24"
|
||||
+ ",data_history_retain_day=24"
|
||||
+ ",excessive_bg_drain_percentage=25";
|
||||
private Context mContext;
|
||||
|
||||
@@ -78,7 +78,7 @@ public class BatteryTipPolicyTest {
|
||||
assertThat(batteryTipPolicy.reducedBatteryPercent).isEqualTo(30);
|
||||
assertThat(batteryTipPolicy.lowBatteryEnabled).isFalse();
|
||||
assertThat(batteryTipPolicy.lowBatteryHour).isEqualTo(10);
|
||||
assertThat(batteryTipPolicy.dataHistoryRetainHour).isEqualTo(24);
|
||||
assertThat(batteryTipPolicy.dataHistoryRetainDay).isEqualTo(24);
|
||||
assertThat(batteryTipPolicy.excessiveBgDrainPercentage).isEqualTo(25);
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ public class BatteryTipPolicyTest {
|
||||
assertThat(batteryTipPolicy.reducedBatteryPercent).isEqualTo(50);
|
||||
assertThat(batteryTipPolicy.lowBatteryEnabled).isFalse();
|
||||
assertThat(batteryTipPolicy.lowBatteryHour).isEqualTo(16);
|
||||
assertThat(batteryTipPolicy.dataHistoryRetainHour).isEqualTo(72);
|
||||
assertThat(batteryTipPolicy.dataHistoryRetainDay).isEqualTo(30);
|
||||
assertThat(batteryTipPolicy.excessiveBgDrainPercentage).isEqualTo(10);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import static com.android.settings.fuelgauge.batterytip.tips.BatteryTip.TipType
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -32,10 +33,12 @@ import android.support.v7.preference.PreferenceGroup;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.SummaryTip;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -72,6 +75,7 @@ public class BatteryTipPreferenceControllerTest {
|
||||
private List<BatteryTip> mOldBatteryTips;
|
||||
private List<BatteryTip> mNewBatteryTips;
|
||||
private Preference mPreference;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -84,6 +88,7 @@ public class BatteryTipPreferenceControllerTest {
|
||||
doReturn(mPreferenceGroup).when(mPreferenceScreen).findPreference(KEY_PREF);
|
||||
mPreference = new Preference(mContext);
|
||||
mPreference.setKey(KEY_TIP);
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
|
||||
mOldBatteryTips = new ArrayList<>();
|
||||
mOldBatteryTips.add(new SummaryTip(BatteryTip.StateType.NEW));
|
||||
@@ -104,7 +109,7 @@ public class BatteryTipPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBatteryTips_updateTwice_firstShowSummaryTipThenRemoveIt() {
|
||||
public void testUpdateBatteryTips_updateTwice_firstShowSummaryTipThenRemoveIt() {
|
||||
// Display summary tip because its state is new
|
||||
mBatteryTipPreferenceController.updateBatteryTips(mOldBatteryTips);
|
||||
assertOnlyContainsSummaryTip(mPreferenceGroup);
|
||||
@@ -114,6 +119,15 @@ public class BatteryTipPreferenceControllerTest {
|
||||
assertThat(mPreferenceGroup.getPreferenceCount()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateBatteryTips_logBatteryTip() {
|
||||
mBatteryTipPreferenceController.updateBatteryTips(mOldBatteryTips);
|
||||
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(any(Context.class),
|
||||
eq(MetricsProto.MetricsEvent.ACTION_BATTERY_TIP_SHOWN),
|
||||
eq(BatteryTip.TipType.SUMMARY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlePreferenceTreeClick_noDialog_invokeCallback() {
|
||||
doReturn(SMART_BATTERY_MANAGER).when(mBatteryTip).getType();
|
||||
|
||||
Reference in New Issue
Block a user