Use system day/night to switch theme instead of from intent extra.

Use value-night to give theme instead of directly from intent extra when Setup day/nNight mode enabled and in Setup flow

Before:
<vision settings>
https://hsv.googleplex.com/4837266235064320
<wifi dialog>
https://hsv.googleplex.com/5687053981319168
<lock screen with disabling button>
https://hsv.googleplex.com/4843506419892224
<lock screen with enabling button>
https://hsv.googleplex.com/5650348922372096
<fingerprint intro>
https://hsv.googleplex.com/5133769046491136
<fingerprint touch>
https://hsv.googleplex.com/5681937198874624
<fingerprint left touch>
https://hsv.googleplex.com/5767441676238848
<squeeze release>
https://hsv.googleplex.com/6632476812247040

After:
<vision settings>
https://hsv.googleplex.com/6213298875793408
<wifi dialog>
https://hsv.googleplex.com/6025790804197376
<lock screen with disabling button>
https://hsv.googleplex.com/5747461219942400
<lock screen with enabling button>
https://hsv.googleplex.com/5766700781797376
<fingerprint intro>
https://hsv.googleplex.com/6751334529236992
<fingerprint touch>
https://hsv.googleplex.com/5625963293442048
<fingerprint left touch>
https://hsv.googleplex.com/4518139360444416
<squeeze release>
https://hsv.googleplex.com/5220720579706880

Bug: 169734655
Test: robo test
Change-Id: I4aab843e28a932c7b823f36f1d8df1e5b2341f4e
This commit is contained in:
pihuei
2020-10-13 19:00:57 +08:00
committed by Pihuei Wang
parent 9a1a35d316
commit 55fb2b745d
16 changed files with 297 additions and 56 deletions

View File

@@ -18,20 +18,42 @@ package com.android.settings;
import static com.google.common.truth.Truth.assertThat;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.sysprop.SetupWizardProperties;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.test.core.app.ApplicationProvider;
import com.google.android.setupcompat.partnerconfig.PartnerConfigHelper;
import com.google.android.setupcompat.util.WizardManagerHelper;
import com.google.android.setupdesign.util.ThemeHelper;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class SetupWizardUtilsTest {
private Context mContext;
@Before
public void setup() {
PartnerConfigHelper.resetInstance();
mContext = ApplicationProvider.getApplicationContext();
}
@Test
public void testCopySetupExtras() {
Intent fromIntent = new Intent();
@@ -66,12 +88,13 @@ public class SetupWizardUtilsTest {
}
@Test
public void testGetTheme_withIntentExtra_shouldReturnExtraTheme() {
public void testGetTheme_withIntentExtra_shouldReturnTheme() {
SetupWizardProperties.theme(ThemeHelper.THEME_GLIF);
Intent intent = createSetupWizardIntent();
intent.putExtra(WizardManagerHelper.EXTRA_THEME, ThemeHelper.THEME_GLIF_V2);
assertThat(SetupWizardUtils.getTheme(intent)).isEqualTo(R.style.GlifV2Theme);
assertThat(SetupWizardUtils.getTheme(mContext, intent))
.isEqualTo(R.style.GlifV2Theme);
}
@Test
@@ -79,26 +102,109 @@ public class SetupWizardUtilsTest {
SetupWizardProperties.theme(ThemeHelper.THEME_GLIF_V2_LIGHT);
Intent intent = createSetupWizardIntent();
assertThat(SetupWizardUtils.getTheme(intent)).isEqualTo(R.style.GlifV2Theme_Light);
assertThat(SetupWizardUtils.getTheme(mContext, intent))
.isEqualTo(R.style.GlifV2Theme_Light);
}
@Test
public void testGetTheme_glifV3Light_shouldReturnThemeResource() {
public void testGetTheme_whenSuwDayNightEnabledAndWithIntentExtra_shouldReturnDayNightTheme() {
FakePartnerContentProvider provider =
Robolectric.setupContentProvider(
FakePartnerContentProvider.class, "com.google.android.setupwizard.partner");
provider.injectFakeDayNightEnabledResult(true);
SetupWizardProperties.theme(ThemeHelper.THEME_GLIF_V2_LIGHT);
Intent intent = createSetupWizardIntent();
intent.putExtra(WizardManagerHelper.EXTRA_THEME, ThemeHelper.THEME_GLIF_V2);
assertThat(SetupWizardUtils.getTheme(mContext, intent))
.isEqualTo(R.style.GlifV2Theme_DayNight);
}
@Test
public void testGetTheme_glifV3Light_shouldReturnLightTheme() {
SetupWizardProperties.theme(ThemeHelper.THEME_GLIF_V3_LIGHT);
Intent intent = createSetupWizardIntent();
assertThat(SetupWizardUtils.getTheme(intent)).isEqualTo(R.style.GlifV3Theme_Light);
assertThat(SetupWizardUtils.getTransparentTheme(intent))
assertThat(SetupWizardUtils.getTheme(mContext, intent))
.isEqualTo(R.style.GlifV3Theme_Light);
assertThat(SetupWizardUtils.getTransparentTheme(mContext, intent))
.isEqualTo(R.style.GlifV3Theme_Light_Transparent);
}
@Test
public void testGetTheme_nonSuw_shouldReturnDayNightTheme() {
public void testGetTheme_glifV3_shouldReturnTheme() {
SetupWizardProperties.theme(ThemeHelper.THEME_GLIF_V3);
Intent intent = createSetupWizardIntent();
assertThat(SetupWizardUtils.getTheme(mContext, intent))
.isEqualTo(R.style.GlifV3Theme);
assertThat(SetupWizardUtils.getTransparentTheme(mContext, intent))
.isEqualTo(R.style.GlifV3Theme_Transparent);
}
@Test
public void testGetTheme_whenSuwDayNightDisabledAndGlifV2_shouldReturnLightTheme() {
FakePartnerContentProvider provider =
Robolectric.setupContentProvider(
FakePartnerContentProvider.class, "com.google.android.setupwizard.partner");
provider.injectFakeDayNightEnabledResult(false);
SetupWizardProperties.theme(ThemeHelper.THEME_GLIF_V2_LIGHT);
Intent intent = createSetupWizardIntent();
assertThat(SetupWizardUtils.getTheme(mContext, intent))
.isEqualTo(R.style.GlifV2Theme_Light);
}
@Test
public void testGetTheme_whenSuwDayNightEnabledAndGlifV2_shouldReturnDayNightTheme() {
FakePartnerContentProvider provider =
Robolectric.setupContentProvider(
FakePartnerContentProvider.class, "com.google.android.setupwizard.partner");
provider.injectFakeDayNightEnabledResult(true);
SetupWizardProperties.theme(ThemeHelper.THEME_GLIF_V2_LIGHT);
Intent intent = createSetupWizardIntent();
assertThat(SetupWizardUtils.getTheme(mContext, intent))
.isEqualTo(R.style.GlifV2Theme_DayNight);
}
@Test
public void testGetTheme_whenSuwDayNightDisabledAndGlifV3_shouldReturnTheme() {
FakePartnerContentProvider provider =
Robolectric.setupContentProvider(
FakePartnerContentProvider.class, "com.google.android.setupwizard.partner");
provider.injectFakeDayNightEnabledResult(false);
SetupWizardProperties.theme(ThemeHelper.THEME_GLIF_V3);
Intent intent = createSetupWizardIntent();
assertThat(SetupWizardUtils.getTheme(mContext, intent))
.isEqualTo(R.style.GlifV3Theme);
assertThat(SetupWizardUtils.getTransparentTheme(mContext, intent))
.isEqualTo(R.style.GlifV3Theme_Transparent);
}
@Test
public void testGetTheme_whenSuwDayNightEnabledAndGlifV3_shouldReturnDayNightTheme() {
FakePartnerContentProvider provider =
Robolectric.setupContentProvider(
FakePartnerContentProvider.class, "com.google.android.setupwizard.partner");
provider.injectFakeDayNightEnabledResult(true);
SetupWizardProperties.theme(ThemeHelper.THEME_GLIF_V3);
Intent intent = createSetupWizardIntent();
assertThat(SetupWizardUtils.getTheme(mContext, intent))
.isEqualTo(R.style.GlifV3Theme_DayNight);
assertThat(SetupWizardUtils.getTransparentTheme(mContext, intent))
.isEqualTo(R.style.GlifV3Theme_DayNight_Transparent);
}
@Test
public void testGetTheme_nonSuw_shouldReturnTheme() {
SetupWizardProperties.theme(ThemeHelper.THEME_GLIF_V3_LIGHT);
Intent intent = new Intent();
assertThat(SetupWizardUtils.getTheme(intent)).isEqualTo(R.style.GlifV3Theme);
assertThat(SetupWizardUtils.getTransparentTheme(intent))
assertThat(SetupWizardUtils.getTheme(mContext, intent)).isEqualTo(R.style.GlifV3Theme);
assertThat(SetupWizardUtils.getTransparentTheme(mContext, intent))
.isEqualTo(R.style.GlifV3Theme_Transparent);
}
@@ -107,4 +213,65 @@ public class SetupWizardUtilsTest {
.putExtra(WizardManagerHelper.EXTRA_IS_SETUP_FLOW, true)
.putExtra(WizardManagerHelper.EXTRA_IS_FIRST_RUN, true);
}
private static final class FakePartnerContentProvider extends ContentProvider {
private final Bundle mFakeProviderDayNightEnabledResultBundle = new Bundle();
@Override
public boolean onCreate() {
return true;
}
@Override
public Cursor query(
@NonNull Uri uri,
@Nullable String[] projection,
@Nullable String selection,
@Nullable String[] selectionArgs,
@Nullable String sortOrder) {
return null;
}
@Nullable
@Override
public String getType(@NonNull Uri uri) {
return null;
}
@Nullable
@Override
public Uri insert(@NonNull Uri uri, @Nullable ContentValues values) {
return null;
}
@Override
public int delete(
@NonNull Uri uri, @Nullable String selection, @Nullable String[] selectionArgs) {
return 0;
}
@Override
public int update(
@NonNull Uri uri,
@Nullable ContentValues values,
@Nullable String selection,
@Nullable String[] selectionArgs) {
return 0;
}
@Override
public Bundle call(String method, String arg, Bundle extras) {
if (TextUtils.equals(method, "isSuwDayNightEnabled")) {
return mFakeProviderDayNightEnabledResultBundle;
}
return null;
}
public FakePartnerContentProvider injectFakeDayNightEnabledResult(boolean dayNightEnabled) {
mFakeProviderDayNightEnabledResultBundle.putBoolean(
"isSuwDayNightEnabled", dayNightEnabled);
return this;
}
}
}