Merge "Revert "Align more prefs for icon space.""
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 87b6372..f4a972b 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -758,11 +758,6 @@
android:icon="@drawable/ic_settings_notifications"
android:exported="true"
android:taskAffinity="">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.DEFAULT" />
- <category android:name="com.android.settings.SHORTCUT" />
- </intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.notification.ZenModeVisualInterruptionSettings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
@@ -778,11 +773,6 @@
<action android:name="android.settings.ZEN_MODE_PRIORITY_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.DEFAULT" />
- <category android:name="com.android.settings.SHORTCUT" />
- </intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.notification.ZenModePrioritySettings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
@@ -802,11 +792,6 @@
<action android:name="android.settings.ACTION_CONDITION_PROVIDER_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.DEFAULT" />
- <category android:name="com.android.settings.SHORTCUT" />
- </intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.notification.ZenModeAutomationSettings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
@@ -950,11 +935,6 @@
<action android:name="android.settings.NIGHT_DISPLAY_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.DEFAULT" />
- <category android:name="com.android.settings.SHORTCUT" />
- </intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.display.NightDisplaySettings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
@@ -1343,11 +1323,6 @@
<action android:name="com.android.settings.TRUSTED_CREDENTIALS_USER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.DEFAULT" />
- <category android:name="com.android.settings.SHORTCUT" />
- </intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.TrustedCredentialsSettings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
@@ -2293,11 +2268,6 @@
<action android:name="android.settings.BATTERY_SAVER_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.DEFAULT" />
- <category android:name="com.android.settings.SHORTCUT" />
- </intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.fuelgauge.BatterySaverSettings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index aa76517..cc203f7 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -329,7 +329,7 @@
}
MenuInflater inflater = getMenuInflater();
- if (mSearchFeatureProvider.isEnabled()) {
+ if (mSearchFeatureProvider.isEnabled(this)) {
mSearchFeatureProvider.setUpSearchMenu(menu, this);
return true;
}
@@ -405,7 +405,7 @@
final FeatureFactory factory = FeatureFactory.getFactory(this);
mDashboardFeatureProvider = factory.getDashboardFeatureProvider(this);
- mSearchFeatureProvider = factory.getSearchFeatureProvider(this);
+ mSearchFeatureProvider = factory.getSearchFeatureProvider();
// Should happen before any call to getIntent()
getMetaData();
@@ -1097,7 +1097,7 @@
@Deprecated
@Override
public boolean onQueryTextSubmit(String query) {
- if (mSearchFeatureProvider.isEnabled()) {
+ if (mSearchFeatureProvider.isEnabled(this)) {
return false;
}
mSearchQuery = query;
@@ -1109,7 +1109,7 @@
@Override
public boolean onQueryTextChange(String newText) {
mSearchQuery = newText;
- if (mSearchFeatureProvider.isEnabled() || mSearchResultsFragment == null) {
+ if (mSearchFeatureProvider.isEnabled(this) || mSearchResultsFragment == null) {
return false;
}
return mSearchResultsFragment.onQueryTextChange(newText);
diff --git a/src/com/android/settings/dashboard/SupportFragment.java b/src/com/android/settings/dashboard/SupportFragment.java
index b1e19fe..8a1a79b 100644
--- a/src/com/android/settings/dashboard/SupportFragment.java
+++ b/src/com/android/settings/dashboard/SupportFragment.java
@@ -119,6 +119,7 @@
.build(),
mNetworkCallback);
mSupportItemAdapter.setHasInternet(hasInternet());
+ mSupportItemAdapter.refreshData();
}
@Override
diff --git a/src/com/android/settings/dashboard/SupportItemAdapter.java b/src/com/android/settings/dashboard/SupportItemAdapter.java
index b125fff..54c5ae6 100644
--- a/src/com/android/settings/dashboard/SupportItemAdapter.java
+++ b/src/com/android/settings/dashboard/SupportItemAdapter.java
@@ -192,7 +192,7 @@
* Create data for the adapter. If there is already data in the adapter, they will be
* destroyed and recreated.
*/
- private void refreshData() {
+ void refreshData() {
mSupportData.clear();
addEscalationCards();
addMoreHelpItems();
@@ -601,7 +601,8 @@
/**
* Data for a single support item.
*/
- private static class SupportData {
+ @VisibleForTesting
+ static class SupportData {
final Intent intent;
final int metricsEvent;
@@ -688,7 +689,8 @@
/**
* Data model for escalation cards.
*/
- private static class EscalationData extends SupportData {
+ @VisibleForTesting
+ static class EscalationData extends SupportData {
@StringRes
final int text1;
@@ -813,4 +815,9 @@
}
}
}
+
+ @VisibleForTesting
+ List<SupportData> getSupportData() {
+ return mSupportData;
+ }
}
diff --git a/src/com/android/settings/notification/ZenModeSettings.java b/src/com/android/settings/notification/ZenModeSettings.java
index 88df549..1d5f09e 100644
--- a/src/com/android/settings/notification/ZenModeSettings.java
+++ b/src/com/android/settings/notification/ZenModeSettings.java
@@ -18,16 +18,14 @@
import android.app.NotificationManager;
import android.app.NotificationManager.Policy;
+import android.content.Context;
import android.os.Bundle;
+import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
-import com.android.settings.SettingsActivity;
public class ZenModeSettings extends ZenModeSettingsBase {
private static final String KEY_PRIORITY_SETTINGS = "priority_settings";
@@ -80,25 +78,25 @@
private void updatePrioritySettingsSummary() {
String s = getResources().getString(R.string.zen_mode_alarms);
- s = appendLowercase(s, isCategoryEnabled(mPolicy, Policy.PRIORITY_CATEGORY_REMINDERS),
+ s = append(s, isCategoryEnabled(mPolicy, Policy.PRIORITY_CATEGORY_REMINDERS),
R.string.zen_mode_reminders);
- s = appendLowercase(s, isCategoryEnabled(mPolicy, Policy.PRIORITY_CATEGORY_EVENTS),
+ s = append(s, isCategoryEnabled(mPolicy, Policy.PRIORITY_CATEGORY_EVENTS),
R.string.zen_mode_events);
if (isCategoryEnabled(mPolicy, Policy.PRIORITY_CATEGORY_MESSAGES)) {
if (mPolicy.priorityMessageSenders == Policy.PRIORITY_SENDERS_ANY) {
- s = appendLowercase(s, true, R.string.zen_mode_all_messages);
+ s = append(s, true, R.string.zen_mode_all_messages);
} else {
- s = appendLowercase(s, true, R.string.zen_mode_selected_messages);
+ s = append(s, true, R.string.zen_mode_selected_messages);
}
}
if (isCategoryEnabled(mPolicy, Policy.PRIORITY_CATEGORY_CALLS)) {
if (mPolicy.priorityCallSenders == Policy.PRIORITY_SENDERS_ANY) {
- s = appendLowercase(s, true, R.string.zen_mode_all_callers);
+ s = append(s, true, R.string.zen_mode_all_callers);
} else {
- s = appendLowercase(s, true, R.string.zen_mode_selected_callers);
+ s = append(s, true, R.string.zen_mode_selected_callers);
}
} else if (isCategoryEnabled(mPolicy, Policy.PRIORITY_CATEGORY_REPEAT_CALLERS)) {
- s = appendLowercase(s, true, R.string.zen_mode_repeat_callers);
+ s = append(s, true, R.string.zen_mode_repeat_callers);
}
mPrioritySettings.setSummary(s);
}
@@ -124,10 +122,11 @@
return (policy.priorityCategories & categoryType) != 0;
}
- private String appendLowercase(String s, boolean condition, int resId) {
+ @VisibleForTesting
+ String append(String s, boolean condition, int resId) {
if (condition) {
- return getResources().getString(R.string.join_many_items_middle, s,
- getResources().getString(resId).toLowerCase());
+ final Context context = getContext();
+ return context.getString(R.string.join_many_items_middle, s, context.getString(resId));
}
return s;
}
diff --git a/src/com/android/settings/overlay/FeatureFactory.java b/src/com/android/settings/overlay/FeatureFactory.java
index 364d5ed..0b8ee8e 100644
--- a/src/com/android/settings/overlay/FeatureFactory.java
+++ b/src/com/android/settings/overlay/FeatureFactory.java
@@ -81,7 +81,7 @@
public abstract EnterprisePrivacyFeatureProvider getEnterprisePrivacyFeatureProvider(
Context context);
- public abstract SearchFeatureProvider getSearchFeatureProvider(Context context);
+ public abstract SearchFeatureProvider getSearchFeatureProvider();
public abstract SurveyFeatureProvider getSurveyFeatureProvider(Context context);
diff --git a/src/com/android/settings/overlay/FeatureFactoryImpl.java b/src/com/android/settings/overlay/FeatureFactoryImpl.java
index 2aa9b34..c2d5d79 100644
--- a/src/com/android/settings/overlay/FeatureFactoryImpl.java
+++ b/src/com/android/settings/overlay/FeatureFactoryImpl.java
@@ -104,9 +104,9 @@
}
@Override
- public SearchFeatureProvider getSearchFeatureProvider(Context context) {
+ public SearchFeatureProvider getSearchFeatureProvider() {
if (mSearchFeatureProvider == null) {
- mSearchFeatureProvider = new SearchFeatureProviderImpl(context);
+ mSearchFeatureProvider = new SearchFeatureProviderImpl();
}
return mSearchFeatureProvider;
}
diff --git a/src/com/android/settings/search2/SearchFeatureProvider.java b/src/com/android/settings/search2/SearchFeatureProvider.java
index ad26eae..8a616a7 100644
--- a/src/com/android/settings/search2/SearchFeatureProvider.java
+++ b/src/com/android/settings/search2/SearchFeatureProvider.java
@@ -27,7 +27,7 @@
/**
* @return true to use the new version of search
*/
- boolean isEnabled();
+ boolean isEnabled(Context context);
/**
* Inserts the Menu items into Settings activity.
diff --git a/src/com/android/settings/search2/SearchFeatureProviderImpl.java b/src/com/android/settings/search2/SearchFeatureProviderImpl.java
index e2d25ad..acb90b7 100644
--- a/src/com/android/settings/search2/SearchFeatureProviderImpl.java
+++ b/src/com/android/settings/search2/SearchFeatureProviderImpl.java
@@ -31,16 +31,11 @@
* FeatureProvider for the refactored search code.
*/
public class SearchFeatureProviderImpl implements SearchFeatureProvider {
- protected Context mContext;
private DatabaseIndexingManager mDatabaseIndexingManager;
- public SearchFeatureProviderImpl(Context context) {
- mContext = context;
- }
-
@Override
- public boolean isEnabled() {
+ public boolean isEnabled(Context context) {
return false;
}
@@ -49,7 +44,7 @@
if (menu == null || activity == null) {
return;
}
- String menuTitle = mContext.getString(R.string.search_menu);
+ String menuTitle = activity.getString(R.string.search_menu);
MenuItem menuItem = menu.add(Menu.NONE, Menu.NONE, Menu.NONE, menuTitle)
.setIcon(R.drawable.abc_ic_search_api_material)
.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@@ -86,7 +81,7 @@
@Override
public void updateIndex(Context context) {
- if (isEnabled()) {
+ if (isEnabled(context)) {
getIndexingManager(context).update();
} else {
Index.getInstance(context).update();
diff --git a/src/com/android/settings/search2/SearchFragment.java b/src/com/android/settings/search2/SearchFragment.java
index fca52e9..1a4e6dc 100644
--- a/src/com/android/settings/search2/SearchFragment.java
+++ b/src/com/android/settings/search2/SearchFragment.java
@@ -66,7 +66,7 @@
public void onAttach(Context context) {
super.onAttach(context);
mSearchFeatureProvider = FeatureFactory.getFactory(context)
- .getSearchFeatureProvider(context);
+ .getSearchFeatureProvider();
}
@Override
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
index 3ffd059..e4a988f 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
@@ -124,7 +124,7 @@
tile.intent = new Intent();
tile.intent.setComponent(new ComponentName("pkg", "class"));
- when(mActivity.getApplicationContext().getSystemService(Context.USER_SERVICE))
+ when(mActivity.getSystemService(Context.USER_SERVICE))
.thenReturn(mUserManager);
mImpl.bindPreferenceToTile(mActivity, preference, tile, "123", Preference.DEFAULT_ORDER);
diff --git a/tests/robotests/src/com/android/settings/dashboard/SupportItemAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/SupportItemAdapterTest.java
index e3d4c94..a877ed2 100644
--- a/tests/robotests/src/com/android/settings/dashboard/SupportItemAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/SupportItemAdapterTest.java
@@ -18,6 +18,7 @@
import android.accounts.Account;
import android.app.Activity;
+import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.view.LayoutInflater;
@@ -26,7 +27,9 @@
import android.widget.SpinnerAdapter;
import com.android.settings.TestConfig;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
+import com.android.settings.dashboard.SupportItemAdapter.EscalationData;
import com.android.settings.overlay.SupportFeatureProvider;
+import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -38,6 +41,8 @@
import com.android.settings.R;
import org.robolectric.shadows.ShadowActivity;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.verify;
import static org.robolectric.Shadows.shadowOf;
import static org.mockito.Mockito.when;
@@ -111,6 +116,37 @@
verify(mSupportFeatureProvider).getSupportEligibleAccounts(mActivity);
}
+ @Test
+ public void testRefreshData_CardUpdatedOnEnteringOrLeavingSupportHours() {
+ // pretend we have support right now
+ when(mSupportFeatureProvider.isSupportTypeEnabled(any(), anyInt()))
+ .thenReturn(true);
+ when(mSupportFeatureProvider.isOperatingNow(anyInt())).thenReturn(true);
+ when(mSupportFeatureProvider.getSupportEligibleAccounts(any())).thenReturn(ONE_ACCOUNT);
+ mSupportItemAdapter = new SupportItemAdapter(mActivity, null, mSupportFeatureProvider,
+ mMetricsFeatureProvider, null);
+
+ // If this doesn't return escalation data something has gone wrong
+ EscalationData data = (EscalationData) mSupportItemAdapter.getSupportData().get(0);
+
+ // precondition, support is enabled
+ assertThat(data.enabled1).isTrue();
+
+ // pretend we support hours are over
+ when(mSupportFeatureProvider.isOperatingNow(anyInt())).thenReturn(false);
+ mSupportItemAdapter.refreshData();
+ data = (EscalationData) mSupportItemAdapter.getSupportData().get(0);
+
+ assertThat(data.enabled1).isFalse();
+
+ // pretend support hours have started again
+ when(mSupportFeatureProvider.isOperatingNow(anyInt())).thenReturn(true);
+ mSupportItemAdapter.refreshData();
+ data = (EscalationData) mSupportItemAdapter.getSupportData().get(0);
+
+ assertThat(data.enabled1).isTrue();
+ }
+
/**
* Check after {@link SupportItemAdapter#bindAccountPicker(SupportItemAdapter.ViewHolder)} is
* invoked, whether the spinner in {@paramref viewHolder} has all the data from {@paramref
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java
new file mode 100644
index 0000000..40cfed5
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2016 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 android.content.Context;
+
+import com.android.settings.R;
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class ZenModeSettingsTest {
+
+ private ZenModeSettings mSettings;
+ private Context mContext;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application.getApplicationContext();
+ mSettings = spy(ZenModeSettings.class);
+ doReturn(mContext).when(mSettings).getContext();
+ }
+
+ @Test
+ public void testAppend_conditionFalse_shouldNotAppend() {
+ String original = "test";
+
+ final String result = mSettings.append(original, false, R.string.zen_mode_alarms);
+
+ assertThat(result).isEqualTo(original);
+ }
+
+ @Test
+ public void testAppend_conditionTrue_shouldAppend() {
+ String original = "test";
+ String alarm = mContext.getString(R.string.zen_mode_alarms);
+
+ final String result = mSettings.append(original, true, R.string.zen_mode_alarms);
+
+ assertThat(result).contains(alarm);
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java
index d9e2dd6..c0b1b3d 100644
--- a/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java
@@ -61,7 +61,7 @@
public void setUp() {
MockitoAnnotations.initMocks(this);
mActivity = Robolectric.buildActivity(Activity.class).create().visible().get();
- mProvider = new SearchFeatureProviderImpl(mActivity);
+ mProvider = new SearchFeatureProviderImpl();
}
@Test
@@ -78,8 +78,8 @@
@Test
public void testUpdateIndexNewSearch_UsesDatabaseIndexingManager() {
- mProvider = spy(new SearchFeatureProviderImpl(mActivity));
- when(mProvider.isEnabled()).thenReturn(true);
+ mProvider = spy(new SearchFeatureProviderImpl());
+ when(mProvider.isEnabled(mActivity)).thenReturn(true);
mProvider.updateIndex(mActivity);
verify(mProvider).getIndexingManager(any(Context.class));
@@ -87,8 +87,8 @@
@Test
public void testUpdateIndexNewSearch_UsesIndex() {
- mProvider = spy(new SearchFeatureProviderImpl(mActivity));
- when(mProvider.isEnabled()).thenReturn(false);
+ mProvider = spy(new SearchFeatureProviderImpl());
+ when(mProvider.isEnabled(mActivity)).thenReturn(false);
mProvider.updateIndex(mActivity);
verify(mProvider, never()).getIndexingManager(any(Context.class));
diff --git a/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java b/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java
index a9c1764..1625f35 100644
--- a/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java
+++ b/tests/robotests/src/com/android/settings/testutils/FakeFeatureFactory.java
@@ -116,7 +116,7 @@
}
@Override
- public SearchFeatureProvider getSearchFeatureProvider(Context context) {
+ public SearchFeatureProvider getSearchFeatureProvider() {
return searchFeatureProvider;
}