Merge "Fix the break of repo hook color check." into qt-dev
diff --git a/res/xml/app_and_notification.xml b/res/xml/app_and_notification.xml
index 323a3b4..eccb0d1 100644
--- a/res/xml/app_and_notification.xml
+++ b/res/xml/app_and_notification.xml
@@ -43,6 +43,7 @@
<!-- Empty category to draw divider -->
<PreferenceCategory
android:key="recent_apps_divider"
+ android:layout="@layout/preference_category_no_label"
android:order="-997"/>
<!-- Notifications (appears before manage_perms), default apps (appears after) -->
diff --git a/res/xml/location_settings.xml b/res/xml/location_settings.xml
index 2f43ce8..9ab80a7 100644
--- a/res/xml/location_settings.xml
+++ b/res/xml/location_settings.xml
@@ -28,6 +28,7 @@
<PreferenceCategory
android:key="location_advanced_settings"
+ android:layout="@layout/preference_category_no_label"
settings:initialExpandedChildrenCount="2">
<!-- This preference category gets removed if new_recent_location_ui is disabled -->
@@ -54,7 +55,8 @@
android:selectable="true" />
<PreferenceCategory
- android:key="location_services" />
+ android:key="location_services"
+ android:layout="@layout/preference_category_no_label"/>
<!-- This preference gets removed if there is no managed profile -->
<PreferenceCategory
@@ -65,5 +67,6 @@
<PreferenceCategory
android:key="location_footer"
+ android:layout="@layout/preference_category_no_label"
settings:allowDividerAbove="false"/>
</PreferenceScreen>
diff --git a/res/xml/managed_profile_settings.xml b/res/xml/managed_profile_settings.xml
index bd44cc1..7b65a3d 100644
--- a/res/xml/managed_profile_settings.xml
+++ b/res/xml/managed_profile_settings.xml
@@ -32,11 +32,18 @@
settings:useAdditionalSummary="true"
settings:controller="com.android.settings.accounts.ContactSearchPreferenceController"/>
- <com.android.settingslib.RestrictedSwitchPreference
+ <!-- Only one of these preferences will be visible at a time, depending on
+ CrossProfileCalendarPreferenceController#isCrossProfileCalendarDisallowedByAdmin -->
+ <SwitchPreference
android:key="cross_profile_calendar"
android:summary="@string/cross_profile_calendar_summary"
android:title="@string/cross_profile_calendar_title"
- settings:useAdditionalSummary="true"
settings:controller="com.android.settings.accounts.CrossProfileCalendarPreferenceController"/>
+ <Preference
+ android:key="cross_profile_calendar_disabled"
+ android:summary="@string/cross_profile_calendar_restricted_summary"
+ android:title="@string/cross_profile_calendar_title"
+ android:enabled="false"
+ settings:controller="com.android.settings.accounts.CrossProfileCalendarDisabledPreferenceController"/>
</PreferenceScreen>
\ No newline at end of file
diff --git a/res/xml/privacy_dashboard_settings.xml b/res/xml/privacy_dashboard_settings.xml
index 45b9d19..aa789b9 100644
--- a/res/xml/privacy_dashboard_settings.xml
+++ b/res/xml/privacy_dashboard_settings.xml
@@ -64,7 +64,8 @@
<!-- Privacy Service -->
<PreferenceCategory
- android:key="privacy_services"/>
+ android:key="privacy_services"
+ android:layout="@layout/preference_category_no_label"/>
<PreferenceCategory
android:key="dashboard_tile_placeholder"/>
diff --git a/res/xml/security_dashboard_settings.xml b/res/xml/security_dashboard_settings.xml
index 9fe3d5b..6a896ce 100644
--- a/res/xml/security_dashboard_settings.xml
+++ b/res/xml/security_dashboard_settings.xml
@@ -96,7 +96,8 @@
<PreferenceCategory
android:order="40"
- android:key="security_settings_device_admin_category">
+ android:key="security_settings_device_admin_category"
+ android:layout="@layout/preference_category_no_label">
<Preference
android:key="manage_device_admin"
diff --git a/src/com/android/settings/accounts/CrossProfileCalendarDisabledPreferenceController.java b/src/com/android/settings/accounts/CrossProfileCalendarDisabledPreferenceController.java
new file mode 100644
index 0000000..c087982
--- /dev/null
+++ b/src/com/android/settings/accounts/CrossProfileCalendarDisabledPreferenceController.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2019 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.accounts;
+import static com.android.settings.accounts.CrossProfileCalendarPreferenceController.isCrossProfileCalendarDisallowedByAdmin;
+
+import android.content.Context;
+import android.os.UserHandle;
+
+import com.android.settings.core.BasePreferenceController;
+
+public class CrossProfileCalendarDisabledPreferenceController extends BasePreferenceController {
+ private UserHandle mManagedUser;
+
+ public void setManagedUser(UserHandle managedUser) {
+ mManagedUser = managedUser;
+ }
+
+ public CrossProfileCalendarDisabledPreferenceController(Context context,
+ String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ if (mManagedUser != null
+ && isCrossProfileCalendarDisallowedByAdmin(
+ mContext, mManagedUser.getIdentifier())) {
+ return AVAILABLE;
+ }
+
+ return DISABLED_FOR_USER;
+ }
+}
diff --git a/src/com/android/settings/accounts/CrossProfileCalendarPreferenceController.java b/src/com/android/settings/accounts/CrossProfileCalendarPreferenceController.java
index aa314d6..863e790 100644
--- a/src/com/android/settings/accounts/CrossProfileCalendarPreferenceController.java
+++ b/src/com/android/settings/accounts/CrossProfileCalendarPreferenceController.java
@@ -15,19 +15,21 @@
import static android.provider.Settings.Secure.CROSS_PROFILE_CALENDAR_ENABLED;
+import android.app.admin.DevicePolicyManager;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.os.UserHandle;
import android.provider.Settings;
-
-import androidx.preference.Preference;
+import android.util.Log;
import com.android.settings.core.TogglePreferenceController;
-import com.android.settingslib.RestrictedLockUtils;
-import com.android.settingslib.RestrictedLockUtilsInternal;
-import com.android.settingslib.RestrictedSwitchPreference;
+
+import java.util.Set;
public class CrossProfileCalendarPreferenceController extends TogglePreferenceController {
+ private static final String TAG = "CrossProfileCalendarPreferenceController";
+
private UserHandle mManagedUser;
public CrossProfileCalendarPreferenceController(Context context, String key) {
@@ -40,19 +42,13 @@
@Override
public int getAvailabilityStatus() {
- return (mManagedUser != null) ? AVAILABLE : DISABLED_FOR_USER;
- }
-
- @Override
- public void updateState(Preference preference) {
- super.updateState(preference);
- if (preference instanceof RestrictedSwitchPreference && mManagedUser != null) {
- final RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
- final RestrictedLockUtils.EnforcedAdmin enforcedAdmin =
- RestrictedLockUtilsInternal.getCrossProfileCalendarEnforcingAdmin(
- mContext, mManagedUser.getIdentifier());
- pref.setDisabledByAdmin(enforcedAdmin);
+ if (mManagedUser != null
+ && !isCrossProfileCalendarDisallowedByAdmin(
+ mContext, mManagedUser.getIdentifier())) {
+ return AVAILABLE;
}
+
+ return DISABLED_FOR_USER;
}
@Override
@@ -74,4 +70,25 @@
return Settings.Secure.putIntForUser(mContext.getContentResolver(),
CROSS_PROFILE_CALENDAR_ENABLED, value, mManagedUser.getIdentifier());
}
+
+ static boolean isCrossProfileCalendarDisallowedByAdmin(Context context, int userId) {
+ final Context managedProfileContext = createPackageContextAsUser(context, userId);
+ final DevicePolicyManager dpm = managedProfileContext.getSystemService(
+ DevicePolicyManager.class);
+ if (dpm == null) {
+ return true;
+ }
+ final Set<String> packages = dpm.getCrossProfileCalendarPackages();
+ return packages != null && packages.isEmpty();
+ }
+
+ private static Context createPackageContextAsUser(Context context, int userId) {
+ try {
+ return context.createPackageContextAsUser(
+ context.getPackageName(), 0 /* flags */, UserHandle.of(userId));
+ } catch (PackageManager.NameNotFoundException e) {
+ Log.e(TAG, "Failed to create user context", e);
+ }
+ return null;
+ }
}
\ No newline at end of file
diff --git a/src/com/android/settings/accounts/ManagedProfileSettings.java b/src/com/android/settings/accounts/ManagedProfileSettings.java
index a4105ef..1f18d07 100644
--- a/src/com/android/settings/accounts/ManagedProfileSettings.java
+++ b/src/com/android/settings/accounts/ManagedProfileSettings.java
@@ -16,17 +16,23 @@
package com.android.settings.accounts;
+import android.app.admin.DevicePolicyManager;
import android.app.settings.SettingsEnums;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.SearchIndexableResource;
import android.util.Log;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceGroup;
+import androidx.preference.PreferenceManager;
+
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.dashboard.DashboardFragment;
@@ -36,6 +42,7 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
/**
* Setting page for managed profile.
@@ -72,6 +79,7 @@
use(WorkModePreferenceController.class).setManagedUser(mManagedUser);
use(ContactSearchPreferenceController.class).setManagedUser(mManagedUser);
use(CrossProfileCalendarPreferenceController.class).setManagedUser(mManagedUser);
+ use(CrossProfileCalendarDisabledPreferenceController.class).setManagedUser(mManagedUser);
}
@Override
diff --git a/src/com/android/settings/deviceinfo/hardwareinfo/HardwareRevisionPreferenceController.java b/src/com/android/settings/deviceinfo/hardwareinfo/HardwareRevisionPreferenceController.java
index f882390..e7f6423 100644
--- a/src/com/android/settings/deviceinfo/hardwareinfo/HardwareRevisionPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/hardwareinfo/HardwareRevisionPreferenceController.java
@@ -21,6 +21,7 @@
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
+import com.android.settings.slices.Sliceable;
public class HardwareRevisionPreferenceController extends BasePreferenceController {
@@ -45,6 +46,17 @@
}
@Override
+ public boolean isCopyableSlice() {
+ return true;
+ }
+
+ @Override
+ public void copy() {
+ Sliceable.setCopyContent(mContext, getSummary(),
+ mContext.getText(R.string.hardware_revision));
+ }
+
+ @Override
public CharSequence getSummary() {
return SystemProperties.get("ro.boot.hardware.revision");
}
diff --git a/src/com/android/settings/notification/ZenModeCallsPreferenceController.java b/src/com/android/settings/notification/ZenModeCallsPreferenceController.java
index 0a8b931..d931f6c 100644
--- a/src/com/android/settings/notification/ZenModeCallsPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeCallsPreferenceController.java
@@ -16,7 +16,9 @@
package com.android.settings.notification;
+import android.app.NotificationManager;
import android.content.Context;
+import android.provider.Settings;
import androidx.preference.Preference;
@@ -50,6 +52,16 @@
public void updateState(Preference preference) {
super.updateState(preference);
- preference.setSummary(mSummaryBuilder.getCallsSettingSummary(getPolicy()));
+ switch (getZenMode()) {
+ case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
+ case Settings.Global.ZEN_MODE_ALARMS:
+ preference.setEnabled(false);
+ preference.setSummary(mBackend.getAlarmsTotalSilenceCallsMessagesSummary(
+ NotificationManager.Policy.PRIORITY_CATEGORY_CALLS));
+ break;
+ default:
+ preference.setEnabled(true);
+ preference.setSummary(mSummaryBuilder.getCallsSettingSummary(getPolicy()));
+ }
}
}
diff --git a/src/com/android/settings/notification/ZenModeMessagesPreferenceController.java b/src/com/android/settings/notification/ZenModeMessagesPreferenceController.java
index 2e41f20..d51be27 100644
--- a/src/com/android/settings/notification/ZenModeMessagesPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeMessagesPreferenceController.java
@@ -16,7 +16,9 @@
package com.android.settings.notification;
+import android.app.NotificationManager;
import android.content.Context;
+import android.provider.Settings;
import androidx.preference.Preference;
@@ -49,6 +51,16 @@
public void updateState(Preference preference) {
super.updateState(preference);
- preference.setSummary(mSummaryBuilder.getMessagesSettingSummary(getPolicy()));
+ switch (getZenMode()) {
+ case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
+ case Settings.Global.ZEN_MODE_ALARMS:
+ preference.setEnabled(false);
+ preference.setSummary(mBackend.getAlarmsTotalSilenceCallsMessagesSummary(
+ NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES));
+ break;
+ default:
+ preference.setEnabled(true);
+ preference.setSummary(mSummaryBuilder.getMessagesSettingSummary(getPolicy()));
+ }
}
}
diff --git a/tests/robotests/src/com/android/settings/accounts/CrossProfileCalendarDisabledPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/CrossProfileCalendarDisabledPreferenceControllerTest.java
new file mode 100644
index 0000000..2226e2c
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accounts/CrossProfileCalendarDisabledPreferenceControllerTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.accounts;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.DISABLED_FOR_USER;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.robolectric.RuntimeEnvironment.application;
+
+import android.app.admin.DevicePolicyManager;
+import android.content.ComponentName;
+import android.content.Context;
+import android.os.UserHandle;
+
+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;
+import org.robolectric.shadows.ShadowDevicePolicyManager;
+
+import java.util.Collections;
+
+@RunWith(RobolectricTestRunner.class)
+public class CrossProfileCalendarDisabledPreferenceControllerTest {
+
+ private static final String PREF_KEY = "cross_profile_calendar_disabled";
+ private static final int MANAGED_USER_ID = 10;
+ private static final String TEST_PACKAGE_NAME = "com.test";
+ private static final ComponentName TEST_COMPONENT_NAME = new ComponentName("test", "test");
+
+ @Mock
+ private UserHandle mManagedUser;
+
+ private Context mContext;
+ private CrossProfileCalendarDisabledPreferenceController mController;
+ private ShadowDevicePolicyManager mDpm;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ mController = new CrossProfileCalendarDisabledPreferenceController(mContext, PREF_KEY);
+ mController.setManagedUser(mManagedUser);
+ mDpm = Shadows.shadowOf(application.getSystemService(DevicePolicyManager.class));
+
+ when(mManagedUser.getIdentifier()).thenReturn(MANAGED_USER_ID);
+ doReturn(mContext).when(mContext).createPackageContextAsUser(
+ any(String.class), anyInt(), any(UserHandle.class));
+ }
+
+ @Test
+ public void getAvailabilityStatus_noPackageAllowed_shouldBeAvailable() {
+ mDpm.setProfileOwner(TEST_COMPONENT_NAME);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_somePackagesAllowed_shouldBeDisabledForUser() {
+ mDpm.setProfileOwner(TEST_COMPONENT_NAME);
+ mDpm.setCrossProfileCalendarPackages(TEST_COMPONENT_NAME,
+ Collections.singleton(TEST_PACKAGE_NAME));
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_FOR_USER);
+ }
+
+ @Test
+ public void getAvailabilityStatus_allPackagesAllowed_shouldBeDisabledForUser() {
+ mDpm.setProfileOwner(TEST_COMPONENT_NAME);
+ mDpm.setCrossProfileCalendarPackages(TEST_COMPONENT_NAME, null);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_FOR_USER);
+ }
+}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/accounts/CrossProfileCalendarPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/CrossProfileCalendarPreferenceControllerTest.java
index c6a48a8..2cbed97 100644
--- a/tests/robotests/src/com/android/settings/accounts/CrossProfileCalendarPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/CrossProfileCalendarPreferenceControllerTest.java
@@ -17,6 +17,9 @@
import static android.provider.Settings.Secure.CROSS_PROFILE_CALENDAR_ENABLED;
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.DISABLED_FOR_USER;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -117,30 +120,27 @@
}
@Test
- public void updateState_noPackageAllowed_preferenceShouldBeDisabled() throws Exception {
+ public void getAvailabilityStatus_noPackageAllowed_shouldBeDisabledForUser() throws Exception {
dpm.setProfileOwner(TEST_COMPONENT_NAME);
- mController.updateState(mPreference);
- verify(mPreference).setDisabledByAdmin(any());
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_FOR_USER);
}
@Test
- public void updateState_somePackagesAllowed_preferenceShouldNotBeDisabled() throws Exception {
+ public void getAvailabilityStatus_somePackagesAllowed_shouldBeAvailable() throws Exception {
dpm.setProfileOwner(TEST_COMPONENT_NAME);
dpm.setCrossProfileCalendarPackages(TEST_COMPONENT_NAME,
Collections.singleton(TEST_PACKAGE_NAME));
- mController.updateState(mPreference);
- verify(mPreference).setDisabledByAdmin(null);
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
- public void updateState_allPackagesAllowed_preferenceShouldNotBeDisabled() throws Exception {
+ public void getAvailabilityStatus_allPackagesAllowed_shouldBeAvailable() throws Exception {
dpm.setProfileOwner(TEST_COMPONENT_NAME);
dpm.setCrossProfileCalendarPackages(TEST_COMPONENT_NAME, null);
- mController.updateState(mPreference);
- verify(mPreference).setDisabledByAdmin(null);
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/HardwareRevisionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/HardwareRevisionPreferenceControllerTest.java
new file mode 100644
index 0000000..98ffbd0
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/HardwareRevisionPreferenceControllerTest.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2019 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.deviceinfo.hardwareinfo;
+
+import static android.content.Context.CLIPBOARD_SERVICE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.ClipboardManager;
+import android.content.Context;
+import android.os.SystemProperties;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class HardwareRevisionPreferenceControllerTest {
+
+ private Context mContext;
+ private HardwareRevisionPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mController = new HardwareRevisionPreferenceController(mContext,
+ "hardware_info_device_revision");
+ }
+
+ @Test
+ public void isSliceable_shouldBeSliceable() {
+ assertThat(mController.isSliceable()).isTrue();
+ }
+
+ @Test
+ public void isCopyableSlice_shouldBeCopyableSlice() {
+ assertThat(mController.isCopyableSlice()).isTrue();
+ }
+
+ @Test
+ public void copy_shouldCopyHardwareRevisionToClipboard() {
+ final String fakeHardwareVer = "FakeVer1.0";
+ SystemProperties.set("ro.boot.hardware.revision", fakeHardwareVer);
+
+ mController.copy();
+
+ final ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(
+ CLIPBOARD_SERVICE);
+ final CharSequence data = clipboard.getPrimaryClip().getItemAt(0).getText();
+
+ assertThat(data.toString()).isEqualTo(fakeHardwareVer);
+ }
+}
\ No newline at end of file