Merge "Add work-only-category controller"

This commit is contained in:
TreeHugger Robot
2017-10-17 19:10:29 +00:00
committed by Android (Google) Code Review
10 changed files with 166 additions and 25 deletions

View File

@@ -74,8 +74,8 @@
android:title="@string/domain_urls_title"
android:fragment="com.android.settings.applications.ManageDomainUrls" />
<com.android.settings.WorkOnlyCategory
android:key="work_defaults"
<com.android.settings.widget.WorkOnlyCategory
android:key="work_app_defaults"
android:title="@string/default_for_work">
<Preference
@@ -93,6 +93,6 @@
<extra android:name="for_work" android:value="true" />
</Preference>
</com.android.settings.WorkOnlyCategory>
</com.android.settings.widget.WorkOnlyCategory>
</PreferenceScreen>

View File

@@ -156,7 +156,7 @@
android:targetClass="com.android.cellbroadcastreceiver.CellBroadcastSettings" />
</com.android.settingslib.RestrictedPreference>
<com.android.settings.WorkOnlyCategory
<com.android.settings.widget.WorkOnlyCategory
android:key="sound_work_settings_section"
android:title="@string/sound_work_settings"
android:order="100">
@@ -193,5 +193,5 @@
android:ringtoneType="alarm"
android:dependency="work_use_personal_sounds" />
</com.android.settings.WorkOnlyCategory>
</com.android.settings.widget.WorkOnlyCategory>
</PreferenceScreen>

View File

@@ -154,7 +154,7 @@
android:targetClass="com.android.cellbroadcastreceiver.CellBroadcastSettings" />
</com.android.settingslib.RestrictedPreference>
<com.android.settings.WorkOnlyCategory
<com.android.settings.widget.WorkOnlyCategory
android:key="sound_work_settings_section"
android:title="@string/sound_work_settings"
android:order="100">
@@ -191,5 +191,5 @@
android:ringtoneType="alarm"
android:dependency="work_use_personal_sounds" />
</com.android.settings.WorkOnlyCategory>
</com.android.settings.widget.WorkOnlyCategory>
</PreferenceScreen>

View File

@@ -26,11 +26,12 @@ import com.android.settings.applications.assist.DefaultAssistPreferenceControlle
import com.android.settings.applications.defaultapps.DefaultBrowserPreferenceController;
import com.android.settings.applications.defaultapps.DefaultEmergencyPreferenceController;
import com.android.settings.applications.defaultapps.DefaultHomePreferenceController;
import com.android.settings.applications.defaultapps.DefaultPaymentSettingsPreferenceController;
import com.android.settings.applications.defaultapps.DefaultPhonePreferenceController;
import com.android.settings.applications.defaultapps.DefaultSmsPreferenceController;
import com.android.settings.applications.defaultapps.DefaultWorkBrowserPreferenceController;
import com.android.settings.widget.WorkOnlyCategoryPreferenceController;
import com.android.settings.applications.defaultapps.DefaultWorkPhonePreferenceController;
import com.android.settings.applications.defaultapps.DefaultPaymentSettingsPreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.search.BaseSearchIndexProvider;
@@ -45,6 +46,7 @@ public class DefaultAppSettings extends DashboardFragment {
static final String TAG = "DefaultAppSettings";
private static final String KEY_DEFAULT_WORK_CATEGORY = "work_app_defaults";
private static final String KEY_ASSIST_VOICE_INPUT = "assist_and_voice_input";
@Override
@@ -69,12 +71,16 @@ public class DefaultAppSettings extends DashboardFragment {
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
final List<AbstractPreferenceController> workControllers = new ArrayList<>();
workControllers.add(new DefaultWorkPhonePreferenceController(context));
workControllers.add(new DefaultWorkBrowserPreferenceController(context));
controllers.addAll(workControllers);
controllers.add(new WorkOnlyCategoryPreferenceController(
context, KEY_DEFAULT_WORK_CATEGORY, workControllers));
controllers.add(new DefaultAssistPreferenceController(context, KEY_ASSIST_VOICE_INPUT,
false /* showSetting */));
controllers.add(new DefaultBrowserPreferenceController(context));
controllers.add(new DefaultWorkBrowserPreferenceController(context));
controllers.add(new DefaultPhonePreferenceController(context));
controllers.add(new DefaultWorkPhonePreferenceController(context));
controllers.add(new DefaultSmsPreferenceController(context));
controllers.add(new DefaultEmergencyPreferenceController(context));
controllers.add(new DefaultHomePreferenceController(context));
@@ -97,10 +103,8 @@ public class DefaultAppSettings extends DashboardFragment {
List<String> keys = super.getNonIndexableKeys(context);
keys.add(KEY_ASSIST_VOICE_INPUT);
// TODO (b/38230148) Remove these keys when we can differentiate work results
keys.add((new DefaultWorkPhonePreferenceController(context))
.getPreferenceKey());
keys.add((new DefaultWorkBrowserPreferenceController(context))
.getPreferenceKey());
keys.add(DefaultWorkPhonePreferenceController.KEY);
keys.add(DefaultWorkBrowserPreferenceController.KEY);
return keys;
}

View File

@@ -23,6 +23,7 @@ import com.android.settings.Utils;
public class DefaultWorkBrowserPreferenceController extends DefaultBrowserPreferenceController {
public static final String KEY = "work_default_browser";
private final UserHandle mUserHandle;
public DefaultWorkBrowserPreferenceController(Context context) {
@@ -35,7 +36,7 @@ public class DefaultWorkBrowserPreferenceController extends DefaultBrowserPrefer
@Override
public String getPreferenceKey() {
return "work_default_browser";
return KEY;
}
@Override

View File

@@ -23,6 +23,7 @@ import com.android.settings.Utils;
public class DefaultWorkPhonePreferenceController extends DefaultPhonePreferenceController {
public static final String KEY = "work_default_phone_app";
private final UserHandle mUserHandle;
public DefaultWorkPhonePreferenceController(Context context) {
@@ -43,6 +44,6 @@ public class DefaultWorkPhonePreferenceController extends DefaultPhonePreference
@Override
public String getPreferenceKey() {
return "work_default_phone_app";
return KEY;
}
}

View File

@@ -12,13 +12,16 @@
* permissions and limitations under the License.
*/
package com.android.settings;
package com.android.settings.widget;
import android.content.Context;
import android.os.UserManager;
import android.support.v7.preference.PreferenceCategory;
import android.util.AttributeSet;
import com.android.settings.SelfAvailablePreference;
import com.android.settings.Utils;
/**
* A PreferenceCategory that is only visible when the device has a work profile.
*/

View File

@@ -0,0 +1,57 @@
/*
* 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.widget;
import android.content.Context;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.AbstractPreferenceController;
import java.util.List;
public class WorkOnlyCategoryPreferenceController extends AbstractPreferenceController
implements PreferenceControllerMixin {
private final String mKey;
private final List<AbstractPreferenceController> mChildren;
public WorkOnlyCategoryPreferenceController(Context context,
String key, List<AbstractPreferenceController> childrenControllers) {
super(context);
mKey = key;
mChildren = childrenControllers;
}
@Override
public boolean isAvailable() {
if (mChildren == null || mChildren.isEmpty()) {
return true;
}
// Category is available if any child is available
for (AbstractPreferenceController controller : mChildren) {
if (controller.isAvailable()) {
return true;
}
}
return false;
}
@Override
public String getPreferenceKey() {
return mKey;
}
}

View File

@@ -17,6 +17,14 @@
package com.android.settings.widget;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.text.InputType;
import android.text.TextWatcher;
import android.view.View;
@@ -33,14 +41,6 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class ValidatedEditTextPreferenceTest {

View File

@@ -0,0 +1,75 @@
/*
* 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.widget;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import android.content.Context;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.AbstractPreferenceController;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.ArrayList;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class WorkOnlyCategoryPreferenceControllerTest {
private Context mContext;
private WorkOnlyCategoryPreferenceController mController;
private List<AbstractPreferenceController> mChildren;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mChildren = new ArrayList<>();
mController = new WorkOnlyCategoryPreferenceController(mContext, "pref_key", mChildren);
}
@Test
public void isAvailable_noChildren_true() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_childrenAvailable_true() {
final AbstractPreferenceController child = mock(AbstractPreferenceController.class);
when(child.isAvailable()).thenReturn(true);
mChildren.add(child);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_childrenUnavailable_false() {
final AbstractPreferenceController child = mock(AbstractPreferenceController.class);
when(child.isAvailable()).thenReturn(false);
mChildren.add(child);
assertThat(mController.isAvailable()).isFalse();
}
}