Snap for 11717025 from 02f1db61d8 to 24Q3-release
Change-Id: Iabe7983621aee785634bc0387946eec0cc3a9dbe
This commit is contained in:
@@ -3064,9 +3064,9 @@
|
||||
<!-- Storage settings screen title -->
|
||||
<string name="storage_settings_title">Storage settings</string>
|
||||
<!-- About phone, title of EID -->
|
||||
<string name="status_eid">EID</string>
|
||||
<string name="status_eid">E​ID</string>
|
||||
<!-- About phone, title of EID for multi-sim devices -->
|
||||
<string name="eid_multi_sim">EID (sim slot <xliff:g id="eid_slot_id">%1$d</xliff:g>)</string>
|
||||
<string name="eid_multi_sim">E​ID (sim slot <xliff:g id="eid_slot_id">%1$d</xliff:g>)</string>
|
||||
<!-- About phone screen, title for IMEI for multi-sim devices -->
|
||||
<string name="imei_multi_sim">IMEI (sim slot <xliff:g id="imei_slot_id">%1$d</xliff:g>)</string>
|
||||
<!-- About phone screen, title for primary IMEI for multi-sim devices -->
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
android:selectable="false"
|
||||
settings:searchable="false" />
|
||||
|
||||
<com.android.settings.widget.CardPreference
|
||||
<com.android.settings.widget.TipCardPreference
|
||||
android:key="battery_tip"
|
||||
android:title="@string/summary_placeholder"
|
||||
settings:controller="com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController" />
|
||||
|
||||
@@ -19,7 +19,9 @@ package com.android.settings.bluetooth;
|
||||
import static android.bluetooth.BluetoothDevice.BOND_NONE;
|
||||
import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -51,6 +53,7 @@ import com.android.settings.dashboard.RestrictedDashboardFragment;
|
||||
import com.android.settings.inputmethod.KeyboardSettingsPreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.slices.SlicePreferenceController;
|
||||
import com.android.settingslib.bluetooth.BluetoothCallback;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
@@ -98,6 +101,20 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
|
||||
|
||||
private UserManager mUserManager;
|
||||
|
||||
private final BluetoothCallback mBluetoothCallback =
|
||||
new BluetoothCallback() {
|
||||
@Override
|
||||
public void onBluetoothStateChanged(int bluetoothState) {
|
||||
if (bluetoothState == BluetoothAdapter.STATE_OFF) {
|
||||
Log.i(TAG, "Bluetooth is off, exit activity.");
|
||||
Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
activity.finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public BluetoothDeviceDetailsFragment() {
|
||||
super(DISALLOW_CONFIG_BLUETOOTH);
|
||||
}
|
||||
@@ -183,6 +200,14 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment
|
||||
use(BlockingPrefWithSliceController.class).setSliceUri(sliceEnabled
|
||||
? featureProvider.getBluetoothDeviceSettingsUri(mCachedDevice.getDevice())
|
||||
: null);
|
||||
|
||||
mManager.getEventManager().registerCallback(mBluetoothCallback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
mManager.getEventManager().unregisterCallback(mBluetoothCallback);
|
||||
}
|
||||
|
||||
private void updateExtraControlUri(int viewWidth) {
|
||||
|
||||
@@ -33,7 +33,7 @@ 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.overlay.FeatureFactory;
|
||||
import com.android.settings.widget.CardPreference;
|
||||
import com.android.settings.widget.TipCardPreference;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import java.util.List;
|
||||
@@ -55,7 +55,7 @@ public class BatteryTipPreferenceController extends BasePreferenceController {
|
||||
private SettingsActivity mSettingsActivity;
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private boolean mNeedUpdate;
|
||||
@VisibleForTesting CardPreference mCardPreference;
|
||||
@VisibleForTesting TipCardPreference mCardPreference;
|
||||
@VisibleForTesting Context mPrefContext;
|
||||
InstrumentedPreferenceFragment mFragment;
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.widget.CardPreference;
|
||||
import com.android.settingslib.HelpUtils;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
@@ -80,9 +79,9 @@ public class BatteryDefenderTip extends BatteryTip {
|
||||
super.updatePreference(preference);
|
||||
final Context context = preference.getContext();
|
||||
|
||||
CardPreference cardPreference = castToCardPreferenceSafely(preference);
|
||||
var cardPreference = castToTipCardPreferenceSafely(preference);
|
||||
if (cardPreference == null) {
|
||||
Log.e(TAG, "cast Preference to CardPreference failed");
|
||||
Log.e(TAG, "cast Preference to TipCardPreference failed");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,10 +23,11 @@ import android.util.SparseIntArray;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.widget.CardPreference;
|
||||
import com.android.settings.widget.TipCardPreference;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -165,7 +166,7 @@ public abstract class BatteryTip implements Comparable<BatteryTip>, Parcelable {
|
||||
preference.setTitle(getTitle(context));
|
||||
preference.setSummary(getSummary(context));
|
||||
preference.setIcon(getIconId());
|
||||
final CardPreference cardPreference = castToCardPreferenceSafely(preference);
|
||||
final TipCardPreference cardPreference = castToTipCardPreferenceSafely(preference);
|
||||
if (cardPreference != null) {
|
||||
cardPreference.resetLayoutState();
|
||||
}
|
||||
@@ -206,7 +207,9 @@ public abstract class BatteryTip implements Comparable<BatteryTip>, Parcelable {
|
||||
return "type=" + mType + " state=" + mState;
|
||||
}
|
||||
|
||||
public CardPreference castToCardPreferenceSafely(Preference preference) {
|
||||
return preference instanceof CardPreference ? (CardPreference) preference : null;
|
||||
/** Returns the converted {@link TipCardPreference} if it is valid. */
|
||||
@Nullable
|
||||
public TipCardPreference castToTipCardPreferenceSafely(Preference preference) {
|
||||
return preference instanceof TipCardPreference ? (TipCardPreference) preference : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import androidx.core.app.ActivityCompat;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.widget.CardPreference;
|
||||
import com.android.settingslib.HelpUtils;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
@@ -74,7 +73,7 @@ public final class IncompatibleChargerTip extends BatteryTip {
|
||||
public void updatePreference(Preference preference) {
|
||||
super.updatePreference(preference);
|
||||
final Context context = preference.getContext();
|
||||
final CardPreference cardPreference = castToCardPreferenceSafely(preference);
|
||||
final var cardPreference = castToTipCardPreferenceSafely(preference);
|
||||
if (cardPreference == null) {
|
||||
Log.e(TAG, "cast Preference to CardPreference failed");
|
||||
return;
|
||||
|
||||
@@ -18,9 +18,13 @@ package com.android.settings.fuelgauge.batteryusage;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
@@ -49,8 +53,8 @@ final class AnomalyEventWrapper {
|
||||
}
|
||||
|
||||
private <T> T getInfo(
|
||||
Function<WarningBannerInfo, T> warningBannerInfoSupplier,
|
||||
Function<WarningItemInfo, T> warningItemInfoSupplier) {
|
||||
@Nullable Function<WarningBannerInfo, T> warningBannerInfoSupplier,
|
||||
@Nullable Function<WarningItemInfo, T> warningItemInfoSupplier) {
|
||||
if (warningBannerInfoSupplier != null && mPowerAnomalyEvent.hasWarningBannerInfo()) {
|
||||
return warningBannerInfoSupplier.apply(mPowerAnomalyEvent.getWarningBannerInfo());
|
||||
} else if (warningItemInfoSupplier != null && mPowerAnomalyEvent.hasWarningItemInfo()) {
|
||||
@@ -252,4 +256,32 @@ final class AnomalyEventWrapper {
|
||||
mSubSettingLauncher.launch();
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean updateSystemSettingsIfAvailable() {
|
||||
final String settingsName =
|
||||
getInfo(WarningBannerInfo::getMainButtonConfigSettingsName, null);
|
||||
final Integer settingsValue =
|
||||
getInfo(WarningBannerInfo::getMainButtonConfigSettingsValue, null);
|
||||
if (TextUtils.isEmpty(settingsName) || settingsValue == null) {
|
||||
Log.d(TAG, "Failed to update settings due to invalid key or value");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
Settings.System.putInt(mContext.getContentResolver(), settingsName, settingsValue);
|
||||
Log.d(
|
||||
TAG,
|
||||
String.format(
|
||||
"Update settings name=%s to value=%d", settingsName, settingsValue));
|
||||
return true;
|
||||
} catch (SecurityException e) {
|
||||
Log.w(
|
||||
TAG,
|
||||
String.format(
|
||||
"Failed to update settings name=%s to value=%d",
|
||||
settingsName, settingsValue),
|
||||
e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,8 @@ public class BatteryTipsController extends BasePreferenceController {
|
||||
mCardPreference.setVisible(false);
|
||||
if (mOnAnomalyConfirmListener != null) {
|
||||
mOnAnomalyConfirmListener.onAnomalyConfirm();
|
||||
} else if (mAnomalyEventWrapper.launchSubSetting()) {
|
||||
} else if (mAnomalyEventWrapper.updateSystemSettingsIfAvailable()
|
||||
|| mAnomalyEventWrapper.launchSubSetting()) {
|
||||
mMetricsFeatureProvider.action(
|
||||
/* attribution= */ SettingsEnums.FUELGAUGE_BATTERY_HISTORY_DETAIL,
|
||||
/* action= */ SettingsEnums.ACTION_BATTERY_TIPS_CARD_ACCEPT,
|
||||
|
||||
@@ -57,6 +57,8 @@ message WarningBannerInfo {
|
||||
// Used in the SubSettingLauncher.setArguments().
|
||||
optional string main_button_source_highlight_key = 6;
|
||||
optional string cancel_button_string = 7;
|
||||
optional string main_button_config_settings_name = 8;
|
||||
optional int32 main_button_config_settings_value = 9;
|
||||
}
|
||||
|
||||
message WarningItemInfo {
|
||||
|
||||
@@ -225,7 +225,7 @@ class SimOnboardingService {
|
||||
}
|
||||
|
||||
fun addItemForRenaming(subInfo: SubscriptionInfo, newName: String) {
|
||||
if (newName.isEmpty() && subInfo.displayName == newName) {
|
||||
if (subInfo.displayName == newName) {
|
||||
return
|
||||
}
|
||||
renameMutableMap[subInfo.subscriptionId] = newName
|
||||
|
||||
@@ -20,6 +20,7 @@ import static android.os.UserManager.USER_TYPE_PROFILE_PRIVATE;
|
||||
import static android.provider.Settings.Secure.HIDE_PRIVATESPACE_ENTRY_POINT;
|
||||
import static android.provider.Settings.Secure.PRIVATE_SPACE_AUTO_LOCK;
|
||||
import static android.provider.Settings.Secure.PRIVATE_SPACE_AUTO_LOCK_AFTER_DEVICE_RESTART;
|
||||
import static android.provider.Settings.Secure.SKIP_FIRST_USE_HINTS;
|
||||
import static android.provider.Settings.Secure.USER_SETUP_COMPLETE;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
@@ -122,6 +123,7 @@ public class PrivateSpaceMaintainer {
|
||||
Log.i(TAG, "Private space created with id: " + mUserHandle.getIdentifier());
|
||||
resetPrivateSpaceSettings();
|
||||
setUserSetupComplete();
|
||||
setSkipFirstUseHints();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -350,6 +352,17 @@ public class PrivateSpaceMaintainer {
|
||||
1, mUserHandle.getIdentifier());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the SKIP_FIRST_USE_HINTS for private profile so that the first launch of an app in
|
||||
* private space will not display introductory hints.
|
||||
*/
|
||||
@GuardedBy("this")
|
||||
private void setSkipFirstUseHints() {
|
||||
Log.d(TAG, "setting SKIP_FIRST_USE_HINTS = 1 for private profile");
|
||||
Settings.Secure.putIntForUser(mContext.getContentResolver(), SKIP_FIRST_USE_HINTS,
|
||||
1, mUserHandle.getIdentifier());
|
||||
}
|
||||
|
||||
private boolean isPrivateSpaceAutoLockSupported() {
|
||||
return android.os.Flags.allowPrivateProfile()
|
||||
&& android.multiuser.Flags.supportAutolockForPrivateSpace()
|
||||
|
||||
164
src/com/android/settings/widget/CardPreference.java
Normal file
164
src/com/android/settings/widget/CardPreference.java
Normal file
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import com.google.android.material.card.MaterialCardView;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/** Preference that wrapped by {@link MaterialCardView} */
|
||||
public class CardPreference extends Preference {
|
||||
@Nullable private View.OnClickListener mPrimaryBtnClickListener = null;
|
||||
@Nullable private View.OnClickListener mSecondaryBtnClickListener = null;
|
||||
@Nullable private String mPrimaryButtonText = null;
|
||||
@Nullable private String mSecondaryButtonText = null;
|
||||
private Optional<Button> mPrimaryButton = Optional.empty();
|
||||
private Optional<Button> mSecondaryButton = Optional.empty();
|
||||
private Optional<View> mButtonsGroup = Optional.empty();
|
||||
private boolean mPrimaryButtonVisible = false;
|
||||
private boolean mSecondaryButtonVisible = false;
|
||||
|
||||
public CardPreference(Context context) {
|
||||
this(context, null /* attrs */);
|
||||
}
|
||||
|
||||
public CardPreference(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs, R.attr.cardPreferenceStyle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
initButtonsAndLayout(holder);
|
||||
}
|
||||
|
||||
private void initButtonsAndLayout(PreferenceViewHolder holder) {
|
||||
mPrimaryButton = Optional.ofNullable((Button) holder.findViewById(android.R.id.button1));
|
||||
mSecondaryButton = Optional.ofNullable((Button) holder.findViewById(android.R.id.button2));
|
||||
mButtonsGroup = Optional.ofNullable(holder.findViewById(R.id.card_preference_buttons));
|
||||
setPrimaryButtonText(mPrimaryButtonText);
|
||||
setPrimaryButtonClickListener(mPrimaryBtnClickListener);
|
||||
setPrimaryButtonVisible(mPrimaryButtonVisible);
|
||||
setSecondaryButtonText(mSecondaryButtonText);
|
||||
setSecondaryButtonClickListener(mSecondaryBtnClickListener);
|
||||
setSecondaryButtonVisible(mSecondaryButtonVisible);
|
||||
}
|
||||
|
||||
/** Clear layout state if needed */
|
||||
public void resetLayoutState() {
|
||||
setPrimaryButtonVisible(false);
|
||||
setSecondaryButtonVisible(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback to be invoked when the primary button is clicked.
|
||||
*
|
||||
* @param l the callback that will run
|
||||
*/
|
||||
public void setPrimaryButtonClickListener(View.OnClickListener l) {
|
||||
mPrimaryButton.ifPresent(button -> button.setOnClickListener(l));
|
||||
mPrimaryBtnClickListener = l;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback to be invoked when the secondary button is clicked.
|
||||
*
|
||||
* @param l the callback that will run
|
||||
*/
|
||||
public void setSecondaryButtonClickListener(View.OnClickListener l) {
|
||||
mSecondaryButton.ifPresent(button -> button.setOnClickListener(l));
|
||||
mSecondaryBtnClickListener = l;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the text to be displayed on primary button.
|
||||
*
|
||||
* @param text text to be displayed
|
||||
*/
|
||||
public void setPrimaryButtonText(String text) {
|
||||
mPrimaryButton.ifPresent(button -> button.setText(text));
|
||||
mPrimaryButtonText = text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the text to be displayed on secondary button.
|
||||
*
|
||||
* @param text text to be displayed
|
||||
*/
|
||||
public void setSecondaryButtonText(String text) {
|
||||
mSecondaryButton.ifPresent(button -> button.setText(text));
|
||||
mSecondaryButtonText = text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the visible on the primary button.
|
||||
*
|
||||
* @param visible {@code true} for visible
|
||||
*/
|
||||
public void setPrimaryButtonVisible(boolean visible) {
|
||||
mPrimaryButton.ifPresent(
|
||||
button -> button.setVisibility(visible ? View.VISIBLE : View.GONE));
|
||||
mPrimaryButtonVisible = visible;
|
||||
updateButtonGroupsVisibility();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the visible on the secondary button.
|
||||
*
|
||||
* @param visible {@code true} for visible
|
||||
*/
|
||||
public void setSecondaryButtonVisible(boolean visible) {
|
||||
mSecondaryButton.ifPresent(
|
||||
button -> button.setVisibility(visible ? View.VISIBLE : View.GONE));
|
||||
mSecondaryButtonVisible = visible;
|
||||
updateButtonGroupsVisibility();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the text of content description on primary button.
|
||||
*
|
||||
* @param text text for the content description
|
||||
*/
|
||||
public void setPrimaryButtonContentDescription(String text) {
|
||||
mPrimaryButton.ifPresent(button -> button.setContentDescription(text));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the text of content description on secondary button.
|
||||
*
|
||||
* @param text text for the content description
|
||||
*/
|
||||
public void setSecondaryButtonContentDescription(String text) {
|
||||
mSecondaryButton.ifPresent(button -> button.setContentDescription(text));
|
||||
}
|
||||
|
||||
private void updateButtonGroupsVisibility() {
|
||||
int visibility =
|
||||
(mPrimaryButtonVisible || mSecondaryButtonVisible) ? View.VISIBLE : View.GONE;
|
||||
mButtonsGroup.ifPresent(group -> group.setVisibility(visibility));
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ import com.android.settingslib.spa.widget.card.CardModel
|
||||
import com.android.settingslib.spa.widget.card.SettingsCard
|
||||
|
||||
/** A preference for settings banner tips card. */
|
||||
class CardPreference
|
||||
class TipCardPreference
|
||||
@JvmOverloads
|
||||
constructor(
|
||||
context: Context,
|
||||
@@ -33,7 +33,7 @@ import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
import com.android.settings.widget.CardPreference;
|
||||
import com.android.settings.widget.TipCardPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
@@ -61,7 +61,7 @@ public class BatteryTipPreferenceControllerTest {
|
||||
@Mock private InstrumentedPreferenceFragment mFragment;
|
||||
|
||||
private Context mContext;
|
||||
private CardPreference mCardPreference;
|
||||
private TipCardPreference mCardPreference;
|
||||
private BatteryTipPreferenceController mBatteryTipPreferenceController;
|
||||
private List<BatteryTip> mNewBatteryTips;
|
||||
|
||||
@@ -69,7 +69,7 @@ public class BatteryTipPreferenceControllerTest {
|
||||
public void setUp() {
|
||||
mContext = ApplicationProvider.getApplicationContext();
|
||||
|
||||
mCardPreference = new CardPreference(mContext);
|
||||
mCardPreference = new TipCardPreference(mContext);
|
||||
when(mPreferenceScreen.getContext()).thenReturn(mContext);
|
||||
doReturn(mCardPreference).when(mPreferenceScreen).findPreference(KEY_PREF);
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.widget.CardPreference;
|
||||
import com.android.settings.widget.TipCardPreference;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -49,7 +49,7 @@ public class BatteryDefenderTipTest {
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private BatteryDefenderTip mBatteryDefenderTip;
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private CardPreference mCardPreference;
|
||||
private TipCardPreference mCardPreference;
|
||||
|
||||
@Rule public MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
@Mock private BatteryTip mBatteryTip;
|
||||
@@ -62,7 +62,7 @@ public class BatteryDefenderTipTest {
|
||||
mMetricsFeatureProvider = mFeatureFactory.metricsFeatureProvider;
|
||||
mBatteryDefenderTip =
|
||||
new BatteryDefenderTip(BatteryTip.StateType.NEW, /* isPluggedIn= */ false);
|
||||
mCardPreference = new CardPreference(mContext);
|
||||
mCardPreference = new TipCardPreference(mContext);
|
||||
|
||||
when(mPreference.getContext()).thenReturn(mContext);
|
||||
}
|
||||
@@ -98,7 +98,7 @@ public class BatteryDefenderTipTest {
|
||||
public void updatePreference_castFail_logErrorMessage() {
|
||||
mBatteryDefenderTip.updatePreference(mPreference);
|
||||
|
||||
assertThat(getLastErrorLog()).isEqualTo("cast Preference to CardPreference failed");
|
||||
assertThat(getLastErrorLog()).isEqualTo("cast Preference to TipCardPreference failed");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -26,7 +26,7 @@ import androidx.preference.Preference;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.widget.CardPreference;
|
||||
import com.android.settings.widget.TipCardPreference;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settingslib.testutils.DrawableTestHelper;
|
||||
|
||||
@@ -87,7 +87,7 @@ public class BatteryTipTest {
|
||||
|
||||
@Test
|
||||
public void updatePreference_resetLayoutState() {
|
||||
CardPreference cardPreference = new CardPreference(mContext);
|
||||
var cardPreference = new TipCardPreference(mContext);
|
||||
cardPreference.setPrimaryButtonVisibility(true);
|
||||
cardPreference.setSecondaryButtonVisibility(true);
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.widget.CardPreference;
|
||||
import com.android.settings.widget.TipCardPreference;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -49,7 +49,7 @@ public final class IncompatibleChargerTipTest {
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private IncompatibleChargerTip mIncompatibleChargerTip;
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private CardPreference mCardPreference;
|
||||
private TipCardPreference mCardPreference;
|
||||
|
||||
@Rule public MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
@Mock private BatteryTip mBatteryTip;
|
||||
@@ -61,7 +61,7 @@ public final class IncompatibleChargerTipTest {
|
||||
mMetricsFeatureProvider = mFeatureFactory.metricsFeatureProvider;
|
||||
mContext = ApplicationProvider.getApplicationContext();
|
||||
mIncompatibleChargerTip = new IncompatibleChargerTip(BatteryTip.StateType.NEW);
|
||||
mCardPreference = new CardPreference(mContext);
|
||||
mCardPreference = new TipCardPreference(mContext);
|
||||
|
||||
when(mPreference.getContext()).thenReturn(mContext);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ import static org.mockito.Mockito.when;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.provider.Settings;
|
||||
import android.util.Pair;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.settings.DisplaySettings;
|
||||
@@ -40,7 +42,6 @@ import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
@@ -51,6 +52,7 @@ import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public final class BatteryTipsCardPreferenceTest {
|
||||
@@ -69,6 +71,7 @@ public final class BatteryTipsCardPreferenceTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mBatteryTipsCardPreference = new BatteryTipsCardPreference(mContext, /* attrs= */ null);
|
||||
@@ -100,10 +103,10 @@ public final class BatteryTipsCardPreferenceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onClick_mainBtnOfSettingsAnomaly_getAdaptiveBrightnessLauncher() {
|
||||
public void onClick_mainBtnOfSettingsAnomalyLaunchPage_getAdaptiveBrightnessLauncher() {
|
||||
final ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
|
||||
PowerAnomalyEvent adaptiveBrightnessAnomaly =
|
||||
BatteryTestUtils.createAdaptiveBrightnessAnomalyEvent();
|
||||
BatteryTestUtils.createAdaptiveBrightnessAnomalyEvent(/* changeSettings= */ false);
|
||||
when(mFeatureFactory.powerUsageFeatureProvider.isBatteryTipsEnabled()).thenReturn(true);
|
||||
when(mFakeView.getId()).thenReturn(R.id.main_button);
|
||||
doNothing().when(mContext).startActivity(captor.capture());
|
||||
@@ -135,6 +138,47 @@ public final class BatteryTipsCardPreferenceTest {
|
||||
PowerAnomalyKey.KEY_BRIGHTNESS.getNumber());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onClick_mainBtnOfSettingsAnomalyChangeSettings_settingsChanged()
|
||||
throws Settings.SettingNotFoundException {
|
||||
Settings.System.putInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.System.SCREEN_BRIGHTNESS_MODE,
|
||||
Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
|
||||
final ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
|
||||
PowerAnomalyEvent adaptiveBrightnessAnomaly =
|
||||
BatteryTestUtils.createAdaptiveBrightnessAnomalyEvent(/* changeSettings= */ true);
|
||||
when(mFeatureFactory.powerUsageFeatureProvider.isBatteryTipsEnabled()).thenReturn(true);
|
||||
when(mFakeView.getId()).thenReturn(R.id.main_button);
|
||||
doNothing().when(mContext).startActivity(captor.capture());
|
||||
|
||||
mPowerUsageAdvanced.onDisplayAnomalyEventUpdated(
|
||||
adaptiveBrightnessAnomaly, adaptiveBrightnessAnomaly);
|
||||
mBatteryTipsCardPreference.onClick(mFakeView);
|
||||
|
||||
assertThat(mBatteryTipsCardPreference.isVisible()).isFalse();
|
||||
assertThat(
|
||||
Settings.System.getInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.System.SCREEN_BRIGHTNESS_MODE))
|
||||
.isEqualTo(Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
|
||||
verify(mContext, never()).startActivity(any(Intent.class));
|
||||
verify(mFeatureFactory.metricsFeatureProvider)
|
||||
.action(
|
||||
SettingsEnums.FUELGAUGE_BATTERY_HISTORY_DETAIL,
|
||||
SettingsEnums.ACTION_BATTERY_TIPS_CARD_SHOW,
|
||||
SettingsEnums.FUELGAUGE_BATTERY_HISTORY_DETAIL,
|
||||
BatteryTipsController.ANOMALY_KEY,
|
||||
PowerAnomalyKey.KEY_BRIGHTNESS.getNumber());
|
||||
verify(mFeatureFactory.metricsFeatureProvider)
|
||||
.action(
|
||||
SettingsEnums.FUELGAUGE_BATTERY_HISTORY_DETAIL,
|
||||
SettingsEnums.ACTION_BATTERY_TIPS_CARD_ACCEPT,
|
||||
SettingsEnums.FUELGAUGE_BATTERY_HISTORY_DETAIL,
|
||||
BatteryTipsController.ANOMALY_KEY,
|
||||
PowerAnomalyKey.KEY_BRIGHTNESS.getNumber());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onClick_dismissBtnOfSettingsAnomaly_cardDismissAndLogged() {
|
||||
final PowerAnomalyEvent screenTimeoutAnomaly =
|
||||
@@ -167,7 +211,6 @@ public final class BatteryTipsCardPreferenceTest {
|
||||
PowerAnomalyKey.KEY_SCREEN_TIMEOUT.getNumber());
|
||||
}
|
||||
|
||||
@Ignore("b/313582999")
|
||||
@Test
|
||||
public void onClick_mainBtnOfAppsAnomaly_selectHighlightSlot() {
|
||||
final PowerAnomalyEvent appsAnomaly = BatteryTestUtils.createAppAnomalyEvent();
|
||||
@@ -177,6 +220,7 @@ public final class BatteryTipsCardPreferenceTest {
|
||||
when(mPowerUsageAdvanced.findRelatedBatteryDiffEntry(any())).thenReturn(mFakeEntry);
|
||||
|
||||
mPowerUsageAdvanced.onDisplayAnomalyEventUpdated(appsAnomaly, appsAnomaly);
|
||||
assertHighlightSlotIndexPair(1, 0);
|
||||
mBatteryTipsCardPreference.onClick(mFakeView);
|
||||
|
||||
assertThat(mBatteryTipsCardPreference.isVisible()).isFalse();
|
||||
@@ -199,7 +243,6 @@ public final class BatteryTipsCardPreferenceTest {
|
||||
PowerAnomalyKey.KEY_APP_TOTAL_HIGHER_THAN_USUAL.getNumber());
|
||||
}
|
||||
|
||||
@Ignore("b/313582999")
|
||||
@Test
|
||||
public void onClick_dismissBtnOfAppsAnomaly_keepHighlightSlotIndex() {
|
||||
final PowerAnomalyEvent appsAnomaly = BatteryTestUtils.createAppAnomalyEvent();
|
||||
@@ -208,6 +251,7 @@ public final class BatteryTipsCardPreferenceTest {
|
||||
when(mPowerUsageAdvanced.findRelatedBatteryDiffEntry(any())).thenReturn(mFakeEntry);
|
||||
|
||||
mPowerUsageAdvanced.onDisplayAnomalyEventUpdated(appsAnomaly, appsAnomaly);
|
||||
assertHighlightSlotIndexPair(1, 0);
|
||||
mBatteryTipsCardPreference.onClick(mFakeView);
|
||||
|
||||
assertThat(mBatteryTipsCardPreference.isVisible()).isFalse();
|
||||
@@ -229,4 +273,21 @@ public final class BatteryTipsCardPreferenceTest {
|
||||
BatteryTipsController.ANOMALY_KEY,
|
||||
PowerAnomalyKey.KEY_APP_TOTAL_HIGHER_THAN_USUAL.getNumber());
|
||||
}
|
||||
|
||||
private void assertHighlightSlotIndexPair(
|
||||
int dailyHighlightSlotIndex, int hourlyHighlightSlotIndex) {
|
||||
assertThat(mPowerUsageAdvanced.mBatteryLevelData.isPresent()).isTrue();
|
||||
assertThat(mPowerUsageAdvanced.mHighlightEventWrapper.isPresent()).isTrue();
|
||||
Pair<Integer, Integer> slotIndexPair =
|
||||
mPowerUsageAdvanced
|
||||
.mHighlightEventWrapper
|
||||
.get()
|
||||
.getHighlightSlotPair(mPowerUsageAdvanced.mBatteryLevelData.get());
|
||||
assertThat(slotIndexPair)
|
||||
.isEqualTo(Pair.create(dailyHighlightSlotIndex, hourlyHighlightSlotIndex));
|
||||
assertThat(mPowerUsageAdvanced.mBatteryChartPreferenceController.mDailyHighlightSlotIndex)
|
||||
.isEqualTo(dailyHighlightSlotIndex);
|
||||
assertThat(mPowerUsageAdvanced.mBatteryChartPreferenceController.mHourlyHighlightSlotIndex)
|
||||
.isEqualTo(hourlyHighlightSlotIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.hardware.usb.UsbPort;
|
||||
import android.hardware.usb.UsbPortStatus;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.room.Room;
|
||||
|
||||
@@ -71,18 +72,14 @@ public class BatteryTestUtils {
|
||||
BatteryManager.BATTERY_STATUS_DISCHARGING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the work profile mode.
|
||||
*/
|
||||
/** Sets the work profile mode. */
|
||||
public static void setWorkProfile(Context context) {
|
||||
final UserManager userManager = context.getSystemService(UserManager.class);
|
||||
Shadows.shadowOf(userManager).setManagedProfile(true);
|
||||
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) {
|
||||
final BatteryStateDatabase inMemoryDatabase =
|
||||
Room.inMemoryDatabaseBuilder(context, BatteryStateDatabase.class)
|
||||
@@ -92,40 +89,39 @@ public class BatteryTestUtils {
|
||||
return inMemoryDatabase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a fake data into the database for testing.
|
||||
*/
|
||||
/** Inserts a fake data into the database for testing. */
|
||||
public static void insertDataToBatteryStateTable(
|
||||
Context context, long timestamp, String packageName) {
|
||||
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(
|
||||
Context context, long timestamp, String packageName, boolean isFullChargeStart) {
|
||||
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(
|
||||
Context context, long timestamp, String packageName, boolean multiple,
|
||||
Context context,
|
||||
long timestamp,
|
||||
String packageName,
|
||||
boolean multiple,
|
||||
boolean isFullChargeStart) {
|
||||
DeviceBatteryState deviceBatteryState =
|
||||
DeviceBatteryState
|
||||
.newBuilder()
|
||||
DeviceBatteryState.newBuilder()
|
||||
.setBatteryLevel(31)
|
||||
.setBatteryStatus(0)
|
||||
.setBatteryHealth(0)
|
||||
.build();
|
||||
BatteryInformation batteryInformation =
|
||||
BatteryInformation
|
||||
.newBuilder()
|
||||
BatteryInformation.newBuilder()
|
||||
.setDeviceBatteryState(deviceBatteryState)
|
||||
.setIsHidden(true)
|
||||
.setBootTimestamp(timestamp - 1)
|
||||
@@ -145,16 +141,15 @@ public class BatteryTestUtils {
|
||||
|
||||
final BatteryState state =
|
||||
new BatteryState(
|
||||
/*uid=*/ 1001L,
|
||||
/*userId=*/ 100L,
|
||||
/* uid= */ 1001L,
|
||||
/* userId= */ 100L,
|
||||
packageName,
|
||||
timestamp,
|
||||
/*consumerType=*/ 2,
|
||||
/* consumerType= */ 2,
|
||||
isFullChargeStart,
|
||||
ConvertUtils.convertBatteryInformationToString(batteryInformation),
|
||||
"");
|
||||
BatteryStateDao dao =
|
||||
BatteryStateDatabase.getInstance(context).batteryStateDao();
|
||||
BatteryStateDao dao = BatteryStateDatabase.getInstance(context).batteryStateDao();
|
||||
if (multiple) {
|
||||
dao.insertAll(ImmutableList.of(state));
|
||||
} else {
|
||||
@@ -162,31 +157,26 @@ 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(
|
||||
Context context, long userId, long timestamp, String packageName) {
|
||||
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(
|
||||
Context context, long userId, long timestamp, String packageName, boolean multiple) {
|
||||
final AppUsageEventEntity entity =
|
||||
new AppUsageEventEntity(
|
||||
/*uid=*/ 101L,
|
||||
/* uid= */ 101L,
|
||||
userId,
|
||||
timestamp,
|
||||
/*appUsageEventType=*/ 2,
|
||||
/* appUsageEventType= */ 2,
|
||||
packageName,
|
||||
/*instanceId=*/ 10001,
|
||||
/*taskRootPackageName=*/ "com.android.settings");
|
||||
AppUsageEventDao dao =
|
||||
BatteryStateDatabase.getInstance(context).appUsageEventDao();
|
||||
/* instanceId= */ 10001,
|
||||
/* taskRootPackageName= */ "com.android.settings");
|
||||
AppUsageEventDao dao = BatteryStateDatabase.getInstance(context).appUsageEventDao();
|
||||
if (multiple) {
|
||||
dao.insertAll(ImmutableList.of(entity));
|
||||
} else {
|
||||
@@ -194,9 +184,7 @@ 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) {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(BatteryManager.EXTRA_PLUGGED, plugged);
|
||||
@@ -207,9 +195,7 @@ public class BatteryTestUtils {
|
||||
return intent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the incompatible charger environment.
|
||||
*/
|
||||
/** Configures the incompatible charger environment. */
|
||||
public static void setupIncompatibleEvent(
|
||||
UsbPort mockUsbPort, UsbManager mockUsbManager, UsbPortStatus mockUsbPortStatus) {
|
||||
final List<UsbPort> usbPorts = new ArrayList<>();
|
||||
@@ -219,19 +205,15 @@ public class BatteryTestUtils {
|
||||
when(mockUsbPort.supportsComplianceWarnings()).thenReturn(true);
|
||||
when(mockUsbPortStatus.isConnected()).thenReturn(true);
|
||||
when(mockUsbPortStatus.getComplianceWarnings())
|
||||
.thenReturn(new int[]{UsbPortStatus.COMPLIANCE_WARNING_DEBUG_ACCESSORY});
|
||||
.thenReturn(new int[] {UsbPortStatus.COMPLIANCE_WARNING_DEBUG_ACCESSORY});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an empty power anomaly event list proto.
|
||||
*/
|
||||
/** Create an empty power anomaly event list proto. */
|
||||
public static PowerAnomalyEventList createEmptyPowerAnomalyEventList() {
|
||||
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() {
|
||||
return PowerAnomalyEventList.newBuilder()
|
||||
.addPowerAnomalyEvents(0, createAdaptiveBrightnessAnomalyEvent())
|
||||
@@ -239,27 +221,35 @@ public class BatteryTestUtils {
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a power anomaly event proto of adaptive brightness.
|
||||
*/
|
||||
/** Create a power anomaly event proto of adaptive brightness. */
|
||||
public static PowerAnomalyEvent createAdaptiveBrightnessAnomalyEvent() {
|
||||
return createAdaptiveBrightnessAnomalyEvent(false);
|
||||
}
|
||||
|
||||
/** Create a power anomaly event proto of adaptive brightness. */
|
||||
public static PowerAnomalyEvent createAdaptiveBrightnessAnomalyEvent(boolean changeSettings) {
|
||||
WarningBannerInfo.Builder warningBannerInfoBuilder =
|
||||
WarningBannerInfo.newBuilder()
|
||||
.setMainButtonDestination(DisplaySettings.class.getName())
|
||||
.setMainButtonSourceMetricsCategory(SettingsEnums.DISPLAY)
|
||||
.setMainButtonSourceHighlightKey("auto_brightness_entry");
|
||||
if (changeSettings) {
|
||||
warningBannerInfoBuilder
|
||||
.setMainButtonConfigSettingsName(Settings.System.SCREEN_BRIGHTNESS_MODE)
|
||||
.setMainButtonConfigSettingsValue(
|
||||
Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
|
||||
}
|
||||
return PowerAnomalyEvent.newBuilder()
|
||||
.setEventId("BrightnessAnomaly")
|
||||
.setType(PowerAnomalyType.TYPE_SETTINGS_BANNER)
|
||||
.setKey(PowerAnomalyKey.KEY_BRIGHTNESS)
|
||||
.setDismissRecordKey(PowerAnomalyKey.KEY_BRIGHTNESS.name())
|
||||
.setScore(1.2f)
|
||||
.setWarningBannerInfo(WarningBannerInfo.newBuilder()
|
||||
.setMainButtonDestination(DisplaySettings.class.getName())
|
||||
.setMainButtonSourceMetricsCategory(SettingsEnums.DISPLAY)
|
||||
.setMainButtonSourceHighlightKey("auto_brightness_entry")
|
||||
.build())
|
||||
.setWarningBannerInfo(warningBannerInfoBuilder.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a power anomaly event proto of screen timeout.
|
||||
*/
|
||||
/** Create a power anomaly event proto of screen timeout. */
|
||||
public static PowerAnomalyEvent createScreenTimeoutAnomalyEvent() {
|
||||
return PowerAnomalyEvent.newBuilder()
|
||||
.setEventId("ScreenTimeoutAnomaly")
|
||||
@@ -267,17 +257,16 @@ public class BatteryTestUtils {
|
||||
.setKey(PowerAnomalyKey.KEY_SCREEN_TIMEOUT)
|
||||
.setDismissRecordKey(PowerAnomalyKey.KEY_SCREEN_TIMEOUT.name())
|
||||
.setScore(1.1f)
|
||||
.setWarningBannerInfo(WarningBannerInfo.newBuilder()
|
||||
.setMainButtonDestination(ScreenTimeoutSettings.class.getName())
|
||||
.setMainButtonSourceMetricsCategory(SettingsEnums.SCREEN_TIMEOUT)
|
||||
.setMainButtonSourceHighlightKey("60000")
|
||||
.build())
|
||||
.setWarningBannerInfo(
|
||||
WarningBannerInfo.newBuilder()
|
||||
.setMainButtonDestination(ScreenTimeoutSettings.class.getName())
|
||||
.setMainButtonSourceMetricsCategory(SettingsEnums.SCREEN_TIMEOUT)
|
||||
.setMainButtonSourceHighlightKey("60000")
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a power anomaly event proto of app anomaly.
|
||||
*/
|
||||
/** Create a power anomaly event proto of app anomaly. */
|
||||
public static PowerAnomalyEvent createAppAnomalyEvent() {
|
||||
return PowerAnomalyEvent.newBuilder()
|
||||
.setEventId("AppAnomaly")
|
||||
@@ -285,10 +274,11 @@ public class BatteryTestUtils {
|
||||
.setKey(PowerAnomalyKey.KEY_APP_TOTAL_HIGHER_THAN_USUAL)
|
||||
.setDismissRecordKey("KEY_APP_1")
|
||||
.setScore(2.0f)
|
||||
.setWarningItemInfo(WarningItemInfo.newBuilder()
|
||||
.setStartTimestamp(1694361600000L) // 2023-09-11 00:00:00
|
||||
.setEndTimestamp(1694368800000L) // 2023-09-11 02:00:00
|
||||
.build())
|
||||
.setWarningItemInfo(
|
||||
WarningItemInfo.newBuilder()
|
||||
.setStartTimestamp(1694361600000L) // 2023-09-11 00:00:00
|
||||
.setEndTimestamp(1694368800000L) // 2023-09-11 02:00:00
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,293 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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
|
||||
*Visibility_setGoneForPrimaryButton_buttonGroupIsGone
|
||||
* 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.widget;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class CardPreferenceTest {
|
||||
private CardPreference mCardPreference;
|
||||
private PreferenceViewHolder mHolder;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Context context = ApplicationProvider.getApplicationContext();
|
||||
context.setTheme(R.style.Theme_Settings);
|
||||
mCardPreference = new CardPreference(context);
|
||||
mHolder =
|
||||
PreferenceViewHolder.createInstanceForTests(
|
||||
View.inflate(context, R.layout.card_preference_layout, /* parent= */ null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newACardPreference_layoutResourceShouldBeCardPreferenceLayout() {
|
||||
Context context = ApplicationProvider.getApplicationContext();
|
||||
context.setTheme(R.style.SettingsPreferenceTheme);
|
||||
CardPreference cardPreference = new CardPreference(context);
|
||||
assertThat(cardPreference.getLayoutResource()).isEqualTo(R.layout.card_preference_layout);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_noButtonVisible_buttonsLayoutIsGone() {
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
assertThat(getCardPreferenceButtonsView().getVisibility()).isEqualTo(GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_setPrimaryButtonVisibility_buttonsLayoutIsVisible() {
|
||||
mCardPreference.setPrimaryButtonVisible(true);
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
assertThat(getCardPreferenceButtonsView().getVisibility()).isEqualTo(VISIBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_setPrimaryButtonVisibilityToVisible() {
|
||||
mCardPreference.setPrimaryButtonVisible(true);
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
assertThat(getPrimaryButton().getVisibility()).isEqualTo(VISIBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_setSecondaryButtonVisibility_buttonsLayoutIsVisible() {
|
||||
mCardPreference.setSecondaryButtonVisible(true);
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
assertThat(getCardPreferenceButtonsView().getVisibility()).isEqualTo(VISIBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_setSecondaryButtonVisibilityToVisible() {
|
||||
mCardPreference.setSecondaryButtonVisible(true);
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
assertThat(getSecondaryButton().getVisibility()).isEqualTo(VISIBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_setPrimaryButtonTextToExpectedText() {
|
||||
String expectedText = "primary-button";
|
||||
mCardPreference.setPrimaryButtonText(expectedText);
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
assertThat(getPrimaryButton().getText().toString()).isEqualTo(expectedText);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_setSecondaryButtonTextToExpectedText() {
|
||||
String expectedText = "secondary-button";
|
||||
mCardPreference.setSecondaryButtonText(expectedText);
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
assertThat(getSecondaryButton().getText().toString()).isEqualTo(expectedText);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_initialTextForPrimaryButtonShouldBeEmpty() {
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
assertThat(getPrimaryButton().getText().toString()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_initialTextForSecondaryButtonShouldBeEmpty() {
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
assertThat(getSecondaryButton().getText().toString()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void performClickOnPrimaryButton_callClickListener() {
|
||||
final boolean[] hasCalled = {false};
|
||||
View.OnClickListener clickListener = v -> hasCalled[0] = true;
|
||||
mCardPreference.setPrimaryButtonClickListener(clickListener);
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
getPrimaryButton().performClick();
|
||||
assertThat(hasCalled[0]).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void performClickOnSecondaryButton_callClickListener() {
|
||||
final boolean[] hasCalled = {false};
|
||||
View.OnClickListener clickListener = v -> hasCalled[0] = true;
|
||||
mCardPreference.setSecondaryButtonClickListener(clickListener);
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
getSecondaryButton().performClick();
|
||||
assertThat(hasCalled[0]).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_primaryButtonDefaultIsGone() {
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
assertThat(getPrimaryButton().getVisibility()).isEqualTo(GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_secondaryButtonDefaultIsGone() {
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
assertThat(getSecondaryButton().getVisibility()).isEqualTo(GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setPrimaryButtonVisibility_setTrueAfterBindViewHolder_isVisible() {
|
||||
mCardPreference.setPrimaryButtonVisible(false);
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
mCardPreference.setPrimaryButtonVisible(true);
|
||||
assertThat(getPrimaryButton().getVisibility()).isEqualTo(VISIBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setPrimaryButtonText_setAfterBindViewHolder_setOnUi() {
|
||||
String expectedText = "123456";
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
mCardPreference.setPrimaryButtonText(expectedText);
|
||||
assertThat(getPrimaryButton().getText().toString()).isEqualTo(expectedText);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setPrimaryButtonText_setNull_isEmptyText() {
|
||||
final String emptyString = "";
|
||||
mCardPreference.setPrimaryButtonText("1234");
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
mCardPreference.setPrimaryButtonText(null);
|
||||
assertThat(getPrimaryButton().getText().toString()).isEqualTo(emptyString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setPrimaryButtonClickListener_setAfterOnBindViewHolder() {
|
||||
final String[] hasCalled = {""};
|
||||
String expectedClickedResult = "was called";
|
||||
View.OnClickListener clickListener = v -> hasCalled[0] = expectedClickedResult;
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
mCardPreference.setPrimaryButtonClickListener(clickListener);
|
||||
getPrimaryButton().performClick();
|
||||
assertThat(hasCalled[0]).isEqualTo(expectedClickedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setPrimaryButtonClickListener_setNull_clearTheOnClickListener() {
|
||||
final String[] hasCalled = {"not called"};
|
||||
View.OnClickListener clickListener = v -> hasCalled[0] = "called once";
|
||||
mCardPreference.setPrimaryButtonClickListener(clickListener);
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
mCardPreference.setPrimaryButtonClickListener(null);
|
||||
getPrimaryButton().performClick();
|
||||
assertThat(hasCalled[0]).isEqualTo("not called");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSecondaryButtonVisibility_setTrueAfterBindViewHolder_isVisible() {
|
||||
mCardPreference.setSecondaryButtonVisible(false);
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
mCardPreference.setSecondaryButtonVisible(true);
|
||||
assertThat(getSecondaryButton().getVisibility()).isEqualTo(VISIBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSecondaryButtonText_setAfterBindViewHolder_setOnUi() {
|
||||
String expectedText = "10101010";
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
mCardPreference.setSecondaryButtonText(expectedText);
|
||||
assertThat(getSecondaryButton().getText().toString()).isEqualTo(expectedText);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSecondaryButtonText_setNull_isEmptyText() {
|
||||
String emptyString = "";
|
||||
mCardPreference.setSecondaryButtonText("1234");
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
mCardPreference.setSecondaryButtonText(null);
|
||||
assertThat(getSecondaryButton().getText().toString()).isEqualTo(emptyString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSecondaryButtonClickListener_setAfterOnBindViewHolder() {
|
||||
final String[] hasCalled = {""};
|
||||
String expectedClickedResult = "2nd was called";
|
||||
View.OnClickListener clickListener = v -> hasCalled[0] = expectedClickedResult;
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
mCardPreference.setSecondaryButtonClickListener(clickListener);
|
||||
getSecondaryButton().performClick();
|
||||
assertThat(hasCalled[0]).isEqualTo(expectedClickedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSecondaryButtonClickListener_setNull_clearTheOnClickListener() {
|
||||
final String[] hasCalled = {"not called"};
|
||||
View.OnClickListener clickListener = v -> hasCalled[0] = "called once";
|
||||
mCardPreference.setSecondaryButtonClickListener(clickListener);
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
mCardPreference.setSecondaryButtonClickListener(null);
|
||||
getSecondaryButton().performClick();
|
||||
assertThat(hasCalled[0]).isEqualTo("not called");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setPrimaryButtonVisibility_setGoneForSecondaryButton_buttonGroupIsGone() {
|
||||
mCardPreference.setPrimaryButtonVisible(true);
|
||||
mCardPreference.setSecondaryButtonVisible(false);
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
assertWithMessage("PreCondition: buttonsView should be Visible")
|
||||
.that(getCardPreferenceButtonsView().getVisibility())
|
||||
.isEqualTo(VISIBLE);
|
||||
mCardPreference.setPrimaryButtonVisible(false);
|
||||
assertThat(getCardPreferenceButtonsView().getVisibility()).isEqualTo(GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSecondaryButtonVisibility_setGoneForPrimaryButton_buttonGroupIsGone() {
|
||||
mCardPreference.setPrimaryButtonVisible(false);
|
||||
mCardPreference.setSecondaryButtonVisible(true);
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
assertWithMessage("PreCondition: buttonsView should be Visible")
|
||||
.that(getCardPreferenceButtonsView().getVisibility())
|
||||
.isEqualTo(VISIBLE);
|
||||
mCardPreference.setSecondaryButtonVisible(false);
|
||||
assertThat(getCardPreferenceButtonsView().getVisibility()).isEqualTo(GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resetLayoutState_buttonGroupIsGone() {
|
||||
mCardPreference.setPrimaryButtonVisible(true);
|
||||
mCardPreference.setSecondaryButtonVisible(true);
|
||||
mCardPreference.onBindViewHolder(mHolder);
|
||||
mCardPreference.resetLayoutState();
|
||||
assertThat(getCardPreferenceButtonsView().getVisibility()).isEqualTo(GONE);
|
||||
}
|
||||
|
||||
private View getCardPreferenceButtonsView() {
|
||||
return mHolder.findViewById(R.id.card_preference_buttons);
|
||||
}
|
||||
|
||||
private Button getPrimaryButton() {
|
||||
return (Button) mHolder.findViewById(android.R.id.button1);
|
||||
}
|
||||
|
||||
private Button getSecondaryButton() {
|
||||
return (Button) mHolder.findViewById(android.R.id.button2);
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class CardPreferenceTest {
|
||||
class TipCardPreferenceTest {
|
||||
|
||||
@get:Rule val composeTestRule = createComposeRule()
|
||||
private lateinit var context: Context
|
||||
@@ -179,7 +179,7 @@ class CardPreferenceTest {
|
||||
fun resetLayoutState_shouldRemoveThePrimaryButton() {
|
||||
val buttonText = "9527"
|
||||
val cardPreference =
|
||||
CardPreference(context)
|
||||
TipCardPreference(context)
|
||||
.apply {
|
||||
primaryButtonText = buttonText
|
||||
primaryButtonVisibility = true
|
||||
@@ -196,7 +196,7 @@ class CardPreferenceTest {
|
||||
fun resetLayoutState_shouldRemoveTheSecondaryButton() {
|
||||
val buttonText = "4567"
|
||||
val cardPreference =
|
||||
CardPreference(context)
|
||||
TipCardPreference(context)
|
||||
.apply {
|
||||
secondaryButtonText = buttonText
|
||||
secondaryButtonVisibility = true
|
||||
@@ -222,7 +222,7 @@ class CardPreferenceTest {
|
||||
secondaryButtonVisibility: Boolean = false,
|
||||
enableDismiss: Boolean = true,
|
||||
) =
|
||||
CardPreference(context)
|
||||
TipCardPreference(context)
|
||||
.apply {
|
||||
this.iconResId = iconResId
|
||||
this.primaryButtonText = primaryButtonText
|
||||
@@ -421,6 +421,30 @@ public class PrivateSpaceMaintainerTest {
|
||||
assertThat(privateSpaceMaintainer.isPrivateSpaceEntryPointEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createPrivateSpace_psDoesNotExist_setsSkipFirstUseHints() {
|
||||
mSetFlagsRule.enableFlags(
|
||||
android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES);
|
||||
assumeTrue(mContext.getSystemService(UserManager.class).canAddPrivateProfile());
|
||||
PrivateSpaceMaintainer privateSpaceMaintainer =
|
||||
PrivateSpaceMaintainer.getInstance(mContext);
|
||||
privateSpaceMaintainer.createPrivateSpace();
|
||||
assertThat(getSecureSkipFirstUseHints()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createPrivateSpace_pSExists_doesNotChangeSkipFirstUseHints() {
|
||||
mSetFlagsRule.enableFlags(
|
||||
android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES);
|
||||
assumeTrue(mContext.getSystemService(UserManager.class).canAddPrivateProfile());
|
||||
PrivateSpaceMaintainer privateSpaceMaintainer =
|
||||
PrivateSpaceMaintainer.getInstance(mContext);
|
||||
privateSpaceMaintainer.createPrivateSpace();
|
||||
assertThat(getSecureSkipFirstUseHints()).isEqualTo(1);
|
||||
privateSpaceMaintainer.createPrivateSpace();
|
||||
assertThat(getSecureSkipFirstUseHints()).isEqualTo(1);
|
||||
}
|
||||
|
||||
private int getSecureUserSetupComplete() {
|
||||
PrivateSpaceMaintainer privateSpaceMaintainer =
|
||||
PrivateSpaceMaintainer.getInstance(mContext);
|
||||
@@ -431,6 +455,16 @@ public class PrivateSpaceMaintainerTest {
|
||||
privateSpaceMaintainer.getPrivateProfileHandle().getIdentifier());
|
||||
}
|
||||
|
||||
private int getSecureSkipFirstUseHints() {
|
||||
PrivateSpaceMaintainer privateSpaceMaintainer =
|
||||
PrivateSpaceMaintainer.getInstance(mContext);
|
||||
return Settings.Secure.getIntForUser(
|
||||
mContentResolver,
|
||||
Settings.Secure.SKIP_FIRST_USE_HINTS,
|
||||
0,
|
||||
privateSpaceMaintainer.getPrivateProfileHandle().getIdentifier());
|
||||
}
|
||||
|
||||
private int getPsSensitiveNotificationsValue(PrivateSpaceMaintainer privateSpaceMaintainer) {
|
||||
return Settings.Secure.getIntForUser(mContentResolver,
|
||||
LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
|
||||
|
||||
Reference in New Issue
Block a user