Snap for 12212122 from c98fd48306
to 24Q4-release
Change-Id: Ifa844ca0cb48d9dd061c8bd4236bd1b5d2326a13
This commit is contained in:
@@ -28,11 +28,13 @@ import android.content.Intent;
|
|||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
|
import android.provider.Settings;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import androidx.annotation.ColorInt;
|
import androidx.annotation.ColorInt;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.fragment.app.DialogFragment;
|
import androidx.fragment.app.DialogFragment;
|
||||||
|
|
||||||
@@ -40,8 +42,6 @@ import com.android.settings.R;
|
|||||||
|
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DialogFragment for Screen flash notification color picker.
|
* DialogFragment for Screen flash notification color picker.
|
||||||
@@ -49,29 +49,33 @@ import java.util.function.Consumer;
|
|||||||
public class ScreenFlashNotificationColorDialogFragment extends DialogFragment implements
|
public class ScreenFlashNotificationColorDialogFragment extends DialogFragment implements
|
||||||
ColorSelectorLayout.OnCheckedChangeListener {
|
ColorSelectorLayout.OnCheckedChangeListener {
|
||||||
|
|
||||||
|
private static final int DEFAULT_COLOR = Color.TRANSPARENT;
|
||||||
private static final int PREVIEW_LONG_TIME_MS = 5000;
|
private static final int PREVIEW_LONG_TIME_MS = 5000;
|
||||||
private static final int BETWEEN_STOP_AND_START_DELAY_MS = 250;
|
private static final int BETWEEN_STOP_AND_START_DELAY_MS = 250;
|
||||||
private static final int MARGIN_FOR_STOP_DELAY_MS = 100;
|
private static final int MARGIN_FOR_STOP_DELAY_MS = 100;
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
static final String EXTRA_COLOR = "extra_color";
|
||||||
@ColorInt
|
@ColorInt
|
||||||
private int mCurrentColor = Color.TRANSPARENT;
|
private int mCurrentColor = DEFAULT_COLOR;
|
||||||
private Consumer<Integer> mConsumer;
|
|
||||||
|
|
||||||
private Timer mTimer = null;
|
private Timer mTimer = null;
|
||||||
private Boolean mIsPreview = false;
|
private Boolean mIsPreview = false;
|
||||||
|
|
||||||
static ScreenFlashNotificationColorDialogFragment getInstance(int initialColor,
|
static ScreenFlashNotificationColorDialogFragment getInstance(int initialColor) {
|
||||||
Consumer<Integer> colorConsumer) {
|
|
||||||
final ScreenFlashNotificationColorDialogFragment result =
|
final ScreenFlashNotificationColorDialogFragment result =
|
||||||
new ScreenFlashNotificationColorDialogFragment();
|
new ScreenFlashNotificationColorDialogFragment();
|
||||||
result.mCurrentColor = initialColor;
|
Bundle bundle = new Bundle();
|
||||||
result.mConsumer = colorConsumer != null ? colorConsumer : i -> {};
|
bundle.putInt(EXTRA_COLOR, initialColor);
|
||||||
|
result.setArguments(bundle);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||||
|
mCurrentColor = getArguments().getInt(EXTRA_COLOR, DEFAULT_COLOR);
|
||||||
|
|
||||||
final View dialogView = getLayoutInflater().inflate(R.layout.layout_color_selector_dialog,
|
final View dialogView = getLayoutInflater().inflate(R.layout.layout_color_selector_dialog,
|
||||||
null);
|
null);
|
||||||
|
|
||||||
@@ -90,7 +94,8 @@ public class ScreenFlashNotificationColorDialogFragment extends DialogFragment i
|
|||||||
})
|
})
|
||||||
.setPositiveButton(R.string.color_selector_dialog_save, (dialog, which) -> {
|
.setPositiveButton(R.string.color_selector_dialog_save, (dialog, which) -> {
|
||||||
mCurrentColor = colorSelectorLayout.getCheckedColor(DEFAULT_SCREEN_FLASH_COLOR);
|
mCurrentColor = colorSelectorLayout.getCheckedColor(DEFAULT_SCREEN_FLASH_COLOR);
|
||||||
mConsumer.accept(mCurrentColor);
|
Settings.System.putInt(getContext().getContentResolver(),
|
||||||
|
Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR, mCurrentColor);
|
||||||
})
|
})
|
||||||
.create();
|
.create();
|
||||||
createdDialog.setOnShowListener(
|
createdDialog.setOnShowListener(
|
||||||
|
@@ -21,10 +21,17 @@ import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
|||||||
import static com.android.settings.accessibility.FlashNotificationsUtil.DEFAULT_SCREEN_FLASH_COLOR;
|
import static com.android.settings.accessibility.FlashNotificationsUtil.DEFAULT_SCREEN_FLASH_COLOR;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.database.ContentObserver;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Handler;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.lifecycle.DefaultLifecycleObserver;
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
@@ -32,24 +39,37 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.core.TogglePreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller for Screen flash notification.
|
* Controller for Screen flash notification.
|
||||||
*/
|
*/
|
||||||
public class ScreenFlashNotificationPreferenceController extends TogglePreferenceController {
|
public class ScreenFlashNotificationPreferenceController extends
|
||||||
|
TogglePreferenceController implements DefaultLifecycleObserver {
|
||||||
|
|
||||||
|
private final FlashNotificationColorContentObserver mFlashNotificationColorContentObserver;
|
||||||
|
|
||||||
private Fragment mParentFragment;
|
private Fragment mParentFragment;
|
||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
|
|
||||||
public ScreenFlashNotificationPreferenceController(Context context, String preferenceKey) {
|
public ScreenFlashNotificationPreferenceController(Context context, String preferenceKey) {
|
||||||
super(context, preferenceKey);
|
super(context, preferenceKey);
|
||||||
|
mFlashNotificationColorContentObserver = new FlashNotificationColorContentObserver(
|
||||||
|
new Handler(mContext.getMainLooper()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setParentFragment(Fragment parentFragment) {
|
public void setParentFragment(Fragment parentFragment) {
|
||||||
this.mParentFragment = parentFragment;
|
this.mParentFragment = parentFragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart(@NonNull LifecycleOwner owner) {
|
||||||
|
mFlashNotificationColorContentObserver.register(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop(@NonNull LifecycleOwner owner) {
|
||||||
|
mFlashNotificationColorContentObserver.unregister(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public int getAvailabilityStatus() {
|
||||||
return AVAILABLE;
|
return AVAILABLE;
|
||||||
@@ -100,14 +120,8 @@ public class ScreenFlashNotificationPreferenceController extends TogglePreferenc
|
|||||||
Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR,
|
Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR,
|
||||||
DEFAULT_SCREEN_FLASH_COLOR);
|
DEFAULT_SCREEN_FLASH_COLOR);
|
||||||
|
|
||||||
final Consumer<Integer> consumer = color -> {
|
|
||||||
Settings.System.putInt(mContext.getContentResolver(),
|
|
||||||
Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR, color);
|
|
||||||
refreshColorSummary();
|
|
||||||
};
|
|
||||||
|
|
||||||
ScreenFlashNotificationColorDialogFragment
|
ScreenFlashNotificationColorDialogFragment
|
||||||
.getInstance(initialColor, consumer)
|
.getInstance(initialColor)
|
||||||
.show(mParentFragment.getParentFragmentManager(),
|
.show(mParentFragment.getParentFragmentManager(),
|
||||||
ScreenFlashNotificationColorDialogFragment.class.getSimpleName());
|
ScreenFlashNotificationColorDialogFragment.class.getSimpleName());
|
||||||
return true;
|
return true;
|
||||||
@@ -128,4 +142,37 @@ public class ScreenFlashNotificationPreferenceController extends TogglePreferenc
|
|||||||
private void refreshColorSummary() {
|
private void refreshColorSummary() {
|
||||||
if (mPreference != null) mPreference.setSummary(getSummary());
|
if (mPreference != null) mPreference.setSummary(getSummary());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final class FlashNotificationColorContentObserver extends ContentObserver {
|
||||||
|
private final Uri mColorUri = Settings.System.getUriFor(
|
||||||
|
Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR);
|
||||||
|
|
||||||
|
FlashNotificationColorContentObserver(Handler handler) {
|
||||||
|
super(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register this observer to given {@link Context}, to be called from lifecycle
|
||||||
|
* {@code onStart} method.
|
||||||
|
*/
|
||||||
|
public void register(@NonNull Context context) {
|
||||||
|
context.getContentResolver().registerContentObserver(
|
||||||
|
mColorUri, /* notifyForDescendants= */ false, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unregister this observer from given {@link Context}, to be called from lifecycle
|
||||||
|
* {@code onStop} method.
|
||||||
|
*/
|
||||||
|
public void unregister(@NonNull Context context) {
|
||||||
|
context.getContentResolver().unregisterContentObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChange(boolean selfChange, @Nullable Uri uri) {
|
||||||
|
if (mColorUri.equals(uri)) {
|
||||||
|
refreshColorSummary();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,6 @@ package com.android.settings.password;
|
|||||||
import static android.hardware.biometrics.BiometricConstants.BIOMETRIC_ERROR_USER_CANCELED;
|
import static android.hardware.biometrics.BiometricConstants.BIOMETRIC_ERROR_USER_CANCELED;
|
||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.hardware.biometrics.BiometricManager;
|
import android.hardware.biometrics.BiometricManager;
|
||||||
import android.hardware.biometrics.BiometricPrompt;
|
import android.hardware.biometrics.BiometricPrompt;
|
||||||
import android.hardware.biometrics.BiometricPrompt.AuthenticationCallback;
|
import android.hardware.biometrics.BiometricPrompt.AuthenticationCallback;
|
||||||
@@ -44,7 +43,6 @@ public class BiometricFragment extends InstrumentedFragment {
|
|||||||
private static final String TAG = "ConfirmDeviceCredential/BiometricFragment";
|
private static final String TAG = "ConfirmDeviceCredential/BiometricFragment";
|
||||||
|
|
||||||
private static final String KEY_PROMPT_INFO = "prompt_info";
|
private static final String KEY_PROMPT_INFO = "prompt_info";
|
||||||
private static final String KEY_CALLING_ACTIVITY = "calling_activity";
|
|
||||||
|
|
||||||
// Re-set by the application. Should be done upon orientation changes, etc
|
// Re-set by the application. Should be done upon orientation changes, etc
|
||||||
private Executor mClientExecutor;
|
private Executor mClientExecutor;
|
||||||
@@ -94,13 +92,10 @@ public class BiometricFragment extends InstrumentedFragment {
|
|||||||
* @param promptInfo
|
* @param promptInfo
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static BiometricFragment newInstance(PromptInfo promptInfo,
|
public static BiometricFragment newInstance(PromptInfo promptInfo) {
|
||||||
ComponentName callingActivity) {
|
|
||||||
BiometricFragment biometricFragment = new BiometricFragment();
|
BiometricFragment biometricFragment = new BiometricFragment();
|
||||||
final Bundle bundle = new Bundle();
|
final Bundle bundle = new Bundle();
|
||||||
bundle.putParcelable(KEY_PROMPT_INFO, promptInfo);
|
bundle.putParcelable(KEY_PROMPT_INFO, promptInfo);
|
||||||
|
|
||||||
bundle.putParcelable(KEY_CALLING_ACTIVITY, callingActivity);
|
|
||||||
biometricFragment.setArguments(bundle);
|
biometricFragment.setArguments(bundle);
|
||||||
return biometricFragment;
|
return biometricFragment;
|
||||||
}
|
}
|
||||||
@@ -135,8 +130,6 @@ public class BiometricFragment extends InstrumentedFragment {
|
|||||||
|
|
||||||
final Bundle bundle = getArguments();
|
final Bundle bundle = getArguments();
|
||||||
final PromptInfo promptInfo = bundle.getParcelable(KEY_PROMPT_INFO);
|
final PromptInfo promptInfo = bundle.getParcelable(KEY_PROMPT_INFO);
|
||||||
final ComponentName callingActivity = bundle.getParcelable(KEY_CALLING_ACTIVITY);
|
|
||||||
|
|
||||||
BiometricPrompt.Builder promptBuilder = new BiometricPrompt.Builder(getContext())
|
BiometricPrompt.Builder promptBuilder = new BiometricPrompt.Builder(getContext())
|
||||||
.setTitle(promptInfo.getTitle())
|
.setTitle(promptInfo.getTitle())
|
||||||
.setUseDefaultTitle() // use default title if title is null/empty
|
.setUseDefaultTitle() // use default title if title is null/empty
|
||||||
@@ -152,7 +145,8 @@ public class BiometricFragment extends InstrumentedFragment {
|
|||||||
promptInfo.isDisallowBiometricsIfPolicyExists())
|
promptInfo.isDisallowBiometricsIfPolicyExists())
|
||||||
.setShowEmergencyCallButton(promptInfo.isShowEmergencyCallButton())
|
.setShowEmergencyCallButton(promptInfo.isShowEmergencyCallButton())
|
||||||
.setReceiveSystemEvents(true)
|
.setReceiveSystemEvents(true)
|
||||||
.setComponentNameForConfirmDeviceCredentialActivity(callingActivity);
|
.setRealCallerForConfirmDeviceCredentialActivity(
|
||||||
|
promptInfo.getRealCallerForConfirmDeviceCredentialActivity());
|
||||||
if (promptInfo.getLogoRes() != 0){
|
if (promptInfo.getLogoRes() != 0){
|
||||||
promptBuilder.setLogoRes(promptInfo.getLogoRes());
|
promptBuilder.setLogoRes(promptInfo.getLogoRes());
|
||||||
}
|
}
|
||||||
|
@@ -238,6 +238,7 @@ public class ConfirmDeviceCredentialActivity extends FragmentActivity {
|
|||||||
promptInfo.setDisallowBiometricsIfPolicyExists(mCheckDevicePolicyManager);
|
promptInfo.setDisallowBiometricsIfPolicyExists(mCheckDevicePolicyManager);
|
||||||
promptInfo.setAuthenticators(mBiometricsAuthenticators);
|
promptInfo.setAuthenticators(mBiometricsAuthenticators);
|
||||||
promptInfo.setNegativeButtonText(negativeButtonText);
|
promptInfo.setNegativeButtonText(negativeButtonText);
|
||||||
|
promptInfo.setRealCallerForConfirmDeviceCredentialActivity(getCallingActivity());
|
||||||
|
|
||||||
if (android.multiuser.Flags.enablePrivateSpaceFeatures()
|
if (android.multiuser.Flags.enablePrivateSpaceFeatures()
|
||||||
&& android.multiuser.Flags.usePrivateSpaceIconInBiometricPrompt()
|
&& android.multiuser.Flags.usePrivateSpaceIconInBiometricPrompt()
|
||||||
@@ -503,8 +504,7 @@ public class ConfirmDeviceCredentialActivity extends FragmentActivity {
|
|||||||
boolean newFragment = false;
|
boolean newFragment = false;
|
||||||
|
|
||||||
if (mBiometricFragment == null) {
|
if (mBiometricFragment == null) {
|
||||||
mBiometricFragment = BiometricFragment.newInstance(promptInfo,
|
mBiometricFragment = BiometricFragment.newInstance(promptInfo);
|
||||||
getCallingActivity());
|
|
||||||
newFragment = true;
|
newFragment = true;
|
||||||
}
|
}
|
||||||
mBiometricFragment.setCallbacks(mExecutor, mAuthenticationCallback);
|
mBiometricFragment.setCallbacks(mExecutor, mAuthenticationCallback);
|
||||||
|
@@ -37,10 +37,13 @@ import static org.robolectric.Shadows.shadowOf;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.fragment.app.testing.FragmentScenario;
|
import androidx.fragment.app.testing.FragmentScenario;
|
||||||
import androidx.lifecycle.Lifecycle;
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.testutils.FakeTimer;
|
import com.android.settings.testutils.FakeTimer;
|
||||||
@@ -56,23 +59,26 @@ import org.robolectric.util.ReflectionHelpers;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class ScreenFlashNotificationColorDialogFragmentTest {
|
public class ScreenFlashNotificationColorDialogFragmentTest {
|
||||||
|
|
||||||
|
private static final int DEFAULT_COLOR = ROSE.mColorInt;
|
||||||
|
|
||||||
private FragmentScenario<TestScreenFlashNotificationColorDialogFragment> mFragmentScenario;
|
private FragmentScenario<TestScreenFlashNotificationColorDialogFragment> mFragmentScenario;
|
||||||
private ScreenFlashNotificationColorDialogFragment mDialogFragment;
|
private ScreenFlashNotificationColorDialogFragment mDialogFragment;
|
||||||
private AlertDialog mAlertDialog;
|
private AlertDialog mAlertDialog;
|
||||||
private ColorSelectorLayout mColorSelectorLayout;
|
private ColorSelectorLayout mColorSelectorLayout;
|
||||||
private int mCurrentColor;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mCurrentColor = ROSE.mColorInt;
|
Settings.System.putInt(ApplicationProvider.getApplicationContext().getContentResolver(),
|
||||||
|
Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR, DEFAULT_COLOR);
|
||||||
|
Bundle fragmentArgs = new Bundle();
|
||||||
|
fragmentArgs.putInt(ScreenFlashNotificationColorDialogFragment.EXTRA_COLOR, DEFAULT_COLOR);
|
||||||
mFragmentScenario = FragmentScenario.launch(
|
mFragmentScenario = FragmentScenario.launch(
|
||||||
TestScreenFlashNotificationColorDialogFragment.class,
|
TestScreenFlashNotificationColorDialogFragment.class,
|
||||||
/* fragmentArgs= */ null,
|
fragmentArgs,
|
||||||
R.style.Theme_AlertDialog_SettingsLib,
|
R.style.Theme_AlertDialog_SettingsLib,
|
||||||
Lifecycle.State.INITIALIZED);
|
Lifecycle.State.INITIALIZED);
|
||||||
setupFragment();
|
setupFragment();
|
||||||
@@ -99,7 +105,7 @@ public class ScreenFlashNotificationColorDialogFragmentTest {
|
|||||||
performClickOnDialog(BUTTON_NEUTRAL);
|
performClickOnDialog(BUTTON_NEUTRAL);
|
||||||
getTimerFromFragment().runOneTask();
|
getTimerFromFragment().runOneTask();
|
||||||
|
|
||||||
assertStartPreview(ROSE.mColorInt);
|
assertStartPreview(DEFAULT_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -168,20 +174,26 @@ public class ScreenFlashNotificationColorDialogFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void clickColorAndClickNegative_assertColor() {
|
public void clickColorAndClickNegative_assertDefaultColor() {
|
||||||
checkColorButton(AZURE);
|
checkColorButton(AZURE);
|
||||||
performClickOnDialog(BUTTON_NEGATIVE);
|
performClickOnDialog(BUTTON_NEGATIVE);
|
||||||
|
|
||||||
assertThat(getTimerFromFragment()).isNull();
|
assertThat(getTimerFromFragment()).isNull();
|
||||||
assertThat(mCurrentColor).isEqualTo(ROSE.mColorInt);
|
assertThat(Settings.System.getInt(
|
||||||
|
ApplicationProvider.getApplicationContext().getContentResolver(),
|
||||||
|
Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR, AZURE.mColorInt)).isEqualTo(
|
||||||
|
DEFAULT_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void clickColorAndClickPositive_assertColor() {
|
public void clickColorAndClickPositive_assertSameColor() {
|
||||||
checkColorButton(BLUE);
|
checkColorButton(BLUE);
|
||||||
performClickOnDialog(BUTTON_POSITIVE);
|
performClickOnDialog(BUTTON_POSITIVE);
|
||||||
|
|
||||||
assertThat(mCurrentColor).isEqualTo(BLUE.mColorInt);
|
assertThat(Settings.System.getInt(
|
||||||
|
ApplicationProvider.getApplicationContext().getContentResolver(),
|
||||||
|
Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR, DEFAULT_COLOR)).isEqualTo(
|
||||||
|
BLUE.mColorInt);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkColorButton(ScreenFlashNotificationColor color) {
|
private void checkColorButton(ScreenFlashNotificationColor color) {
|
||||||
@@ -201,11 +213,6 @@ public class ScreenFlashNotificationColorDialogFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setupFragment() {
|
private void setupFragment() {
|
||||||
mFragmentScenario.onFragment(fragment -> {
|
|
||||||
ReflectionHelpers.setField(fragment, "mCurrentColor", mCurrentColor);
|
|
||||||
ReflectionHelpers.setField(fragment, "mConsumer",
|
|
||||||
(Consumer<Integer>) selectedColor -> mCurrentColor = selectedColor);
|
|
||||||
});
|
|
||||||
mFragmentScenario.moveToState(Lifecycle.State.RESUMED);
|
mFragmentScenario.moveToState(Lifecycle.State.RESUMED);
|
||||||
|
|
||||||
mFragmentScenario.onFragment(fragment -> {
|
mFragmentScenario.onFragment(fragment -> {
|
||||||
|
@@ -57,8 +57,6 @@ import org.robolectric.annotation.Implementation;
|
|||||||
import org.robolectric.annotation.Implements;
|
import org.robolectric.annotation.Implements;
|
||||||
import org.robolectric.annotation.Resetter;
|
import org.robolectric.annotation.Resetter;
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@Config(shadows = {
|
@Config(shadows = {
|
||||||
ScreenFlashNotificationPreferenceControllerTest
|
ScreenFlashNotificationPreferenceControllerTest
|
||||||
@@ -83,7 +81,6 @@ public class ScreenFlashNotificationPreferenceControllerTest {
|
|||||||
private FragmentManager mFragmentManager;
|
private FragmentManager mFragmentManager;
|
||||||
@Mock
|
@Mock
|
||||||
private ScreenFlashNotificationColorDialogFragment mDialogFragment;
|
private ScreenFlashNotificationColorDialogFragment mDialogFragment;
|
||||||
|
|
||||||
private ScreenFlashNotificationPreferenceController mController;
|
private ScreenFlashNotificationPreferenceController mController;
|
||||||
private ContentResolver mContentResolver;
|
private ContentResolver mContentResolver;
|
||||||
|
|
||||||
@@ -92,6 +89,7 @@ public class ScreenFlashNotificationPreferenceControllerTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
FragmentActivity fragmentActivity = Robolectric.setupActivity(FragmentActivity.class);
|
FragmentActivity fragmentActivity = Robolectric.setupActivity(FragmentActivity.class);
|
||||||
Context context = fragmentActivity.getApplicationContext();
|
Context context = fragmentActivity.getApplicationContext();
|
||||||
|
|
||||||
ShadowScreenFlashNotificationColorDialogFragment.setInstance(mDialogFragment);
|
ShadowScreenFlashNotificationColorDialogFragment.setInstance(mDialogFragment);
|
||||||
ShadowFlashNotificationsUtils.setColorDescriptionText(COLOR_DESCRIPTION_TEXT);
|
ShadowFlashNotificationsUtils.setColorDescriptionText(COLOR_DESCRIPTION_TEXT);
|
||||||
|
|
||||||
@@ -99,8 +97,9 @@ public class ScreenFlashNotificationPreferenceControllerTest {
|
|||||||
mController = new ScreenFlashNotificationPreferenceController(context, PREFERENCE_KEY);
|
mController = new ScreenFlashNotificationPreferenceController(context, PREFERENCE_KEY);
|
||||||
when(mPreferenceScreen.findPreference(PREFERENCE_KEY)).thenReturn(mPreference);
|
when(mPreferenceScreen.findPreference(PREFERENCE_KEY)).thenReturn(mPreference);
|
||||||
when(mPreference.getKey()).thenReturn(PREFERENCE_KEY);
|
when(mPreference.getKey()).thenReturn(PREFERENCE_KEY);
|
||||||
mController.setParentFragment(mParentFragment);
|
|
||||||
when(mParentFragment.getParentFragmentManager()).thenReturn(mFragmentManager);
|
when(mParentFragment.getParentFragmentManager()).thenReturn(mFragmentManager);
|
||||||
|
|
||||||
|
mController.setParentFragment(mParentFragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
@@ -181,6 +180,7 @@ public class ScreenFlashNotificationPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void handlePreferenceTreeClick() {
|
public void handlePreferenceTreeClick() {
|
||||||
mController.handlePreferenceTreeClick(mPreference);
|
mController.handlePreferenceTreeClick(mPreference);
|
||||||
|
|
||||||
verify(mDialogFragment).show(any(FragmentManager.class), anyString());
|
verify(mDialogFragment).show(any(FragmentManager.class), anyString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +194,7 @@ public class ScreenFlashNotificationPreferenceControllerTest {
|
|||||||
|
|
||||||
@Implementation
|
@Implementation
|
||||||
protected static ScreenFlashNotificationColorDialogFragment getInstance(
|
protected static ScreenFlashNotificationColorDialogFragment getInstance(
|
||||||
int initialColor, Consumer<Integer> colorConsumer) {
|
int initialColor) {
|
||||||
return sInstance;
|
return sInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -50,6 +50,7 @@ import org.robolectric.shadows.ShadowLooper;
|
|||||||
import org.robolectric.shadows.ShadowPausedAsyncTask;
|
import org.robolectric.shadows.ShadowPausedAsyncTask;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@@ -185,12 +186,7 @@ public class AppChannelsBypassingDndPreferenceControllerTest {
|
|||||||
NotificationManager.IMPORTANCE_DEFAULT));
|
NotificationManager.IMPORTANCE_DEFAULT));
|
||||||
|
|
||||||
ParceledListSlice<NotificationChannelGroup> groups = new ParceledListSlice<>(
|
ParceledListSlice<NotificationChannelGroup> groups = new ParceledListSlice<>(
|
||||||
new ArrayList<NotificationChannelGroup>() {
|
Arrays.asList(group1, group2)
|
||||||
{
|
|
||||||
add(group1);
|
|
||||||
add(group2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
when(mBackend.getGroups(eq(mAppRow.pkg), eq(mAppRow.uid))).thenReturn(groups);
|
when(mBackend.getGroups(eq(mAppRow.pkg), eq(mAppRow.uid))).thenReturn(groups);
|
||||||
|
Reference in New Issue
Block a user