Snap for 8671920 from b88be2407f to tm-qpr1-release

Change-Id: I9528bd8b62f916f76b287e8d7db6ab43de203bf2
This commit is contained in:
Android Build Coastguard Worker
2022-06-02 01:25:56 +00:00
11 changed files with 38 additions and 233 deletions

View File

@@ -0,0 +1 @@
{}

View File

@@ -0,0 +1 @@
{}

View File

@@ -0,0 +1 @@
{}

View File

@@ -11763,12 +11763,6 @@
<!-- [CHAR LIMIT=60] Summary string on dark theme explaining why the toggle is disabled while the setting is off--> <!-- [CHAR LIMIT=60] Summary string on dark theme explaining why the toggle is disabled while the setting is off-->
<string name="dark_ui_mode_disabled_summary_dark_theme_off">Temporarily turned on due to Battery Saver</string> <string name="dark_ui_mode_disabled_summary_dark_theme_off">Temporarily turned on due to Battery Saver</string>
<!-- [CHAR_LIMIT=NONE] Summary that is shown in the footer when dark mode is selected -->
<string name="dark_ui_settings_dark_summary">Supported apps will also switch to dark theme</string>
<!-- [CHAR_LIMIT=40] Positive button text in dark theme notification -->
<string name="dark_ui_settings_dialog_acknowledge">Got it</string>
<!-- [CHAR_LIMIT=50] Title string in the dark theme slice(suggestion) --> <!-- [CHAR_LIMIT=50] Title string in the dark theme slice(suggestion) -->
<string name="dark_theme_slice_title">Try Dark theme</string> <string name="dark_theme_slice_title">Try Dark theme</string>

View File

@@ -1,89 +0,0 @@
/*
* 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.display;
import android.app.Dialog;
import android.app.UiModeManager;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
public class DarkUIInfoDialogFragment extends InstrumentedDialogFragment
implements DialogInterface.OnClickListener{
@Override
public int getMetricsCategory() {
return SettingsEnums.DIALOG_DARK_UI_INFO;
}
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
Context context = getContext();
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
LayoutInflater inflater = LayoutInflater.from(dialog.getContext());
View titleView = inflater.inflate(R.layout.settings_dialog_title, null);
((ImageView) titleView.findViewById(R.id.settings_icon))
.setImageDrawable(context.getDrawable(R.drawable.dark_theme));
((TextView) titleView.findViewById(R.id.settings_title)).setText(R.string.dark_ui_mode);
dialog.setCustomTitle(titleView)
.setMessage(R.string.dark_ui_settings_dark_summary)
.setPositiveButton(
R.string.dark_ui_settings_dialog_acknowledge,
this);
return dialog.create();
}
@Override
public void onDismiss(@NonNull DialogInterface dialog) {
enableDarkTheme();
super.onDismiss(dialog);
}
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// We have to manually dismiss the dialog because changing night mode causes it to
// recreate itself.
dialogInterface.dismiss();
enableDarkTheme();
}
private void enableDarkTheme() {
final Context context = getContext();
if (context != null) {
Settings.Secure.putInt(context.getContentResolver(),
Settings.Secure.DARK_MODE_DIALOG_SEEN,
DarkUIPreferenceController.DIALOG_SEEN);
context.getSystemService(UiModeManager.class)
.setNightMode(UiModeManager.MODE_NIGHT_YES);
}
}
}

View File

@@ -23,10 +23,8 @@ import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.PowerManager; import android.os.PowerManager;
import android.provider.Settings;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.Fragment;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
@@ -39,7 +37,6 @@ import com.android.settingslib.core.lifecycle.events.OnStop;
public class DarkUIPreferenceController extends TogglePreferenceController implements public class DarkUIPreferenceController extends TogglePreferenceController implements
LifecycleObserver, OnStart, OnStop { LifecycleObserver, OnStart, OnStop {
public static final String DARK_MODE_PREFS = "dark_mode_prefs";
public static final String PREF_DARK_MODE_DIALOG_SEEN = "dark_mode_dialog_seen"; public static final String PREF_DARK_MODE_DIALOG_SEEN = "dark_mode_dialog_seen";
public static final int DIALOG_SEEN = 1; public static final int DIALOG_SEEN = 1;
@@ -48,9 +45,6 @@ public class DarkUIPreferenceController extends TogglePreferenceController imple
private UiModeManager mUiModeManager; private UiModeManager mUiModeManager;
private PowerManager mPowerManager; private PowerManager mPowerManager;
private Context mContext;
private Fragment mFragment;
private BroadcastReceiver mReceiver = new BroadcastReceiver() { private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override @Override
@@ -61,7 +55,6 @@ public class DarkUIPreferenceController extends TogglePreferenceController imple
public DarkUIPreferenceController(Context context, String key) { public DarkUIPreferenceController(Context context, String key) {
super(context, key); super(context, key);
mContext = context;
mUiModeManager = context.getSystemService(UiModeManager.class); mUiModeManager = context.getSystemService(UiModeManager.class);
mPowerManager = context.getSystemService(PowerManager.class); mPowerManager = context.getSystemService(PowerManager.class);
} }
@@ -86,12 +79,6 @@ public class DarkUIPreferenceController extends TogglePreferenceController imple
@Override @Override
public boolean setChecked(boolean isChecked) { public boolean setChecked(boolean isChecked) {
final boolean dialogSeen =
Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.DARK_MODE_DIALOG_SEEN, 0) == DIALOG_SEEN;
if (!dialogSeen && isChecked) {
showDarkModeDialog();
}
return mUiModeManager.setNightModeActivated(isChecked); return mUiModeManager.setNightModeActivated(isChecked);
} }
@@ -100,13 +87,6 @@ public class DarkUIPreferenceController extends TogglePreferenceController imple
return R.string.menu_key_display; return R.string.menu_key_display;
} }
private void showDarkModeDialog() {
final DarkUIInfoDialogFragment frag = new DarkUIInfoDialogFragment();
if (mFragment != null && mFragment.getFragmentManager() != null) {
frag.show(mFragment.getFragmentManager(), getClass().getName());
}
}
@VisibleForTesting @VisibleForTesting
void updateEnabledStateIfNeeded() { void updateEnabledStateIfNeeded() {
if (mPreference == null) { if (mPreference == null) {
@@ -133,11 +113,6 @@ public class DarkUIPreferenceController extends TogglePreferenceController imple
new IntentFilter(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED)); new IntentFilter(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED));
} }
// used by AccessibilitySettings
public void setParentFragment(Fragment fragment) {
mFragment = fragment;
}
@Override @Override
public void onStop() { public void onStop() {
mContext.unregisterReceiver(mReceiver); mContext.unregisterReceiver(mReceiver);

View File

@@ -27,7 +27,6 @@ import androidx.preference.Preference;
import com.android.settings.core.BasePreferenceController; import com.android.settings.core.BasePreferenceController;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
/** /**
* Controller for custom mode night mode time settings * Controller for custom mode night mode time settings
@@ -35,7 +34,6 @@ import java.time.format.DateTimeFormatter;
public class DarkModeCustomPreferenceController extends BasePreferenceController { public class DarkModeCustomPreferenceController extends BasePreferenceController {
private static final String START_TIME_KEY = "dark_theme_start_time"; private static final String START_TIME_KEY = "dark_theme_start_time";
private static final String END_TIME_KEY = "dark_theme_end_time"; private static final String END_TIME_KEY = "dark_theme_end_time";
public static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("hh:mm a");
private final UiModeManager mUiModeManager; private final UiModeManager mUiModeManager;
private TimeFormatter mFormat; private TimeFormatter mFormat;
private DarkModeSettingsFragment mFragmet; private DarkModeSettingsFragment mFragmet;
@@ -63,7 +61,10 @@ public class DarkModeCustomPreferenceController extends BasePreferenceController
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
return AVAILABLE; return mUiModeManager.getNightMode() == MODE_NIGHT_CUSTOM
&& mUiModeManager.getNightModeCustomType()
== UiModeManager.MODE_NIGHT_CUSTOM_TYPE_SCHEDULE
? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
} }
public TimePickerDialog getDialog() { public TimePickerDialog getDialog() {
@@ -88,13 +89,6 @@ public class DarkModeCustomPreferenceController extends BasePreferenceController
@Override @Override
protected void refreshSummary(Preference preference) { protected void refreshSummary(Preference preference) {
if (mUiModeManager.getNightMode() != MODE_NIGHT_CUSTOM
|| mUiModeManager.getNightModeCustomType()
!= UiModeManager.MODE_NIGHT_CUSTOM_TYPE_SCHEDULE) {
preference.setVisible(false);
return;
}
preference.setVisible(true);
final LocalTime time; final LocalTime time;
if (TextUtils.equals(getPreferenceKey(), START_TIME_KEY)) { if (TextUtils.equals(getPreferenceKey(), START_TIME_KEY)) {
time = mUiModeManager.getCustomNightModeStart(); time = mUiModeManager.getCustomNightModeStart();

View File

@@ -21,6 +21,7 @@ import android.os.Bundle;
import android.os.PowerManager; import android.os.PowerManager;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment; import com.android.settings.dashboard.DashboardFragment;
@@ -43,9 +44,6 @@ public class DarkModeSettingsFragment extends DashboardFragment {
private DarkModeObserver mContentObserver; private DarkModeObserver mContentObserver;
private DarkModeCustomPreferenceController mCustomStartController; private DarkModeCustomPreferenceController mCustomStartController;
private DarkModeCustomPreferenceController mCustomEndController; private DarkModeCustomPreferenceController mCustomEndController;
private Runnable mCallback = () -> {
updatePreferenceStates();
};
private static final int DIALOG_START_TIME = 0; private static final int DIALOG_START_TIME = 0;
private static final int DIALOG_END_TIME = 1; private static final int DIALOG_END_TIME = 1;
@@ -60,7 +58,12 @@ public class DarkModeSettingsFragment extends DashboardFragment {
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
// Listen for changes only while visible. // Listen for changes only while visible.
mContentObserver.subscribe(mCallback); mContentObserver.subscribe(() -> {
PreferenceScreen preferenceScreen = getPreferenceScreen();
mCustomStartController.displayPreference(preferenceScreen);
mCustomEndController.displayPreference(preferenceScreen);
updatePreferenceStates();
});
} }
@Override @Override

View File

@@ -1,65 +0,0 @@
/*
* 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.display;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.provider.Settings;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class DarkUIInfoDialogFragmentTest {
private DarkUIInfoDialogFragment mFragment;
@Mock
private DialogInterface dialog;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mFragment = spy(new DarkUIInfoDialogFragment());
}
@Test
public void dialogDismissedOnConfirmation() {
doReturn(RuntimeEnvironment.application).when(mFragment).getContext();
SharedPreferences prefs = RuntimeEnvironment.application.getSharedPreferences(
DarkUIPreferenceController.DARK_MODE_PREFS,
Context.MODE_PRIVATE);
assertThat(prefs.getBoolean(DarkUIPreferenceController.PREF_DARK_MODE_DIALOG_SEEN, false))
.isFalse();
mFragment.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
verify(dialog, times(1)).dismiss();
assertThat(Settings.Secure.getInt(RuntimeEnvironment.application.getContentResolver(),
Settings.Secure.DARK_MODE_DIALOG_SEEN, -1)).isEqualTo(1);
}
}

View File

@@ -16,35 +16,33 @@
package com.android.settings.display; package com.android.settings.display;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import android.content.Context; import android.content.Context;
import androidx.fragment.app.Fragment;
import com.android.settings.display.darkmode.DarkModePreference; import com.android.settings.display.darkmode.DarkModePreference;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
public class DarkUIPreferenceControllerTest { public class DarkUIPreferenceControllerTest {
private DarkUIPreferenceController mController; private DarkUIPreferenceController mController;
private Context mContext; private Context mContext;
@Mock
private Fragment mFragment;
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application); mContext = spy(RuntimeEnvironment.application);
mController = spy(new DarkUIPreferenceController(mContext, "dark_ui_mode")); mController = spy(new DarkUIPreferenceController(mContext, "dark_ui_mode"));
mController.setParentFragment(mFragment);
mController.mPreference = new DarkModePreference(mContext, null /* AttributeSet attrs */); mController.mPreference = new DarkModePreference(mContext, null /* AttributeSet attrs */);
mController.onStart(); mController.onStart();
} }

View File

@@ -15,6 +15,11 @@
package com.android.settings.display.darkmode; package com.android.settings.display.darkmode;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@@ -71,68 +76,55 @@ public class DarkModeCustomPreferenceControllerTest {
} }
@Test @Test
public void nightMode_manualOn_hidePreference() { public void getAvailabilityStatus_nightModeManualOn_unavailable() {
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_YES); when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_YES);
mConfig.uiMode = Configuration.UI_MODE_NIGHT_YES; mConfig.uiMode = Configuration.UI_MODE_NIGHT_YES;
mController.refreshSummary(mPreference); assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
verify(mPreference).setVisible(eq(false));
} }
@Test @Test
public void nightMode_manualOff_hidePreference() { public void getAvailabilityStatus_nightModeManualOff_unavailable() {
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_NO); when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_NO);
mConfig.uiMode = Configuration.UI_MODE_NIGHT_NO; mConfig.uiMode = Configuration.UI_MODE_NIGHT_NO;
mController.refreshSummary(mPreference); assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
verify(mPreference).setVisible(eq(false));
} }
@Test @Test
public void nightMode_customOn_showPreference() { public void getAvailabilityStatus_nightModeCustomOn_available() {
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM); when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM);
mConfig.uiMode = Configuration.UI_MODE_NIGHT_YES; mConfig.uiMode = Configuration.UI_MODE_NIGHT_YES;
mController.refreshSummary(mPreference); assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
verify(mPreference).setVisible(eq(true));
} }
@Test @Test
public void nightMode_customOff_showPreference() { public void getAvailabilityStatus_nightModeCustomOff_available() {
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM); when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM);
mConfig.uiMode = Configuration.UI_MODE_NIGHT_NO; mConfig.uiMode = Configuration.UI_MODE_NIGHT_NO;
mController.refreshSummary(mPreference); assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
verify(mPreference).setVisible(eq(true));
} }
@Test @Test
public void nightMode_customBedtimeOn_hidePreference() { public void getAvailabilityStatus_nightModeCustomBedtimeOn_unavailable() {
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM); when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM);
when(mService.getNightModeCustomType()) when(mService.getNightModeCustomType())
.thenReturn(UiModeManager.MODE_NIGHT_CUSTOM_TYPE_BEDTIME); .thenReturn(UiModeManager.MODE_NIGHT_CUSTOM_TYPE_BEDTIME);
mConfig.uiMode = Configuration.UI_MODE_NIGHT_YES; mConfig.uiMode = Configuration.UI_MODE_NIGHT_YES;
mController.refreshSummary(mPreference); assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
verify(mPreference).setVisible(eq(false));
} }
@Test @Test
public void nightMode_customBedtimeOff_hidePreference() { public void getAvailabilityStatus_nightModeCustomBedtimeOff_unavailable() {
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM); when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM);
when(mService.getNightModeCustomType()) when(mService.getNightModeCustomType())
.thenReturn(UiModeManager.MODE_NIGHT_CUSTOM_TYPE_BEDTIME); .thenReturn(UiModeManager.MODE_NIGHT_CUSTOM_TYPE_BEDTIME);
mConfig.uiMode = Configuration.UI_MODE_NIGHT_NO; mConfig.uiMode = Configuration.UI_MODE_NIGHT_NO;
mController.refreshSummary(mPreference); assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
verify(mPreference).setVisible(eq(false));
} }
@Test @Test