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
<extra android:name="for_work" android:value="true" />
</Preference>
- </com.android.settings.WorkOnlyCategory>
+ </com.android.settings.widget.WorkOnlyCategory>
</PreferenceScreen>
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">
android:ringtoneType="alarm"
android:dependency="work_use_personal_sounds" />
- </com.android.settings.WorkOnlyCategory>
+ </com.android.settings.widget.WorkOnlyCategory>
</PreferenceScreen>
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">
android:ringtoneType="alarm"
android:dependency="work_use_personal_sounds" />
- </com.android.settings.WorkOnlyCategory>
+ </com.android.settings.widget.WorkOnlyCategory>
</PreferenceScreen>
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;
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
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));
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;
}
public class DefaultWorkBrowserPreferenceController extends DefaultBrowserPreferenceController {
+ public static final String KEY = "work_default_browser";
private final UserHandle mUserHandle;
public DefaultWorkBrowserPreferenceController(Context context) {
@Override
public String getPreferenceKey() {
- return "work_default_browser";
+ return KEY;
}
@Override
public class DefaultWorkPhonePreferenceController extends DefaultPhonePreferenceController {
+ public static final String KEY = "work_default_phone_app";
private final UserHandle mUserHandle;
public DefaultWorkPhonePreferenceController(Context context) {
@Override
public String getPreferenceKey() {
- return "work_default_phone_app";
+ return KEY;
}
}
* 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.
*/
--- /dev/null
+/*
+ * 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;
+ }
+}
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;
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 {
--- /dev/null
+/*
+ * 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();
+ }
+}