Merge "Update bad calibration error message" into udc-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index ff4096f..5904282 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -3717,7 +3717,7 @@
<!-- Show channel-level notification settings (channel passed in as extras) -->
<activity android:name=".notification.app.ChannelPanelActivity"
android:label="@string/notification_channel_title"
- android:theme="@style/Theme.Panel.Material"
+ android:theme="@style/Theme.Panel"
android:excludeFromRecents="true"
android:configChanges="keyboardHidden|screenSize"
android:exported="true">
diff --git a/res/drawable/button_border_selected.xml b/res/drawable/button_border_selected.xml
index 1402380..0cd4aa5 100644
--- a/res/drawable/button_border_selected.xml
+++ b/res/drawable/button_border_selected.xml
@@ -15,7 +15,10 @@
limitations under the License.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
android:shape="rectangle">
+ <solid
+ android:color="?androidprv:attr/materialColorSurfaceContainer" />
<stroke
android:width="2dp"
android:color="?android:attr/colorAccent"/>
diff --git a/res/drawable/button_border_unselected.xml b/res/drawable/button_border_unselected.xml
index d0ce75b..2c2ef3d 100644
--- a/res/drawable/button_border_unselected.xml
+++ b/res/drawable/button_border_unselected.xml
@@ -18,7 +18,7 @@
android:shape="rectangle">
<stroke
android:width="1dp"
- android:color="?android:attr/colorAccent"/>
+ android:color="@color/notification_importance_button_unselected"/>
<corners android:radius="@dimen/rect_button_radius" />
</shape>
diff --git a/res/values/themes.xml b/res/values/themes.xml
index 8f13279..eeba1c7 100644
--- a/res/values/themes.xml
+++ b/res/values/themes.xml
@@ -227,9 +227,6 @@
<item name="android:fontFamily">@*android:string/config_headlineFontFamilyMedium</item>
</style>
- <style name="Theme.Panel.Material" parent="Theme.Panel" >
- <item name="android:switchStyle">@style/Switch.SettingsLib</item>
- </style>
<!-- Material theme for the pages containing TabLayout and ViewPager -->
<style name="Theme.TabTheme" parent="@style/Theme.MaterialComponents.DayNight">
<item name="colorPrimary">@*android:color/edge_effect_device_default_light</item>
diff --git a/src/com/android/settings/print/PrintSettingsFragment.java b/src/com/android/settings/print/PrintSettingsFragment.java
index ed21b6f..cd80998 100644
--- a/src/com/android/settings/print/PrintSettingsFragment.java
+++ b/src/com/android/settings/print/PrintSettingsFragment.java
@@ -28,6 +28,7 @@
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
+import android.os.UserManager;
import android.print.PrintJob;
import android.print.PrintJobId;
import android.print.PrintJobInfo;
@@ -45,6 +46,7 @@
import android.widget.Button;
import android.widget.TextView;
+import androidx.annotation.VisibleForTesting;
import androidx.loader.app.LoaderManager.LoaderCallbacks;
import androidx.loader.content.AsyncTaskLoader;
import androidx.loader.content.Loader;
@@ -92,6 +94,22 @@
private PrintServicesController mPrintServicesController;
private Button mAddNewServiceButton;
+ @VisibleForTesting
+ boolean mIsUiRestricted;
+
+ public PrintSettingsFragment() {
+ super(UserManager.DISALLOW_PRINTING);
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.print_settings;
+ }
@Override
public int getMetricsCategory() {
@@ -107,12 +125,19 @@
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View root = super.onCreateView(inflater, container, savedInstanceState);
- addPreferencesFromResource(R.xml.print_settings);
+ mIsUiRestricted = isUiRestricted();
+ setupPreferences();
+ return root;
+ }
- mActivePrintJobsCategory = (PreferenceCategory) findPreference(
- PRINT_JOBS_CATEGORY);
- mPrintServicesCategory = (PreferenceCategory) findPreference(
- PRINT_SERVICES_CATEGORY);
+ @VisibleForTesting
+ void setupPreferences() {
+ if (mIsUiRestricted) {
+ return;
+ }
+
+ mActivePrintJobsCategory = (PreferenceCategory) findPreference(PRINT_JOBS_CATEGORY);
+ mPrintServicesCategory = (PreferenceCategory) findPreference(PRINT_SERVICES_CATEGORY);
getPreferenceScreen().removePreference(mActivePrintJobsCategory);
mPrintJobsController = new PrintJobsController();
@@ -120,20 +145,20 @@
mPrintServicesController = new PrintServicesController();
getLoaderManager().initLoader(LOADER_ID_PRINT_SERVICES, null, mPrintServicesController);
-
- return root;
- }
-
- @Override
- public void onStart() {
- super.onStart();
- setHasOptionsMenu(true);
- startSubSettingsIfNeeded();
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
+ setupEmptyViews();
+ }
+
+ @VisibleForTesting
+ void setupEmptyViews() {
+ if (mIsUiRestricted) {
+ return;
+ }
+
ViewGroup contentRoot = (ViewGroup) getListView().getParent();
View emptyView = getActivity().getLayoutInflater().inflate(
R.layout.empty_print_state, contentRoot, false);
@@ -153,6 +178,23 @@
}
@Override
+ public void onStart() {
+ super.onStart();
+ startSettings();
+ }
+
+ @VisibleForTesting
+ void startSettings() {
+ if (mIsUiRestricted) {
+ getPreferenceScreen().removeAll();
+ return;
+ }
+
+ setHasOptionsMenu(true);
+ startSubSettingsIfNeeded();
+ }
+
+ @Override
protected String getIntentActionString() {
return Settings.ACTION_PRINT_SETTINGS;
}
diff --git a/src/com/android/settings/print/ProfileSettingsPreferenceFragment.java b/src/com/android/settings/print/ProfileSettingsPreferenceFragment.java
index e41e1da..63b83f1 100644
--- a/src/com/android/settings/print/ProfileSettingsPreferenceFragment.java
+++ b/src/com/android/settings/print/ProfileSettingsPreferenceFragment.java
@@ -27,13 +27,17 @@
import android.widget.Spinner;
import com.android.settings.R;
-import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.dashboard.RestrictedDashboardFragment;
import com.android.settings.dashboard.profileselector.UserAdapter;
/**
* Base fragment class for per profile settings.
*/
-public abstract class ProfileSettingsPreferenceFragment extends SettingsPreferenceFragment {
+public abstract class ProfileSettingsPreferenceFragment extends RestrictedDashboardFragment {
+
+ public ProfileSettingsPreferenceFragment(String restrictionKey) {
+ super(restrictionKey);
+ }
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
diff --git a/tests/unit/src/com/android/settings/print/PrintSettingsFragmentTest.java b/tests/unit/src/com/android/settings/print/PrintSettingsFragmentTest.java
new file mode 100644
index 0000000..c52c5bc
--- /dev/null
+++ b/tests/unit/src/com/android/settings/print/PrintSettingsFragmentTest.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2023 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.print;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+import android.content.Context;
+import android.os.Looper;
+import android.view.View;
+
+import androidx.preference.PreferenceManager;
+import androidx.preference.PreferenceScreen;
+import androidx.test.core.app.ApplicationProvider;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.platform.app.InstrumentationRegistry;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
+
+@RunWith(AndroidJUnit4.class)
+public class PrintSettingsFragmentTest {
+ @Rule
+ public final MockitoRule mMockitoRule = MockitoJUnit.rule();
+ @Spy
+ private final Context mContext = ApplicationProvider.getApplicationContext();
+
+ private PrintSettingsFragment mFragment;
+ private PreferenceManager mPreferenceManager;
+ private PreferenceScreen mPreferenceScreen;
+
+ @Before
+ public void setUp() {
+ if (Looper.myLooper() == null) {
+ Looper.prepare();
+ }
+ mPreferenceManager = new PreferenceManager(mContext);
+ mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext);
+
+ InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
+ mFragment = spy(new PrintSettingsFragment());
+ doReturn(mPreferenceScreen).when(mFragment).getPreferenceScreen();
+ });
+ }
+
+ @Test
+ public void setupPreferences_uiIsRestricted_doNotAddPreferences() {
+ mFragment.mIsUiRestricted = true;
+
+ mFragment.setupPreferences();
+
+ verify(mFragment, never()).findPreference(any(CharSequence.class));
+ }
+
+ @Test
+ public void setupEmptyViews_uiIsRestricted_doNotSetEmptyView() {
+ mFragment.mIsUiRestricted = true;
+
+ mFragment.setupEmptyViews();
+
+ verify(mFragment, never()).setEmptyView(any(View.class));
+ }
+
+ @Test
+ public void startSettings_uiIsRestricted_removeAllPreferences() {
+ mFragment.mIsUiRestricted = true;
+
+ mFragment.startSettings();
+
+ assertThat(mPreferenceScreen.getPreferenceCount()).isEqualTo(0);
+ verify(mFragment, never()).setHasOptionsMenu(true);
+ }
+}