Merge sc-v2-dev-plus-aosp-without-vendor@8084891
Bug: 214455710 Merged-In: I962c318f41adcf180b885f2052ce0ec4952edfb6 Change-Id: I77764eaf895ac3c13c7440adb5b3f597a516d690
This commit is contained in:
@@ -55,6 +55,7 @@ import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
@@ -208,6 +209,7 @@ public class MainClearTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testShowWipeEuicc_euiccEnabled_unprovisioned() {
|
||||
prepareEuiccState(
|
||||
true /* isEuiccEnabled */,
|
||||
@@ -226,6 +228,7 @@ public class MainClearTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testShowWipeEuicc_developerMode_unprovisioned() {
|
||||
prepareEuiccState(
|
||||
true /* isEuiccEnabled */,
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON;
|
||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
@@ -46,7 +47,6 @@ public class AccessibilityButtonFooterPreferenceControllerTest {
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||
|
||||
@Spy
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
@Spy
|
||||
@@ -76,4 +76,15 @@ public class AccessibilityButtonFooterPreferenceControllerTest {
|
||||
assertThat(mPreference.getTitle()).isEqualTo(
|
||||
mContext.getText(R.string.accessibility_button_gesture_description));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_navigationGestureDisabled_setCorrectTitle() {
|
||||
when(mResources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode))
|
||||
.thenReturn(NAV_BAR_MODE_2BUTTON);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.getTitle()).isEqualTo(
|
||||
mContext.getText(R.string.accessibility_button_description));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.accessibility;
|
||||
|
||||
import static android.provider.Settings.Secure.ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU;
|
||||
import static android.provider.Settings.Secure.ACCESSIBILITY_BUTTON_MODE_GESTURE;
|
||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON;
|
||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
|
||||
|
||||
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.Mockito.when;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
/** Tests for {@link AccessibilityButtonGesturePreferenceController}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AccessibilityButtonGesturePreferenceControllerTest {
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||
|
||||
@Spy
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
@Spy
|
||||
private final Resources mResources = mContext.getResources();
|
||||
private final ContentResolver mContentResolver = mContext.getContentResolver();
|
||||
private final ListPreference mListPreference = new ListPreference(mContext);
|
||||
private AccessibilityButtonGesturePreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mController = new AccessibilityButtonGesturePreferenceController(mContext,
|
||||
"test_key");
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_navigationGestureEnabled_returnAvailable() {
|
||||
when(mResources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode))
|
||||
.thenReturn(NAV_BAR_MODE_GESTURAL);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_navigationGestureDisabled_returnConditionallyUnavailable() {
|
||||
when(mResources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode))
|
||||
.thenReturn(NAV_BAR_MODE_2BUTTON);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_a11yBtnModeGesture_navigationBarValue() {
|
||||
Settings.Secure.putInt(mContentResolver, Settings.Secure.ACCESSIBILITY_BUTTON_MODE,
|
||||
ACCESSIBILITY_BUTTON_MODE_GESTURE);
|
||||
|
||||
mController.updateState(mListPreference);
|
||||
|
||||
final String gestureValue = String.valueOf(ACCESSIBILITY_BUTTON_MODE_GESTURE);
|
||||
assertThat(mListPreference.getValue()).isEqualTo(gestureValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_a11yBtnModeFloatingMenu_floatingMenuValue() {
|
||||
final String floatingMenuValue = String.valueOf(ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU);
|
||||
|
||||
mController.onPreferenceChange(mListPreference, floatingMenuValue);
|
||||
|
||||
assertThat(mListPreference.getValue()).isEqualTo(floatingMenuValue);
|
||||
}
|
||||
}
|
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.accessibility;
|
||||
|
||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON;
|
||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
/** Tests for {@link AccessibilityButtonPreferenceController}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AccessibilityButtonPreferenceControllerTest {
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||
@Spy
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
@Spy
|
||||
private final Resources mResources = mContext.getResources();
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
private Preference mPreference;
|
||||
private AccessibilityButtonPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mController = new AccessibilityButtonPreferenceController(mContext, "test_key");
|
||||
mPreference = new Preference(mContext);
|
||||
mPreference.setKey("test_key");
|
||||
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_navigationGestureEnabled_setCorrectTitle() {
|
||||
when(mResources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode))
|
||||
.thenReturn(NAV_BAR_MODE_GESTURAL);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.getTitle()).isEqualTo(
|
||||
mContext.getText(R.string.accessibility_button_gesture_title));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_navigationGestureDisabled_setCorrectTitle() {
|
||||
when(mResources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode))
|
||||
.thenReturn(NAV_BAR_MODE_2BUTTON);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.getTitle()).isEqualTo(
|
||||
mContext.getText(R.string.accessibility_button_title));
|
||||
}
|
||||
}
|
@@ -19,6 +19,8 @@ package com.android.settings.accessibility;
|
||||
import static android.provider.Settings.Secure.ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU;
|
||||
import static android.provider.Settings.Secure.ACCESSIBILITY_BUTTON_MODE_NAVIGATION_BAR;
|
||||
|
||||
import static com.android.settings.testutils.ImageTestUtils.drawableToBitmap;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -28,12 +30,11 @@ import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.provider.Settings;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.ImageTestUtils;
|
||||
import com.android.settingslib.widget.IllustrationPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
@@ -62,7 +63,7 @@ public class AccessibilityButtonPreviewPreferenceControllerTest {
|
||||
public void setUp() {
|
||||
when(mContext.getContentResolver()).thenReturn(mContentResolver);
|
||||
mController = new AccessibilityButtonPreviewPreferenceController(mContext, "test_key");
|
||||
mController.mPreview = new ImageView(mContext);
|
||||
mController.mIllustrationPreference = new IllustrationPreference(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -74,8 +75,8 @@ public class AccessibilityButtonPreviewPreferenceControllerTest {
|
||||
|
||||
final Drawable navigationBarDrawable = mContext.getDrawable(
|
||||
R.drawable.accessibility_button_navigation);
|
||||
assertThat(ImageTestUtils.drawableToBitmap(mController.mPreview.getDrawable()).sameAs(
|
||||
ImageTestUtils.drawableToBitmap(navigationBarDrawable))).isTrue();
|
||||
assertThat(drawableToBitmap(mController.mIllustrationPreference.getImageDrawable()).sameAs(
|
||||
drawableToBitmap(navigationBarDrawable))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -90,10 +91,11 @@ public class AccessibilityButtonPreviewPreferenceControllerTest {
|
||||
mController.mContentObserver.onChange(false);
|
||||
|
||||
final Drawable smallFloatingMenuWithTenOpacityDrawable =
|
||||
FloatingMenuLayerDrawable.createLayerDrawable(mContext,
|
||||
AccessibilityLayerDrawable.createLayerDrawable(mContext,
|
||||
R.drawable.accessibility_button_preview_small_floating_menu, 10);
|
||||
assertThat(mController.mPreview.getDrawable().getConstantState()).isEqualTo(
|
||||
smallFloatingMenuWithTenOpacityDrawable.getConstantState());
|
||||
assertThat(
|
||||
mController.mIllustrationPreference.getImageDrawable().getConstantState())
|
||||
.isEqualTo(smallFloatingMenuWithTenOpacityDrawable.getConstantState());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.accessibility;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
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;
|
||||
|
||||
/** Tests for {@link AccessibilityDialogUtils} */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AccessibilityDialogUtilsTest {
|
||||
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext.setTheme(R.style.Theme_AppCompat);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateSoftwareShortcutInDialog_correctDialogType_success() {
|
||||
final AlertDialog dialog = AccessibilityDialogUtils.showEditShortcutDialog(
|
||||
mContext, AccessibilityDialogUtils.DialogType.EDIT_SHORTCUT_GENERIC, "Title",
|
||||
null);
|
||||
|
||||
assertThat(
|
||||
AccessibilityDialogUtils.updateSoftwareShortcutInDialog(mContext, dialog)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateSoftwareShortcutInDialog_useNotSupportedDialog_fail() {
|
||||
final AlertDialog dialog = new AlertDialog.Builder(mContext).setTitle("Title").show();
|
||||
|
||||
assertThat(AccessibilityDialogUtils.updateSoftwareShortcutInDialog(mContext,
|
||||
dialog)).isFalse();
|
||||
}
|
||||
}
|
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.accessibility;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
/**
|
||||
* Tests for {@link AccessibilityFooterPreferenceController}.
|
||||
*/
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AccessibilityFooterPreferenceControllerTest {
|
||||
|
||||
private static final String TEST_KEY = "test_pref_key";
|
||||
private static final String TEST_TITLE = "test_title";
|
||||
private static final String TEST_INTRODUCTION_TITLE = "test_introduction_title";
|
||||
private static final String TEST_CONTENT_DESCRIPTION = "test_content_description";
|
||||
private static final int TEST_HELP_ID = 12345;
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||
|
||||
@Spy
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
private AccessibilityFooterPreferenceController mController;
|
||||
private AccessibilityFooterPreference mPreference;
|
||||
private PreferenceViewHolder mPreferenceViewHolder;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mController = new AccessibilityFooterPreferenceController(mContext, TEST_KEY);
|
||||
mPreference = new AccessibilityFooterPreference(mContext);
|
||||
mPreference.setKey(TEST_KEY);
|
||||
mPreference.setTitle(TEST_TITLE);
|
||||
|
||||
final LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
final View view = inflater.inflate(R.layout.preference_footer, null);
|
||||
mPreferenceViewHolder = PreferenceViewHolder.createInstanceForTests(view);
|
||||
mPreference.onBindViewHolder(mPreferenceViewHolder);
|
||||
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setIntroductionTitle_setCorrectIntroductionTitle() {
|
||||
mController.setIntroductionTitle(TEST_INTRODUCTION_TITLE);
|
||||
|
||||
assertThat(mController.getIntroductionTitle()).isEqualTo(TEST_INTRODUCTION_TITLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_setIntroductionTitle_setCorrectIntroductionTitle() {
|
||||
mController.setIntroductionTitle(TEST_INTRODUCTION_TITLE);
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mPreference.onBindViewHolder(mPreferenceViewHolder);
|
||||
|
||||
final TextView summaryView = (TextView) mPreferenceViewHolder
|
||||
.findViewById(android.R.id.title);
|
||||
assertThat(summaryView.getContentDescription().toString())
|
||||
.contains(TEST_INTRODUCTION_TITLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setupHelpLink_setCorrectHelpLinkAndContentDescription() {
|
||||
mController.setupHelpLink(TEST_HELP_ID, TEST_CONTENT_DESCRIPTION);
|
||||
|
||||
assertThat(mController.getHelpResource()).isEqualTo(TEST_HELP_ID);
|
||||
assertThat(mController.getLearnMoreContentDescription())
|
||||
.isEqualTo(TEST_CONTENT_DESCRIPTION);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_setHelpResource_emptyString_notVisible() {
|
||||
mController.setupHelpLink(R.string.help_url_timeout, TEST_CONTENT_DESCRIPTION);
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mPreference.onBindViewHolder(mPreferenceViewHolder);
|
||||
|
||||
final TextView learnMoreView = (TextView) mPreferenceViewHolder
|
||||
.findViewById(com.android.settingslib.R.id.settingslib_learn_more);
|
||||
assertThat(learnMoreView.getContentDescription()).isNull();
|
||||
assertThat(learnMoreView.getVisibility()).isEqualTo(View.GONE);
|
||||
assertThat(mPreference.isLinkEnabled()).isFalse();
|
||||
}
|
||||
}
|
@@ -30,9 +30,9 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
/** Tests for {@link FloatingMenuLayerDrawable}. */
|
||||
/** Tests for {@link AccessibilityLayerDrawable}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class FloatingMenuLayerDrawableTest {
|
||||
public class AccessibilityLayerDrawableTest {
|
||||
|
||||
private static final int TEST_RES_ID =
|
||||
com.android.internal.R.drawable.ic_accessibility_magnification;
|
||||
@@ -46,8 +46,8 @@ public class FloatingMenuLayerDrawableTest {
|
||||
R.drawable.accessibility_button_preview_base);
|
||||
final Drawable expected2ndDrawable = mContext.getDrawable(TEST_RES_ID);
|
||||
|
||||
final FloatingMenuLayerDrawable actualDrawable =
|
||||
FloatingMenuLayerDrawable.createLayerDrawable(mContext, TEST_RES_ID,
|
||||
final AccessibilityLayerDrawable actualDrawable =
|
||||
AccessibilityLayerDrawable.createLayerDrawable(mContext, TEST_RES_ID,
|
||||
/* opacity= */ 27);
|
||||
|
||||
final Drawable actual1stDrawable = actualDrawable.getDrawable(0);
|
||||
@@ -60,14 +60,14 @@ public class FloatingMenuLayerDrawableTest {
|
||||
|
||||
@Test
|
||||
public void updateLayerDrawable_expectedFloatingMenuLayerDrawableState() {
|
||||
final FloatingMenuLayerDrawable originalDrawable =
|
||||
FloatingMenuLayerDrawable.createLayerDrawable(mContext, TEST_RES_ID, /* opacity= */
|
||||
final AccessibilityLayerDrawable originalDrawable =
|
||||
AccessibilityLayerDrawable.createLayerDrawable(mContext, TEST_RES_ID, /* opacity= */
|
||||
72);
|
||||
|
||||
originalDrawable.updateLayerDrawable(mContext, TEST_RES_ID_2, /* opacity= */ 27);
|
||||
|
||||
assertThat(originalDrawable.getConstantState()).isEqualTo(
|
||||
new FloatingMenuLayerDrawable.FloatingMenuLayerDrawableState(mContext,
|
||||
new AccessibilityLayerDrawable.AccessibilityLayerDrawableState(mContext,
|
||||
TEST_RES_ID_2, /* opacity= */ 27));
|
||||
}
|
||||
}
|
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.accessibility;
|
||||
|
||||
import static com.android.settings.accessibility.AccessibilityScreenSizeForSetupWizardActivity.VISION_FRAGMENT_NO;
|
||||
import static com.android.settings.core.SettingsBaseActivity.EXTRA_PAGE_TRANSITION_TYPE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.AccessibilityScreenSizeForSetupWizardActivity.FragmentType;
|
||||
import com.android.settingslib.transition.SettingsTransitionHelper.TransitionType;
|
||||
|
||||
import com.google.android.setupcompat.template.FooterBarMixin;
|
||||
import com.google.android.setupdesign.GlifLayout;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
/** Tests for {@link AccessibilityScreenSizeForSetupWizardActivity} */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AccessibilityScreenSizeForSetupWizardActivityTest {
|
||||
|
||||
private Context mContext = ApplicationProvider.getApplicationContext();
|
||||
|
||||
private AccessibilityScreenSizeForSetupWizardActivity setupActivity(int fragmentType) {
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra(VISION_FRAGMENT_NO, fragmentType);
|
||||
return Robolectric.buildActivity(AccessibilityScreenSizeForSetupWizardActivity.class,
|
||||
intent).create().get();
|
||||
}
|
||||
|
||||
private AccessibilityScreenSizeForSetupWizardActivity setupActivity(int fragmentType,
|
||||
int transitionType) {
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra(VISION_FRAGMENT_NO, fragmentType);
|
||||
intent.putExtra(EXTRA_PAGE_TRANSITION_TYPE, transitionType);
|
||||
return Robolectric.buildActivity(AccessibilityScreenSizeForSetupWizardActivity.class,
|
||||
intent).create().get();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setupActivity_fontSizePage_returnFontSizeTitle() {
|
||||
final AccessibilityScreenSizeForSetupWizardActivity activity =
|
||||
setupActivity(FragmentType.FONT_SIZE, TransitionType.TRANSITION_FADE);
|
||||
|
||||
final GlifLayout layout = activity.findViewById(R.id.setup_wizard_layout);
|
||||
assertThat(layout.getHeaderText()).isEqualTo(mContext.getText(R.string.title_font_size));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setupActivity_generateDoneButton() {
|
||||
final AccessibilityScreenSizeForSetupWizardActivity activity =
|
||||
setupActivity(FragmentType.FONT_SIZE, TransitionType.TRANSITION_FADE);
|
||||
|
||||
final GlifLayout layout = activity.findViewById(R.id.setup_wizard_layout);
|
||||
final FooterBarMixin mixin = layout.getMixin(FooterBarMixin.class);
|
||||
assertThat(mixin.getPrimaryButton().getText()).isEqualTo(mContext.getText(R.string.done));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPause_getPendingTransitionEnterAnimationResourceId_transitionFade_should() {
|
||||
final AccessibilityScreenSizeForSetupWizardActivity activity =
|
||||
setupActivity(FragmentType.FONT_SIZE, TransitionType.TRANSITION_FADE);
|
||||
|
||||
activity.onPause();
|
||||
|
||||
assertThat(shadowOf(activity).getPendingTransitionEnterAnimationResourceId())
|
||||
.isEqualTo(R.anim.sud_stay);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPause_getPendingTransitionExitAnimationResourceId_transitionFade_should() {
|
||||
final AccessibilityScreenSizeForSetupWizardActivity activity =
|
||||
setupActivity(FragmentType.FONT_SIZE, TransitionType.TRANSITION_FADE);
|
||||
|
||||
activity.onPause();
|
||||
|
||||
assertThat(shadowOf(activity).getPendingTransitionExitAnimationResourceId())
|
||||
.isEqualTo(android.R.anim.fade_out);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPause_getPendingTransitionEnterAnimationResourceId_transitionNone_should() {
|
||||
final AccessibilityScreenSizeForSetupWizardActivity activity =
|
||||
setupActivity(FragmentType.FONT_SIZE);
|
||||
|
||||
activity.onPause();
|
||||
|
||||
assertThat(shadowOf(activity).getPendingTransitionEnterAnimationResourceId())
|
||||
.isNotEqualTo(R.anim.sud_stay);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPause_getPendingTransitionExitAnimationResourceId_transitionNone_should() {
|
||||
final AccessibilityScreenSizeForSetupWizardActivity activity =
|
||||
setupActivity(FragmentType.FONT_SIZE);
|
||||
|
||||
activity.onPause();
|
||||
|
||||
assertThat(shadowOf(activity).getPendingTransitionExitAnimationResourceId())
|
||||
.isNotEqualTo(android.R.anim.fade_out);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateHeaderLayout_displaySizePage_returnDisplaySizeTitle() {
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra(VISION_FRAGMENT_NO, FragmentType.SCREEN_SIZE);
|
||||
intent.putExtra(EXTRA_PAGE_TRANSITION_TYPE, TransitionType.TRANSITION_FADE);
|
||||
final AccessibilityScreenSizeForSetupWizardActivity activity = Robolectric.buildActivity(
|
||||
AccessibilityScreenSizeForSetupWizardActivity.class, intent).get();
|
||||
activity.setContentView(R.layout.accessibility_screen_size_setup_wizard);
|
||||
activity.updateHeaderLayout();
|
||||
final GlifLayout layout = activity.findViewById(R.id.setup_wizard_layout);
|
||||
assertThat(layout.getHeaderText()).isEqualTo(mContext.getText(R.string.screen_zoom_title));
|
||||
}
|
||||
}
|
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static com.android.settings.accessibility.AccessibilityScreenSizeForSetupWizardActivity.VISION_FRAGMENT_NO;
|
||||
import static com.android.settings.accessibility.AccessibilitySettingsForSetupWizardActivity.CLASS_NAME_FONT_SIZE_SETTINGS_FOR_SUW;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
@@ -26,8 +27,7 @@ import android.content.Intent;
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.display.FontSizePreferenceFragmentForSetupWizard;
|
||||
import com.android.settings.accessibility.AccessibilityScreenSizeForSetupWizardActivity.FragmentType;
|
||||
|
||||
import com.google.android.setupcompat.util.WizardManagerHelper;
|
||||
|
||||
@@ -42,45 +42,47 @@ import org.robolectric.Shadows;
|
||||
@SmallTest
|
||||
public class AccessibilitySettingsForSetupWizardActivityTest {
|
||||
|
||||
@Test
|
||||
public void createSetupAccessibilityActivity_shouldBeSUWTheme() {
|
||||
final Intent intent = new Intent();
|
||||
AccessibilitySettingsForSetupWizardActivity activity =
|
||||
Robolectric.buildActivity(AccessibilitySettingsForSetupWizardActivity.class, intent).get();
|
||||
@Test
|
||||
public void createSetupAccessibilityActivity_shouldBeSUWTheme() {
|
||||
final Intent intent = new Intent();
|
||||
AccessibilitySettingsForSetupWizardActivity activity =
|
||||
Robolectric.buildActivity(AccessibilitySettingsForSetupWizardActivity.class,
|
||||
intent).get();
|
||||
|
||||
assertThat(activity.getThemeResId()).isEqualTo(R.style.GlifV3Theme_Light);
|
||||
}
|
||||
assertThat(activity.getThemeResId()).isEqualTo(R.style.GlifV3Theme_Light);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreate_hasFontSizeComponent_shouldGoToFontSizePreferenceDirectly() {
|
||||
AccessibilitySettingsForSetupWizardActivity activity =
|
||||
Robolectric.buildActivity(AccessibilitySettingsForSetupWizardActivity.class,
|
||||
new Intent(Intent.ACTION_MAIN).setComponent(new ComponentName(
|
||||
RuntimeEnvironment.application, CLASS_NAME_FONT_SIZE_SETTINGS_FOR_SUW)).
|
||||
putExtra(WizardManagerHelper.EXTRA_IS_FIRST_RUN, true).
|
||||
putExtra(WizardManagerHelper.EXTRA_IS_SETUP_FLOW, true)).get();
|
||||
@Test
|
||||
public void onCreate_hasFontSizeComponent_shouldGoToFontSizePreferenceDirectly() {
|
||||
AccessibilitySettingsForSetupWizardActivity activity =
|
||||
Robolectric.buildActivity(AccessibilitySettingsForSetupWizardActivity.class,
|
||||
new Intent(Intent.ACTION_MAIN).setComponent(new ComponentName(
|
||||
RuntimeEnvironment.application,
|
||||
CLASS_NAME_FONT_SIZE_SETTINGS_FOR_SUW))
|
||||
.putExtra(WizardManagerHelper.EXTRA_IS_FIRST_RUN, true)
|
||||
.putExtra(WizardManagerHelper.EXTRA_IS_SETUP_FLOW, true)).get();
|
||||
|
||||
activity.tryLaunchFontSizeSettings();
|
||||
activity.tryLaunchFontSizeSettings();
|
||||
|
||||
final Intent launchIntent = Shadows.shadowOf(activity).getNextStartedActivity();
|
||||
assertThat(launchIntent).isNotNull();
|
||||
assertThat(launchIntent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT)).isEqualTo(
|
||||
FontSizePreferenceFragmentForSetupWizard.class.getName());
|
||||
assertThat(activity.isFinishing()).isTrue();
|
||||
}
|
||||
final Intent launchIntent = Shadows.shadowOf(activity).getNextStartedActivity();
|
||||
assertThat(launchIntent).isNotNull();
|
||||
assertThat(launchIntent.getIntExtra(VISION_FRAGMENT_NO, -1)).isEqualTo(
|
||||
FragmentType.FONT_SIZE);
|
||||
assertThat(activity.isFinishing()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreate_noFontSizeComponent_shouldNotFinishCurrentActivity() {
|
||||
AccessibilitySettingsForSetupWizardActivity activity =
|
||||
Robolectric.buildActivity(AccessibilitySettingsForSetupWizardActivity.class,
|
||||
new Intent(Intent.ACTION_MAIN).
|
||||
putExtra(WizardManagerHelper.EXTRA_IS_FIRST_RUN, true).
|
||||
putExtra(WizardManagerHelper.EXTRA_IS_SETUP_FLOW, true)).get();
|
||||
@Test
|
||||
public void onCreate_noFontSizeComponent_shouldNotFinishCurrentActivity() {
|
||||
AccessibilitySettingsForSetupWizardActivity activity =
|
||||
Robolectric.buildActivity(AccessibilitySettingsForSetupWizardActivity.class,
|
||||
new Intent(Intent.ACTION_MAIN)
|
||||
.putExtra(WizardManagerHelper.EXTRA_IS_FIRST_RUN, true)
|
||||
.putExtra(WizardManagerHelper.EXTRA_IS_SETUP_FLOW, true)).get();
|
||||
|
||||
activity.tryLaunchFontSizeSettings();
|
||||
activity.tryLaunchFontSizeSettings();
|
||||
|
||||
final Intent launchIntent = Shadows.shadowOf(activity).getNextStartedActivity();
|
||||
assertThat(launchIntent).isNull();
|
||||
assertThat(activity.isFinishing()).isFalse();
|
||||
}
|
||||
final Intent launchIntent = Shadows.shadowOf(activity).getNextStartedActivity();
|
||||
assertThat(launchIntent).isNull();
|
||||
assertThat(activity.isFinishing()).isFalse();
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.accessibility;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.google.android.setupdesign.GlifPreferenceLayout;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
/** Tests for {@link AccessibilitySetupWizardUtils} */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AccessibilitySetupWizardUtilsTest {
|
||||
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
|
||||
@Test
|
||||
public void setupGlifPreferenceLayout_assignValueToVariable() {
|
||||
final String title = "title";
|
||||
final String description = "description";
|
||||
final Drawable icon = mock(Drawable.class);
|
||||
GlifPreferenceLayout layout = mock(GlifPreferenceLayout.class);
|
||||
|
||||
AccessibilitySetupWizardUtils.updateGlifPreferenceLayout(mContext, layout, title,
|
||||
description, icon);
|
||||
|
||||
verify(layout).setHeaderText(title);
|
||||
verify(layout).setDescriptionText(description);
|
||||
verify(layout).setIcon(icon);
|
||||
verify(layout).setHeaderText(title);
|
||||
}
|
||||
}
|
@@ -180,8 +180,8 @@ public class AccessibilityShortcutPreferenceFragmentTest {
|
||||
savedInstanceState.putInt(KEY_SAVED_USER_SHORTCUT_TYPE,
|
||||
AccessibilityUtil.UserShortcutType.SOFTWARE
|
||||
| AccessibilityUtil.UserShortcutType.HARDWARE);
|
||||
mFragment.onCreate(savedInstanceState);
|
||||
mFragment.onAttach(mContext);
|
||||
mFragment.onCreate(savedInstanceState);
|
||||
mFragment.setupEditShortcutDialog(dialog);
|
||||
final int value = mFragment.getShortcutTypeCheckBoxValue();
|
||||
mFragment.saveNonEmptyUserShortcutType(value);
|
||||
@@ -195,9 +195,11 @@ public class AccessibilityShortcutPreferenceFragmentTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowFragment.class)
|
||||
public void showGeneralCategory_shouldInitCategory() {
|
||||
final Bundle savedInstanceState = new Bundle();
|
||||
when(mFragment.showGeneralCategory()).thenReturn(true);
|
||||
mFragment.onAttach(mContext);
|
||||
mFragment.onCreate(savedInstanceState);
|
||||
|
||||
verify(mFragment).initGeneralCategory();
|
||||
|
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.accessibility;
|
||||
|
||||
import static com.android.settings.accessibility.AccessibilityScreenSizeForSetupWizardActivity.VISION_FRAGMENT_NO;
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.SettingsBaseActivity.EXTRA_PAGE_TRANSITION_TYPE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.accessibility.AccessibilityScreenSizeForSetupWizardActivity.FragmentType;
|
||||
import com.android.settingslib.transition.SettingsTransitionHelper.TransitionType;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
/** Tests for {@link FontSizePreferenceController}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class FontSizePreferenceControllerTest {
|
||||
private static final String TEST_KEY = "test_key";
|
||||
|
||||
private Activity mActivity;
|
||||
private FontSizePreferenceController mController;
|
||||
Preference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mActivity = Robolectric.setupActivity(Activity.class);
|
||||
mController = new FontSizePreferenceController(mActivity, TEST_KEY);
|
||||
mPreference = new Preference(mActivity);
|
||||
mPreference.setKey(TEST_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_returnAvailable() {
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_launchActivityWithExpectedValues() {
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
final Intent nextActivity = shadowOf(mActivity).getNextStartedActivity();
|
||||
assertThat(nextActivity.getIntExtra(VISION_FRAGMENT_NO, /* defaultValue= */-1))
|
||||
.isEqualTo(FragmentType.FONT_SIZE);
|
||||
assertThat(nextActivity.getIntExtra(EXTRA_PAGE_TRANSITION_TYPE, /* defaultValue= */-1))
|
||||
.isEqualTo(TransitionType.TRANSITION_FADE);
|
||||
}
|
||||
}
|
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.accessibility;
|
||||
|
||||
import static com.android.settings.accessibility.AccessibilityScreenSizeForSetupWizardActivity.VISION_FRAGMENT_NO;
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.SettingsBaseActivity.EXTRA_PAGE_TRANSITION_TYPE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.accessibility.AccessibilityScreenSizeForSetupWizardActivity.FragmentType;
|
||||
import com.android.settingslib.transition.SettingsTransitionHelper.TransitionType;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
/** Tests for {@link ScreenSizePreferenceController}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class ScreenSizePreferenceControllerTest {
|
||||
private static final String TEST_KEY = "test_key";
|
||||
|
||||
private Activity mActivity;
|
||||
private ScreenSizePreferenceController mController;
|
||||
Preference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mActivity = Robolectric.setupActivity(Activity.class);
|
||||
mController = new ScreenSizePreferenceController(mActivity, TEST_KEY);
|
||||
mPreference = new Preference(mActivity);
|
||||
mPreference.setKey(TEST_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_returnAvailable() {
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_launchActivityWithExpectedValues() {
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
final Intent nextActivity = shadowOf(mActivity).getNextStartedActivity();
|
||||
assertThat(nextActivity.getIntExtra(VISION_FRAGMENT_NO, /* defaultValue= */-1))
|
||||
.isEqualTo(FragmentType.SCREEN_SIZE);
|
||||
assertThat(nextActivity.getIntExtra(EXTRA_PAGE_TRANSITION_TYPE, /* defaultValue= */-1))
|
||||
.isEqualTo(TransitionType.TRANSITION_FADE);
|
||||
}
|
||||
}
|
@@ -43,7 +43,6 @@ import android.os.UserManager;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.dashboard.DashboardFeatureProviderImpl;
|
||||
import com.android.settings.testutils.shadow.ShadowAccountManager;
|
||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||
@@ -151,9 +150,9 @@ public class AccountDetailDashboardFragmentTest {
|
||||
|
||||
final FragmentActivity activity = Robolectric.setupActivity(FragmentActivity.class);
|
||||
final Preference preference = new Preference(mContext);
|
||||
dashboardFeatureProvider.bindPreferenceToTileAndGetObservers(activity,
|
||||
false /* forceRoundedIcon */, MetricsProto.MetricsEvent.DASHBOARD_SUMMARY,
|
||||
preference, tile, null /* key */, Preference.DEFAULT_ORDER);
|
||||
dashboardFeatureProvider.bindPreferenceToTileAndGetObservers(activity, mFragment,
|
||||
false /* forceRoundedIcon */, preference, tile, null /* key */,
|
||||
Preference.DEFAULT_ORDER);
|
||||
|
||||
assertThat(preference.getKey()).isEqualTo(tile.getKey(mContext));
|
||||
preference.performClick();
|
||||
|
@@ -18,8 +18,17 @@ package com.android.settings.applications.managedomainurls;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.verify.domain.DomainVerificationManager;
|
||||
import android.content.pm.verify.domain.DomainVerificationUserState;
|
||||
import android.util.IconDrawableFactory;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -28,6 +37,8 @@ import com.android.settingslib.applications.ApplicationsState;
|
||||
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;
|
||||
|
||||
@@ -40,16 +51,30 @@ public class DomainAppPreferenceControllerTest {
|
||||
private Context mContext;
|
||||
private IconDrawableFactory mIconDrawableFactory;
|
||||
|
||||
@Mock
|
||||
private DomainVerificationManager mDomainVerificationManager;
|
||||
@Mock
|
||||
private DomainVerificationUserState mDomainVerificationUserState;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mIconDrawableFactory = IconDrawableFactory.newInstance(mContext);
|
||||
mAppEntry = new ApplicationsState.AppEntry(
|
||||
mContext, createApplicationInfo(mContext.getPackageName()), 0);
|
||||
when(mContext.getSystemService(DomainVerificationManager.class)).thenReturn(
|
||||
mDomainVerificationManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLayoutResource_shouldUseAppPreferenceLayout() {
|
||||
public void getLayoutResource_shouldUseAppPreferenceLayout()
|
||||
throws PackageManager.NameNotFoundException {
|
||||
final DomainVerificationUserState domainVerificationUserState = mock(
|
||||
DomainVerificationUserState.class);
|
||||
doReturn(domainVerificationUserState).when(
|
||||
mDomainVerificationManager).getDomainVerificationUserState(anyString());
|
||||
doReturn(true).when(domainVerificationUserState).isLinkHandlingAllowed();
|
||||
final DomainAppPreference pref = new DomainAppPreference(
|
||||
mContext, mIconDrawableFactory, mAppEntry);
|
||||
|
||||
|
@@ -104,12 +104,16 @@ public class CombinedBiometricStatusPreferenceControllerTest {
|
||||
RestrictedLockUtils.EnforcedAdmin admin = mock(RestrictedLockUtils.EnforcedAdmin.class);
|
||||
|
||||
mController.mPreference = restrictedPreference;
|
||||
mController.updateStateInternal(admin);
|
||||
mController.updateStateInternal(admin, true, true);
|
||||
verify(restrictedPreference).setDisabledByAdmin(eq(admin));
|
||||
|
||||
reset(admin);
|
||||
mController.updateStateInternal(admin, true, false);
|
||||
verify(restrictedPreference).setDisabledByAdmin(eq(null));
|
||||
|
||||
mController.updateStateInternal(null /* enforcedAdmin */);
|
||||
verify(restrictedPreference, never()).setDisabledByAdmin(any());
|
||||
mController.updateStateInternal(admin, false, true);
|
||||
verify(restrictedPreference).setDisabledByAdmin(eq(null));
|
||||
|
||||
mController.updateStateInternal(admin, false, false);
|
||||
verify(restrictedPreference).setDisabledByAdmin(eq(null));
|
||||
}
|
||||
}
|
||||
|
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.bluetooth;
|
||||
|
||||
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.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
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;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class BluetoothFilesPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private BluetoothFilesPreferenceController mController;
|
||||
private Preference mPreference;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mController = new BluetoothFilesPreferenceController(mContext);
|
||||
mPreference = new Preference(mContext);
|
||||
mPreference.setKey(BluetoothFilesPreferenceController.KEY_RECEIVED_FILES);
|
||||
doReturn(mPackageManager).when(mContext).getPackageManager();
|
||||
doReturn(true).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlePreferenceTreeClick_sendBroadcast() {
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
final Intent intent = ShadowApplication.getInstance().getNextStartedActivity();
|
||||
assertThat(intent).isNotNull();
|
||||
assertThat(intent.getAction())
|
||||
.isEqualTo(BluetoothFilesPreferenceController.ACTION_OPEN_FILES);
|
||||
|
||||
final Bundle bundle = intent.getExtras();
|
||||
assertThat(bundle.getInt(BluetoothFilesPreferenceController.EXTRA_DIRECTION)).isEqualTo(1);
|
||||
assertThat(bundle.getBoolean(BluetoothFilesPreferenceController.EXTRA_SHOW_ALL_FILES))
|
||||
.isTrue();
|
||||
}
|
||||
}
|
@@ -98,20 +98,6 @@ public class ForgetDeviceDialogFragmentTest {
|
||||
assertThat(mActivity.isFinishing()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDialog_untetheredDevice_showUntetheredMessage() {
|
||||
when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET))
|
||||
.thenReturn("true".getBytes());
|
||||
|
||||
FragmentController.setupFragment(mFragment, FragmentActivity.class,
|
||||
0 /* containerViewId */, null /* bundle */);
|
||||
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
|
||||
|
||||
assertThat(shadowDialog.getMessage()).isEqualTo(
|
||||
mContext.getString(R.string.bluetooth_untethered_unpair_dialog_body, DEVICE_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDialog_normalDevice_showNormalMessage() {
|
||||
when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET))
|
||||
|
@@ -174,18 +174,36 @@ public class PreferenceXmlParserUtilsTest {
|
||||
assertThat(entries).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractHomepageMetadata_shouldContainKeyAndHighlightableMenuKey()
|
||||
throws IOException, XmlPullParserException {
|
||||
List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
|
||||
R.xml.top_level_settings,
|
||||
MetadataFlag.FLAG_NEED_KEY | MetadataFlag.FLAG_NEED_HIGHLIGHTABLE_MENU_KEY);
|
||||
|
||||
assertThat(metadata).isNotEmpty();
|
||||
for (Bundle bundle : metadata) {
|
||||
assertThat(bundle.getString(PreferenceXmlParserUtils.METADATA_KEY)).isNotNull();
|
||||
assertThat(bundle.getString(PreferenceXmlParserUtils.METADATA_HIGHLIGHTABLE_MENU_KEY))
|
||||
.isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(qualifiers = "mcc999")
|
||||
public void extractMetadata_shouldContainKeyAndControllerName()
|
||||
public void extractMetadata_shouldContainKeyAndControllerNameAndHighlightableMenuKey()
|
||||
throws IOException, XmlPullParserException {
|
||||
List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
|
||||
R.xml.location_settings,
|
||||
MetadataFlag.FLAG_NEED_KEY | MetadataFlag.FLAG_NEED_PREF_CONTROLLER);
|
||||
MetadataFlag.FLAG_NEED_KEY | MetadataFlag.FLAG_NEED_PREF_CONTROLLER
|
||||
| MetadataFlag.FLAG_NEED_HIGHLIGHTABLE_MENU_KEY);
|
||||
|
||||
assertThat(metadata).isNotEmpty();
|
||||
for (Bundle bundle : metadata) {
|
||||
assertThat(bundle.getString(PreferenceXmlParserUtils.METADATA_KEY)).isNotNull();
|
||||
assertThat(bundle.getString(PreferenceXmlParserUtils.METADATA_CONTROLLER)).isNotNull();
|
||||
assertThat(bundle.getString(PreferenceXmlParserUtils.METADATA_HIGHLIGHTABLE_MENU_KEY))
|
||||
.isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -114,6 +114,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
private Bundle mSwitchMetaData;
|
||||
private DashboardFeatureProviderImpl mImpl;
|
||||
private boolean mForceRoundedIcon;
|
||||
private DashboardFragment mFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -144,6 +145,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
.thenReturn(new ResolveInfo());
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mImpl = new DashboardFeatureProviderImpl(mContext);
|
||||
mFragment = new TestFragment();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -159,8 +161,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
doReturn(Icon.createWithBitmap(Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565)))
|
||||
.when(tile).getIcon(any(Context.class));
|
||||
mActivityInfo.metaData.putString(SettingsActivity.META_DATA_KEY_FRAGMENT_CLASS, "HI");
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mForceRoundedIcon,
|
||||
MetricsEvent.SETTINGS_GESTURES, preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mFragment, mForceRoundedIcon,
|
||||
preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
|
||||
assertThat(preference.getTitle()).isEqualTo(mContext.getText(R.string.settings_label));
|
||||
assertThat(preference.getSummary())
|
||||
@@ -180,8 +182,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
doReturn(Icon.createWithBitmap(Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565)))
|
||||
.when(tile).getIcon(any(Context.class));
|
||||
final List<DynamicDataObserver> observers = mImpl.bindPreferenceToTileAndGetObservers(
|
||||
mActivity, mForceRoundedIcon, MetricsEvent.SETTINGS_GESTURES, preference, tile,
|
||||
null /* key*/, Preference.DEFAULT_ORDER);
|
||||
mActivity, mFragment, mForceRoundedIcon, preference, tile, null /* key*/,
|
||||
Preference.DEFAULT_ORDER);
|
||||
|
||||
assertThat(preference.getTitle()).isEqualTo(mContext.getText(R.string.settings_label));
|
||||
assertThat(preference.getSummary())
|
||||
@@ -198,8 +200,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
mActivityInfo.metaData.putInt(META_DATA_KEY_ORDER, 10);
|
||||
final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mForceRoundedIcon,
|
||||
MetricsEvent.SETTINGS_GESTURES, preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mFragment, mForceRoundedIcon,
|
||||
preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
|
||||
assertThat(preference.getFragment()).isNull();
|
||||
assertThat(preference.getOnPreferenceClickListener()).isNotNull();
|
||||
@@ -214,8 +216,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
tile.userHandle.add(mock(UserHandle.class));
|
||||
tile.userHandle.add(mock(UserHandle.class));
|
||||
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mForceRoundedIcon,
|
||||
MetricsEvent.SETTINGS_GESTURES, preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mFragment, mForceRoundedIcon,
|
||||
preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
preference.getOnPreferenceClickListener().onPreferenceClick(null);
|
||||
|
||||
verify(mActivity).getSupportFragmentManager();
|
||||
@@ -231,15 +233,15 @@ public class DashboardFeatureProviderImplTest {
|
||||
when(mActivity.getSystemService(Context.USER_SERVICE))
|
||||
.thenReturn(mUserManager);
|
||||
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mForceRoundedIcon,
|
||||
MetricsEvent.SETTINGS_GESTURES, preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mFragment, mForceRoundedIcon,
|
||||
preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
preference.getOnPreferenceClickListener().onPreferenceClick(null);
|
||||
|
||||
verify(mFeatureFactory.metricsFeatureProvider).logStartedIntent(
|
||||
any(Intent.class),
|
||||
eq(MetricsEvent.SETTINGS_GESTURES));
|
||||
verify(mActivity)
|
||||
.startActivityForResultAsUser(any(Intent.class), anyInt(), any(UserHandle.class));
|
||||
.startActivityAsUser(any(Intent.class), any(UserHandle.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -250,21 +252,21 @@ public class DashboardFeatureProviderImplTest {
|
||||
tile.userHandle = new ArrayList<>();
|
||||
tile.userHandle.add(mock(UserHandle.class));
|
||||
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mForceRoundedIcon,
|
||||
MetricsEvent.SETTINGS_GESTURES, preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mFragment, mForceRoundedIcon,
|
||||
preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
preference.getOnPreferenceClickListener().onPreferenceClick(null);
|
||||
verify(mFeatureFactory.metricsFeatureProvider).logStartedIntent(
|
||||
any(Intent.class),
|
||||
anyInt());
|
||||
verify(mActivity)
|
||||
.startActivityForResultAsUser(any(Intent.class), anyInt(), any(UserHandle.class));
|
||||
.startActivityAsUser(any(Intent.class), any(UserHandle.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindPreference_nullPreference_shouldIgnore() {
|
||||
final Tile tile = mock(Tile.class);
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mForceRoundedIcon,
|
||||
MetricsEvent.VIEW_UNKNOWN, null, tile, "123", Preference.DEFAULT_ORDER);
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mFragment, mForceRoundedIcon,
|
||||
null /* keys */, tile, "123", Preference.DEFAULT_ORDER);
|
||||
|
||||
verifyZeroInteractions(tile);
|
||||
}
|
||||
@@ -273,8 +275,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
public void bindPreference_withNullKeyNullPriority_shouldGenerateKeyAndPriority() {
|
||||
final Preference preference = new Preference(RuntimeEnvironment.application);
|
||||
final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mForceRoundedIcon,
|
||||
MetricsEvent.VIEW_UNKNOWN, preference, tile, null /*key */,
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mFragment, mForceRoundedIcon,
|
||||
preference, tile, null /* key */,
|
||||
Preference.DEFAULT_ORDER);
|
||||
|
||||
assertThat(preference.getKey()).isNotNull();
|
||||
@@ -288,9 +290,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
|
||||
final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mForceRoundedIcon,
|
||||
MetricsEvent.VIEW_UNKNOWN, preference, tile, null /*key */,
|
||||
Preference.DEFAULT_ORDER);
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mFragment, mForceRoundedIcon,
|
||||
preference, tile, null /* key */, Preference.DEFAULT_ORDER);
|
||||
|
||||
assertThat(preference.getSummary()).isNull();
|
||||
}
|
||||
@@ -304,8 +305,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
mActivityInfo.metaData.putString(TileUtils.META_DATA_PREFERENCE_SUMMARY_URI, uriString);
|
||||
|
||||
final List<DynamicDataObserver> observers = mImpl.bindPreferenceToTileAndGetObservers(
|
||||
mActivity, mForceRoundedIcon, MetricsEvent.VIEW_UNKNOWN, preference, tile,
|
||||
null /*key */, Preference.DEFAULT_ORDER);
|
||||
mActivity, mFragment, mForceRoundedIcon, preference, tile, null /* key */,
|
||||
Preference.DEFAULT_ORDER);
|
||||
|
||||
assertThat(preference.getSummary()).isEqualTo(ShadowTileUtils.MOCK_SUMMARY);
|
||||
assertThat(observers.get(0).getUri().toString()).isEqualTo(uriString);
|
||||
@@ -320,8 +321,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
mActivityInfo.metaData.putString(TileUtils.META_DATA_PREFERENCE_TITLE_URI, uriString);
|
||||
|
||||
final List<DynamicDataObserver> observers = mImpl.bindPreferenceToTileAndGetObservers(
|
||||
mActivity, mForceRoundedIcon, MetricsEvent.VIEW_UNKNOWN, preference, tile,
|
||||
null /*key */, Preference.DEFAULT_ORDER);
|
||||
mActivity, mFragment, mForceRoundedIcon, preference, tile, null /* key */,
|
||||
Preference.DEFAULT_ORDER);
|
||||
|
||||
assertThat(preference.getTitle()).isEqualTo(ShadowTileUtils.MOCK_SUMMARY);
|
||||
assertThat(observers.get(0).getUri().toString()).isEqualTo(uriString);
|
||||
@@ -336,9 +337,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putBoolean(EXTRA_SWITCH_SET_CHECKED_ERROR, false);
|
||||
ShadowTileUtils.setResultBundle(bundle);
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mForceRoundedIcon,
|
||||
MetricsEvent.VIEW_UNKNOWN, preference, tile, null /*key */,
|
||||
Preference.DEFAULT_ORDER);
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mFragment, mForceRoundedIcon,
|
||||
preference, tile, null /* key */, Preference.DEFAULT_ORDER);
|
||||
|
||||
preference.callChangeListener(false);
|
||||
|
||||
@@ -358,9 +358,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putBoolean(EXTRA_SWITCH_SET_CHECKED_ERROR, true);
|
||||
ShadowTileUtils.setResultBundle(bundle);
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mForceRoundedIcon,
|
||||
MetricsEvent.VIEW_UNKNOWN, preference, tile, null /*key */,
|
||||
Preference.DEFAULT_ORDER);
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mFragment, mForceRoundedIcon,
|
||||
preference, tile, null /* key */, Preference.DEFAULT_ORDER);
|
||||
|
||||
preference.callChangeListener(true);
|
||||
|
||||
@@ -378,8 +377,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
final Tile tile = new ProviderTile(mProviderInfo, CategoryKey.CATEGORY_HOMEPAGE,
|
||||
mSwitchMetaData);
|
||||
final List<DynamicDataObserver> observers = mImpl.bindPreferenceToTileAndGetObservers(
|
||||
mActivity, mForceRoundedIcon, MetricsEvent.VIEW_UNKNOWN, preference, tile,
|
||||
null /*key */, Preference.DEFAULT_ORDER);
|
||||
mActivity, mFragment, mForceRoundedIcon, preference, tile, null /* key */,
|
||||
Preference.DEFAULT_ORDER);
|
||||
|
||||
ShadowTileUtils.setProviderChecked(false);
|
||||
observers.get(0).onDataChanged();
|
||||
@@ -397,9 +396,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
final Preference preference = new Preference(RuntimeEnvironment.application);
|
||||
mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "key");
|
||||
final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mForceRoundedIcon,
|
||||
MetricsEvent.VIEW_UNKNOWN, preference, tile, null /* key */,
|
||||
Preference.DEFAULT_ORDER);
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mFragment, mForceRoundedIcon,
|
||||
preference, tile, null /* key */, Preference.DEFAULT_ORDER);
|
||||
|
||||
assertThat(preference.getKey()).isEqualTo(tile.getKey(mContext));
|
||||
}
|
||||
@@ -483,8 +481,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
mActivityInfo.metaData.putInt(META_DATA_KEY_ORDER, 10);
|
||||
final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mForceRoundedIcon,
|
||||
MetricsEvent.VIEW_UNKNOWN, preference, tile, "123", baseOrder);
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mFragment, mForceRoundedIcon,
|
||||
preference, tile, "123", baseOrder);
|
||||
|
||||
assertThat(preference.getOrder()).isEqualTo(tile.getOrder() + baseOrder);
|
||||
}
|
||||
@@ -496,8 +494,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
mActivityInfo.metaData.putInt(META_DATA_KEY_ORDER, 10);
|
||||
final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
mActivityInfo.metaData.putInt(META_DATA_KEY_ORDER, testOrder);
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mForceRoundedIcon,
|
||||
MetricsEvent.VIEW_UNKNOWN, preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mFragment, mForceRoundedIcon,
|
||||
preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
|
||||
assertThat(preference.getOrder()).isEqualTo(testOrder);
|
||||
}
|
||||
@@ -508,8 +506,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
mActivityInfo.metaData.putString(META_DATA_KEY_ORDER, "hello");
|
||||
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mForceRoundedIcon,
|
||||
MetricsEvent.VIEW_UNKNOWN, preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
mImpl.bindPreferenceToTileAndGetObservers(mActivity, mFragment, mForceRoundedIcon,
|
||||
preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
|
||||
assertThat(preference.getOrder()).isEqualTo(Preference.DEFAULT_ORDER);
|
||||
}
|
||||
@@ -522,8 +520,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "key");
|
||||
mActivityInfo.metaData.putString("com.android.settings.intent.action", "TestAction");
|
||||
tile.userHandle = null;
|
||||
mImpl.bindPreferenceToTileAndGetObservers(activity, mForceRoundedIcon,
|
||||
MetricsEvent.SETTINGS_GESTURES, preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
mImpl.bindPreferenceToTileAndGetObservers(activity, mFragment, mForceRoundedIcon,
|
||||
preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
preference.performClick();
|
||||
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
|
||||
|
||||
@@ -546,8 +544,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
mActivityInfo.metaData.putString("com.android.settings.intent.action", "TestAction");
|
||||
tile.userHandle = null;
|
||||
|
||||
mImpl.bindPreferenceToTileAndGetObservers(activity, mForceRoundedIcon,
|
||||
MetricsEvent.SETTINGS_GESTURES, preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
mImpl.bindPreferenceToTileAndGetObservers(activity, mFragment, mForceRoundedIcon,
|
||||
preference, tile, "123", Preference.DEFAULT_ORDER);
|
||||
preference.performClick();
|
||||
|
||||
final ShadowActivity.IntentForResult launchIntent =
|
||||
@@ -568,7 +566,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
mImpl.openTileIntent(mActivity, tile);
|
||||
|
||||
verify(mActivity, never())
|
||||
.startActivityForResult(any(Intent.class), eq(0));
|
||||
.startActivity(any(Intent.class));
|
||||
verify(mActivity).getSupportFragmentManager();
|
||||
}
|
||||
|
||||
@@ -585,7 +583,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
mImpl.openTileIntent(mActivity, tile);
|
||||
|
||||
verify(mActivity, never())
|
||||
.startActivityForResult(any(Intent.class), eq(0));
|
||||
.startActivity(any(Intent.class));
|
||||
verify(mActivity).getSupportFragmentManager();
|
||||
}
|
||||
|
||||
@@ -602,7 +600,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
mImpl.openTileIntent(mActivity, tile);
|
||||
|
||||
verify(mActivity)
|
||||
.startActivityForResult(any(Intent.class), eq(0));
|
||||
.startActivity(any(Intent.class));
|
||||
verify(mActivity, never()).getSupportFragmentManager();
|
||||
}
|
||||
|
||||
@@ -623,7 +621,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
|
||||
final ArgumentCaptor<UserHandle> argument = ArgumentCaptor.forClass(UserHandle.class);
|
||||
verify(mActivity)
|
||||
.startActivityForResultAsUser(any(Intent.class), anyInt(), argument.capture());
|
||||
.startActivityAsUser(any(Intent.class), argument.capture());
|
||||
assertThat(argument.getValue().getIdentifier()).isEqualTo(userId);
|
||||
verify(mActivity, never()).getSupportFragmentManager();
|
||||
}
|
||||
@@ -642,7 +640,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
mImpl.openTileIntent(mActivity, tile);
|
||||
|
||||
verify(mActivity, never())
|
||||
.startActivityForResultAsUser(any(Intent.class), anyInt(), any(UserHandle.class));
|
||||
.startActivityAsUser(any(Intent.class), any(UserHandle.class));
|
||||
verify(mActivity).getSupportFragmentManager();
|
||||
}
|
||||
|
||||
@@ -665,8 +663,26 @@ public class DashboardFeatureProviderImplTest {
|
||||
|
||||
final ArgumentCaptor<UserHandle> argument = ArgumentCaptor.forClass(UserHandle.class);
|
||||
verify(mActivity)
|
||||
.startActivityForResultAsUser(any(Intent.class), anyInt(), argument.capture());
|
||||
.startActivityAsUser(any(Intent.class), argument.capture());
|
||||
assertThat(argument.getValue().getIdentifier()).isEqualTo(0);
|
||||
verify(mActivity, never()).getSupportFragmentManager();
|
||||
}
|
||||
|
||||
private static class TestFragment extends DashboardFragment {
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.SETTINGS_GESTURES;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.gestures;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return "TestFragment";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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 android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
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 LockscreenClockPreferenceControllerTest {
|
||||
|
||||
private static final String TEST_KEY = "test_key";
|
||||
private static final String SETTING_KEY = Settings.Secure.LOCKSCREEN_USE_DOUBLE_LINE_CLOCK;
|
||||
|
||||
private Context mContext;
|
||||
private ContentResolver mContentResolver;
|
||||
private LockscreenClockPreferenceController mController;
|
||||
|
||||
@Mock
|
||||
private Preference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mContentResolver = mContext.getContentResolver();
|
||||
mController = new LockscreenClockPreferenceController(mContext, TEST_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_SettingIs1_returnTrue() {
|
||||
Settings.Secure.putInt(mContentResolver, SETTING_KEY, 1);
|
||||
|
||||
assertThat(mController.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_SettingIs0_returnFalse() {
|
||||
Settings.Secure.putInt(mContentResolver, SETTING_KEY, 0);
|
||||
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_SettingIsNotSet_returnTrue() {
|
||||
Settings.Secure.putString(mContentResolver, SETTING_KEY, null);
|
||||
|
||||
assertThat(mController.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_true_SettingIsNot0() {
|
||||
mController.setChecked(true);
|
||||
|
||||
assertThat(Settings.Secure.getInt(mContentResolver, SETTING_KEY, 0)).isNotEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_false_SettingIs0() {
|
||||
mController.setChecked(false);
|
||||
|
||||
assertThat(Settings.Secure.getInt(mContentResolver, SETTING_KEY, 0)).isEqualTo(0);
|
||||
}
|
||||
}
|
@@ -29,6 +29,7 @@ import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.testutils.shadow.ShadowActivityEmbeddingUtils;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@@ -43,7 +44,7 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowPackageManager;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {SettingsShadowResources.class})
|
||||
@Config(shadows = {SettingsShadowResources.class, ShadowActivityEmbeddingUtils.class})
|
||||
public class TopLevelWallpaperPreferenceControllerTest {
|
||||
private static final String TEST_KEY = "test_key";
|
||||
|
||||
@@ -204,18 +205,32 @@ public class TopLevelWallpaperPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_launchClearTask() {
|
||||
mShadowPackageManager.setResolveInfosForIntent(
|
||||
mWallpaperIntent, Lists.newArrayList());
|
||||
public void handlePreferenceTreeClick_embeddingActivityDisabled_launchWithTaskFlag() {
|
||||
ShadowActivityEmbeddingUtils.setIsEmbeddingActivityEnabled(false);
|
||||
mShadowPackageManager.setResolveInfosForIntent(
|
||||
mStylesAndWallpaperIntent, Lists.newArrayList(mock(ResolveInfo.class)));
|
||||
|
||||
Preference preference = new Preference(mContext);
|
||||
preference.setKey(TEST_KEY);
|
||||
|
||||
mController.handlePreferenceTreeClick(preference);
|
||||
|
||||
assertThat((Shadows.shadowOf(mContext).getNextStartedActivityForResult()
|
||||
.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_TASK) != 0).isTrue();
|
||||
int flags = Shadows.shadowOf(mContext).getNextStartedActivityForResult().intent.getFlags();
|
||||
assertThat((flags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0).isTrue();
|
||||
assertThat((flags & Intent.FLAG_ACTIVITY_CLEAR_TASK) != 0).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_embeddingActivityEnabled_launchWithoutTaskFlag() {
|
||||
ShadowActivityEmbeddingUtils.setIsEmbeddingActivityEnabled(true);
|
||||
mShadowPackageManager.setResolveInfosForIntent(
|
||||
mStylesAndWallpaperIntent, Lists.newArrayList(mock(ResolveInfo.class)));
|
||||
Preference preference = new Preference(mContext);
|
||||
preference.setKey(TEST_KEY);
|
||||
|
||||
mController.handlePreferenceTreeClick(preference);
|
||||
|
||||
int flags = Shadows.shadowOf(mContext).getNextStartedActivityForResult().intent.getFlags();
|
||||
assertThat((flags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0).isFalse();
|
||||
assertThat((flags & Intent.FLAG_ACTIVITY_CLEAR_TASK) != 0).isFalse();
|
||||
}
|
||||
}
|
||||
|
@@ -16,17 +16,18 @@
|
||||
|
||||
package com.android.settings.dream;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.Button;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.dream.DreamBackend;
|
||||
import com.android.settingslib.widget.MainSwitchPreference;
|
||||
import com.android.settingslib.widget.LayoutPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -46,7 +47,9 @@ public class StartNowPreferenceControllerTest {
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private MainSwitchPreference mPref;
|
||||
private LayoutPreference mLayoutPref;
|
||||
@Mock
|
||||
private Button mButton;
|
||||
@Mock
|
||||
private DreamBackend mBackend;
|
||||
|
||||
@@ -56,36 +59,29 @@ public class StartNowPreferenceControllerTest {
|
||||
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mController = new StartNowPreferenceController(mContext, "key");
|
||||
mPref = mock(MainSwitchPreference.class);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPref);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mLayoutPref);
|
||||
when(mLayoutPref.findViewById(R.id.dream_start_now_button)).thenReturn(mButton);
|
||||
|
||||
ReflectionHelpers.setField(mController, "mBackend", mBackend);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_shouldAddOnSwitchChangeListener() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mPref).addOnSwitchChangeListener(mController);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_neverDreaming_preferenceShouldDidabled() {
|
||||
public void updateState_neverDreaming_buttonShouldDidabled() {
|
||||
when(mBackend.getWhenToDreamSetting()).thenReturn(DreamBackend.NEVER);
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mController.updateState(mPref);
|
||||
mController.updateState(mLayoutPref);
|
||||
|
||||
verify(mPref).setEnabled(false);
|
||||
verify(mButton).setEnabled(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_dreamIsAvailable_preferenceShouldEnabled() {
|
||||
public void updateState_dreamIsAvailable_buttonShouldEnabled() {
|
||||
when(mBackend.getWhenToDreamSetting()).thenReturn(DreamBackend.EITHER);
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mController.updateState(mPref);
|
||||
mController.updateState(mLayoutPref);
|
||||
|
||||
verify(mPref).setEnabled(true);
|
||||
verify(mButton).setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
@@ -356,7 +356,7 @@ public class EnterprisePrivacyFeatureProviderImplTest {
|
||||
addWorkPolicyInfoIntent(mOwner.getPackageName(), true, false);
|
||||
assertThat(mProvider.hasWorkPolicyInfo()).isFalse();
|
||||
|
||||
assertThat(mProvider.showWorkPolicyInfo()).isFalse();
|
||||
assertThat(mProvider.showWorkPolicyInfo(mContext)).isFalse();
|
||||
verify(mContext, never()).startActivity(any());
|
||||
}
|
||||
|
||||
@@ -365,12 +365,12 @@ public class EnterprisePrivacyFeatureProviderImplTest {
|
||||
// If the intent is not resolved, then there's no info to show for DO
|
||||
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(mOwner);
|
||||
assertThat(mProvider.hasWorkPolicyInfo()).isFalse();
|
||||
assertThat(mProvider.showWorkPolicyInfo()).isFalse();
|
||||
assertThat(mProvider.showWorkPolicyInfo(mContext)).isFalse();
|
||||
|
||||
// If the intent is resolved, then we can use it to launch the activity
|
||||
Intent intent = addWorkPolicyInfoIntent(mOwner.getPackageName(), true, false);
|
||||
assertThat(mProvider.hasWorkPolicyInfo()).isTrue();
|
||||
assertThat(mProvider.showWorkPolicyInfo()).isTrue();
|
||||
assertThat(mProvider.showWorkPolicyInfo(mContext)).isTrue();
|
||||
verify(mContext).startActivity(intentEquals(intent));
|
||||
}
|
||||
|
||||
@@ -382,12 +382,12 @@ public class EnterprisePrivacyFeatureProviderImplTest {
|
||||
|
||||
// If the intent is not resolved, then there's no info to show for PO
|
||||
assertThat(mProvider.hasWorkPolicyInfo()).isFalse();
|
||||
assertThat(mProvider.showWorkPolicyInfo()).isFalse();
|
||||
assertThat(mProvider.showWorkPolicyInfo(mContext)).isFalse();
|
||||
|
||||
// If the intent is resolved, then we can use it to launch the activity in managed profile
|
||||
Intent intent = addWorkPolicyInfoIntent(mOwner.getPackageName(), false, true);
|
||||
assertThat(mProvider.hasWorkPolicyInfo()).isTrue();
|
||||
assertThat(mProvider.showWorkPolicyInfo()).isTrue();
|
||||
assertThat(mProvider.showWorkPolicyInfo(mContext)).isTrue();
|
||||
verify(mContext)
|
||||
.startActivityAsUser(
|
||||
intentEquals(intent),
|
||||
@@ -402,12 +402,12 @@ public class EnterprisePrivacyFeatureProviderImplTest {
|
||||
|
||||
// If the intent is not resolved, then there's no info to show for COMP
|
||||
assertThat(mProvider.hasWorkPolicyInfo()).isFalse();
|
||||
assertThat(mProvider.showWorkPolicyInfo()).isFalse();
|
||||
assertThat(mProvider.showWorkPolicyInfo(mContext)).isFalse();
|
||||
|
||||
// If the intent is resolved, then we can use it to launch the activity for device owner
|
||||
Intent intent = addWorkPolicyInfoIntent(mOwner.getPackageName(), true, true);
|
||||
assertThat(mProvider.hasWorkPolicyInfo()).isTrue();
|
||||
assertThat(mProvider.showWorkPolicyInfo()).isTrue();
|
||||
assertThat(mProvider.showWorkPolicyInfo(mContext)).isTrue();
|
||||
verify(mContext).startActivity(intentEquals(intent));
|
||||
}
|
||||
|
||||
|
@@ -30,9 +30,11 @@ import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.AppOpsManager;
|
||||
import android.app.backup.BackupManager;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -123,6 +125,9 @@ public class AdvancedPowerUsageDetailTest {
|
||||
private BatteryUtils mBatteryUtils;
|
||||
@Mock
|
||||
private BatteryOptimizeUtils mBatteryOptimizeUtils;
|
||||
@Mock
|
||||
private BackupManager mBackupManager;
|
||||
|
||||
private Context mContext;
|
||||
private Preference mForegroundPreference;
|
||||
private Preference mBackgroundPreference;
|
||||
@@ -180,9 +185,10 @@ public class AdvancedPowerUsageDetailTest {
|
||||
|
||||
mFragment.mHeaderPreference = mHeaderPreference;
|
||||
mFragment.mState = mState;
|
||||
mFragment.enableTriState = true;
|
||||
mFragment.mEnableTriState = true;
|
||||
mFragment.mBatteryUtils = new BatteryUtils(RuntimeEnvironment.application);
|
||||
mFragment.mBatteryOptimizeUtils = mBatteryOptimizeUtils;
|
||||
mFragment.mBackupManager = mBackupManager;
|
||||
mAppEntry.info = mock(ApplicationInfo.class);
|
||||
|
||||
mTestActivity = spy(new SettingsActivity());
|
||||
@@ -231,7 +237,7 @@ public class AdvancedPowerUsageDetailTest {
|
||||
|
||||
@Test
|
||||
public void testGetPreferenceScreenResId_disableTriState_returnLegacyLayout() {
|
||||
mFragment.enableTriState = false;
|
||||
mFragment.mEnableTriState = false;
|
||||
assertThat(mFragment.getPreferenceScreenResId()).isEqualTo(R.xml.power_usage_detail_legacy);
|
||||
}
|
||||
|
||||
@@ -431,6 +437,21 @@ public class AdvancedPowerUsageDetailTest {
|
||||
.isEqualTo("No usage for past 24 hr");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitHeader_noUsageTimeButConsumedPower_hasEmptySummary() {
|
||||
Bundle bundle = new Bundle(3);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, /* value */ 0);
|
||||
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, /* value */ 0);
|
||||
bundle.putInt(AdvancedPowerUsageDetail.EXTRA_POWER_USAGE_AMOUNT, /* value */ 10);
|
||||
when(mFragment.getArguments()).thenReturn(bundle);
|
||||
|
||||
mFragment.initHeader();
|
||||
|
||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||
verify(mEntityHeaderController).setSummary(captor.capture());
|
||||
assertThat(captor.getValue().toString()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitHeader_backgroundTwoMinForegroundZero_hasCorrectSummary() {
|
||||
final long backgroundTimeTwoMinutes = 120000;
|
||||
@@ -771,13 +792,71 @@ public class AdvancedPowerUsageDetailTest {
|
||||
assertThat(mOptimizePreference.isChecked()).isTrue();
|
||||
assertThat(mRestrictedPreference.isChecked()).isFalse();
|
||||
assertThat(mUnrestrictedPreference.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnPause_optimizationModeChanged_logPreference() {
|
||||
final int mode = BatteryOptimizeUtils.MODE_RESTRICTED;
|
||||
mFragment.mOptimizationMode = mode;
|
||||
when(mBatteryOptimizeUtils.getAppOptimizationMode()).thenReturn(mode);
|
||||
mOptimizePreference.setKey(KEY_PREF_OPTIMIZED);
|
||||
|
||||
mFragment.onRadioButtonClicked(mOptimizePreference);
|
||||
mFragment.onPause();
|
||||
|
||||
verify(mMetricsFeatureProvider)
|
||||
.action(
|
||||
mContext,
|
||||
SettingsEnums.ACTION_APP_BATTERY_USAGE_OPTIMIZED,
|
||||
(Pair<Integer, Object>[]) new Pair[] {
|
||||
new Pair(ConvertUtils.METRIC_KEY_PACKAGE, null),
|
||||
new Pair(ConvertUtils.METRIC_KEY_BATTERY_USAGE, "app label")
|
||||
});
|
||||
.action(
|
||||
SettingsEnums.OPEN_APP_BATTERY_USAGE,
|
||||
SettingsEnums.ACTION_APP_BATTERY_USAGE_OPTIMIZED,
|
||||
SettingsEnums.OPEN_APP_BATTERY_USAGE,
|
||||
/* package name*/ "none",
|
||||
/* consumed battery */ 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnPause_optimizationModeIsNotChanged_notInvokeLogging() {
|
||||
final int mode = BatteryOptimizeUtils.MODE_OPTIMIZED;
|
||||
mFragment.mOptimizationMode = mode;
|
||||
when(mBatteryOptimizeUtils.getAppOptimizationMode()).thenReturn(mode);
|
||||
mOptimizePreference.setKey(KEY_PREF_OPTIMIZED);
|
||||
|
||||
mFragment.onRadioButtonClicked(mOptimizePreference);
|
||||
mFragment.onPause();
|
||||
|
||||
verifyZeroInteractions(mMetricsFeatureProvider);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notifyBackupManager_optimizationModeIsNotChanged_notInvokeDataChanged() {
|
||||
final int mode = BatteryOptimizeUtils.MODE_RESTRICTED;
|
||||
mFragment.mOptimizationMode = mode;
|
||||
when(mBatteryOptimizeUtils.getAppOptimizationMode()).thenReturn(mode);
|
||||
|
||||
mFragment.notifyBackupManager();
|
||||
|
||||
verifyZeroInteractions(mBackupManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notifyBackupManager_optimizationModeIsChanged_invokeDataChanged() {
|
||||
mFragment.mOptimizationMode = BatteryOptimizeUtils.MODE_RESTRICTED;
|
||||
when(mBatteryOptimizeUtils.getAppOptimizationMode())
|
||||
.thenReturn(BatteryOptimizeUtils.MODE_UNRESTRICTED);
|
||||
|
||||
mFragment.notifyBackupManager();
|
||||
|
||||
verify(mBackupManager).dataChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notifyBackupManager_triStateIsNotEnabled_notInvokeDataChanged() {
|
||||
mFragment.mOptimizationMode = BatteryOptimizeUtils.MODE_RESTRICTED;
|
||||
when(mBatteryOptimizeUtils.getAppOptimizationMode())
|
||||
.thenReturn(BatteryOptimizeUtils.MODE_UNRESTRICTED);
|
||||
mFragment.mEnableTriState = false;
|
||||
|
||||
mFragment.onPause();
|
||||
|
||||
verifyZeroInteractions(mBackupManager);
|
||||
}
|
||||
}
|
||||
|
@@ -67,11 +67,13 @@ public class BatteryAppListPreferenceControllerTest {
|
||||
private Context mContext;
|
||||
private PowerGaugePreference mPreference;
|
||||
private BatteryAppListPreferenceController mPreferenceController;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
final Resources resources = spy(mContext.getResources());
|
||||
when(mContext.getResources()).thenReturn(resources);
|
||||
@@ -79,9 +81,8 @@ public class BatteryAppListPreferenceControllerTest {
|
||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
||||
when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
|
||||
when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {});
|
||||
when(resources.getTextArray(R.array.allowlist_hide_summary_in_battery_usage))
|
||||
when(mFeatureFactory.powerUsageFeatureProvider.getHideApplicationSummary(mContext))
|
||||
.thenReturn(new String[] {"com.android.googlequicksearchbox"});
|
||||
FakeFeatureFactory.setupForTest();
|
||||
|
||||
mPreference = new PowerGaugePreference(mContext);
|
||||
|
||||
|
@@ -0,0 +1,407 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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;
|
||||
|
||||
import static com.android.settings.fuelgauge.BatteryBackupHelper.DELIMITER;
|
||||
import static com.android.settings.fuelgauge.BatteryBackupHelper.DELIMITER_MODE;
|
||||
import static com.android.settings.fuelgauge.BatteryOptimizeUtils.MODE_RESTRICTED;
|
||||
import static com.android.settings.fuelgauge.BatteryOptimizeUtils.MODE_UNRESTRICTED;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
|
||||
import android.app.AppOpsManager;
|
||||
import android.app.backup.BackupDataInputStream;
|
||||
import android.app.backup.BackupDataOutput;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.IPackageManager;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ParceledListSlice;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.IDeviceIdleController;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settingslib.fuelgauge.PowerAllowlistBackend;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.annotation.Resetter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {BatteryBackupHelperTest.ShadowUserHandle.class})
|
||||
public final class BatteryBackupHelperTest {
|
||||
private static final String PACKAGE_NAME1 = "com.android.testing.1";
|
||||
private static final String PACKAGE_NAME2 = "com.android.testing.2";
|
||||
private static final String PACKAGE_NAME3 = "com.android.testing.3";
|
||||
|
||||
private Context mContext;
|
||||
private BatteryBackupHelper mBatteryBackupHelper;
|
||||
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private BackupDataOutput mBackupDataOutput;
|
||||
@Mock
|
||||
private BackupDataInputStream mBackupDataInputStream;
|
||||
@Mock
|
||||
private IDeviceIdleController mDeviceController;
|
||||
@Mock
|
||||
private IPackageManager mIPackageManager;
|
||||
@Mock
|
||||
private AppOpsManager mAppOpsManager;
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
@Mock
|
||||
private PowerAllowlistBackend mPowerAllowlistBackend;
|
||||
@Mock
|
||||
private BatteryOptimizeUtils mBatteryOptimizeUtils;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
doReturn(mContext).when(mContext).getApplicationContext();
|
||||
doReturn(mAppOpsManager).when(mContext).getSystemService(AppOpsManager.class);
|
||||
doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
|
||||
doReturn(mPackageManager).when(mContext).getPackageManager();
|
||||
mBatteryBackupHelper = new BatteryBackupHelper(mContext);
|
||||
mBatteryBackupHelper.mIDeviceIdleController = mDeviceController;
|
||||
mBatteryBackupHelper.mIPackageManager = mIPackageManager;
|
||||
mBatteryBackupHelper.mPowerAllowlistBackend = mPowerAllowlistBackend;
|
||||
mBatteryBackupHelper.mBatteryOptimizeUtils = mBatteryOptimizeUtils;
|
||||
mockUid(1001 /*fake uid*/, PACKAGE_NAME1);
|
||||
mockUid(1002 /*fake uid*/, PACKAGE_NAME2);
|
||||
mockUid(BatteryUtils.UID_NULL, PACKAGE_NAME3);
|
||||
}
|
||||
|
||||
@After
|
||||
public void resetShadows() {
|
||||
ShadowUserHandle.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void performBackup_nullPowerList_notBackupPowerList() throws Exception {
|
||||
doReturn(null).when(mDeviceController).getFullPowerWhitelist();
|
||||
mBatteryBackupHelper.performBackup(null, mBackupDataOutput, null);
|
||||
|
||||
verify(mBackupDataOutput, never()).writeEntityHeader(anyString(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void performBackup_emptyPowerList_notBackupPowerList() throws Exception {
|
||||
doReturn(new String[0]).when(mDeviceController).getFullPowerWhitelist();
|
||||
mBatteryBackupHelper.performBackup(null, mBackupDataOutput, null);
|
||||
|
||||
verify(mBackupDataOutput, never()).writeEntityHeader(anyString(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void performBackup_remoteException_notBackupPowerList() throws Exception {
|
||||
doThrow(new RemoteException()).when(mDeviceController).getFullPowerWhitelist();
|
||||
mBatteryBackupHelper.performBackup(null, mBackupDataOutput, null);
|
||||
|
||||
verify(mBackupDataOutput, never()).writeEntityHeader(anyString(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void performBackup_oneFullPowerListElement_backupFullPowerListData()
|
||||
throws Exception {
|
||||
final String[] fullPowerList = {"com.android.package"};
|
||||
doReturn(fullPowerList).when(mDeviceController).getFullPowerWhitelist();
|
||||
|
||||
mBatteryBackupHelper.performBackup(null, mBackupDataOutput, null);
|
||||
|
||||
final byte[] expectedBytes = fullPowerList[0].getBytes();
|
||||
verify(mBackupDataOutput).writeEntityHeader(
|
||||
BatteryBackupHelper.KEY_FULL_POWER_LIST, expectedBytes.length);
|
||||
verify(mBackupDataOutput).writeEntityData(expectedBytes, expectedBytes.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void performBackup_backupFullPowerListData() throws Exception {
|
||||
final String[] fullPowerList = {"com.android.package1", "com.android.package2"};
|
||||
doReturn(fullPowerList).when(mDeviceController).getFullPowerWhitelist();
|
||||
|
||||
mBatteryBackupHelper.performBackup(null, mBackupDataOutput, null);
|
||||
|
||||
final String expectedResult = fullPowerList[0] + DELIMITER + fullPowerList[1];
|
||||
final byte[] expectedBytes = expectedResult.getBytes();
|
||||
verify(mBackupDataOutput).writeEntityHeader(
|
||||
BatteryBackupHelper.KEY_FULL_POWER_LIST, expectedBytes.length);
|
||||
verify(mBackupDataOutput).writeEntityData(expectedBytes, expectedBytes.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void performBackup_nonOwner_ignoreAllBackupAction() throws Exception {
|
||||
ShadowUserHandle.setUid(1);
|
||||
final String[] fullPowerList = {"com.android.package"};
|
||||
doReturn(fullPowerList).when(mDeviceController).getFullPowerWhitelist();
|
||||
|
||||
mBatteryBackupHelper.performBackup(null, mBackupDataOutput, null);
|
||||
|
||||
verify(mBackupDataOutput, never()).writeEntityHeader(anyString(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void backupOptimizationMode_nullInstalledApps_ignoreBackupOptimization()
|
||||
throws Exception {
|
||||
final UserInfo userInfo =
|
||||
new UserInfo(/*userId=*/ 0, /*userName=*/ "google", /*flag=*/ 0);
|
||||
doReturn(Arrays.asList(userInfo)).when(mUserManager).getProfiles(anyInt());
|
||||
doThrow(new RuntimeException())
|
||||
.when(mIPackageManager)
|
||||
.getInstalledApplications(anyInt(), anyInt());
|
||||
|
||||
mBatteryBackupHelper.backupOptimizationMode(mBackupDataOutput, null);
|
||||
|
||||
verify(mBackupDataOutput, never()).writeEntityHeader(anyString(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void backupOptimizationMode_backupOptimizationMode() throws Exception {
|
||||
final List<String> allowlistedApps = Arrays.asList(PACKAGE_NAME1);
|
||||
createTestingData(PACKAGE_NAME1, PACKAGE_NAME2, PACKAGE_NAME3);
|
||||
|
||||
mBatteryBackupHelper.backupOptimizationMode(mBackupDataOutput, allowlistedApps);
|
||||
|
||||
// 2 for UNRESTRICTED mode and 1 for RESTRICTED mode.
|
||||
final String expectedResult = PACKAGE_NAME1 + ":2," + PACKAGE_NAME2 + ":1,";
|
||||
verifyBackupData(expectedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void backupOptimizationMode_backupOptimizationModeAndIgnoreSystemApp()
|
||||
throws Exception {
|
||||
final List<String> allowlistedApps = Arrays.asList(PACKAGE_NAME1);
|
||||
createTestingData(PACKAGE_NAME1, PACKAGE_NAME2, PACKAGE_NAME3);
|
||||
// Sets "com.android.testing.1" as system app.
|
||||
doReturn(true).when(mPowerAllowlistBackend).isSysAllowlisted(PACKAGE_NAME1);
|
||||
doReturn(false).when(mPowerAllowlistBackend).isDefaultActiveApp(anyString());
|
||||
|
||||
mBatteryBackupHelper.backupOptimizationMode(mBackupDataOutput, allowlistedApps);
|
||||
|
||||
// "com.android.testing.2" for RESTRICTED mode.
|
||||
final String expectedResult = PACKAGE_NAME2 + ":1,";
|
||||
verifyBackupData(expectedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void backupOptimizationMode_backupOptimizationModeAndIgnoreDefaultApp()
|
||||
throws Exception {
|
||||
final List<String> allowlistedApps = Arrays.asList(PACKAGE_NAME1);
|
||||
createTestingData(PACKAGE_NAME1, PACKAGE_NAME2, PACKAGE_NAME3);
|
||||
// Sets "com.android.testing.1" as device default app.
|
||||
doReturn(true).when(mPowerAllowlistBackend).isDefaultActiveApp(PACKAGE_NAME1);
|
||||
doReturn(false).when(mPowerAllowlistBackend).isSysAllowlisted(anyString());
|
||||
|
||||
mBatteryBackupHelper.backupOptimizationMode(mBackupDataOutput, allowlistedApps);
|
||||
|
||||
// "com.android.testing.2" for RESTRICTED mode.
|
||||
final String expectedResult = PACKAGE_NAME2 + ":1,";
|
||||
verifyBackupData(expectedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restoreEntity_nonOwner_notReadBackupData() throws Exception {
|
||||
ShadowUserHandle.setUid(1);
|
||||
mockBackupData(30 /*dataSize*/, BatteryBackupHelper.KEY_OPTIMIZATION_LIST);
|
||||
|
||||
mBatteryBackupHelper.restoreEntity(mBackupDataInputStream);
|
||||
|
||||
verifyZeroInteractions(mBackupDataInputStream);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restoreEntity_zeroDataSize_notReadBackupData() throws Exception {
|
||||
final int zeroDataSize = 0;
|
||||
mockBackupData(zeroDataSize, BatteryBackupHelper.KEY_OPTIMIZATION_LIST);
|
||||
|
||||
mBatteryBackupHelper.restoreEntity(mBackupDataInputStream);
|
||||
|
||||
verify(mBackupDataInputStream, never()).read(any(), anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restoreEntity_incorrectDataKey_notReadBackupData() throws Exception {
|
||||
final String incorrectDataKey = BatteryBackupHelper.KEY_FULL_POWER_LIST;
|
||||
mockBackupData(30 /*dataSize*/, incorrectDataKey);
|
||||
|
||||
mBatteryBackupHelper.restoreEntity(mBackupDataInputStream);
|
||||
|
||||
verify(mBackupDataInputStream, never()).read(any(), anyInt(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restoreEntity_readExpectedDataFromBackupData() throws Exception {
|
||||
final int dataSize = 30;
|
||||
mockBackupData(dataSize, BatteryBackupHelper.KEY_OPTIMIZATION_LIST);
|
||||
|
||||
mBatteryBackupHelper.restoreEntity(mBackupDataInputStream);
|
||||
|
||||
final ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class);
|
||||
verify(mBackupDataInputStream).read(captor.capture(), eq(0), eq(dataSize));
|
||||
assertThat(captor.getValue().length).isEqualTo(dataSize);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restoreOptimizationMode_nullBytesData_skipRestore() throws Exception {
|
||||
mBatteryBackupHelper.restoreOptimizationMode(new byte[0]);
|
||||
verifyZeroInteractions(mBatteryOptimizeUtils);
|
||||
|
||||
mBatteryBackupHelper.restoreOptimizationMode("invalid data format".getBytes());
|
||||
verifyZeroInteractions(mBatteryOptimizeUtils);
|
||||
|
||||
mBatteryBackupHelper.restoreOptimizationMode(DELIMITER.getBytes());
|
||||
verifyZeroInteractions(mBatteryOptimizeUtils);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restoreOptimizationMode_invalidModeFormat_skipRestore() throws Exception {
|
||||
final String invalidNumberFormat = "google";
|
||||
final String packageModes =
|
||||
PACKAGE_NAME1 + DELIMITER_MODE + MODE_RESTRICTED + DELIMITER +
|
||||
PACKAGE_NAME2 + DELIMITER_MODE + invalidNumberFormat;
|
||||
|
||||
mBatteryBackupHelper.restoreOptimizationMode(packageModes.getBytes());
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
|
||||
final InOrder inOrder = inOrder(mBatteryOptimizeUtils);
|
||||
inOrder.verify(mBatteryOptimizeUtils).setAppUsageState(MODE_RESTRICTED);
|
||||
inOrder.verify(mBatteryOptimizeUtils, never()).setAppUsageState(anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restoreOptimizationMode_restoreExpectedModes() throws Exception {
|
||||
final String packageModes =
|
||||
PACKAGE_NAME1 + DELIMITER_MODE + MODE_RESTRICTED + DELIMITER +
|
||||
PACKAGE_NAME2 + DELIMITER_MODE + MODE_UNRESTRICTED + DELIMITER +
|
||||
PACKAGE_NAME3 + DELIMITER_MODE + MODE_RESTRICTED + DELIMITER;
|
||||
|
||||
mBatteryBackupHelper.restoreOptimizationMode(packageModes.getBytes());
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
|
||||
final InOrder inOrder = inOrder(mBatteryOptimizeUtils);
|
||||
inOrder.verify(mBatteryOptimizeUtils).setAppUsageState(MODE_RESTRICTED);
|
||||
inOrder.verify(mBatteryOptimizeUtils).setAppUsageState(MODE_UNRESTRICTED);
|
||||
inOrder.verify(mBatteryOptimizeUtils, never()).setAppUsageState(MODE_RESTRICTED);
|
||||
}
|
||||
|
||||
private void mockUid(int uid, String packageName) throws Exception {
|
||||
doReturn(uid).when(mPackageManager)
|
||||
.getPackageUid(packageName, PackageManager.GET_META_DATA);
|
||||
}
|
||||
|
||||
private void mockBackupData(int dataSize, String dataKey) {
|
||||
doReturn(dataSize).when(mBackupDataInputStream).size();
|
||||
doReturn(dataKey).when(mBackupDataInputStream).getKey();
|
||||
}
|
||||
|
||||
private void verifyBackupData(String expectedResult) throws Exception {
|
||||
final byte[] expectedBytes = expectedResult.getBytes();
|
||||
verify(mBackupDataOutput).writeEntityHeader(
|
||||
BatteryBackupHelper.KEY_OPTIMIZATION_LIST, expectedBytes.length);
|
||||
verify(mBackupDataOutput).writeEntityData(expectedBytes, expectedBytes.length);
|
||||
}
|
||||
|
||||
private void createTestingData(
|
||||
String packageName1, String packageName2, String packageName3) throws Exception {
|
||||
// Sets the getInstalledApplications() method for testing.
|
||||
final UserInfo userInfo =
|
||||
new UserInfo(/*userId=*/ 0, /*userName=*/ "google", /*flag=*/ 0);
|
||||
doReturn(Arrays.asList(userInfo)).when(mUserManager).getProfiles(anyInt());
|
||||
final ApplicationInfo applicationInfo1 = new ApplicationInfo();
|
||||
applicationInfo1.enabled = true;
|
||||
applicationInfo1.uid = 1;
|
||||
applicationInfo1.packageName = packageName1;
|
||||
final ApplicationInfo applicationInfo2 = new ApplicationInfo();
|
||||
applicationInfo2.enabled = false;
|
||||
applicationInfo2.uid = 2;
|
||||
applicationInfo2.packageName = packageName2;
|
||||
applicationInfo2.enabledSetting = PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER;
|
||||
final ApplicationInfo applicationInfo3 = new ApplicationInfo();
|
||||
applicationInfo3.enabled = false;
|
||||
applicationInfo3.uid = 3;
|
||||
applicationInfo3.packageName = packageName3;
|
||||
applicationInfo3.enabledSetting = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
|
||||
doReturn(new ParceledListSlice<ApplicationInfo>(
|
||||
Arrays.asList(applicationInfo1, applicationInfo2, applicationInfo3)))
|
||||
.when(mIPackageManager)
|
||||
.getInstalledApplications(anyInt(), anyInt());
|
||||
// Sets the AppOpsManager for checkOpNoThrow() method.
|
||||
doReturn(AppOpsManager.MODE_ALLOWED)
|
||||
.when(mAppOpsManager)
|
||||
.checkOpNoThrow(
|
||||
AppOpsManager.OP_RUN_ANY_IN_BACKGROUND,
|
||||
applicationInfo1.uid,
|
||||
applicationInfo1.packageName);
|
||||
doReturn(AppOpsManager.MODE_IGNORED)
|
||||
.when(mAppOpsManager)
|
||||
.checkOpNoThrow(
|
||||
AppOpsManager.OP_RUN_ANY_IN_BACKGROUND,
|
||||
applicationInfo2.uid,
|
||||
applicationInfo2.packageName);
|
||||
}
|
||||
|
||||
@Implements(UserHandle.class)
|
||||
public static class ShadowUserHandle {
|
||||
// Sets the default as thte OWNER role.
|
||||
private static int sUid = 0;
|
||||
|
||||
public static void setUid(int uid) {
|
||||
sUid = uid;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static int myUserId() {
|
||||
return sUid;
|
||||
}
|
||||
|
||||
@Resetter
|
||||
public static void reset() {
|
||||
sUid = 0;
|
||||
}
|
||||
}
|
||||
}
|
@@ -103,7 +103,11 @@ public final class BatteryChartPreferenceControllerTest {
|
||||
resources.getConfiguration().setLocales(new LocaleList(new Locale("en_US")));
|
||||
doReturn(resources).when(mContext).getResources();
|
||||
doReturn(new String[] {"com.android.googlequicksearchbox"})
|
||||
.when(resources).getTextArray(R.array.allowlist_hide_summary_in_battery_usage);
|
||||
.when(mFeatureFactory.powerUsageFeatureProvider)
|
||||
.getHideApplicationSummary(mContext);
|
||||
doReturn(new String[] {"com.android.gms.persistent"})
|
||||
.when(mFeatureFactory.powerUsageFeatureProvider)
|
||||
.getHideApplicationEntries(mContext);
|
||||
mBatteryChartPreferenceController = createController();
|
||||
mBatteryChartPreferenceController.mPrefContext = mContext;
|
||||
mBatteryChartPreferenceController.mAppListPrefGroup = mAppListGroup;
|
||||
@@ -339,14 +343,12 @@ public final class BatteryChartPreferenceControllerTest {
|
||||
assertThat(mBatteryChartPreferenceController.handlePreferenceTreeClick(
|
||||
mPowerGaugePreference)).isTrue();
|
||||
verify(mMetricsFeatureProvider)
|
||||
.action(
|
||||
mContext,
|
||||
SettingsEnums.ACTION_BATTERY_USAGE_SYSTEM_ITEM,
|
||||
(Pair<Integer, Object>[]) new Pair[] {
|
||||
new Pair(ConvertUtils.METRIC_KEY_PACKAGE, null),
|
||||
new Pair(ConvertUtils.METRIC_KEY_BATTERY_LEVEL, 0),
|
||||
new Pair(ConvertUtils.METRIC_KEY_BATTERY_USAGE, null)
|
||||
});
|
||||
.action(
|
||||
SettingsEnums.OPEN_BATTERY_USAGE,
|
||||
SettingsEnums.ACTION_BATTERY_USAGE_SYSTEM_ITEM,
|
||||
SettingsEnums.OPEN_BATTERY_USAGE,
|
||||
/* package name */ "none",
|
||||
/* percentage of total */ 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -358,14 +360,12 @@ public final class BatteryChartPreferenceControllerTest {
|
||||
assertThat(mBatteryChartPreferenceController.handlePreferenceTreeClick(
|
||||
mPowerGaugePreference)).isTrue();
|
||||
verify(mMetricsFeatureProvider)
|
||||
.action(
|
||||
mContext,
|
||||
SettingsEnums.ACTION_BATTERY_USAGE_APP_ITEM,
|
||||
(Pair<Integer, Object>[]) new Pair[] {
|
||||
new Pair(ConvertUtils.METRIC_KEY_PACKAGE, null),
|
||||
new Pair(ConvertUtils.METRIC_KEY_BATTERY_LEVEL, 0),
|
||||
new Pair(ConvertUtils.METRIC_KEY_BATTERY_USAGE, null)
|
||||
});
|
||||
.action(
|
||||
SettingsEnums.OPEN_BATTERY_USAGE,
|
||||
SettingsEnums.ACTION_BATTERY_USAGE_APP_ITEM,
|
||||
SettingsEnums.OPEN_BATTERY_USAGE,
|
||||
/* package name */ "none",
|
||||
/* percentage of total */ 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -660,7 +660,7 @@ public final class BatteryChartPreferenceControllerTest {
|
||||
|
||||
// Verifies the items which are defined in the array list.
|
||||
assertThat(mBatteryChartPreferenceController
|
||||
.isValidToShowEntry("com.google.android.gms.persistent"))
|
||||
.isValidToShowEntry("com.android.gms.persistent"))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
|
@@ -17,6 +17,7 @@ package com.android.settings.fuelgauge;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
@@ -28,6 +29,7 @@ import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.Drawable.ConstantState;
|
||||
import android.os.BatteryConsumer;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
@@ -41,6 +43,10 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.annotation.Resetter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -48,6 +54,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {BatteryDiffEntryTest.ShadowUserHandle.class})
|
||||
public final class BatteryDiffEntryTest {
|
||||
|
||||
private Context mContext;
|
||||
@@ -60,10 +67,12 @@ public final class BatteryDiffEntryTest {
|
||||
@Mock private Drawable mockBadgedDrawable;
|
||||
@Mock private BatteryHistEntry mBatteryHistEntry;
|
||||
@Mock private PackageInfo mockPackageInfo;
|
||||
@Mock private ConstantState mockConstantState;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
ShadowUserHandle.reset();
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
doReturn(mContext).when(mContext).getApplicationContext();
|
||||
doReturn(mockUserManager).when(mContext).getSystemService(UserManager.class);
|
||||
@@ -229,6 +238,7 @@ public final class BatteryDiffEntryTest {
|
||||
final ContentValues values = getContentValuesWithType(
|
||||
ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY);
|
||||
final BatteryHistEntry batteryHistEntry = new BatteryHistEntry(values);
|
||||
mockConstantState(mockDrawable);
|
||||
|
||||
final BatteryDiffEntry entry = createBatteryDiffEntry(10, batteryHistEntry);
|
||||
|
||||
@@ -239,20 +249,32 @@ public final class BatteryDiffEntryTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAppIcon_uidConsumerWithNullIcon_returnDefaultActivityIcon()
|
||||
public void testGetAppIcon_uidConsumerForNonOwner_returnDefaultActivityIconWithBadge()
|
||||
throws Exception {
|
||||
ShadowUserHandle.setUid(10);
|
||||
final BatteryDiffEntry entry = createBatteryDiffEntry(mockDrawable);
|
||||
final int userId = UserHandle.getUserId(1001);
|
||||
mockConstantState(mockDrawable);
|
||||
mockConstantState(mockBadgedDrawable);
|
||||
doReturn(mockBadgedDrawable).when(mockUserManager)
|
||||
.getBadgedIconForUser(mockDrawable, new UserHandle(userId));
|
||||
.getBadgedIconForUser(eq(mockDrawable), any());
|
||||
|
||||
entry.mAppIcon = null;
|
||||
assertThat(entry.getAppIcon()).isEqualTo(mockBadgedDrawable);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAppIcon_uidConsumerWithNullIcon_returnDefaultActivityIcon()
|
||||
throws Exception {
|
||||
final BatteryDiffEntry entry = createBatteryDiffEntry(mockDrawable);
|
||||
mockConstantState(mockDrawable);
|
||||
|
||||
entry.mAppIcon = null;
|
||||
assertThat(entry.getAppIcon()).isEqualTo(mockDrawable);
|
||||
assertThat(BatteryDiffEntry.sResourceCache).hasSize(1);
|
||||
// Verifies the app label in the cache.
|
||||
final BatteryEntry.NameAndIcon nameAndIcon =
|
||||
BatteryDiffEntry.sResourceCache.get(entry.getKey());
|
||||
assertThat(nameAndIcon.icon).isEqualTo(mockBadgedDrawable);
|
||||
assertThat(nameAndIcon.icon).isEqualTo(mockDrawable);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -272,19 +294,17 @@ public final class BatteryDiffEntryTest {
|
||||
@Test
|
||||
public void testClearCache_switchLocale_clearCacheIconAndLabel() throws Exception {
|
||||
final int userId = UserHandle.getUserId(1001);
|
||||
doReturn(mockBadgedDrawable).when(mockUserManager)
|
||||
.getBadgedIconForUser(mockDrawable, new UserHandle(userId));
|
||||
doReturn(mockDrawable2).when(mockUserManager)
|
||||
.getBadgedIconForUser(mockDrawable2, new UserHandle(userId));
|
||||
Locale.setDefault(new Locale("en_US"));
|
||||
final BatteryDiffEntry entry1 = createBatteryDiffEntry(mockDrawable);
|
||||
assertThat(entry1.getAppIcon()).isEqualTo(mockBadgedDrawable);
|
||||
mockConstantState(mockDrawable);
|
||||
assertThat(entry1.getAppIcon()).isEqualTo(mockDrawable);
|
||||
// Switch the locale into another one.
|
||||
Locale.setDefault(new Locale("zh_TW"));
|
||||
|
||||
final BatteryDiffEntry entry2 = createBatteryDiffEntry(mockDrawable2);
|
||||
|
||||
// We should get new drawable without caching.
|
||||
mockConstantState(mockDrawable2);
|
||||
assertThat(entry2.getAppIcon()).isEqualTo(mockDrawable2);
|
||||
// Verifies the cache is updated into the new drawable.
|
||||
final BatteryEntry.NameAndIcon nameAndIcon =
|
||||
@@ -440,4 +460,34 @@ public final class BatteryDiffEntryTest {
|
||||
.getPackagesForUid(1001);
|
||||
return createBatteryDiffEntry(10, batteryHistEntry);
|
||||
}
|
||||
|
||||
private void mockConstantState(Drawable drawable) {
|
||||
doReturn(mockConstantState).when(drawable).getConstantState();
|
||||
doReturn(drawable).when(mockConstantState).newDrawable();
|
||||
}
|
||||
|
||||
@Implements(UserHandle.class)
|
||||
public static class ShadowUserHandle {
|
||||
// Sets the default as thte OWNER role.
|
||||
private static int sUid = 0;
|
||||
|
||||
public static void setUid(int uid) {
|
||||
sUid = uid;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static int myUserId() {
|
||||
return sUid;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static int getUserId(int userId) {
|
||||
return sUid;
|
||||
}
|
||||
|
||||
@Resetter
|
||||
public static void reset() {
|
||||
sUid = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -16,9 +16,9 @@
|
||||
|
||||
package com.android.settings.fuelgauge;
|
||||
|
||||
import static com.android.settings.fuelgauge.BatteryOptimizeUtils.AppUsageState.OPTIMIZED;
|
||||
import static com.android.settings.fuelgauge.BatteryOptimizeUtils.AppUsageState.RESTRICTED;
|
||||
import static com.android.settings.fuelgauge.BatteryOptimizeUtils.AppUsageState.UNRESTRICTED;
|
||||
import static com.android.settings.fuelgauge.BatteryOptimizeUtils.MODE_OPTIMIZED;
|
||||
import static com.android.settings.fuelgauge.BatteryOptimizeUtils.MODE_RESTRICTED;
|
||||
import static com.android.settings.fuelgauge.BatteryOptimizeUtils.MODE_UNRESTRICTED;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@@ -26,6 +26,7 @@ import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.AppOpsManager;
|
||||
@@ -41,15 +42,17 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class BatteryOptimizeUtilsTest {
|
||||
|
||||
private static final int UID = 12345;
|
||||
private static final String PACKAGE_NAME = "com.android.app";
|
||||
|
||||
@Mock BatteryUtils mockBatteryUtils;
|
||||
@Mock AppOpsManager mockAppOpsManager;
|
||||
@Mock PowerAllowlistBackend mockBackend;
|
||||
@Mock BatteryUtils mMockBatteryUtils;
|
||||
@Mock AppOpsManager mMockAppOpsManager;
|
||||
@Mock PowerAllowlistBackend mMockBackend;
|
||||
|
||||
private Context mContext;
|
||||
private BatteryOptimizeUtils mBatteryOptimizeUtils;
|
||||
@@ -59,42 +62,48 @@ public class BatteryOptimizeUtilsTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mBatteryOptimizeUtils = spy(new BatteryOptimizeUtils(mContext, UID, PACKAGE_NAME));
|
||||
mBatteryOptimizeUtils.mAppOpsManager = mockAppOpsManager;
|
||||
mBatteryOptimizeUtils.mBatteryUtils = mockBatteryUtils;
|
||||
mBatteryOptimizeUtils.mPowerAllowListBackend = mockBackend;
|
||||
mBatteryOptimizeUtils.mAppOpsManager = mMockAppOpsManager;
|
||||
mBatteryOptimizeUtils.mBatteryUtils = mMockBatteryUtils;
|
||||
mBatteryOptimizeUtils.mPowerAllowListBackend = mMockBackend;
|
||||
// Sets the default mode as MODE_RESTRICTED.
|
||||
mBatteryOptimizeUtils.mMode = AppOpsManager.MODE_IGNORED;
|
||||
mBatteryOptimizeUtils.mAllowListed = false;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAppUsageState_returnRestricted() {
|
||||
when(mockBackend.isAllowlisted(anyString())).thenReturn(false);
|
||||
when(mockAppOpsManager.checkOpNoThrow(anyInt(), anyInt(), anyString()))
|
||||
public void testGetAppOptimizationMode_returnRestricted() {
|
||||
when(mMockBackend.isAllowlisted(anyString())).thenReturn(false);
|
||||
when(mMockAppOpsManager.checkOpNoThrow(anyInt(), anyInt(), anyString()))
|
||||
.thenReturn(AppOpsManager.MODE_IGNORED);
|
||||
|
||||
assertThat(mBatteryOptimizeUtils.getAppUsageState()).isEqualTo(RESTRICTED);
|
||||
assertThat(mBatteryOptimizeUtils.getAppOptimizationMode())
|
||||
.isEqualTo(MODE_RESTRICTED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAppUsageState_returnUnrestricted() {
|
||||
when(mockBackend.isAllowlisted(anyString())).thenReturn(true);
|
||||
when(mockAppOpsManager.checkOpNoThrow(anyInt(), anyInt(), anyString()))
|
||||
public void testGetAppOptimizationMode_returnUnrestricted() {
|
||||
when(mMockBackend.isAllowlisted(anyString())).thenReturn(true);
|
||||
when(mMockAppOpsManager.checkOpNoThrow(anyInt(), anyInt(), anyString()))
|
||||
.thenReturn(AppOpsManager.MODE_ALLOWED);
|
||||
|
||||
assertThat(mBatteryOptimizeUtils.getAppUsageState()).isEqualTo(UNRESTRICTED);
|
||||
assertThat(mBatteryOptimizeUtils.getAppOptimizationMode())
|
||||
.isEqualTo(MODE_UNRESTRICTED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAppUsageState_returnOptimized() {
|
||||
when(mockBackend.isAllowlisted(anyString())).thenReturn(false);
|
||||
when(mockAppOpsManager.checkOpNoThrow(anyInt(), anyInt(), anyString()))
|
||||
public void testGetAppOptimizationMode_returnOptimized() {
|
||||
when(mMockBackend.isAllowlisted(anyString())).thenReturn(false);
|
||||
when(mMockAppOpsManager.checkOpNoThrow(anyInt(), anyInt(), anyString()))
|
||||
.thenReturn(AppOpsManager.MODE_ALLOWED);
|
||||
|
||||
assertThat(mBatteryOptimizeUtils.getAppUsageState()).isEqualTo(OPTIMIZED);
|
||||
assertThat(mBatteryOptimizeUtils.getAppOptimizationMode())
|
||||
.isEqualTo(MODE_OPTIMIZED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsSystemOrDefaultApp_isSystemOrDefaultApp_returnTrue() {
|
||||
when(mockBackend.isAllowlisted(anyString())).thenReturn(true);
|
||||
when(mockBackend.isDefaultActiveApp(anyString())).thenReturn(true);
|
||||
when(mMockBackend.isAllowlisted(anyString())).thenReturn(true);
|
||||
when(mMockBackend.isDefaultActiveApp(anyString())).thenReturn(true);
|
||||
|
||||
assertThat(mBatteryOptimizeUtils.isSystemOrDefaultApp()).isTrue();
|
||||
}
|
||||
@@ -118,29 +127,49 @@ public class BatteryOptimizeUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAppUsageState_Restricted_verifyAction() {
|
||||
mBatteryOptimizeUtils.setAppUsageState(RESTRICTED);
|
||||
public void testSetAppUsageState_Restricted_verifyAction() throws Exception {
|
||||
// Sets the current mode as MODE_UNRESTRICTED.
|
||||
mBatteryOptimizeUtils.mAllowListed = false;
|
||||
mBatteryOptimizeUtils.mMode = AppOpsManager.MODE_ALLOWED;
|
||||
|
||||
verify(mockBatteryUtils).setForceAppStandby(UID,
|
||||
mBatteryOptimizeUtils.setAppUsageState(MODE_RESTRICTED);
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
|
||||
verify(mMockBatteryUtils).setForceAppStandby(UID,
|
||||
PACKAGE_NAME, AppOpsManager.MODE_IGNORED);
|
||||
verify(mockBackend).removeApp(PACKAGE_NAME);
|
||||
verify(mMockBackend).removeApp(PACKAGE_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAppUsageState_Unrestricted_verifyAction() {
|
||||
mBatteryOptimizeUtils.setAppUsageState(UNRESTRICTED);
|
||||
public void testSetAppUsageState_Unrestricted_verifyAction() throws Exception {
|
||||
mBatteryOptimizeUtils.setAppUsageState(MODE_UNRESTRICTED);
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
|
||||
verify(mockBatteryUtils).setForceAppStandby(UID,
|
||||
verify(mMockBatteryUtils).setForceAppStandby(UID,
|
||||
PACKAGE_NAME, AppOpsManager.MODE_ALLOWED);
|
||||
verify(mockBackend).addApp(PACKAGE_NAME);
|
||||
verify(mMockBackend).addApp(PACKAGE_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAppUsageState_Optimized_verifyAction() {
|
||||
mBatteryOptimizeUtils.setAppUsageState(OPTIMIZED);
|
||||
public void testSetAppUsageState_Optimized_verifyAction() throws Exception {
|
||||
mBatteryOptimizeUtils.setAppUsageState(MODE_OPTIMIZED);
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
|
||||
verify(mockBatteryUtils).setForceAppStandby(UID,
|
||||
verify(mMockBatteryUtils).setForceAppStandby(UID,
|
||||
PACKAGE_NAME, AppOpsManager.MODE_ALLOWED);
|
||||
verify(mockBackend).removeApp(PACKAGE_NAME);
|
||||
verify(mMockBackend).removeApp(PACKAGE_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAppUsageState_sameUnrestrictedMode_verifyNoAction() throws Exception {
|
||||
// Sets the current mode as MODE_UNRESTRICTED.
|
||||
mBatteryOptimizeUtils.mAllowListed = true;
|
||||
mBatteryOptimizeUtils.mMode = AppOpsManager.MODE_ALLOWED;
|
||||
|
||||
mBatteryOptimizeUtils.setAppUsageState(MODE_UNRESTRICTED);
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
|
||||
verifyZeroInteractions(mMockBackend);
|
||||
verifyZeroInteractions(mMockBatteryUtils);
|
||||
}
|
||||
}
|
||||
|
@@ -29,9 +29,6 @@ import android.util.Pair;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -51,16 +48,12 @@ public class BatterySaverControllerTest {
|
||||
|
||||
private BatterySaverController mBatterySaverController;
|
||||
private Context mContext;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mMetricsFeatureProvider = mFeatureFactory.metricsFeatureProvider;
|
||||
mBatterySaverController = spy(new BatterySaverController(mContext));
|
||||
ReflectionHelpers.setField(mBatterySaverController, "mPowerManager", mPowerManager);
|
||||
ReflectionHelpers.setField(mBatterySaverController, "mBatterySaverPref", mBatterySaverPref);
|
||||
@@ -81,49 +74,6 @@ public class BatterySaverControllerTest {
|
||||
verify(mBatterySaverPref).setSummary("Off");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_onPowerSaveModeChanged_manualTrigger_logsType() {
|
||||
when(mPowerManager.isPowerSaveMode()).thenReturn(true);
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.AUTOMATIC_POWER_SAVE_MODE, -1);
|
||||
|
||||
mBatterySaverController.onPowerSaveModeChanged();
|
||||
verify(mMetricsFeatureProvider).action(mContext, SettingsEnums.FUELGAUGE_BATTERY_SAVER,
|
||||
Pair.create(SettingsEnums.FIELD_BATTERY_SAVER_SCHEDULE_TYPE,
|
||||
SettingsEnums.BATTERY_SAVER_SCHEDULE_TYPE_NO_SCHEDULE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_onPowerSaveModeChanged_triggerPercent_logsTypeAndPercentage() {
|
||||
when(mPowerManager.isPowerSaveMode()).thenReturn(true);
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.AUTOMATIC_POWER_SAVE_MODE,
|
||||
PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
|
||||
final int percentageVal = 15;
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL, percentageVal);
|
||||
|
||||
mBatterySaverController.onPowerSaveModeChanged();
|
||||
verify(mMetricsFeatureProvider).action(mContext, SettingsEnums.FUELGAUGE_BATTERY_SAVER,
|
||||
Pair.create(SettingsEnums.FIELD_BATTERY_SAVER_SCHEDULE_TYPE,
|
||||
SettingsEnums.BATTERY_SAVER_SCHEDULE_TYPE_BASED_ON_PERCENTAGE),
|
||||
Pair.create(SettingsEnums.FIELD_BATTERY_SAVER_PERCENTAGE_VALUE,
|
||||
percentageVal));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_onPowerSaveModeChanged_triggerDynamic_logsType() {
|
||||
when(mPowerManager.isPowerSaveMode()).thenReturn(true);
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.AUTOMATIC_POWER_SAVE_MODE,
|
||||
PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC);
|
||||
|
||||
mBatterySaverController.onPowerSaveModeChanged();
|
||||
verify(mMetricsFeatureProvider).action(mContext, SettingsEnums.FUELGAUGE_BATTERY_SAVER,
|
||||
Pair.create(SettingsEnums.FIELD_BATTERY_SAVER_SCHEDULE_TYPE,
|
||||
SettingsEnums.BATTERY_SAVER_SCHEDULE_TYPE_BASED_ON_ROUTINE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_batterySaverOn_showSummaryOn() {
|
||||
when(mPowerManager.isPowerSaveMode()).thenReturn(true);
|
||||
@@ -167,4 +117,10 @@ public class BatterySaverControllerTest {
|
||||
|
||||
assertThat(mBatterySaverController.getSummary()).isEqualTo("Off");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_returnAvailable() {
|
||||
assertThat(mBatterySaverController.getAvailabilityStatus())
|
||||
.isEqualTo(BatterySaverController.AVAILABLE);
|
||||
}
|
||||
}
|
||||
|
@@ -40,6 +40,7 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -67,7 +68,7 @@ public final class ConvertUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_returnsExpectedContentValues() {
|
||||
public void convert_returnsExpectedContentValues() {
|
||||
final int expectedType = 3;
|
||||
when(mockBatteryEntry.getUid()).thenReturn(1001);
|
||||
when(mockBatteryEntry.getLabel()).thenReturn("Settings");
|
||||
@@ -124,7 +125,7 @@ public final class ConvertUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert_nullBatteryEntry_returnsExpectedContentValues() {
|
||||
public void convert_nullBatteryEntry_returnsExpectedContentValues() {
|
||||
final ContentValues values =
|
||||
ConvertUtils.convert(
|
||||
/*entry=*/ null,
|
||||
@@ -151,7 +152,7 @@ public final class ConvertUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetIndexedUsageMap_nullOrEmptyHistoryMap_returnEmptyCollection() {
|
||||
public void getIndexedUsageMap_nullOrEmptyHistoryMap_returnEmptyCollection() {
|
||||
final int timeSlotSize = 2;
|
||||
final long[] batteryHistoryKeys = new long[] {101L, 102L, 103L, 104L, 105L};
|
||||
|
||||
@@ -166,7 +167,7 @@ public final class ConvertUtilsTest {
|
||||
.isEmpty();
|
||||
}
|
||||
@Test
|
||||
public void testGetIndexedUsageMap_returnsExpectedResult() {
|
||||
public void getIndexedUsageMap_returnsExpectedResult() {
|
||||
// Creates the fake testing data.
|
||||
final int timeSlotSize = 2;
|
||||
final long[] batteryHistoryKeys = new long[] {101L, 102L, 103L, 104L, 105L};
|
||||
@@ -278,7 +279,7 @@ public final class ConvertUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetIndexedUsageMap_usageTimeExceed_returnsExpectedResult() {
|
||||
public void getIndexedUsageMap_usageTimeExceed_returnsExpectedResult() {
|
||||
final int timeSlotSize = 1;
|
||||
final long[] batteryHistoryKeys = new long[] {101L, 102L, 103L};
|
||||
final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap =
|
||||
@@ -320,7 +321,7 @@ public final class ConvertUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetIndexedUsageMap_hideBackgroundUsageTime_returnsExpectedResult() {
|
||||
public void getIndexedUsageMap_hideBackgroundUsageTime_returnsExpectedResult() {
|
||||
final long[] batteryHistoryKeys = new long[] {101L, 102L, 103L};
|
||||
final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap = new HashMap<>();
|
||||
final BatteryHistEntry fakeEntry = createBatteryHistEntry(
|
||||
@@ -339,8 +340,8 @@ public final class ConvertUtilsTest {
|
||||
"package3", "label3", 500, 5L, 3600000L, 7200000L);
|
||||
entryMap.put(entry.getKey(), entry);
|
||||
batteryHistoryMap.put(Long.valueOf(batteryHistoryKeys[2]), entryMap);
|
||||
when(mPowerUsageFeatureProvider.getHideBackgroundUsageTimeList(mContext))
|
||||
.thenReturn(Arrays.asList((CharSequence) "package3"));
|
||||
when(mPowerUsageFeatureProvider.getHideBackgroundUsageTimeSet(mContext))
|
||||
.thenReturn(new HashSet(Arrays.asList((CharSequence) "package3")));
|
||||
|
||||
final Map<Integer, List<BatteryDiffEntry>> purgedResultMap =
|
||||
ConvertUtils.getIndexedUsageMap(
|
||||
|
@@ -18,11 +18,7 @@ package com.android.settings.fuelgauge;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -36,8 +32,6 @@ import com.android.settings.R;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@@ -52,7 +46,6 @@ public final class ExpandDividerPreferenceTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mImageView = spy(new ImageView(mContext));
|
||||
mTextView = spy(new TextView(mContext));
|
||||
@@ -64,9 +57,9 @@ public final class ExpandDividerPreferenceTest {
|
||||
@Test
|
||||
public void testConstructor_returnExpectedResult() {
|
||||
assertThat(mExpandDividerPreference.getKey())
|
||||
.isEqualTo(ExpandDividerPreference.PREFERENCE_KEY);
|
||||
.isEqualTo(ExpandDividerPreference.PREFERENCE_KEY);
|
||||
assertThat(mExpandDividerPreference.getLayoutResource())
|
||||
.isEqualTo(R.layout.preference_expand_divider);
|
||||
.isEqualTo(R.layout.preference_expand_divider);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,9 +68,7 @@ public final class ExpandDividerPreferenceTest {
|
||||
mExpandDividerPreference.mTextView = mTextView;
|
||||
|
||||
mExpandDividerPreference.setTitle(titleContent);
|
||||
final ArgumentCaptor<Runnable> captor = ArgumentCaptor.forClass(Runnable.class);
|
||||
verify(mTextView).postDelayed(captor.capture(), eq(50L));
|
||||
captor.getValue().run();
|
||||
|
||||
verify(mTextView).setText(titleContent);
|
||||
}
|
||||
|
||||
@@ -86,7 +77,7 @@ public final class ExpandDividerPreferenceTest {
|
||||
final boolean[] isExpandedArray = new boolean[] {false};
|
||||
mExpandDividerPreference.mImageView = mImageView;
|
||||
mExpandDividerPreference.setOnExpandListener(
|
||||
isExpanded -> isExpandedArray[0] = isExpanded);
|
||||
isExpanded -> isExpandedArray[0] = isExpanded);
|
||||
|
||||
// Click the item first time from false -> true.
|
||||
mExpandDividerPreference.onClick();
|
||||
@@ -106,7 +97,7 @@ public final class ExpandDividerPreferenceTest {
|
||||
final boolean[] isExpandedArray = new boolean[] {false};
|
||||
mExpandDividerPreference.mImageView = mImageView;
|
||||
mExpandDividerPreference.setOnExpandListener(
|
||||
isExpanded -> isExpandedArray[0] = isExpanded);
|
||||
isExpanded -> isExpandedArray[0] = isExpanded);
|
||||
|
||||
mExpandDividerPreference.setIsExpanded(true);
|
||||
|
||||
|
@@ -18,8 +18,6 @@ package com.android.settings.fuelgauge;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.android.settingslib.widget.RadioButtonPreference;
|
||||
@@ -76,8 +74,8 @@ public class OptimizedPreferenceControllerTest {
|
||||
@Test
|
||||
public void testUpdateState_isOptimizedStates_prefChecked() {
|
||||
when(mockBatteryOptimizeUtils.isValidPackageName()).thenReturn(true);
|
||||
when(mockBatteryOptimizeUtils.getAppUsageState()).thenReturn(
|
||||
BatteryOptimizeUtils.AppUsageState.OPTIMIZED);
|
||||
when(mockBatteryOptimizeUtils.getAppOptimizationMode()).thenReturn(
|
||||
BatteryOptimizeUtils.MODE_OPTIMIZED);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
@@ -98,14 +96,11 @@ public class OptimizedPreferenceControllerTest {
|
||||
mPreference.setKey(mController.KEY_OPTIMIZED_PREF);
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
verify(mockBatteryOptimizeUtils).setAppUsageState(
|
||||
BatteryOptimizeUtils.AppUsageState.OPTIMIZED);
|
||||
assertThat(mController.handlePreferenceTreeClick(mPreference)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlePreferenceTreeClick_incorrectPrefKey_noAction() {
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
verifyZeroInteractions(mockBatteryOptimizeUtils);
|
||||
assertThat(mController.handlePreferenceTreeClick(mPreference)).isFalse();
|
||||
}
|
||||
}
|
||||
|
@@ -156,6 +156,11 @@ public class PowerUsageFeatureProviderImplTest {
|
||||
assertThat(mPowerFeatureProvider.isSmartBatterySupported()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAdaptiveChargingSupported_returnFalse() {
|
||||
assertThat(mPowerFeatureProvider.isAdaptiveChargingSupported()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetResumeChargeIntent_returnNull() {
|
||||
assertThat(mPowerFeatureProvider.getResumeChargeIntent()).isNull();
|
||||
|
@@ -18,8 +18,6 @@ package com.android.settings.fuelgauge;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.android.settingslib.widget.RadioButtonPreference;
|
||||
@@ -84,8 +82,8 @@ public class RestrictedPreferenceControllerTest {
|
||||
@Test
|
||||
public void testUpdateState_isRestrictedStates_prefChecked() {
|
||||
when(mockBatteryOptimizeUtils.isValidPackageName()).thenReturn(true);
|
||||
when(mockBatteryOptimizeUtils.getAppUsageState()).thenReturn(
|
||||
BatteryOptimizeUtils.AppUsageState.RESTRICTED);
|
||||
when(mockBatteryOptimizeUtils.getAppOptimizationMode()).thenReturn(
|
||||
BatteryOptimizeUtils.MODE_RESTRICTED);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
@@ -106,14 +104,11 @@ public class RestrictedPreferenceControllerTest {
|
||||
mPreference.setKey(mController.KEY_RESTRICTED_PREF);
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
verify(mockBatteryOptimizeUtils).setAppUsageState(
|
||||
BatteryOptimizeUtils.AppUsageState.RESTRICTED);
|
||||
assertThat(mController.handlePreferenceTreeClick(mPreference)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlePreferenceTreeClick_incorrectPrefKey_noAction() {
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
verifyZeroInteractions(mockBatteryOptimizeUtils);
|
||||
assertThat(mController.handlePreferenceTreeClick(mPreference)).isFalse();
|
||||
}
|
||||
}
|
||||
|
@@ -21,11 +21,7 @@ import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -36,9 +32,7 @@ import android.content.Context;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -50,23 +44,13 @@ import org.robolectric.annotation.Config;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class TopLevelBatteryPreferenceControllerTest {
|
||||
private Context mContext;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private TopLevelBatteryPreferenceController mController;
|
||||
private BatterySettingsFeatureProvider mBatterySettingsFeatureProvider;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mContext = spy(Robolectric.setupActivity(Activity.class));
|
||||
mController = new TopLevelBatteryPreferenceController(mContext, "test_key");
|
||||
mBatterySettingsFeatureProvider =
|
||||
mFeatureFactory.batterySettingsFeatureProvider;
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
TopLevelBatteryPreferenceController.sReplacingActivityMap.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -80,54 +64,6 @@ public class TopLevelBatteryPreferenceControllerTest {
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_noFragment_noCustomActivityCalled() {
|
||||
Preference preference = new Preference(mContext);
|
||||
|
||||
assertThat(mController.handlePreferenceTreeClick(preference)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_sameActivityReturned_noCustomActivityCalled() {
|
||||
String fragmentPath = "my.fragment.ClassName";
|
||||
Preference preference = mock(Preference.class);
|
||||
when(preference.getFragment()).thenReturn(fragmentPath);
|
||||
ComponentName pathName = mController.convertClassPathToComponentName(fragmentPath);
|
||||
when(mBatterySettingsFeatureProvider.getReplacingActivity(any())).thenReturn(pathName);
|
||||
|
||||
assertThat(mController.handlePreferenceTreeClick(preference)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_newActivityReturned_newActivityRedirected() {
|
||||
String fragmentPath = "my.fragment.ClassName";
|
||||
Preference preference = mock(Preference.class);
|
||||
when(preference.getFragment()).thenReturn(fragmentPath);
|
||||
String newFragmentPath = "my.fragment.NewClassName";
|
||||
ComponentName newPathName = mController.convertClassPathToComponentName(newFragmentPath);
|
||||
when(mBatterySettingsFeatureProvider.getReplacingActivity(any())).thenReturn(
|
||||
newPathName);
|
||||
doNothing().when(mContext).startActivity(any());
|
||||
|
||||
assertThat(mController.handlePreferenceTreeClick(preference)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_calledMultipleTimes_fetchedFromCache() {
|
||||
String fragmentPath = "my.fragment.ClassName";
|
||||
Preference preference = mock(Preference.class);
|
||||
when(preference.getFragment()).thenReturn(fragmentPath);
|
||||
String newFragmentPath = "my.fragment.NewClassName";
|
||||
ComponentName newPathName = mController.convertClassPathToComponentName(newFragmentPath);
|
||||
when(mBatterySettingsFeatureProvider.getReplacingActivity(any())).thenReturn(
|
||||
newPathName);
|
||||
doNothing().when(mContext).startActivity(any());
|
||||
|
||||
assertThat(mController.handlePreferenceTreeClick(preference)).isTrue();
|
||||
assertThat(mController.handlePreferenceTreeClick(preference)).isTrue();
|
||||
verify(mBatterySettingsFeatureProvider, times(1)).getReplacingActivity(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertClassPathToComponentName_nullInput_returnsNull() {
|
||||
assertThat(mController.convertClassPathToComponentName(null)).isNull();
|
||||
@@ -156,6 +92,7 @@ public class TopLevelBatteryPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void getDashboardLabel_returnsCorrectLabel() {
|
||||
mController.mPreference = new Preference(mContext);
|
||||
BatteryInfo info = new BatteryInfo();
|
||||
info.batteryPercentString = "3%";
|
||||
assertThat(mController.getDashboardLabel(mContext, info, true))
|
||||
|
@@ -19,8 +19,6 @@ package com.android.settings.fuelgauge;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.android.settingslib.widget.RadioButtonPreference;
|
||||
@@ -84,8 +82,8 @@ public class UnrestrictedPreferenceControllerTest {
|
||||
@Test
|
||||
public void testUpdateState_isUnrestrictedStates_prefChecked() {
|
||||
when(mockBatteryOptimizeUtils.isValidPackageName()).thenReturn(true);
|
||||
when(mockBatteryOptimizeUtils.getAppUsageState()).thenReturn(
|
||||
BatteryOptimizeUtils.AppUsageState.UNRESTRICTED);
|
||||
when(mockBatteryOptimizeUtils.getAppOptimizationMode()).thenReturn(
|
||||
BatteryOptimizeUtils.MODE_UNRESTRICTED);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
@@ -106,14 +104,11 @@ public class UnrestrictedPreferenceControllerTest {
|
||||
mPreference.setKey(mController.KEY_UNRESTRICTED_PREF);
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
verify(mockBatteryOptimizeUtils).setAppUsageState(
|
||||
BatteryOptimizeUtils.AppUsageState.UNRESTRICTED);
|
||||
assertThat(mController.handlePreferenceTreeClick(mPreference)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlePreferenceTreeClick_incorrectPrefKey_noAction() {
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
verifyZeroInteractions(mockBatteryOptimizeUtils);
|
||||
assertThat(mController.handlePreferenceTreeClick(mPreference)).isFalse();
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,116 @@
|
||||
package com.android.settings.fuelgauge.batterysaver;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.Settings;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public final class BatterySaverScheduleSettingsTest {
|
||||
|
||||
private Context mContext;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private BatterySaverScheduleSettings mBatterySaverScheduleSettings;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mBatterySaverScheduleSettings = new BatterySaverScheduleSettings();
|
||||
mBatterySaverScheduleSettings.onAttach(mContext);
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mMetricsFeatureProvider = mFeatureFactory.metricsFeatureProvider;
|
||||
|
||||
setSchedule(PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE, 1);
|
||||
mBatterySaverScheduleSettings.onResume();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPause_withNoScheduleType_logExpectedData() {
|
||||
int expectedPercentage = 0;
|
||||
setSchedule(PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE, expectedPercentage);
|
||||
|
||||
mBatterySaverScheduleSettings.onPause();
|
||||
|
||||
verifySchedule("key_battery_saver_no_schedule", expectedPercentage);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPause_withRoutineScheduleType_logExpectedData() {
|
||||
int expectedPercentage = 0;
|
||||
setSchedule(PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC, expectedPercentage);
|
||||
|
||||
mBatterySaverScheduleSettings.onPause();
|
||||
|
||||
verifySchedule("key_battery_saver_routine", expectedPercentage);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPause_withPercentageScheduleType_logExpectedData() {
|
||||
int expectedPercentage = 10;
|
||||
setSchedule(PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE, expectedPercentage);
|
||||
|
||||
mBatterySaverScheduleSettings.onPause();
|
||||
|
||||
verifySchedule("key_battery_saver_percentage", expectedPercentage);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPause_scheduleTypeAndPercentageAreNotChanged_notLogAnyData() {
|
||||
mBatterySaverScheduleSettings.onResume();
|
||||
mBatterySaverScheduleSettings.onPause();
|
||||
|
||||
waitAWhile();
|
||||
verifyNoMoreInteractions(mMetricsFeatureProvider);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPause_multipleScheduleTypeChanges_logLastChangedData() {
|
||||
int expectedPercentage = 10;
|
||||
setSchedule(PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE, 0);
|
||||
setSchedule(PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC, 0);
|
||||
setSchedule(PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE, expectedPercentage);
|
||||
|
||||
mBatterySaverScheduleSettings.onPause();
|
||||
|
||||
verifySchedule("key_battery_saver_percentage", expectedPercentage);
|
||||
}
|
||||
|
||||
private void setSchedule(int scheduleType, int schedulePercentage) {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.AUTOMATIC_POWER_SAVE_MODE, scheduleType);
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL, schedulePercentage);
|
||||
}
|
||||
|
||||
private void verifySchedule(String scheduleTypeKey, int schedulePercentage) {
|
||||
waitAWhile();
|
||||
verify(mMetricsFeatureProvider).action(SettingsEnums.FUELGAUGE_BATTERY_SAVER,
|
||||
SettingsEnums.FIELD_BATTERY_SAVER_SCHEDULE_TYPE,
|
||||
SettingsEnums.FIELD_BATTERY_SAVER_PERCENTAGE_VALUE,
|
||||
scheduleTypeKey, schedulePercentage);
|
||||
}
|
||||
|
||||
private void waitAWhile() {
|
||||
try {
|
||||
Thread.sleep(200);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
@@ -18,12 +18,10 @@ package com.android.settings.location;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
@@ -34,7 +32,7 @@ import androidx.preference.PreferenceScreen;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
|
||||
import com.android.settingslib.location.RecentLocationAccesses;
|
||||
import com.android.settingslib.applications.RecentAppOpsAccess;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -48,7 +46,6 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowDeviceConfig.class})
|
||||
@@ -61,7 +58,7 @@ public class RecentLocationAccessPreferenceControllerTest {
|
||||
@Mock
|
||||
private DashboardFragment mDashboardFragment;
|
||||
@Mock
|
||||
private RecentLocationAccesses mRecentLocationApps;
|
||||
private RecentAppOpsAccess mRecentLocationApps;
|
||||
|
||||
private Context mContext;
|
||||
private RecentLocationAccessPreferenceController mController;
|
||||
@@ -110,17 +107,4 @@ public class RecentLocationAccessPreferenceControllerTest {
|
||||
mContext.getText(R.string.location_recent_location_access_view_details));
|
||||
assertThat(details.hasOnClickListeners()).isTrue();
|
||||
}
|
||||
|
||||
private List<RecentLocationAccesses.Access> createMockAccesses(int count) {
|
||||
final List<RecentLocationAccesses.Access> accesses = new ArrayList<>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
final Drawable icon = mock(Drawable.class);
|
||||
// Add mock accesses
|
||||
final RecentLocationAccesses.Access access = new RecentLocationAccesses.Access(
|
||||
"packageName", android.os.Process.myUserHandle(), icon,
|
||||
"appTitle" + i, "appSummary" + i, 1000 - i);
|
||||
accesses.add(access);
|
||||
}
|
||||
return accesses;
|
||||
}
|
||||
}
|
||||
|
@@ -209,82 +209,6 @@ public class MobileNetworkSummaryControllerTest {
|
||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID)).isEqualTo(sub1.getSubscriptionId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_twoSubscriptions_correctSummaryAndFragment() {
|
||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, false);
|
||||
final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
|
||||
final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
|
||||
when(sub1.getSubscriptionId()).thenReturn(1);
|
||||
when(sub2.getSubscriptionId()).thenReturn(2);
|
||||
|
||||
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1, sub2));
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
mController.onResume();
|
||||
assertThat(mController.getSummary()).isEqualTo("2 SIMs");
|
||||
assertThat(mPreference.getFragment()).isEqualTo(MobileNetworkListFragment.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummaryAfterUpdate_twoSubscriptionsBecomesOne_correctSummaryAndFragment() {
|
||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, false);
|
||||
final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
|
||||
final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
|
||||
when(sub1.getSubscriptionId()).thenReturn(1);
|
||||
when(sub2.getSubscriptionId()).thenReturn(2);
|
||||
when(sub1.getDisplayName()).thenReturn("sub1");
|
||||
when(sub2.getDisplayName()).thenReturn("sub2");
|
||||
|
||||
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1, sub2));
|
||||
SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1, sub2));
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
mController.onResume();
|
||||
assertThat(mController.getSummary()).isEqualTo("2 SIMs");
|
||||
assertThat(mPreference.getFragment()).isEqualTo(MobileNetworkListFragment.class.getName());
|
||||
|
||||
// Simulate sub2 having disappeared - the end result should change to be the same as
|
||||
// if there were just one subscription.
|
||||
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1));
|
||||
mController.onSubscriptionsChanged();
|
||||
assertThat(mController.getSummary()).isEqualTo("sub1");
|
||||
assertThat(mPreference.getFragment()).isNull();
|
||||
final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
doNothing().when(mContext).startActivity(intentCaptor.capture());
|
||||
mPreference.getOnPreferenceClickListener().onPreferenceClick(mPreference);
|
||||
assertThat(intentCaptor.getValue().getComponent().getClassName()).isEqualTo(
|
||||
MobileNetworkActivity.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummaryAfterUpdate_oneSubscriptionBecomesTwo_correctSummaryAndFragment() {
|
||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, false);
|
||||
final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
|
||||
final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
|
||||
when(sub1.getSubscriptionId()).thenReturn(1);
|
||||
when(sub2.getSubscriptionId()).thenReturn(2);
|
||||
when(sub1.getDisplayName()).thenReturn("sub1");
|
||||
when(sub2.getDisplayName()).thenReturn("sub2");
|
||||
|
||||
when(mSubscriptionManager.getAvailableSubscriptionInfoList()).thenReturn(
|
||||
Arrays.asList(sub1));
|
||||
SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1));
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
mController.onResume();
|
||||
assertThat(mController.getSummary()).isEqualTo("sub1");
|
||||
assertThat(mPreference.getFragment()).isNull();
|
||||
final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
doNothing().when(mContext).startActivity(intentCaptor.capture());
|
||||
mPreference.getOnPreferenceClickListener().onPreferenceClick(mPreference);
|
||||
assertThat(intentCaptor.getValue().getComponent().getClassName()).isEqualTo(
|
||||
MobileNetworkActivity.class.getName());
|
||||
|
||||
// Simulate sub2 appearing in the list of subscriptions and check the results.
|
||||
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1, sub2));
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
mController.onResume();
|
||||
assertThat(mController.getSummary()).isEqualTo("2 SIMs");
|
||||
assertThat(mPreference.getFragment()).isEqualTo(MobileNetworkListFragment.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_providerModel_Enabled() {
|
||||
final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
|
||||
@@ -296,15 +220,9 @@ public class MobileNetworkSummaryControllerTest {
|
||||
|
||||
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1, sub2));
|
||||
SubscriptionUtil.setActiveSubscriptionsForTesting(Arrays.asList(sub1, sub2));
|
||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, true);
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
mController.onResume();
|
||||
assertThat(mController.getSummary()).isEqualTo("sub1, sub2");
|
||||
|
||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, false);
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
mController.onResume();
|
||||
assertThat(mController.getSummary()).isEqualTo("2 SIMs");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -158,7 +158,6 @@ public class NetworkProviderSettingsTest {
|
||||
.when(mFirstWifiEntryPreferenceCategory).getKey();
|
||||
mNetworkProviderSettings.mFirstWifiEntryPreferenceCategory =
|
||||
mFirstWifiEntryPreferenceCategory;
|
||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -292,6 +292,18 @@ public class RedactNotificationPreferenceControllerTest {
|
||||
assertThat(mWorkController.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_admin() {
|
||||
Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
||||
LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS,
|
||||
1, 0);
|
||||
|
||||
ShadowRestrictedLockUtilsInternal.setKeyguardDisabledFeatures(
|
||||
KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);
|
||||
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_false() throws Exception {
|
||||
Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
||||
|
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.notification;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.media.Spatializer;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@Ignore("b/200896161")
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class SpatialAudioPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private AudioManager mAudioManager;
|
||||
@Mock
|
||||
private Spatializer mSpatializer;
|
||||
|
||||
private SpatialAudioPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when((Object) mContext.getSystemService(AudioManager.class)).thenReturn(mAudioManager);
|
||||
when(mAudioManager.getSpatializer()).thenReturn(mSpatializer);
|
||||
mController = new SpatialAudioPreferenceController(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_levelNone_shouldReturnUnsupported() {
|
||||
when(mSpatializer.getImmersiveAudioLevel()).thenReturn(
|
||||
Spatializer.SPATIALIZER_IMMERSIVE_LEVEL_NONE);
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_levelMultiChannel_shouldReturnAvailable() {
|
||||
when(mSpatializer.getImmersiveAudioLevel()).thenReturn(
|
||||
Spatializer.SPATIALIZER_IMMERSIVE_LEVEL_MULTICHANNEL);
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_withTrue_shouldEnableSpatializer() {
|
||||
mController.setChecked(true);
|
||||
|
||||
verify(mSpatializer).setEnabled(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_withFalse_shouldDisableSpatializer() {
|
||||
mController.setChecked(false);
|
||||
|
||||
verify(mSpatializer).setEnabled(false);
|
||||
}
|
||||
}
|
@@ -17,8 +17,6 @@
|
||||
|
||||
package com.android.settings.panel;
|
||||
|
||||
import static com.android.settings.panel.PanelContent.VIEW_TYPE_SLIDER;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -212,38 +210,6 @@ public class PanelFragmentTest {
|
||||
assertThat(titleView.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sliderPanelType_notDisplayFooterDivider() {
|
||||
mFakePanelContent.setViewType(VIEW_TYPE_SLIDER);
|
||||
final ActivityController<FakeSettingsPanelActivity> activityController =
|
||||
Robolectric.buildActivity(FakeSettingsPanelActivity.class);
|
||||
activityController.setup();
|
||||
final PanelFragment panelFragment = (PanelFragment)
|
||||
Objects.requireNonNull(activityController
|
||||
.get()
|
||||
.getSupportFragmentManager()
|
||||
.findFragmentById(R.id.main_content));
|
||||
final View footerDivider = panelFragment.mLayoutView.findViewById(R.id.footer_divider);
|
||||
// Check visibility
|
||||
assertThat(footerDivider.getVisibility()).isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultPanelType_notDisplayFooterDivider() {
|
||||
mFakePanelContent.setViewType(0 /* viewType */);
|
||||
final ActivityController<FakeSettingsPanelActivity> activityController =
|
||||
Robolectric.buildActivity(FakeSettingsPanelActivity.class);
|
||||
activityController.setup();
|
||||
final PanelFragment panelFragment = (PanelFragment)
|
||||
Objects.requireNonNull(activityController
|
||||
.get()
|
||||
.getSupportFragmentManager()
|
||||
.findFragmentById(R.id.main_content));
|
||||
final View footerDivider = panelFragment.mLayoutView.findViewById(R.id.footer_divider);
|
||||
// Check visibility
|
||||
assertThat(footerDivider.getVisibility()).isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onHeaderChanged_updateHeader_verifyTitle() {
|
||||
mFakePanelContent.setIcon(IconCompat.createWithResource(mContext, R.drawable.ic_android));
|
||||
|
@@ -19,7 +19,6 @@ package com.android.settings.panel;
|
||||
import static com.android.settings.panel.PanelContent.VIEW_TYPE_SLIDER;
|
||||
import static com.android.settings.panel.PanelSlicesAdapter.MAX_NUM_OF_SLICES;
|
||||
import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_INDICATOR_SLICE_URI;
|
||||
import static com.android.settings.slices.CustomSliceRegistry.VOLUME_MEDIA_URI;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@@ -124,53 +123,6 @@ public class PanelSlicesAdapterTest {
|
||||
assertThat(adapter.getData().size()).isEqualTo(MAX_NUM_OF_SLICES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mediaOutputIndicatorSlice_shouldNotAllowDividerAbove() {
|
||||
addTestLiveData(MEDIA_OUTPUT_INDICATOR_SLICE_URI);
|
||||
|
||||
final PanelSlicesAdapter adapter =
|
||||
new PanelSlicesAdapter(mPanelFragment, mData, 0 /* metrics category */);
|
||||
final int position = 0;
|
||||
final ViewGroup view = new FrameLayout(mContext);
|
||||
final SliceRowViewHolder viewHolder =
|
||||
adapter.onCreateViewHolder(view, 0 /* view type*/);
|
||||
|
||||
adapter.onBindViewHolder(viewHolder, position);
|
||||
|
||||
assertThat(viewHolder.isDividerAllowedAbove()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sliderPanelType_shouldAllowDividerBelow() {
|
||||
addTestLiveData(VOLUME_MEDIA_URI);
|
||||
mFakePanelContent.setViewType(PanelContent.VIEW_TYPE_SLIDER);
|
||||
|
||||
final PanelSlicesAdapter adapter =
|
||||
new PanelSlicesAdapter(mPanelFragment, mData, 0 /* metrics category */);
|
||||
final int position = 0;
|
||||
final ViewGroup view = new FrameLayout(mContext);
|
||||
final SliceRowViewHolder viewHolder =
|
||||
adapter.onCreateViewHolder(view, PanelContent.VIEW_TYPE_SLIDER);
|
||||
adapter.onBindViewHolder(viewHolder, position);
|
||||
|
||||
assertThat(viewHolder.isDividerAllowedBelow()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultPanelType_shouldAllowDividerBelow() {
|
||||
addTestLiveData(VOLUME_MEDIA_URI);
|
||||
mFakePanelContent.setViewType(0 /* viewType */);
|
||||
|
||||
final PanelSlicesAdapter adapter =
|
||||
new PanelSlicesAdapter(mPanelFragment, mData, 0 /* metrics category */);
|
||||
final int position = 0;
|
||||
final ViewGroup view = new FrameLayout(mContext);
|
||||
final SliceRowViewHolder viewHolder = adapter.onCreateViewHolder(view, 0/* viewType */);
|
||||
adapter.onBindViewHolder(viewHolder, position);
|
||||
|
||||
assertThat(viewHolder.isDividerAllowedBelow()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mediaOutputIndicatorSlice_notSliderPanel_noSliderLayout() {
|
||||
addTestLiveData(MEDIA_OUTPUT_INDICATOR_SLICE_URI);
|
||||
|
@@ -80,7 +80,7 @@ public class WorkPolicyInfoPreferenceControllerTest {
|
||||
|
||||
final Preference pref = new Preference(mContext);
|
||||
assertThat(controller.handlePreferenceTreeClick(pref)).isFalse();
|
||||
verify(mEnterpriseProvider, never()).showWorkPolicyInfo();
|
||||
verify(mEnterpriseProvider, never()).showWorkPolicyInfo(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -92,6 +92,6 @@ public class WorkPolicyInfoPreferenceControllerTest {
|
||||
final Preference pref = new Preference(mContext);
|
||||
pref.setKey(controller.getPreferenceKey());
|
||||
assertThat(controller.handlePreferenceTreeClick(pref)).isTrue();
|
||||
verify(mEnterpriseProvider).showWorkPolicyInfo();
|
||||
verify(mEnterpriseProvider).showWorkPolicyInfo(mContext);
|
||||
}
|
||||
}
|
||||
|
@@ -19,7 +19,6 @@ package com.android.settings.search;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
@@ -29,6 +28,8 @@ import android.net.Uri;
|
||||
import android.provider.Settings;
|
||||
import android.widget.Toolbar;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||
@@ -46,13 +47,13 @@ import org.robolectric.shadows.ShadowPackageManager;
|
||||
public class SearchFeatureProviderImplTest {
|
||||
|
||||
private SearchFeatureProviderImpl mProvider;
|
||||
private Activity mActivity;
|
||||
private FragmentActivity mActivity;
|
||||
private ShadowPackageManager mPackageManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
FakeFeatureFactory.setupForTest();
|
||||
mActivity = Robolectric.setupActivity(Activity.class);
|
||||
mActivity = Robolectric.setupActivity(FragmentActivity.class);
|
||||
mProvider = new SearchFeatureProviderImpl();
|
||||
mPackageManager = Shadows.shadowOf(mActivity.getPackageManager());
|
||||
Settings.Global.putInt(mActivity.getContentResolver(),
|
||||
|
@@ -707,6 +707,7 @@ public class SettingsSliceProviderTest {
|
||||
.setIcon(SliceTestUtils.FAKE_ICON)
|
||||
.setFragmentName(SliceTestUtils.FAKE_FRAGMENT_NAME)
|
||||
.setPreferenceControllerClassName(SliceTestUtils.FAKE_CONTROLLER_NAME)
|
||||
.setHighlightMenuRes(SliceTestUtils.FAKE_HIGHLIGHT_MENU_RES)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
@@ -322,6 +322,8 @@ public class SliceBroadcastReceiverTest {
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.FRAGMENT, SliceTestUtils.FAKE_FRAGMENT_NAME);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.CONTROLLER, controllerClass);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.SLICE_URI, buildUri(key).toSafeString());
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.HIGHLIGHT_MENU_RESOURCE,
|
||||
SliceTestUtils.FAKE_HIGHLIGHT_MENU_RES);
|
||||
mDb.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, values);
|
||||
}
|
||||
|
||||
|
@@ -35,6 +35,7 @@ class SliceTestUtils {
|
||||
public static final int FAKE_ICON = 1234;
|
||||
public static final String FAKE_FRAGMENT_NAME = FakeIndexProvider.class.getName();
|
||||
public static final String FAKE_CONTROLLER_NAME = FakeToggleController.class.getName();
|
||||
public static final int FAKE_HIGHLIGHT_MENU_RES = FakeToggleController.HIGHLIGHT_MENU_RES;
|
||||
|
||||
|
||||
public static void insertSliceToDb(Context context, String key) {
|
||||
@@ -75,6 +76,8 @@ class SliceTestUtils {
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.UNAVAILABLE_SLICE_SUBTITLE,
|
||||
customizedUnavailableSliceSubtitle);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.PUBLIC_SLICE, isPublicSlice);
|
||||
values.put(SlicesDatabaseHelper.IndexColumns.HIGHLIGHT_MENU_RESOURCE,
|
||||
FAKE_HIGHLIGHT_MENU_RES);
|
||||
|
||||
db.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, values);
|
||||
db.close();
|
||||
|
@@ -102,6 +102,7 @@ public class SlicesDatabaseAccessorTest {
|
||||
assertThat(data.getFragmentClassName()).isEqualTo(SliceTestUtils.FAKE_FRAGMENT_NAME);
|
||||
assertThat(data.getUri()).isNull();
|
||||
assertThat(data.getPreferenceController()).isEqualTo(SliceTestUtils.FAKE_CONTROLLER_NAME);
|
||||
assertThat(data.getHighlightMenuRes()).isEqualTo(SliceTestUtils.FAKE_HIGHLIGHT_MENU_RES);
|
||||
assertThat(data.getUnavailableSliceSubtitle()).isNull();
|
||||
}
|
||||
|
||||
@@ -122,6 +123,7 @@ public class SlicesDatabaseAccessorTest {
|
||||
assertThat(data.getFragmentClassName()).isEqualTo(SliceTestUtils.FAKE_FRAGMENT_NAME);
|
||||
assertThat(data.getUri()).isNull();
|
||||
assertThat(data.getPreferenceController()).isEqualTo(SliceTestUtils.FAKE_CONTROLLER_NAME);
|
||||
assertThat(data.getHighlightMenuRes()).isEqualTo(SliceTestUtils.FAKE_HIGHLIGHT_MENU_RES);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@@ -154,6 +156,7 @@ public class SlicesDatabaseAccessorTest {
|
||||
assertThat(data.getFragmentClassName()).isEqualTo(SliceTestUtils.FAKE_FRAGMENT_NAME);
|
||||
assertThat(data.getUri()).isEqualTo(uri);
|
||||
assertThat(data.getPreferenceController()).isEqualTo(SliceTestUtils.FAKE_CONTROLLER_NAME);
|
||||
assertThat(data.getHighlightMenuRes()).isEqualTo(SliceTestUtils.FAKE_HIGHLIGHT_MENU_RES);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@@ -289,6 +292,7 @@ public class SlicesDatabaseAccessorTest {
|
||||
assertThat(data.getFragmentClassName()).isEqualTo(SliceTestUtils.FAKE_FRAGMENT_NAME);
|
||||
assertThat(data.getUri()).isNull();
|
||||
assertThat(data.getPreferenceController()).isEqualTo(SliceTestUtils.FAKE_CONTROLLER_NAME);
|
||||
assertThat(data.getHighlightMenuRes()).isEqualTo(SliceTestUtils.FAKE_HIGHLIGHT_MENU_RES);
|
||||
assertThat(data.getUnavailableSliceSubtitle()).isNull();
|
||||
}
|
||||
|
||||
@@ -309,6 +313,7 @@ public class SlicesDatabaseAccessorTest {
|
||||
assertThat(data.getFragmentClassName()).isEqualTo(SliceTestUtils.FAKE_FRAGMENT_NAME);
|
||||
assertThat(data.getUri()).isNull();
|
||||
assertThat(data.getPreferenceController()).isEqualTo(SliceTestUtils.FAKE_CONTROLLER_NAME);
|
||||
assertThat(data.getHighlightMenuRes()).isEqualTo(SliceTestUtils.FAKE_HIGHLIGHT_MENU_RES);
|
||||
assertThat(data.getUnavailableSliceSubtitle()).isEqualTo(subtitle);
|
||||
}
|
||||
|
||||
|
@@ -43,17 +43,18 @@ import java.util.List;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class SlicesIndexerTest {
|
||||
|
||||
private final String[] KEYS = new String[]{"key1", "key2", "key3"};
|
||||
private final String[] TITLES = new String[]{"title1", "title2", "title3"};
|
||||
private final String SUMMARY = "subtitle";
|
||||
private final String SCREEN_TITLE = "screen title";
|
||||
private final String KEYWORDS = "a, b, c";
|
||||
private final String FRAGMENT_NAME = "fragment name";
|
||||
private final int ICON = 1234; // I declare a thumb war
|
||||
private final Uri URI = Uri.parse("content://com.android.settings.slices/test");
|
||||
private final String PREF_CONTROLLER = "com.android.settings.slices.tester";
|
||||
private final int SLICE_TYPE = SliceData.SliceType.SLIDER;
|
||||
private final String UNAVAILABLE_SLICE_SUBTITLE = "subtitleOfUnavailableSlice";
|
||||
private static final String[] KEYS = new String[]{"key1", "key2", "key3"};
|
||||
private static final String[] TITLES = new String[]{"title1", "title2", "title3"};
|
||||
private static final String SUMMARY = "subtitle";
|
||||
private static final String SCREEN_TITLE = "screen title";
|
||||
private static final String KEYWORDS = "a, b, c";
|
||||
private static final String FRAGMENT_NAME = "fragment name";
|
||||
private static final int ICON = 1234; // I declare a thumb war
|
||||
private static final Uri URI = Uri.parse("content://com.android.settings.slices/test");
|
||||
private static final String PREF_CONTROLLER = "com.android.settings.slices.tester";
|
||||
private static final int SLICE_TYPE = SliceData.SliceType.SLIDER;
|
||||
private static final String UNAVAILABLE_SLICE_SUBTITLE = "subtitleOfUnavailableSlice";
|
||||
private static final int HIGHLIGHT_MENU_KEY = 5678; // I declare a thumb war
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@@ -142,6 +143,9 @@ public class SlicesIndexerTest {
|
||||
.isEqualTo(UNAVAILABLE_SLICE_SUBTITLE);
|
||||
assertThat(cursor.getInt(
|
||||
cursor.getColumnIndex(IndexColumns.PUBLIC_SLICE))).isEqualTo(0);
|
||||
assertThat(cursor.getInt(
|
||||
cursor.getColumnIndex(IndexColumns.HIGHLIGHT_MENU_RESOURCE)))
|
||||
.isEqualTo(HIGHLIGHT_MENU_KEY);
|
||||
cursor.moveToNext();
|
||||
}
|
||||
} finally {
|
||||
@@ -187,6 +191,9 @@ public class SlicesIndexerTest {
|
||||
.isEqualTo(UNAVAILABLE_SLICE_SUBTITLE);
|
||||
assertThat(cursor.getInt(
|
||||
cursor.getColumnIndex(IndexColumns.PUBLIC_SLICE))).isEqualTo(1);
|
||||
assertThat(cursor.getInt(
|
||||
cursor.getColumnIndex(IndexColumns.HIGHLIGHT_MENU_RESOURCE)))
|
||||
.isEqualTo(HIGHLIGHT_MENU_KEY);
|
||||
cursor.moveToNext();
|
||||
}
|
||||
} finally {
|
||||
@@ -220,7 +227,8 @@ public class SlicesIndexerTest {
|
||||
.setUri(URI)
|
||||
.setPreferenceControllerClassName(PREF_CONTROLLER)
|
||||
.setSliceType(SLICE_TYPE)
|
||||
.setUnavailableSliceSubtitle(UNAVAILABLE_SLICE_SUBTITLE);
|
||||
.setUnavailableSliceSubtitle(UNAVAILABLE_SLICE_SUBTITLE)
|
||||
.setHighlightMenuRes(HIGHLIGHT_MENU_KEY);
|
||||
|
||||
if (isPublicSlice) {
|
||||
builder.setIsPublicSlice(true);
|
||||
|
@@ -21,6 +21,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.accessibility.AccessibilityMetricsFeatureProvider;
|
||||
import com.android.settings.accessibility.AccessibilitySearchFeatureProvider;
|
||||
import com.android.settings.accounts.AccountFeatureProvider;
|
||||
import com.android.settings.applications.ApplicationFeatureProvider;
|
||||
@@ -89,6 +90,7 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
public SecuritySettingsFeatureProvider securitySettingsFeatureProvider;
|
||||
public GameSettingsFeatureProvider gameSettingsFeatureProvider;
|
||||
public AccessibilitySearchFeatureProvider mAccessibilitySearchFeatureProvider;
|
||||
public AccessibilityMetricsFeatureProvider mAccessibilityMetricsFeatureProvider;
|
||||
|
||||
/**
|
||||
* Call this in {@code @Before} method of the test class to use fake factory.
|
||||
@@ -139,6 +141,7 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
securitySettingsFeatureProvider = mock(SecuritySettingsFeatureProvider.class);
|
||||
gameSettingsFeatureProvider = mock(GameSettingsFeatureProvider.class);
|
||||
mAccessibilitySearchFeatureProvider = mock(AccessibilitySearchFeatureProvider.class);
|
||||
mAccessibilityMetricsFeatureProvider = mock(AccessibilityMetricsFeatureProvider.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -280,4 +283,9 @@ public class FakeFeatureFactory extends FeatureFactory {
|
||||
public AccessibilitySearchFeatureProvider getAccessibilitySearchFeatureProvider() {
|
||||
return mAccessibilitySearchFeatureProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessibilityMetricsFeatureProvider getAccessibilityMetricsFeatureProvider() {
|
||||
return mAccessibilityMetricsFeatureProvider;
|
||||
}
|
||||
}
|
||||
|
@@ -27,6 +27,7 @@ import com.android.settings.slices.SliceBackgroundWorker;
|
||||
public class FakeToggleController extends TogglePreferenceController {
|
||||
|
||||
public static final String AVAILABILITY_KEY = "fake_toggle_availability_key";
|
||||
public static final int HIGHLIGHT_MENU_RES = 5678;
|
||||
|
||||
public static final IntentFilter INTENT_FILTER = new IntentFilter(
|
||||
WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
|
||||
@@ -70,6 +71,11 @@ public class FakeToggleController extends TogglePreferenceController {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliceHighlightMenuRes() {
|
||||
return HIGHLIGHT_MENU_RES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends SliceBackgroundWorker> getBackgroundWorkerClass() {
|
||||
return TestWorker.class;
|
||||
|
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.testutils.shadow;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.activityembedding.ActivityEmbeddingUtils;
|
||||
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
|
||||
/**
|
||||
* Shadow class for {@link ActivityEmbeddingUtils} to test embedding activity features.
|
||||
*/
|
||||
@Implements(ActivityEmbeddingUtils.class)
|
||||
public class ShadowActivityEmbeddingUtils {
|
||||
private static boolean sIsEmbeddingActivityEnabled;
|
||||
|
||||
@Implementation
|
||||
public static boolean isEmbeddingActivityEnabled(Context context) {
|
||||
return sIsEmbeddingActivityEnabled;
|
||||
}
|
||||
|
||||
public static void setIsEmbeddingActivityEnabled(boolean isEmbeddingActivityEnabled) {
|
||||
sIsEmbeddingActivityEnabled = isEmbeddingActivityEnabled;
|
||||
}
|
||||
}
|
@@ -106,7 +106,7 @@ public class WifiSettingsTest {
|
||||
mWifiSettings.mConfigureWifiSettingsPreference = new Preference(mContext);
|
||||
mWifiSettings.mWifiPickerTracker = mMockWifiPickerTracker;
|
||||
mWifiSettings.mWifiManager = mWifiManager;
|
||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_PROVIDER_MODEL, false);
|
||||
mWifiSettings.IS_ENABLED_PROVIDER_MODEL = false;
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -18,27 +18,70 @@ package com.android.settings.wifi.addappnetworks;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
import android.annotation.Nullable;
|
||||
import android.app.IActivityManager;
|
||||
import android.os.RemoteException;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AddAppNetworksActivityTest {
|
||||
|
||||
@Mock
|
||||
private IActivityManager mIActivityManager;
|
||||
|
||||
private AddAppNetworksActivity mActivity;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mActivity = Robolectric.buildActivity(AddAppNetworksActivity.class).create().get();
|
||||
mActivity.mActivityManager = mIActivityManager;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startActivity_withPackageName_bundleShouldHaveRightPackageName() {
|
||||
final String packageName = RuntimeEnvironment.application.getPackageName();
|
||||
final AddAppNetworksActivity activity =
|
||||
Robolectric.buildActivity(AddAppNetworksActivity.class).create().get();
|
||||
shadowOf(activity).setCallingPackage(packageName);
|
||||
public void getCallingAppPackageName_nullPackageName_returnNotNull() {
|
||||
fakeCallingPackage("com.android.settings");
|
||||
|
||||
activity.showAddNetworksFragment();
|
||||
assertThat(mActivity.getCallingAppPackageName()).isNotNull();
|
||||
}
|
||||
|
||||
assertThat(activity.mBundle.getString(AddAppNetworksActivity.KEY_CALLING_PACKAGE_NAME))
|
||||
.isEqualTo(packageName);
|
||||
@Test
|
||||
public void getCallingAppPackageName_withPackageName_returnNull() {
|
||||
fakeCallingPackage(null);
|
||||
|
||||
assertThat(mActivity.getCallingAppPackageName()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void showAddNetworksFragment_nullPackageName_returnFalse() {
|
||||
fakeCallingPackage(null);
|
||||
|
||||
assertThat(mActivity.showAddNetworksFragment()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void showAddNetworksFragment_withPackageName_returnTrue() {
|
||||
fakeCallingPackage("com.android.settings");
|
||||
|
||||
assertThat(mActivity.showAddNetworksFragment()).isTrue();
|
||||
}
|
||||
|
||||
private void fakeCallingPackage(@Nullable String packageName) {
|
||||
try {
|
||||
when(mIActivityManager.getLaunchedFromPackage(any())).thenReturn(packageName);
|
||||
} catch (RemoteException e) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -16,16 +16,82 @@
|
||||
|
||||
package com.android.settings.wifi.dpp;
|
||||
|
||||
import static com.android.settings.wifi.dpp.WifiDppEnrolleeActivity.ACTION_ENROLLEE_QR_CODE_SCANNER;
|
||||
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
import com.android.settingslib.wifi.WifiRestrictionsCache;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class WifiDppEnrolleeActivityTest {
|
||||
|
||||
private static final String WIFI_SSID = "wifi-ssid";
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
@Mock
|
||||
WifiRestrictionsCache mWifiRestrictionsCache;
|
||||
@Mock
|
||||
Intent mIntent;
|
||||
|
||||
WifiDppEnrolleeActivity mActivity;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
when(mWifiRestrictionsCache.isConfigWifiAllowed()).thenReturn(true);
|
||||
when(mIntent.getAction()).thenReturn(ACTION_ENROLLEE_QR_CODE_SCANNER);
|
||||
when(mIntent.getStringExtra(WifiDppUtils.EXTRA_WIFI_SSID)).thenReturn(WIFI_SSID);
|
||||
|
||||
mActivity = spy(Robolectric.setupActivity(WifiDppEnrolleeActivity.class));
|
||||
mActivity.mWifiRestrictionsCache = mWifiRestrictionsCache;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchActivity_noIntentAction_shouldNotFatalException() {
|
||||
WifiDppEnrolleeActivity wifiDppEnrolleeActivity =
|
||||
Robolectric.setupActivity(WifiDppEnrolleeActivity.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleIntent_noIntentAction_shouldFinish() {
|
||||
when(mIntent.getAction()).thenReturn(null);
|
||||
|
||||
mActivity.handleIntent(mIntent);
|
||||
|
||||
verify(mActivity).finish();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleIntent_notAllowedConfigWifi_shouldFinish() {
|
||||
when(mWifiRestrictionsCache.isConfigWifiAllowed()).thenReturn(false);
|
||||
|
||||
mActivity.handleIntent(mIntent);
|
||||
|
||||
verify(mActivity).finish();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleIntent_hasIntentDataAndAllowedConfigWifi_shouldShowFragment() {
|
||||
when(mWifiRestrictionsCache.isConfigWifiAllowed()).thenReturn(true);
|
||||
doNothing().when(mActivity).showQrCodeScannerFragment(WIFI_SSID);
|
||||
|
||||
mActivity.handleIntent(mIntent);
|
||||
|
||||
verify(mActivity).showQrCodeScannerFragment(WIFI_SSID);
|
||||
}
|
||||
}
|
||||
|
@@ -27,6 +27,8 @@ import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiConfiguration.KeyMgmt;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.wifitrackerlib.WifiEntry;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -80,4 +82,12 @@ public class WifiDppUtilsTest {
|
||||
assertThat(intent.getBooleanExtra(WifiDppUtils.EXTRA_WIFI_HIDDEN_SSID, false))
|
||||
.isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEnrolleeQrCodeScannerIntent_isExplicitIntent() {
|
||||
Intent intent = WifiDppUtils.getEnrolleeQrCodeScannerIntent(
|
||||
ApplicationProvider.getApplicationContext(), null);
|
||||
assertThat(intent.getComponent()).isNotNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user