Snap for 10752753 from a5027a20ff to udc-qpr1-release

Change-Id: I9ebd4b02989e82890d8bde4dd47472b5cfc6b25b
This commit is contained in:
Android Build Coastguard Worker
2023-09-02 01:19:34 +00:00
15 changed files with 315 additions and 128 deletions

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2023 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.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?android:attr/colorAccent"/>
</selector>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2023 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.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/palette_list_color_yellow"/>
</selector>

View File

@@ -20,6 +20,6 @@
android:viewportWidth="24" android:viewportWidth="24"
android:viewportHeight="24"> android:viewportHeight="24">
<path <path
android:fillColor="?android:attr/colorAccent" android:fillColor="@color/color_accent_selector"
android:pathData="M7,20h4c0,1.1 -0.9,2 -2,2S7,21.1 7,20zM5,19h8v-2H5V19zM16.5,9.5c0,3.82 -2.66,5.86 -3.77,6.5H5.27C4.16,15.36 1.5,13.32 1.5,9.5C1.5,5.36 4.86,2 9,2S16.5,5.36 16.5,9.5zM14.5,9.5C14.5,6.47 12.03,4 9,4S3.5,6.47 3.5,9.5c0,2.47 1.49,3.89 2.35,4.5h6.3C13.01,13.39 14.5,11.97 14.5,9.5zM21.37,7.37L20,8l1.37,0.63L22,10l0.63,-1.37L24,8l-1.37,-0.63L22,6L21.37,7.37zM19,6l0.94,-2.06L22,3l-2.06,-0.94L19,0l-0.94,2.06L16,3l2.06,0.94L19,6z"/> android:pathData="M7,20h4c0,1.1 -0.9,2 -2,2S7,21.1 7,20zM5,19h8v-2H5V19zM16.5,9.5c0,3.82 -2.66,5.86 -3.77,6.5H5.27C4.16,15.36 1.5,13.32 1.5,9.5C1.5,5.36 4.86,2 9,2S16.5,5.36 16.5,9.5zM14.5,9.5C14.5,6.47 12.03,4 9,4S3.5,6.47 3.5,9.5c0,2.47 1.49,3.89 2.35,4.5h6.3C13.01,13.39 14.5,11.97 14.5,9.5zM21.37,7.37L20,8l1.37,0.63L22,10l0.63,-1.37L24,8l-1.37,-0.63L22,6L21.37,7.37zM19,6l0.94,-2.06L22,3l-2.06,-0.94L19,0l-0.94,2.06L16,3l2.06,0.94L19,6z"/>
</vector> </vector>

View File

@@ -0,0 +1,25 @@
<!--
Copyright (C) 2023 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/color_battery_anomaly_yellow_selector"
android:pathData="M1,21h22L12,2 1,21zM13,18h-2v-2h2v2zM13,14h-2v-4h2v4z"/>
</vector>

View File

@@ -61,7 +61,7 @@
android:text="@string/battery_tips_card_action_button" android:text="@string/battery_tips_card_action_button"
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorPrimary" android:textColor="?android:attr/textColorPrimary"
app:strokeColor="?android:attr/colorAccent" app:strokeColor="@color/color_accent_selector"
app:strokeWidth="1dp" /> app:strokeWidth="1dp" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View File

@@ -1409,6 +1409,17 @@
<integer-array name="network_mode_3g_deprecated_carrier_id" translatable="false"> <integer-array name="network_mode_3g_deprecated_carrier_id" translatable="false">
</integer-array> </integer-array>
<!-- The following 2 arrays are for battery tips card. Please keep them the same size. -->
<string-array name="battery_tips_card_icons" translatable="false">
<item>ic_battery_tips_lightbulb</item>
<item>ic_battery_tips_warning_icon</item>
</string-array>
<string-array name="battery_tips_card_colors" translatable="false">
<item>color_accent_selector</item>
<item>color_battery_anomaly_yellow_selector</item>
</string-array>
<!-- The following 3 arrays are for power anomaly tips card. Please keep them the same size. --> <!-- The following 3 arrays are for power anomaly tips card. Please keep them the same size. -->
<string-array name="power_anomaly_titles"> <string-array name="power_anomaly_titles">
<item>Turn on adaptive brightness to extend battery life</item> <item>Turn on adaptive brightness to extend battery life</item>

View File

@@ -6992,7 +6992,7 @@
<!-- Summary text for system preference title, showing important setting items under system setting [CHAR LIMIT=NONE]--> <!-- Summary text for system preference title, showing important setting items under system setting [CHAR LIMIT=NONE]-->
<string name="system_dashboard_summary">Languages, gestures, time, backup</string> <string name="system_dashboard_summary">Languages, gestures, time, backup</string>
<!-- Summary text for language preference title, showing important setting items under language setting [CHAR LIMIT=NONE]--> <!-- Summary text for language preference title, showing important setting items under language setting [CHAR LIMIT=NONE]-->
<string name="languages_setting_summary">System languages, app languages, speech</string> <string name="languages_setting_summary">System languages, app languages, regional preferences, speech</string>
<!--Search Keywords [CHAR LIMIT=NONE]--> <!--Search Keywords [CHAR LIMIT=NONE]-->
<string name="keywords_wifi">wifi, wi-fi, network connection, internet, wireless, data, wi fi</string> <string name="keywords_wifi">wifi, wi-fi, network connection, internet, wireless, data, wi fi</string>

View File

@@ -109,6 +109,7 @@ public class BluetoothDetailsAudioDeviceTypeController extends BluetoothDetailsC
mAudioManager.setBluetoothAudioDeviceCategory(mCachedDevice.getAddress(), mAudioManager.setBluetoothAudioDeviceCategory(mCachedDevice.getAddress(),
mCachedDevice.getDevice().getType() == DEVICE_TYPE_LE, mCachedDevice.getDevice().getType() == DEVICE_TYPE_LE,
Integer.parseInt(value)); Integer.parseInt(value));
mCachedDevice.onAudioDeviceCategoryChanged();
} }
} }
return true; return true;

View File

@@ -16,6 +16,8 @@
package com.android.settings.bluetooth; package com.android.settings.bluetooth;
import static android.media.Spatializer.SPATIALIZER_IMMERSIVE_LEVEL_NONE;
import android.content.Context; import android.content.Context;
import android.media.AudioDeviceAttributes; import android.media.AudioDeviceAttributes;
import android.media.AudioDeviceInfo; import android.media.AudioDeviceInfo;
@@ -51,9 +53,7 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
@VisibleForTesting @VisibleForTesting
PreferenceCategory mProfilesContainer; PreferenceCategory mProfilesContainer;
@VisibleForTesting @VisibleForTesting
AudioDeviceAttributes mAudioDevice; AudioDeviceAttributes mAudioDevice = null;
private boolean mIsAvailable;
public BluetoothDetailsSpatialAudioController( public BluetoothDetailsSpatialAudioController(
Context context, Context context,
@@ -63,13 +63,11 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
super(context, fragment, device, lifecycle); super(context, fragment, device, lifecycle);
AudioManager audioManager = context.getSystemService(AudioManager.class); AudioManager audioManager = context.getSystemService(AudioManager.class);
mSpatializer = audioManager.getSpatializer(); mSpatializer = audioManager.getSpatializer();
getAvailableDevice();
} }
@Override @Override
public boolean isAvailable() { public boolean isAvailable() {
return mIsAvailable; return mSpatializer.getImmersiveAudioLevel() != SPATIALIZER_IMMERSIVE_LEVEL_NONE;
} }
@Override @Override
@@ -77,15 +75,11 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
SwitchPreference switchPreference = (SwitchPreference) preference; SwitchPreference switchPreference = (SwitchPreference) preference;
String key = switchPreference.getKey(); String key = switchPreference.getKey();
if (TextUtils.equals(key, KEY_SPATIAL_AUDIO)) { if (TextUtils.equals(key, KEY_SPATIAL_AUDIO)) {
if (switchPreference.isChecked()) { updateSpatializerEnabled(switchPreference.isChecked());
mSpatializer.addCompatibleAudioDevice(mAudioDevice); refreshSpatialAudioEnabled(switchPreference);
} else {
mSpatializer.removeCompatibleAudioDevice(mAudioDevice);
}
refresh();
return true; return true;
} else if (TextUtils.equals(key, KEY_HEAD_TRACKING)) { } else if (TextUtils.equals(key, KEY_HEAD_TRACKING)) {
mSpatializer.setHeadTrackerEnabled(switchPreference.isChecked(), mAudioDevice); updateSpatializerHeadTracking(switchPreference.isChecked());
return true; return true;
} else { } else {
Log.w(TAG, "invalid key name."); Log.w(TAG, "invalid key name.");
@@ -93,6 +87,26 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
} }
} }
private void updateSpatializerEnabled(boolean enabled) {
if (mAudioDevice == null) {
Log.w(TAG, "cannot update spatializer enabled for null audio device.");
return;
}
if (enabled) {
mSpatializer.addCompatibleAudioDevice(mAudioDevice);
} else {
mSpatializer.removeCompatibleAudioDevice(mAudioDevice);
}
}
private void updateSpatializerHeadTracking(boolean enabled) {
if (mAudioDevice == null) {
Log.w(TAG, "cannot update spatializer head tracking for null audio device.");
return;
}
mSpatializer.setHeadTrackerEnabled(enabled, mAudioDevice);
}
@Override @Override
public String getPreferenceKey() { public String getPreferenceKey() {
return KEY_SPATIAL_AUDIO_GROUP; return KEY_SPATIAL_AUDIO_GROUP;
@@ -106,12 +120,31 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
@Override @Override
protected void refresh() { protected void refresh() {
SwitchPreference spatialAudioPref = mProfilesContainer.findPreference(KEY_SPATIAL_AUDIO); if (mAudioDevice == null) {
if (spatialAudioPref == null) { getAvailableDevice();
spatialAudioPref = createSpatialAudioPreference(mProfilesContainer.getContext());
mProfilesContainer.addPreference(spatialAudioPref);
} }
SwitchPreference spatialAudioPref = mProfilesContainer.findPreference(KEY_SPATIAL_AUDIO);
if (spatialAudioPref == null && mAudioDevice != null) {
spatialAudioPref = createSpatialAudioPreference(mProfilesContainer.getContext());
mProfilesContainer.addPreference(spatialAudioPref);
} else if (mAudioDevice == null || !mSpatializer.isAvailableForDevice(mAudioDevice)) {
if (spatialAudioPref != null) {
mProfilesContainer.removePreference(spatialAudioPref);
}
final SwitchPreference headTrackingPref =
mProfilesContainer.findPreference(KEY_HEAD_TRACKING);
if (headTrackingPref != null) {
mProfilesContainer.removePreference(headTrackingPref);
}
mAudioDevice = null;
return;
}
refreshSpatialAudioEnabled(spatialAudioPref);
}
private void refreshSpatialAudioEnabled(SwitchPreference spatialAudioPref) {
boolean isSpatialAudioOn = mSpatializer.getCompatibleAudioDevices().contains(mAudioDevice); boolean isSpatialAudioOn = mSpatializer.getCompatibleAudioDevices().contains(mAudioDevice);
Log.d(TAG, "refresh() isSpatialAudioOn : " + isSpatialAudioOn); Log.d(TAG, "refresh() isSpatialAudioOn : " + isSpatialAudioOn);
spatialAudioPref.setChecked(isSpatialAudioOn); spatialAudioPref.setChecked(isSpatialAudioOn);
@@ -121,9 +154,13 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
headTrackingPref = createHeadTrackingPreference(mProfilesContainer.getContext()); headTrackingPref = createHeadTrackingPreference(mProfilesContainer.getContext());
mProfilesContainer.addPreference(headTrackingPref); mProfilesContainer.addPreference(headTrackingPref);
} }
refreshHeadTracking(spatialAudioPref, headTrackingPref);
}
private void refreshHeadTracking(SwitchPreference spatialAudioPref,
SwitchPreference headTrackingPref) {
boolean isHeadTrackingAvailable = boolean isHeadTrackingAvailable =
isSpatialAudioOn && mSpatializer.hasHeadTracker(mAudioDevice); spatialAudioPref.isChecked() && mSpatializer.hasHeadTracker(mAudioDevice);
Log.d(TAG, "refresh() has head tracker : " + mSpatializer.hasHeadTracker(mAudioDevice)); Log.d(TAG, "refresh() has head tracker : " + mSpatializer.hasHeadTracker(mAudioDevice));
headTrackingPref.setVisible(isHeadTrackingAvailable); headTrackingPref.setVisible(isHeadTrackingAvailable);
if (isHeadTrackingAvailable) { if (isHeadTrackingAvailable) {
@@ -173,7 +210,6 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
AudioDeviceInfo.TYPE_HEARING_AID, AudioDeviceInfo.TYPE_HEARING_AID,
mCachedDevice.getAddress()); mCachedDevice.getAddress());
mIsAvailable = true;
if (mSpatializer.isAvailableForDevice(bleHeadsetDevice)) { if (mSpatializer.isAvailableForDevice(bleHeadsetDevice)) {
mAudioDevice = bleHeadsetDevice; mAudioDevice = bleHeadsetDevice;
} else if (mSpatializer.isAvailableForDevice(bleSpeakerDevice)) { } else if (mSpatializer.isAvailableForDevice(bleSpeakerDevice)) {
@@ -182,20 +218,20 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
mAudioDevice = bleBroadcastDevice; mAudioDevice = bleBroadcastDevice;
} else if (mSpatializer.isAvailableForDevice(a2dpDevice)) { } else if (mSpatializer.isAvailableForDevice(a2dpDevice)) {
mAudioDevice = a2dpDevice; mAudioDevice = a2dpDevice;
} else { } else if (mSpatializer.isAvailableForDevice(hearingAidDevice)) {
mIsAvailable = mSpatializer.isAvailableForDevice(hearingAidDevice);
mAudioDevice = hearingAidDevice; mAudioDevice = hearingAidDevice;
} else {
mAudioDevice = null;
} }
Log.d(TAG, "getAvailableDevice() device : " Log.d(TAG, "getAvailableDevice() device : "
+ mCachedDevice.getDevice().getAnonymizedAddress() + mCachedDevice.getDevice().getAnonymizedAddress()
+ ", type : " + mAudioDevice.getType() + ", is available : " + (mAudioDevice != null)
+ ", is available : " + mIsAvailable); + ", type : " + (mAudioDevice == null ? "no type" : mAudioDevice.getType()));
} }
@VisibleForTesting @VisibleForTesting
void setAvailableDevice(AudioDeviceAttributes audioDevice) { void setAvailableDevice(AudioDeviceAttributes audioDevice) {
mAudioDevice = audioDevice; mAudioDevice = audioDevice;
mIsAvailable = mSpatializer.isAvailableForDevice(audioDevice);
} }
} }

View File

@@ -47,4 +47,9 @@ public class SettingsUIDeviceConfig {
*/ */
public static final String BT_LE_AUDIO_DEVICE_DETAIL_ENABLED = public static final String BT_LE_AUDIO_DEVICE_DETAIL_ENABLED =
"bt_le_audio_device_detail_enabled"; "bt_le_audio_device_detail_enabled";
/**
* {@code true} if long press home button to search is enabled.
*/
public static final String LONG_PRESS_HOME_BUTTON_TO_SEARCH =
"long_press_home_button_to_search";
} }

View File

@@ -23,6 +23,7 @@ import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
@@ -51,6 +52,8 @@ public class BatteryTipsCardPreference extends Preference implements View.OnClic
private String mAnomalyEventId; private String mAnomalyEventId;
private PowerAnomalyKey mPowerAnomalyKey; private PowerAnomalyKey mPowerAnomalyKey;
private int mIconResourceId = 0;
private int mMainButtonStrokeColorResourceId = 0;
@VisibleForTesting @VisibleForTesting
CharSequence mMainButtonLabel; CharSequence mMainButtonLabel;
@@ -73,6 +76,26 @@ public class BatteryTipsCardPreference extends Preference implements View.OnClic
mPowerAnomalyKey = null; mPowerAnomalyKey = null;
} }
/**
* Sets the icon in tips card.
*/
public void setIconResourceId(int resourceId) {
if (mIconResourceId != resourceId) {
mIconResourceId = resourceId;
notifyChanged();
}
}
/**
* Sets the stroke color of main button in tips card.
*/
public void setMainButtonStrokeColorResourceId(int resourceId) {
if (mMainButtonStrokeColorResourceId != resourceId) {
mMainButtonStrokeColorResourceId = resourceId;
notifyChanged();
}
}
/** /**
* Sets the anomaly event id which is used in metrics. * Sets the anomaly event id which is used in metrics.
*/ */
@@ -159,9 +182,15 @@ public class BatteryTipsCardPreference extends Preference implements View.OnClic
MaterialButton mainButton = (MaterialButton) view.findViewById(R.id.main_button); MaterialButton mainButton = (MaterialButton) view.findViewById(R.id.main_button);
mainButton.setOnClickListener(this); mainButton.setOnClickListener(this);
mainButton.setText(mMainButtonLabel); mainButton.setText(mMainButtonLabel);
if (mMainButtonStrokeColorResourceId != 0) {
mainButton.setStrokeColorResource(mMainButtonStrokeColorResourceId);
}
MaterialButton dismissButton = (MaterialButton) view.findViewById(R.id.dismiss_button); MaterialButton dismissButton = (MaterialButton) view.findViewById(R.id.dismiss_button);
dismissButton.setOnClickListener(this); dismissButton.setOnClickListener(this);
dismissButton.setText(mDismissButtonLabel); dismissButton.setText(mDismissButtonLabel);
if (mIconResourceId != 0) {
((ImageView) view.findViewById(R.id.icon)).setImageResource(mIconResourceId);
}
if (!mPowerUsageFeatureProvider.isBatteryTipsFeedbackEnabled()) { if (!mPowerUsageFeatureProvider.isBatteryTipsFeedbackEnabled()) {
return; return;

View File

@@ -77,23 +77,29 @@ public class BatteryTipsController extends BasePreferenceController {
return null; return null;
} }
private String getStringFromResource(int resourceId, int resourceIndex) {
if (resourceId < 0) {
return null;
}
final String[] stringArray = mContext.getResources().getStringArray(resourceId);
return (resourceIndex >= 0 && resourceIndex < stringArray.length)
? stringArray[resourceIndex] : null;
}
private int getResourceId(int resourceId, int resourceIndex, String defType) {
final String key = getStringFromResource(resourceId, resourceIndex);
return TextUtils.isEmpty(key) ? 0
: mContext.getResources().getIdentifier(key, defType, mContext.getPackageName());
}
private String getString(PowerAnomalyEvent powerAnomalyEvent, private String getString(PowerAnomalyEvent powerAnomalyEvent,
Function<WarningBannerInfo, String> warningBannerInfoSupplier, Function<WarningBannerInfo, String> warningBannerInfoSupplier,
Function<WarningItemInfo, String> warningItemInfoSupplier, Function<WarningItemInfo, String> warningItemInfoSupplier,
int resourceId, int resourceIndex) { int resourceId, int resourceIndex) {
String string = String string =
getInfo(powerAnomalyEvent, warningBannerInfoSupplier, warningItemInfoSupplier); getInfo(powerAnomalyEvent, warningBannerInfoSupplier, warningItemInfoSupplier);
return (!TextUtils.isEmpty(string) || resourceId < 0) ? string
if (!TextUtils.isEmpty(string) || resourceId < 0) { : getStringFromResource(resourceId, resourceIndex);
return string;
}
String[] stringArray = mContext.getResources().getStringArray(resourceId);
if (resourceIndex >= 0 && resourceIndex < stringArray.length) {
string = stringArray[resourceIndex];
}
return string;
} }
@VisibleForTesting @VisibleForTesting
@@ -107,6 +113,13 @@ public class BatteryTipsController extends BasePreferenceController {
return; return;
} }
// Get card icon and color styles
final int cardStyleId = powerAnomalyEvent.getType().getNumber();
final int iconResId = getResourceId(
R.array.battery_tips_card_icons, cardStyleId, "drawable");
final int colorResId = getResourceId(
R.array.battery_tips_card_colors, cardStyleId, "color");
// Get card preference strings and navigate fragment info // Get card preference strings and navigate fragment info
final PowerAnomalyKey powerAnomalyKey = powerAnomalyEvent.hasKey() final PowerAnomalyKey powerAnomalyKey = powerAnomalyEvent.hasKey()
? powerAnomalyEvent.getKey() : null; ? powerAnomalyEvent.getKey() : null;
@@ -133,10 +146,12 @@ public class BatteryTipsController extends BasePreferenceController {
String preferenceHighlightKey = getInfo(powerAnomalyEvent, String preferenceHighlightKey = getInfo(powerAnomalyEvent,
WarningBannerInfo::getMainButtonSourceHighlightKey, null); WarningBannerInfo::getMainButtonSourceHighlightKey, null);
// Updated card preference and main button fragment launcher // Update card preference and main button fragment launcher
mCardPreference.setAnomalyEventId(powerAnomalyEvent.getEventId()); mCardPreference.setAnomalyEventId(powerAnomalyEvent.getEventId());
mCardPreference.setPowerAnomalyKey(powerAnomalyKey); mCardPreference.setPowerAnomalyKey(powerAnomalyKey);
mCardPreference.setTitle(titleString); mCardPreference.setTitle(titleString);
mCardPreference.setIconResourceId(iconResId);
mCardPreference.setMainButtonStrokeColorResourceId(colorResId);
mCardPreference.setMainButtonLabel(mainBtnString); mCardPreference.setMainButtonLabel(mainBtnString);
mCardPreference.setDismissButtonLabel(dismissBtnString); mCardPreference.setDismissButtonLabel(dismissBtnString);
mCardPreference.setMainButtonLauncherInfo( mCardPreference.setMainButtonLauncherInfo(

View File

@@ -16,6 +16,9 @@
package com.android.settings.bluetooth; package com.android.settings.bluetooth;
import static android.media.Spatializer.SPATIALIZER_IMMERSIVE_LEVEL_MULTICHANNEL;
import static android.media.Spatializer.SPATIALIZER_IMMERSIVE_LEVEL_NONE;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
@@ -62,6 +65,8 @@ public class BluetoothDetailsSpatialAudioControllerTest extends BluetoothDetails
@Mock @Mock
private BluetoothDevice mBluetoothDevice; private BluetoothDevice mBluetoothDevice;
private AudioDeviceAttributes mAvailableDevice;
private BluetoothDetailsSpatialAudioController mController; private BluetoothDetailsSpatialAudioController mController;
private SwitchPreference mSpatialAudioPref; private SwitchPreference mSpatialAudioPref;
private SwitchPreference mHeadTrackingPref; private SwitchPreference mHeadTrackingPref;
@@ -86,94 +91,32 @@ public class BluetoothDetailsSpatialAudioControllerTest extends BluetoothDetails
when(mProfilesContainer.findPreference(KEY_SPATIAL_AUDIO)).thenReturn(mSpatialAudioPref); when(mProfilesContainer.findPreference(KEY_SPATIAL_AUDIO)).thenReturn(mSpatialAudioPref);
when(mProfilesContainer.findPreference(KEY_HEAD_TRACKING)).thenReturn(mHeadTrackingPref); when(mProfilesContainer.findPreference(KEY_HEAD_TRACKING)).thenReturn(mHeadTrackingPref);
}
@Test mAvailableDevice = new AudioDeviceAttributes(
public void isAvailable_spatialAudioSupportA2dpDevice_returnsTrue() {
AudioDeviceAttributes a2dpDevice = new AudioDeviceAttributes(
AudioDeviceAttributes.ROLE_OUTPUT, AudioDeviceAttributes.ROLE_OUTPUT,
AudioDeviceInfo.TYPE_BLUETOOTH_A2DP, AudioDeviceInfo.TYPE_BLUETOOTH_A2DP,
MAC_ADDRESS); MAC_ADDRESS);
when(mSpatializer.isAvailableForDevice(a2dpDevice)).thenReturn(true);
mController.setAvailableDevice(a2dpDevice);
assertThat(mController.isAvailable()).isTrue();
assertThat(mController.mAudioDevice.getType())
.isEqualTo(AudioDeviceInfo.TYPE_BLUETOOTH_A2DP);
} }
@Test @Test
public void isAvailable_spatialAudioSupportBleHeadsetDevice_returnsTrue() { public void isAvailable_forSpatializerWithLevelNone_returnsFalse() {
AudioDeviceAttributes bleHeadsetDevice = new AudioDeviceAttributes( when(mSpatializer.getImmersiveAudioLevel()).thenReturn(SPATIALIZER_IMMERSIVE_LEVEL_NONE);
AudioDeviceAttributes.ROLE_OUTPUT,
AudioDeviceInfo.TYPE_BLE_HEADSET,
MAC_ADDRESS);
when(mSpatializer.isAvailableForDevice(bleHeadsetDevice)).thenReturn(true);
mController.setAvailableDevice(bleHeadsetDevice);
assertThat(mController.isAvailable()).isTrue();
assertThat(mController.mAudioDevice.getType())
.isEqualTo(AudioDeviceInfo.TYPE_BLE_HEADSET);
}
@Test
public void isAvailable_spatialAudioSupportBleSpeakerDevice_returnsTrue() {
AudioDeviceAttributes bleSpeakerDevice = new AudioDeviceAttributes(
AudioDeviceAttributes.ROLE_OUTPUT,
AudioDeviceInfo.TYPE_BLE_SPEAKER,
MAC_ADDRESS);
when(mSpatializer.isAvailableForDevice(bleSpeakerDevice)).thenReturn(true);
mController.setAvailableDevice(bleSpeakerDevice);
assertThat(mController.isAvailable()).isTrue();
assertThat(mController.mAudioDevice.getType())
.isEqualTo(AudioDeviceInfo.TYPE_BLE_SPEAKER);
}
@Test
public void isAvailable_spatialAudioSupportBleBroadcastDevice_returnsTrue() {
AudioDeviceAttributes bleBroadcastDevice = new AudioDeviceAttributes(
AudioDeviceAttributes.ROLE_OUTPUT,
AudioDeviceInfo.TYPE_BLE_BROADCAST,
MAC_ADDRESS);
when(mSpatializer.isAvailableForDevice(bleBroadcastDevice)).thenReturn(true);
mController.setAvailableDevice(bleBroadcastDevice);
assertThat(mController.isAvailable()).isTrue();
assertThat(mController.mAudioDevice.getType())
.isEqualTo(AudioDeviceInfo.TYPE_BLE_BROADCAST);
}
@Test
public void isAvailable_spatialAudioSupportHearingAidDevice_returnsTrue() {
AudioDeviceAttributes hearingAidDevice = new AudioDeviceAttributes(
AudioDeviceAttributes.ROLE_OUTPUT,
AudioDeviceInfo.TYPE_HEARING_AID,
MAC_ADDRESS);
when(mSpatializer.isAvailableForDevice(hearingAidDevice)).thenReturn(true);
mController.setAvailableDevice(hearingAidDevice);
assertThat(mController.isAvailable()).isTrue();
assertThat(mController.mAudioDevice.getType())
.isEqualTo(AudioDeviceInfo.TYPE_HEARING_AID);
}
@Test
public void isAvailable_spatialAudioNotSupported_returnsFalse() {
assertThat(mController.isAvailable()).isFalse(); assertThat(mController.isAvailable()).isFalse();
assertThat(mController.mAudioDevice.getType()) }
.isEqualTo(AudioDeviceInfo.TYPE_HEARING_AID);
@Test
public void isAvailable_forSpatializerWithLevelNotNone_returnsTrue() {
when(mSpatializer.getImmersiveAudioLevel()).thenReturn(
SPATIALIZER_IMMERSIVE_LEVEL_MULTICHANNEL);
assertThat(mController.isAvailable()).isTrue();
} }
@Test @Test
public void refresh_spatialAudioIsTurnedOn_checksSpatialAudioPreference() { public void refresh_spatialAudioIsTurnedOn_checksSpatialAudioPreference() {
List<AudioDeviceAttributes> compatibleAudioDevices = new ArrayList<>(); List<AudioDeviceAttributes> compatibleAudioDevices = new ArrayList<>();
mController.setAvailableDevice(mAvailableDevice);
compatibleAudioDevices.add(mController.mAudioDevice); compatibleAudioDevices.add(mController.mAudioDevice);
when(mSpatializer.isAvailableForDevice(mController.mAudioDevice)).thenReturn(true);
when(mSpatializer.getCompatibleAudioDevices()).thenReturn(compatibleAudioDevices); when(mSpatializer.getCompatibleAudioDevices()).thenReturn(compatibleAudioDevices);
mController.refresh(); mController.refresh();
@@ -207,13 +150,14 @@ public class BluetoothDetailsSpatialAudioControllerTest extends BluetoothDetails
public void public void
refresh_spatialAudioOnAndHeadTrackingIsNotAvailable_hidesHeadTrackingPreference() { refresh_spatialAudioOnAndHeadTrackingIsNotAvailable_hidesHeadTrackingPreference() {
List<AudioDeviceAttributes> compatibleAudioDevices = new ArrayList<>(); List<AudioDeviceAttributes> compatibleAudioDevices = new ArrayList<>();
mController.setAvailableDevice(mAvailableDevice);
compatibleAudioDevices.add(mController.mAudioDevice); compatibleAudioDevices.add(mController.mAudioDevice);
when(mSpatializer.getCompatibleAudioDevices()).thenReturn(compatibleAudioDevices); when(mSpatializer.getCompatibleAudioDevices()).thenReturn(compatibleAudioDevices);
when(mSpatializer.hasHeadTracker(mController.mAudioDevice)).thenReturn(false); when(mSpatializer.hasHeadTracker(mController.mAudioDevice)).thenReturn(false);
mController.refresh(); mController.refresh();
assertThat(mHeadTrackingPref.isVisible()).isFalse(); verify(mProfilesContainer).removePreference(mHeadTrackingPref);
} }
@Test @Test
@@ -223,14 +167,16 @@ public class BluetoothDetailsSpatialAudioControllerTest extends BluetoothDetails
mController.refresh(); mController.refresh();
assertThat(mHeadTrackingPref.isVisible()).isFalse(); verify(mProfilesContainer).removePreference(mHeadTrackingPref);
} }
@Test @Test
public void refresh_headTrackingIsTurnedOn_checksHeadTrackingPreference() { public void refresh_headTrackingIsTurnedOn_checksHeadTrackingPreference() {
List<AudioDeviceAttributes> compatibleAudioDevices = new ArrayList<>(); List<AudioDeviceAttributes> compatibleAudioDevices = new ArrayList<>();
mController.setAvailableDevice(mAvailableDevice);
compatibleAudioDevices.add(mController.mAudioDevice); compatibleAudioDevices.add(mController.mAudioDevice);
when(mSpatializer.getCompatibleAudioDevices()).thenReturn(compatibleAudioDevices); when(mSpatializer.getCompatibleAudioDevices()).thenReturn(compatibleAudioDevices);
when(mSpatializer.isAvailableForDevice(mController.mAudioDevice)).thenReturn(true);
when(mSpatializer.hasHeadTracker(mController.mAudioDevice)).thenReturn(true); when(mSpatializer.hasHeadTracker(mController.mAudioDevice)).thenReturn(true);
when(mSpatializer.isHeadTrackerEnabled(mController.mAudioDevice)).thenReturn(true); when(mSpatializer.isHeadTrackerEnabled(mController.mAudioDevice)).thenReturn(true);
@@ -242,8 +188,10 @@ public class BluetoothDetailsSpatialAudioControllerTest extends BluetoothDetails
@Test @Test
public void refresh_headTrackingIsTurnedOff_unchecksHeadTrackingPreference() { public void refresh_headTrackingIsTurnedOff_unchecksHeadTrackingPreference() {
List<AudioDeviceAttributes> compatibleAudioDevices = new ArrayList<>(); List<AudioDeviceAttributes> compatibleAudioDevices = new ArrayList<>();
mController.setAvailableDevice(mAvailableDevice);
compatibleAudioDevices.add(mController.mAudioDevice); compatibleAudioDevices.add(mController.mAudioDevice);
when(mSpatializer.getCompatibleAudioDevices()).thenReturn(compatibleAudioDevices); when(mSpatializer.getCompatibleAudioDevices()).thenReturn(compatibleAudioDevices);
when(mSpatializer.isAvailableForDevice(mController.mAudioDevice)).thenReturn(true);
when(mSpatializer.hasHeadTracker(mController.mAudioDevice)).thenReturn(true); when(mSpatializer.hasHeadTracker(mController.mAudioDevice)).thenReturn(true);
when(mSpatializer.isHeadTrackerEnabled(mController.mAudioDevice)).thenReturn(false); when(mSpatializer.isHeadTrackerEnabled(mController.mAudioDevice)).thenReturn(false);
@@ -254,6 +202,7 @@ public class BluetoothDetailsSpatialAudioControllerTest extends BluetoothDetails
@Test @Test
public void turnedOnSpatialAudio_invokesAddCompatibleAudioDevice() { public void turnedOnSpatialAudio_invokesAddCompatibleAudioDevice() {
mController.setAvailableDevice(mAvailableDevice);
mSpatialAudioPref.setChecked(true); mSpatialAudioPref.setChecked(true);
mController.onPreferenceClick(mSpatialAudioPref); mController.onPreferenceClick(mSpatialAudioPref);
verify(mSpatializer).addCompatibleAudioDevice(mController.mAudioDevice); verify(mSpatializer).addCompatibleAudioDevice(mController.mAudioDevice);
@@ -261,6 +210,7 @@ public class BluetoothDetailsSpatialAudioControllerTest extends BluetoothDetails
@Test @Test
public void turnedOffSpatialAudio_invokesRemoveCompatibleAudioDevice() { public void turnedOffSpatialAudio_invokesRemoveCompatibleAudioDevice() {
mController.setAvailableDevice(mAvailableDevice);
mSpatialAudioPref.setChecked(false); mSpatialAudioPref.setChecked(false);
mController.onPreferenceClick(mSpatialAudioPref); mController.onPreferenceClick(mSpatialAudioPref);
verify(mSpatializer).removeCompatibleAudioDevice(mController.mAudioDevice); verify(mSpatializer).removeCompatibleAudioDevice(mController.mAudioDevice);
@@ -268,6 +218,7 @@ public class BluetoothDetailsSpatialAudioControllerTest extends BluetoothDetails
@Test @Test
public void turnedOnHeadTracking_invokesSetHeadTrackerEnabled_setsTrue() { public void turnedOnHeadTracking_invokesSetHeadTrackerEnabled_setsTrue() {
mController.setAvailableDevice(mAvailableDevice);
mHeadTrackingPref.setChecked(true); mHeadTrackingPref.setChecked(true);
mController.onPreferenceClick(mHeadTrackingPref); mController.onPreferenceClick(mHeadTrackingPref);
verify(mSpatializer).setHeadTrackerEnabled(true, mController.mAudioDevice); verify(mSpatializer).setHeadTrackerEnabled(true, mController.mAudioDevice);
@@ -275,6 +226,7 @@ public class BluetoothDetailsSpatialAudioControllerTest extends BluetoothDetails
@Test @Test
public void turnedOffHeadTracking_invokesSetHeadTrackerEnabled_setsFalse() { public void turnedOffHeadTracking_invokesSetHeadTrackerEnabled_setsFalse() {
mController.setAvailableDevice(mAvailableDevice);
mHeadTrackingPref.setChecked(false); mHeadTrackingPref.setChecked(false);
mController.onPreferenceClick(mHeadTrackingPref); mController.onPreferenceClick(mHeadTrackingPref);
verify(mSpatializer).setHeadTrackerEnabled(false, mController.mAudioDevice); verify(mSpatializer).setHeadTrackerEnabled(false, mController.mAudioDevice);

View File

@@ -26,6 +26,7 @@ import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.LocaleList; import android.os.LocaleList;
import com.android.settings.R;
import com.android.settings.testutils.BatteryTestUtils; import com.android.settings.testutils.BatteryTestUtils;
import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.FakeFeatureFactory;
@@ -83,6 +84,9 @@ public final class BatteryTipsControllerTest {
// Check pre-defined string // Check pre-defined string
verify(mBatteryTipsCardPreference).setTitle( verify(mBatteryTipsCardPreference).setTitle(
"Turn on adaptive brightness to extend battery life"); "Turn on adaptive brightness to extend battery life");
verify(mBatteryTipsCardPreference).setIconResourceId(R.drawable.ic_battery_tips_lightbulb);
verify(mBatteryTipsCardPreference).setMainButtonStrokeColorResourceId(
R.color.color_accent_selector);
verify(mBatteryTipsCardPreference).setMainButtonLabel("View Settings"); verify(mBatteryTipsCardPreference).setMainButtonLabel("View Settings");
verify(mBatteryTipsCardPreference).setDismissButtonLabel("Got it"); verify(mBatteryTipsCardPreference).setDismissButtonLabel("Got it");
// Check proto info // Check proto info
@@ -103,6 +107,9 @@ public final class BatteryTipsControllerTest {
verify(mBatteryTipsCardPreference).setAnomalyEventId("ScreenTimeoutAnomaly"); verify(mBatteryTipsCardPreference).setAnomalyEventId("ScreenTimeoutAnomaly");
verify(mBatteryTipsCardPreference).setTitle("Reduce screen timeout to extend battery life"); verify(mBatteryTipsCardPreference).setTitle("Reduce screen timeout to extend battery life");
verify(mBatteryTipsCardPreference).setIconResourceId(R.drawable.ic_battery_tips_lightbulb);
verify(mBatteryTipsCardPreference).setMainButtonStrokeColorResourceId(
R.color.color_accent_selector);
verify(mBatteryTipsCardPreference).setMainButtonLabel("View Settings"); verify(mBatteryTipsCardPreference).setMainButtonLabel("View Settings");
verify(mBatteryTipsCardPreference).setDismissButtonLabel("Got it"); verify(mBatteryTipsCardPreference).setDismissButtonLabel("Got it");
verify(mBatteryTipsCardPreference).setMainButtonLauncherInfo( verify(mBatteryTipsCardPreference).setMainButtonLauncherInfo(
@@ -129,6 +136,9 @@ public final class BatteryTipsControllerTest {
verify(mBatteryTipsCardPreference).setAnomalyEventId("ScreenTimeoutAnomaly"); verify(mBatteryTipsCardPreference).setAnomalyEventId("ScreenTimeoutAnomaly");
verify(mBatteryTipsCardPreference).setTitle(testTitle); verify(mBatteryTipsCardPreference).setTitle(testTitle);
verify(mBatteryTipsCardPreference).setIconResourceId(R.drawable.ic_battery_tips_lightbulb);
verify(mBatteryTipsCardPreference).setMainButtonStrokeColorResourceId(
R.color.color_accent_selector);
verify(mBatteryTipsCardPreference).setMainButtonLabel("View Settings"); verify(mBatteryTipsCardPreference).setMainButtonLabel("View Settings");
verify(mBatteryTipsCardPreference).setDismissButtonLabel("Got it"); verify(mBatteryTipsCardPreference).setDismissButtonLabel("Got it");
verify(mBatteryTipsCardPreference).setMainButtonLauncherInfo( verify(mBatteryTipsCardPreference).setMainButtonLauncherInfo(
@@ -138,4 +148,27 @@ public final class BatteryTipsControllerTest {
verify(mFeatureFactory.metricsFeatureProvider).action( verify(mFeatureFactory.metricsFeatureProvider).action(
mContext, SettingsEnums.ACTION_BATTERY_TIPS_CARD_SHOW, "ScreenTimeoutAnomaly"); mContext, SettingsEnums.ACTION_BATTERY_TIPS_CARD_SHOW, "ScreenTimeoutAnomaly");
} }
@Test
public void handleBatteryTipsCardUpdated_appAnomaly_showAnomaly() {
PowerAnomalyEvent event = BatteryTestUtils.createAppAnomalyEvent();
when(mFeatureFactory.powerUsageFeatureProvider.isBatteryTipsEnabled()).thenReturn(true);
mBatteryTipsController.handleBatteryTipsCardUpdated(event);
verify(mBatteryTipsCardPreference).setAnomalyEventId("AppAnomaly");
verify(mBatteryTipsCardPreference).setTitle(
"Chrome used more battery than usual in foreground");
verify(mBatteryTipsCardPreference).setIconResourceId(
R.drawable.ic_battery_tips_warning_icon);
verify(mBatteryTipsCardPreference).setMainButtonStrokeColorResourceId(
R.color.color_battery_anomaly_yellow_selector);
verify(mBatteryTipsCardPreference).setMainButtonLabel("Check");
verify(mBatteryTipsCardPreference).setDismissButtonLabel("Got it");
verify(mBatteryTipsCardPreference).setMainButtonLauncherInfo(
null, null, null);
verify(mBatteryTipsCardPreference).setVisible(true);
verify(mFeatureFactory.metricsFeatureProvider).action(
mContext, SettingsEnums.ACTION_BATTERY_TIPS_CARD_SHOW, "AppAnomaly");
}
} }

View File

@@ -39,6 +39,7 @@ import com.android.settings.fuelgauge.batteryusage.PowerAnomalyEventList;
import com.android.settings.fuelgauge.batteryusage.PowerAnomalyKey; import com.android.settings.fuelgauge.batteryusage.PowerAnomalyKey;
import com.android.settings.fuelgauge.batteryusage.PowerAnomalyType; import com.android.settings.fuelgauge.batteryusage.PowerAnomalyType;
import com.android.settings.fuelgauge.batteryusage.WarningBannerInfo; import com.android.settings.fuelgauge.batteryusage.WarningBannerInfo;
import com.android.settings.fuelgauge.batteryusage.WarningItemInfo;
import com.android.settings.fuelgauge.batteryusage.db.AppUsageEventDao; import com.android.settings.fuelgauge.batteryusage.db.AppUsageEventDao;
import com.android.settings.fuelgauge.batteryusage.db.AppUsageEventEntity; import com.android.settings.fuelgauge.batteryusage.db.AppUsageEventEntity;
import com.android.settings.fuelgauge.batteryusage.db.BatteryState; import com.android.settings.fuelgauge.batteryusage.db.BatteryState;
@@ -70,14 +71,18 @@ public class BatteryTestUtils {
BatteryManager.BATTERY_STATUS_DISCHARGING); BatteryManager.BATTERY_STATUS_DISCHARGING);
} }
/** Sets the work profile mode. */ /**
* Sets the work profile mode.
*/
public static void setWorkProfile(Context context) { public static void setWorkProfile(Context context) {
final UserManager userManager = context.getSystemService(UserManager.class); final UserManager userManager = context.getSystemService(UserManager.class);
Shadows.shadowOf(userManager).setManagedProfile(true); Shadows.shadowOf(userManager).setManagedProfile(true);
Shadows.shadowOf(userManager).setIsSystemUser(false); Shadows.shadowOf(userManager).setIsSystemUser(false);
} }
/** Creates and sets up the in-memory {@link BatteryStateDatabase}. */ /**
* Creates and sets up the in-memory {@link BatteryStateDatabase}.
*/
public static BatteryStateDatabase setUpBatteryStateDatabase(Context context) { public static BatteryStateDatabase setUpBatteryStateDatabase(Context context) {
final BatteryStateDatabase inMemoryDatabase = final BatteryStateDatabase inMemoryDatabase =
Room.inMemoryDatabaseBuilder(context, BatteryStateDatabase.class) Room.inMemoryDatabaseBuilder(context, BatteryStateDatabase.class)
@@ -87,21 +92,27 @@ public class BatteryTestUtils {
return inMemoryDatabase; return inMemoryDatabase;
} }
/** Inserts a fake data into the database for testing. */ /**
* Inserts a fake data into the database for testing.
*/
public static void insertDataToBatteryStateTable( public static void insertDataToBatteryStateTable(
Context context, long timestamp, String packageName) { Context context, long timestamp, String packageName) {
insertDataToBatteryStateTable( insertDataToBatteryStateTable(
context, timestamp, packageName, /*multiple=*/ false, /*isFullChargeStart=*/ false); context, timestamp, packageName, /*multiple=*/ false, /*isFullChargeStart=*/ false);
} }
/** Inserts a fake data into the database for testing. */ /**
* Inserts a fake data into the database for testing.
*/
public static void insertDataToBatteryStateTable( public static void insertDataToBatteryStateTable(
Context context, long timestamp, String packageName, boolean isFullChargeStart) { Context context, long timestamp, String packageName, boolean isFullChargeStart) {
insertDataToBatteryStateTable( insertDataToBatteryStateTable(
context, timestamp, packageName, /*multiple=*/ false, isFullChargeStart); context, timestamp, packageName, /*multiple=*/ false, isFullChargeStart);
} }
/** Inserts a fake data into the database for testing. */ /**
* Inserts a fake data into the database for testing.
*/
public static void insertDataToBatteryStateTable( public static void insertDataToBatteryStateTable(
Context context, long timestamp, String packageName, boolean multiple, Context context, long timestamp, String packageName, boolean multiple,
boolean isFullChargeStart) { boolean isFullChargeStart) {
@@ -151,14 +162,18 @@ public class BatteryTestUtils {
} }
} }
/** Inserts a fake data into the database for testing. */ /**
* Inserts a fake data into the database for testing.
*/
public static void insertDataToAppUsageEventTable( public static void insertDataToAppUsageEventTable(
Context context, long userId, long timestamp, String packageName) { Context context, long userId, long timestamp, String packageName) {
insertDataToAppUsageEventTable( insertDataToAppUsageEventTable(
context, userId, timestamp, packageName, /*multiple=*/ false); context, userId, timestamp, packageName, /*multiple=*/ false);
} }
/** Inserts a fake data into the database for testing. */ /**
* Inserts a fake data into the database for testing.
*/
public static void insertDataToAppUsageEventTable( public static void insertDataToAppUsageEventTable(
Context context, long userId, long timestamp, String packageName, boolean multiple) { Context context, long userId, long timestamp, String packageName, boolean multiple) {
final AppUsageEventEntity entity = final AppUsageEventEntity entity =
@@ -179,7 +194,9 @@ public class BatteryTestUtils {
} }
} }
/** Gets customized battery changed intent. */ /**
* Gets customized battery changed intent.
*/
public static Intent getCustomBatteryIntent(int plugged, int level, int scale, int status) { public static Intent getCustomBatteryIntent(int plugged, int level, int scale, int status) {
Intent intent = new Intent(); Intent intent = new Intent();
intent.putExtra(BatteryManager.EXTRA_PLUGGED, plugged); intent.putExtra(BatteryManager.EXTRA_PLUGGED, plugged);
@@ -190,7 +207,9 @@ public class BatteryTestUtils {
return intent; return intent;
} }
/** Configures the incompatible charger environment. */ /**
* Configures the incompatible charger environment.
*/
public static void setupIncompatibleEvent( public static void setupIncompatibleEvent(
UsbPort mockUsbPort, UsbManager mockUsbManager, UsbPortStatus mockUsbPortStatus) { UsbPort mockUsbPort, UsbManager mockUsbManager, UsbPortStatus mockUsbPortStatus) {
final List<UsbPort> usbPorts = new ArrayList<>(); final List<UsbPort> usbPorts = new ArrayList<>();
@@ -203,12 +222,16 @@ public class BatteryTestUtils {
.thenReturn(new int[]{UsbPortStatus.COMPLIANCE_WARNING_OTHER}); .thenReturn(new int[]{UsbPortStatus.COMPLIANCE_WARNING_OTHER});
} }
/** Create an empty power anomaly event list proto. */ /**
* Create an empty power anomaly event list proto.
*/
public static PowerAnomalyEventList createEmptyPowerAnomalyEventList() { public static PowerAnomalyEventList createEmptyPowerAnomalyEventList() {
return PowerAnomalyEventList.getDefaultInstance(); return PowerAnomalyEventList.getDefaultInstance();
} }
/** Create an non-empty power anomaly event list proto. */ /**
* Create an non-empty power anomaly event list proto.
*/
public static PowerAnomalyEventList createNonEmptyPowerAnomalyEventList() { public static PowerAnomalyEventList createNonEmptyPowerAnomalyEventList() {
return PowerAnomalyEventList.newBuilder() return PowerAnomalyEventList.newBuilder()
.addPowerAnomalyEvents(0, createAdaptiveBrightnessAnomalyEvent()) .addPowerAnomalyEvents(0, createAdaptiveBrightnessAnomalyEvent())
@@ -216,7 +239,9 @@ public class BatteryTestUtils {
.build(); .build();
} }
/** Create a power anomaly event proto of adaptive brightness. */ /**
* Create a power anomaly event proto of adaptive brightness.
*/
public static PowerAnomalyEvent createAdaptiveBrightnessAnomalyEvent() { public static PowerAnomalyEvent createAdaptiveBrightnessAnomalyEvent() {
return PowerAnomalyEvent.newBuilder() return PowerAnomalyEvent.newBuilder()
.setEventId("BrightnessAnomaly") .setEventId("BrightnessAnomaly")
@@ -231,7 +256,9 @@ public class BatteryTestUtils {
.build(); .build();
} }
/** Create a power anomaly event proto of screen timeout. */ /**
* Create a power anomaly event proto of screen timeout.
*/
public static PowerAnomalyEvent createScreenTimeoutAnomalyEvent() { public static PowerAnomalyEvent createScreenTimeoutAnomalyEvent() {
return PowerAnomalyEvent.newBuilder() return PowerAnomalyEvent.newBuilder()
.setEventId("ScreenTimeoutAnomaly") .setEventId("ScreenTimeoutAnomaly")
@@ -245,4 +272,21 @@ public class BatteryTestUtils {
.build()) .build())
.build(); .build();
} }
/**
* Create a power anomaly event proto of app anomaly.
*/
public static PowerAnomalyEvent createAppAnomalyEvent() {
return PowerAnomalyEvent.newBuilder()
.setEventId("AppAnomaly")
.setType(PowerAnomalyType.TYPE_APPS_ITEM)
.setKey(PowerAnomalyKey.KEY_APP)
.setScore(2.0f)
.setWarningItemInfo(WarningItemInfo.newBuilder()
.setTitleString("Chrome used more battery than usual in foreground")
.setMainButtonString("Check")
.setCancelButtonString("Got it")
.build())
.build();
}
} }