diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index d4357318c8a..9a771ac9848 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1892,7 +1892,8 @@
android:name=".development.DevelopmentSettingsDisabledActivity"
android:icon="@drawable/ic_settings_development"
android:label="@string/development_settings_title"
- android:theme="@android:style/Theme.NoDisplay">
+ android:excludeFromRecents="true"
+ android:theme="@style/Transparent">
@@ -3069,10 +3070,12 @@
-
profiles = mUm.getProfiles(UserHandle.myUserId());
+ final int profilesCount = profiles.size();
+ mUserHandle = null;
+ for (int i = 0; i < profilesCount; i++) {
+ UserInfo userInfo = profiles.get(i);
+ if (userInfo.isManagedProfile()) {
+ // We assume there's only one managed profile, otherwise UI needs to change.
+ mUserHandle = userInfo.getUserHandle();
+ break;
+ }
+ }
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/homepage/conditional/AbnormalRingerConditionBaseTest.java b/tests/robotests/src/com/android/settings/homepage/conditional/v2/AbnormalRingerConditionControllerBaseTest.java
similarity index 61%
rename from tests/robotests/src/com/android/settings/homepage/conditional/AbnormalRingerConditionBaseTest.java
rename to tests/robotests/src/com/android/settings/homepage/conditional/v2/AbnormalRingerConditionControllerBaseTest.java
index efc5ceab889..dc06710335e 100644
--- a/tests/robotests/src/com/android/settings/homepage/conditional/AbnormalRingerConditionBaseTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/conditional/v2/AbnormalRingerConditionControllerBaseTest.java
@@ -14,15 +14,13 @@
* limitations under the License.
*/
-package com.android.settings.homepage.conditional;
+package com.android.settings.homepage.conditional.v2;
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
import android.content.Context;
import android.content.Intent;
-import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -35,7 +33,7 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
@RunWith(SettingsRobolectricTestRunner.class)
-public class AbnormalRingerConditionBaseTest {
+public class AbnormalRingerConditionControllerBaseTest {
@Mock
private ConditionManager mConditionManager;
@@ -47,53 +45,39 @@ public class AbnormalRingerConditionBaseTest {
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
- when(mConditionManager.getContext()).thenReturn(mContext);
- mCondition = new TestCondition(mConditionManager);
+
+ mCondition = new TestCondition(mContext, mConditionManager);
}
@Test
- public void newInstance_shouldMonitorRingerStateChangeBroadcast() {
+ public void startMonitor_shouldMonitorRingerStateChangeBroadcast() {
final Intent broadcast1 = new Intent("foo.bar.action");
final Intent broadcast2 = new Intent(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION);
+ mCondition.startMonitoringStateChange();
+
mContext.sendBroadcast(broadcast1);
- assertThat(mCondition.mRefreshCalled).isFalse();
+ verify(mConditionManager, never()).onConditionChanged();
mContext.sendBroadcast(broadcast2);
- assertThat(mCondition.mRefreshCalled).isTrue();
+ verify(mConditionManager).onConditionChanged();
}
- private static class TestCondition extends AbnormalRingerConditionBase {
- private boolean mRefreshCalled;
+ private static class TestCondition extends AbnormalRingerConditionController {
- TestCondition(ConditionManager manager) {
- super(manager);
+ public TestCondition(Context appContext, ConditionManager conditionManager) {
+ super(appContext, conditionManager);
}
- @Override
- public void refreshState() {
- mRefreshCalled = true;
- }
@Override
- public int getMetricsConstant() {
+ public long getId() {
return 0;
}
@Override
- public Drawable getIcon() {
- return null;
+ public boolean isDisplayable() {
+ return false;
}
-
- @Override
- public CharSequence getTitle() {
- return null;
- }
-
- @Override
- public CharSequence getSummary() {
- return null;
- }
-
}
}
diff --git a/tests/robotests/src/com/android/settings/homepage/conditional/BackgroundDataConditionTest.java b/tests/robotests/src/com/android/settings/homepage/conditional/v2/BackgroundDataConditionControllerTest.java
similarity index 79%
rename from tests/robotests/src/com/android/settings/homepage/conditional/BackgroundDataConditionTest.java
rename to tests/robotests/src/com/android/settings/homepage/conditional/v2/BackgroundDataConditionControllerTest.java
index 289fa7c22ba..b12d786067a 100644
--- a/tests/robotests/src/com/android/settings/homepage/conditional/BackgroundDataConditionTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/conditional/v2/BackgroundDataConditionControllerTest.java
@@ -13,13 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.settings.homepage.conditional;
+package com.android.settings.homepage.conditional.v2;
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.content.Intent;
@@ -31,30 +30,25 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
@RunWith(SettingsRobolectricTestRunner.class)
-public class BackgroundDataConditionTest {
- @Mock
- private ConditionManager mConditionManager;
-
+public class BackgroundDataConditionControllerTest {
private Context mContext;
+ private BackgroundDataConditionController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
- when(mConditionManager.getContext()).thenReturn(mContext);
+ mController = new BackgroundDataConditionController(mContext);
}
@Test
public void onPrimaryClick_shouldReturn2SummaryActivity() {
final ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(Intent.class);
- BackgroundDataCondition backgroundDataCondition
- = new BackgroundDataCondition(mConditionManager);
- backgroundDataCondition.onPrimaryClick();
+ mController.onPrimaryClick(mContext);
verify(mContext).startActivity(argumentCaptor.capture());
Intent intent = argumentCaptor.getValue();
diff --git a/tests/robotests/src/com/android/settings/homepage/conditional/v2/BatterySaverConditionControllerTest.java b/tests/robotests/src/com/android/settings/homepage/conditional/v2/BatterySaverConditionControllerTest.java
new file mode 100644
index 00000000000..8849e2d58f3
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/homepage/conditional/v2/BatterySaverConditionControllerTest.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2018 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.homepage.conditional.v2;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+import android.content.Context;
+import android.content.IntentFilter;
+import android.os.PowerManager;
+
+import com.android.settings.fuelgauge.BatterySaverReceiver;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.Shadows;
+import org.robolectric.shadows.ShadowPowerManager;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class BatterySaverConditionControllerTest {
+ @Mock
+ private ConditionManager mConditionManager;
+
+ private ShadowPowerManager mPowerManager;
+ private Context mContext;
+ private BatterySaverConditionController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ mPowerManager = Shadows.shadowOf(mContext.getSystemService(PowerManager.class));
+ mController = new BatterySaverConditionController(mContext, mConditionManager);
+ }
+
+ @Test
+ public void startMonitor_shouldRegisterReceiver() {
+ mController.startMonitoringStateChange();
+
+ verify(mContext).registerReceiver(any(BatterySaverReceiver.class), any(IntentFilter.class));
+ }
+
+ @Test
+ public void stopMonitor_shouldUnregisterReceiver() {
+ mController.startMonitoringStateChange();
+ mController.stopMonitoringStateChange();
+
+ verify(mContext).unregisterReceiver(any(BatterySaverReceiver.class));
+ }
+
+ @Test
+ public void isDisplayable_PowerSaverOn_true() {
+ mPowerManager.setIsPowerSaveMode(true);
+
+ assertThat(mController.isDisplayable()).isTrue();
+ }
+
+ @Test
+ public void isDisplayable_PowerSaverOff_false() {
+ mPowerManager.setIsPowerSaveMode(false);
+
+ assertThat(mController.isDisplayable()).isFalse();
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/homepage/conditional/v2/WorkModeConditionControllerTest.java b/tests/robotests/src/com/android/settings/homepage/conditional/v2/WorkModeConditionControllerTest.java
new file mode 100644
index 00000000000..04d58412883
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/homepage/conditional/v2/WorkModeConditionControllerTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2018 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.homepage.conditional.v2;
+
+import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+import android.content.ComponentName;
+import android.content.Context;
+
+import com.android.settings.Settings;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class WorkModeConditionControllerTest {
+
+ private Context mContext;
+ private WorkModeConditionController mController;
+
+ @Before
+ public void setUp() {
+ mContext = spy(RuntimeEnvironment.application);
+ mController = new WorkModeConditionController(mContext);
+ }
+
+ @Test
+ public void onPrimaryClick_shouldLaunchAccountsSetting() {
+ final ComponentName componentName =
+ new ComponentName(mContext, Settings.AccountDashboardActivity.class);
+
+ mController.onPrimaryClick(mContext);
+
+ verify(mContext).startActivity(
+ argThat(intent -> intent.getComponent().equals(componentName)));
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java b/tests/robotests/src/com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java
index b6b3d60748a..67d5dc60977 100644
--- a/tests/robotests/src/com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java
+++ b/tests/robotests/src/com/android/settings/wallpaper/WallpaperSuggestionActivityTest.java
@@ -17,14 +17,13 @@
package com.android.settings.wallpaper;
import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.Mockito.when;
import android.app.WallpaperManager;
import android.content.Context;
-import android.content.Intent;
import android.content.res.Resources;
-import com.android.settings.SubSettings;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.After;
@@ -35,14 +34,11 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
-import org.robolectric.Shadows;
import org.robolectric.android.controller.ActivityController;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.Resetter;
-import org.robolectric.shadows.ShadowActivity;
-import org.robolectric.shadows.ShadowPackageManager;
@RunWith(SettingsRobolectricTestRunner.class)
public class WallpaperSuggestionActivityTest {
@@ -65,20 +61,6 @@ public class WallpaperSuggestionActivityTest {
ShadowWallpaperManager.reset();
}
- @Test
- public void launch_primarySuggestionActivityDoesNotExist_shouldFallback() {
- ShadowPackageManager packageManager =
- Shadows.shadowOf(RuntimeEnvironment.application.getPackageManager());
- packageManager.removePackage("com.android.settings");
-
- ShadowActivity activity = Shadows.shadowOf(mController.setup().get());
- final Intent intent = activity.getNextStartedActivity();
-
- assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
- assertThat(intent.getFlags()).isEqualTo(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
- assertThat(activity.isFinishing()).isTrue();
- }
-
@Test
public void wallpaperServiceEnabled_no_shouldReturnTrue() {
when(mContext.getResources()).thenReturn(mResources);