[Battery usage U] [UI] Show total "Screen On Time" in the battery usage page
Screen record: https://drive.google.com/open?id=16ZOp1E2YBzWQXbnXl786FaLFPel-S9CF&authuser=0&resourcekey=0-oRqCrdTc9FZjVgsq9orhEw&usp=drive_link For Arabic: https://drive.google.com/open?id=1zh_4jcUnqLC6CDgwju1qQkWJ0QCtm19c&authuser=0&resourcekey=0-kuKfDdOTWxqOUmD0RfPNLQ&usp=drive_link Next step: show screen on time for each app Bug: 258120710 Test: manual Change-Id: I2085a2a85ebd50b2ac876972f6a8ebbf6f20246c
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.fuelgauge.batteryusage;
|
||||
|
||||
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.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.os.LocaleList;
|
||||
|
||||
import androidx.preference.PreferenceCategory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public final class ScreenOnTimeControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private ScreenOnTimeController mScreenOnTimeController;
|
||||
|
||||
@Mock
|
||||
private PreferenceCategory mRootPreference;
|
||||
@Mock
|
||||
private TextViewPreference mScreenOnTimeTextPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
Locale.setDefault(new Locale("en_US"));
|
||||
org.robolectric.shadows.ShadowSettings.set24HourTimeFormat(false);
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
final Resources resources = spy(mContext.getResources());
|
||||
resources.getConfiguration().setLocales(new LocaleList(new Locale("en_US")));
|
||||
doReturn(resources).when(mContext).getResources();
|
||||
mScreenOnTimeController = new ScreenOnTimeController(mContext);
|
||||
mScreenOnTimeController.mPrefContext = mContext;
|
||||
mScreenOnTimeController.mRootPreference = mRootPreference;
|
||||
mScreenOnTimeController.mScreenOnTimeTextPreference = mScreenOnTimeTextPreference;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleSceenOnTimeUpdated_nullScreenOnTime_hideAllPreference() {
|
||||
mScreenOnTimeController.handleSceenOnTimeUpdated(
|
||||
/* screenOnTime= */ null, "Friday 12:00-now");
|
||||
|
||||
verify(mRootPreference).setVisible(false);
|
||||
verify(mScreenOnTimeTextPreference).setVisible(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void showCategoryTitle_null_sinceLastFullCharge() {
|
||||
mScreenOnTimeController.showCategoryTitle(null);
|
||||
|
||||
verify(mRootPreference).setTitle("Screen time since last full charge");
|
||||
verify(mRootPreference).setVisible(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void showCategoryTitle_notNull_slotTimestamp() {
|
||||
mScreenOnTimeController.showCategoryTitle("Friday 12:00-now");
|
||||
|
||||
verify(mRootPreference).setTitle("Screen time for Friday 12:00-now");
|
||||
verify(mRootPreference).setVisible(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void showScreenOnTimeText_returnExpectedResult() {
|
||||
mScreenOnTimeController.showScreenOnTimeText(1600000000L);
|
||||
|
||||
ArgumentCaptor<CharSequence> argumentCaptor = ArgumentCaptor.forClass(CharSequence.class);
|
||||
verify(mScreenOnTimeTextPreference).setText(argumentCaptor.capture());
|
||||
assertThat(argumentCaptor.getValue().toString()).isEqualTo("18 days, 12 hr, 27 min");
|
||||
verify(mScreenOnTimeTextPreference).setVisible(true);
|
||||
}
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.fuelgauge.batteryusage;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public final class TextViewPreferenceTest {
|
||||
|
||||
private Context mContext;
|
||||
private TextViewPreference mTextViewPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mTextViewPreference = new TextViewPreference(mContext, /*attrs=*/ null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructor_returnExpectedResult() {
|
||||
assertThat(mTextViewPreference.getLayoutResource()).isEqualTo(
|
||||
R.layout.preference_text_view);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setText_returnExpectedResult() {
|
||||
final String text = "TEST_TEXT";
|
||||
mTextViewPreference.setText(text);
|
||||
|
||||
assertThat(mTextViewPreference.mText.toString()).isEqualTo(text);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user