diff --git a/res/drawable/ic_partial_system_update_current.xml b/res/drawable/ic_partial_system_update_current.xml new file mode 100644 index 00000000000..18be2033c08 --- /dev/null +++ b/res/drawable/ic_partial_system_update_current.xml @@ -0,0 +1,24 @@ + + + + diff --git a/res/drawable/ic_partial_system_update_stale.xml b/res/drawable/ic_partial_system_update_stale.xml new file mode 100644 index 00000000000..711be2caed6 --- /dev/null +++ b/res/drawable/ic_partial_system_update_stale.xml @@ -0,0 +1,24 @@ + + + + diff --git a/res/layout/captioning_preview.xml b/res/layout/captioning_preview.xml index b90c3a5c296..d8d2e4fbc5d 100644 --- a/res/layout/captioning_preview.xml +++ b/res/layout/captioning_preview.xml @@ -15,41 +15,32 @@ limitations under the License. --> - + android:layout_height="wrap_content"> + + + android:layout_height="wrap_content" + android:layout_gravity="bottom|start" + android:padding="16dp"> - - - - - - + android:text="@string/captioning_preview_text"/> - - - - + diff --git a/res/layout/magnification_video_preference.xml b/res/layout/magnification_video_preference.xml index fe7f26fe2de..ff7089c8389 100644 --- a/res/layout/magnification_video_preference.xml +++ b/res/layout/magnification_video_preference.xml @@ -16,7 +16,9 @@ + android:layout_height="wrap_content" + android:clipChildren="true" + android:clipToPadding="true"> Face authentication How to set up Face unlock + + Set up Face unlock Use your face to authenticate @@ -4815,7 +4817,7 @@ Interaction controls - Downloaded services + Downloaded apps Experimental @@ -4921,7 +4923,7 @@ Touch feedback - Use service + Use %1$s Use color correction @@ -5147,7 +5149,7 @@ - View and platform actions + View and perform actions It can track your interactions @@ -10056,6 +10058,12 @@ Dark Theme + + On / Temporarily disabled due to Battery Saver + + + Temporarily turned on due to Battery Saver + Supported apps will also switch to dark theme diff --git a/res/xml/captioning_settings.xml b/res/xml/captioning_settings.xml index 312973854c9..56e0e2d3d76 100644 --- a/res/xml/captioning_settings.xml +++ b/res/xml/captioning_settings.xml @@ -21,6 +21,12 @@ android:key="captioning_preference_screen" android:title="@string/accessibility_captioning_title" > + + diff --git a/src/com/android/settings/accessibility/CaptionPropertiesFragment.java b/src/com/android/settings/accessibility/CaptionPropertiesFragment.java index ae7e3fdb4fb..bddca9cead7 100644 --- a/src/com/android/settings/accessibility/CaptionPropertiesFragment.java +++ b/src/com/android/settings/accessibility/CaptionPropertiesFragment.java @@ -22,13 +22,8 @@ import android.content.Context; import android.content.res.Resources; import android.graphics.Color; import android.os.Bundle; -import android.preference.PreferenceFrameLayout; import android.provider.Settings; -import android.view.LayoutInflater; import android.view.View; -import android.view.View.OnLayoutChangeListener; -import android.view.ViewGroup; -import android.view.ViewGroup.LayoutParams; import android.view.accessibility.CaptioningManager; import android.view.accessibility.CaptioningManager.CaptionStyle; @@ -46,6 +41,7 @@ import com.android.settings.widget.SwitchBar; import com.android.settings.widget.ToggleSwitch; import com.android.settings.widget.ToggleSwitch.OnBeforeCheckedChangeListener; import com.android.settingslib.accessibility.AccessibilityUtils; +import com.android.settingslib.widget.LayoutPreference; import java.util.Locale; @@ -54,6 +50,7 @@ import java.util.Locale; */ public class CaptionPropertiesFragment extends SettingsPreferenceFragment implements OnPreferenceChangeListener, OnValueChangedListener { + private static final String PREF_CAPTION_PREVIEW = "caption_preview"; private static final String PREF_BACKGROUND_COLOR = "captioning_background_color"; private static final String PREF_BACKGROUND_OPACITY = "captioning_background_opacity"; private static final String PREF_FOREGROUND_COLOR = "captioning_foreground_color"; @@ -115,43 +112,6 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment installUpdateListeners(); } - @Override - public View onCreateView( - LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final View rootView = inflater.inflate(R.layout.captioning_preview, container, false); - - // We have to do this now because PreferenceFrameLayout looks at it - // only when the view is added. - if (container instanceof PreferenceFrameLayout) { - ((PreferenceFrameLayout.LayoutParams) rootView.getLayoutParams()).removeBorders = true; - } - - final View content = super.onCreateView(inflater, container, savedInstanceState); - ((ViewGroup) rootView.findViewById(R.id.properties_fragment)).addView( - content, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); - - return rootView; - } - - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - final boolean enabled = mCaptioningManager.isEnabled(); - mPreviewText = (SubtitleView) view.findViewById(R.id.preview_text); - mPreviewText.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE); - - mPreviewWindow = view.findViewById(R.id.preview_window); - mPreviewViewport = view.findViewById(R.id.preview_viewport); - mPreviewViewport.addOnLayoutChangeListener(new OnLayoutChangeListener() { - @Override - public void onLayoutChange(View v, int left, int top, int right, int bottom, - int oldLeft, int oldTop, int oldRight, int oldBottom) { - refreshPreviewText(); - } - }); - } - @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); @@ -263,6 +223,19 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment } private void initializeAllPreferences() { + final LayoutPreference captionPreview = findPreference(PREF_CAPTION_PREVIEW); + + final boolean enabled = mCaptioningManager.isEnabled(); + mPreviewText = captionPreview.findViewById(R.id.preview_text); + mPreviewText.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE); + + mPreviewWindow = captionPreview.findViewById(R.id.preview_window); + + mPreviewViewport = captionPreview.findViewById(R.id.preview_viewport); + mPreviewViewport.addOnLayoutChangeListener( + (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) + -> refreshPreviewText()); + mLocale = (LocalePreference) findPreference(PREF_LOCALE); mFontSize = (ListPreference) findPreference(PREF_FONT_SIZE); @@ -370,9 +343,9 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment /** * Unpack the specified color value and update the preferences. * - * @param color color preference + * @param color color preference * @param opacity opacity preference - * @param value packed value + * @param value packed value */ private void parseColorOpacity(ColorPreference color, ColorPreference opacity, int value) { final int colorValue; diff --git a/src/com/android/settings/accessibility/ShortcutServicePickerFragment.java b/src/com/android/settings/accessibility/ShortcutServicePickerFragment.java index bb262833b42..dcf1f1cbf85 100644 --- a/src/com/android/settings/accessibility/ShortcutServicePickerFragment.java +++ b/src/com/android/settings/accessibility/ShortcutServicePickerFragment.java @@ -15,8 +15,6 @@ */ package com.android.settings.accessibility; -import static android.content.DialogInterface.BUTTON_POSITIVE; - import static com.android.internal.accessibility.AccessibilityShortcutController.COLOR_INVERSION_COMPONENT_NAME; import static com.android.internal.accessibility.AccessibilityShortcutController.DALTONIZER_COMPONENT_NAME; @@ -25,7 +23,6 @@ import android.app.Dialog; import android.app.settings.SettingsEnums; import android.content.ComponentName; import android.content.Context; -import android.content.DialogInterface; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; @@ -191,6 +188,7 @@ public class ShortcutServicePickerFragment extends RadioButtonPickerFragment { ((ShortcutServicePickerFragment) fragment).onServiceConfirmed( bundle.getString(EXTRA_KEY)); } + dismiss(); } } diff --git a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java index b28d8b5e541..4fe65073a86 100644 --- a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java @@ -85,6 +85,16 @@ public class ToggleAccessibilityServicePreferenceFragment mLockPatternUtils = new LockPatternUtils(getActivity()); } + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + mSwitchBar.setLabelDelegate((boolean isChecked) -> { + final AccessibilityServiceInfo info = getAccessibilityServiceInfo(); + return getString(R.string.accessibility_service_master_switch_title, + info.getResolveInfo().loadLabel(getPackageManager())); + }); + } + @Override public void onResume() { mSettingsContentObserver.register(getContentResolver()); @@ -120,7 +130,7 @@ public class ToggleAccessibilityServicePreferenceFragment return serviceInfo; } } - return null; + throw new IllegalStateException("ServiceInfo is not found."); } @Override @@ -128,18 +138,12 @@ public class ToggleAccessibilityServicePreferenceFragment switch (dialogId) { case DIALOG_ID_ENABLE_WARNING: { final AccessibilityServiceInfo info = getAccessibilityServiceInfo(); - if (info == null) { - return null; - } mDialog = AccessibilityServiceWarning .createCapabilitiesDialog(getActivity(), info, this); break; } case DIALOG_ID_DISABLE_WARNING: { AccessibilityServiceInfo info = getAccessibilityServiceInfo(); - if (info == null) { - return null; - } mDialog = AccessibilityServiceWarning .createDisableDialog(getActivity(), info, this); break; diff --git a/src/com/android/settings/biometrics/face/FaceEnrollEducation.java b/src/com/android/settings/biometrics/face/FaceEnrollEducation.java index fae17852325..956ba49d6be 100644 --- a/src/com/android/settings/biometrics/face/FaceEnrollEducation.java +++ b/src/com/android/settings/biometrics/face/FaceEnrollEducation.java @@ -33,6 +33,7 @@ import android.view.View; import android.view.accessibility.AccessibilityManager; import android.widget.Button; import android.widget.CompoundButton; +import android.widget.TextView; import com.android.settings.R; import com.android.settings.Utils; @@ -59,19 +60,28 @@ public class FaceEnrollEducation extends BiometricEnrollBase { private View mIllustrationAccessibility; private Handler mHandler; private Intent mResultIntent; + private TextView mDescriptionText; private CompoundButton.OnCheckedChangeListener mSwitchDiversityListener = new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + int titleRes = isChecked ? + R.string.security_settings_face_enroll_education_title_accessibility + : R.string.security_settings_face_enroll_education_title; + getLayout().setHeaderText(titleRes); + setTitle(titleRes); + if (isChecked) { mIllustrationNormal.stop(); mIllustrationNormal.setVisibility(View.INVISIBLE); mIllustrationAccessibility.setVisibility(View.VISIBLE); + mDescriptionText.setVisibility(View.INVISIBLE); } else { mIllustrationNormal.setVisibility(View.VISIBLE); mIllustrationNormal.start(); mIllustrationAccessibility.setVisibility(View.INVISIBLE); + mDescriptionText.setVisibility(View.VISIBLE); } } }; @@ -88,6 +98,7 @@ public class FaceEnrollEducation extends BiometricEnrollBase { mIllustrationNormal = findViewById(R.id.illustration_normal); mIllustrationAccessibility = findViewById(R.id.illustration_accessibility); + mDescriptionText = findViewById(R.id.sud_layout_description); mFooterBarMixin = getLayout().getMixin(FooterBarMixin.class); mFooterBarMixin.setSecondaryButton( diff --git a/src/com/android/settings/biometrics/face/FaceSettingsRemoveButtonPreferenceController.java b/src/com/android/settings/biometrics/face/FaceSettingsRemoveButtonPreferenceController.java index 990e68d2d36..d532a7636f4 100644 --- a/src/com/android/settings/biometrics/face/FaceSettingsRemoveButtonPreferenceController.java +++ b/src/com/android/settings/biometrics/face/FaceSettingsRemoveButtonPreferenceController.java @@ -94,6 +94,7 @@ public class FaceSettingsRemoveButtonPreferenceController extends BasePreference Log.e(TAG, "Unable to remove face: " + face.getBiometricId() + " error: " + errMsgId + " " + errString); Toast.makeText(mContext, errString, Toast.LENGTH_SHORT).show(); + mRemoving = false; } @Override @@ -131,6 +132,7 @@ public class FaceSettingsRemoveButtonPreferenceController extends BasePreference mFaceManager.remove(faces.get(0), mUserId, mRemovalCallback); } else { mButton.setEnabled(true); + mRemoving = false; } } }; diff --git a/src/com/android/settings/display/DarkUIPreferenceController.java b/src/com/android/settings/display/DarkUIPreferenceController.java index 9df2402850e..d3d30b50221 100644 --- a/src/com/android/settings/display/DarkUIPreferenceController.java +++ b/src/com/android/settings/display/DarkUIPreferenceController.java @@ -17,27 +17,53 @@ package com.android.settings.display; import android.app.UiModeManager; +import android.content.BroadcastReceiver; import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.os.PowerManager; import android.provider.Settings; import androidx.annotation.VisibleForTesting; import androidx.fragment.app.Fragment; +import androidx.preference.Preference; +import androidx.preference.PreferenceScreen; +import androidx.preference.SwitchPreference; +import com.android.settings.R; import com.android.settings.core.TogglePreferenceController; +import com.android.settingslib.core.lifecycle.LifecycleObserver; +import com.android.settingslib.core.lifecycle.events.OnStart; +import com.android.settingslib.core.lifecycle.events.OnStop; -public class DarkUIPreferenceController extends TogglePreferenceController { +public class DarkUIPreferenceController extends TogglePreferenceController implements + LifecycleObserver, OnStart, OnStop { public static final String DARK_MODE_PREFS = "dark_mode_prefs"; public static final String PREF_DARK_MODE_DIALOG_SEEN = "dark_mode_dialog_seen"; public static final int DIALOG_SEEN = 1; + + @VisibleForTesting + SwitchPreference mPreference; + private UiModeManager mUiModeManager; + private PowerManager mPowerManager; private Context mContext; + private Fragment mFragment; + private BroadcastReceiver mReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + updateEnabledStateIfNeeded(); + } + }; + public DarkUIPreferenceController(Context context, String key) { super(context, key); mContext = context; mUiModeManager = context.getSystemService(UiModeManager.class); + mPowerManager = context.getSystemService(PowerManager.class); } @Override @@ -45,6 +71,18 @@ public class DarkUIPreferenceController extends TogglePreferenceController { return mUiModeManager.getNightMode() == UiModeManager.MODE_NIGHT_YES; } + @Override + public void displayPreference(PreferenceScreen screen) { + super.displayPreference(screen); + mPreference = screen.findPreference(getPreferenceKey()); + } + + @Override + public void updateState(Preference preference) { + super.updateState(preference); + updateEnabledStateIfNeeded(); + } + @Override public boolean setChecked(boolean isChecked) { final boolean dialogSeen = @@ -67,6 +105,29 @@ public class DarkUIPreferenceController extends TogglePreferenceController { } } + @VisibleForTesting + void updateEnabledStateIfNeeded() { + if (mPreference == null) { + return; + } + boolean isBatterySaver = isPowerSaveMode(); + mPreference.setEnabled(!isBatterySaver); + if (isBatterySaver) { + int stringId = mUiModeManager.getNightMode() == UiModeManager.MODE_NIGHT_YES + ? R.string.dark_ui_mode_disabled_summary_dark_theme_on + : R.string.dark_ui_mode_disabled_summary_dark_theme_off; + mPreference.setSummary(mContext.getString(stringId)); + } else { + mPreference.setSummary(null); + } + } + + @VisibleForTesting + boolean isPowerSaveMode() { + return mPowerManager.isPowerSaveMode(); + } + + @VisibleForTesting void setUiModeManager(UiModeManager uiModeManager) { mUiModeManager = uiModeManager; @@ -76,6 +137,17 @@ public class DarkUIPreferenceController extends TogglePreferenceController { mFragment = fragment; } + @Override + public void onStart() { + mContext.registerReceiver(mReceiver, + new IntentFilter(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED)); + } + + @Override + public void onStop() { + mContext.unregisterReceiver(mReceiver); + } + @Override public int getAvailabilityStatus() { return AVAILABLE; diff --git a/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java b/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java index 1fe7e7d1d8a..d5e17233a72 100644 --- a/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java +++ b/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java @@ -79,7 +79,6 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC private final PackageManager mPm; private final NotificationBackend mNotificationBackend; private IUsageStatsManager mUsageStatsManager; - private final int mUserId; private final IconDrawableFactory mIconDrawableFactory; private Calendar mCal; @@ -104,7 +103,6 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC ApplicationsState appState, Fragment host) { super(context); mIconDrawableFactory = IconDrawableFactory.newInstance(context); - mUserId = UserHandle.myUserId(); mPm = context.getPackageManager(); mHost = host; mApplicationsState = appState; @@ -177,7 +175,6 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC e.printStackTrace(); } if (events != null) { - ArrayMap aggregatedStats = new ArrayMap<>(); UsageEvents.Event event = new UsageEvents.Event(); @@ -205,7 +202,8 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC } } - private static String getKey(int userId, String pkg) { + @VisibleForTesting + static String getKey(int userId, String pkg) { return userId + "|" + pkg; } @@ -252,12 +250,13 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC } boolean rebindPref = true; - NotificationAppPreference pref = appPreferences.remove(pkgName); + NotificationAppPreference pref = appPreferences.remove(getKey(app.getUserId(), + pkgName)); if (pref == null) { pref = new NotificationAppPreference(prefContext); rebindPref = false; } - pref.setKey(pkgName); + pref.setKey(getKey(app.getUserId(), pkgName)); pref.setTitle(appEntry.label); pref.setIcon(mIconDrawableFactory.getBadgedIcon(appEntry.info)); pref.setIconSize(TwoTargetPreference.ICON_SIZE_SMALL); @@ -267,11 +266,11 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC Bundle args = new Bundle(); args.putString(AppInfoBase.ARG_PACKAGE_NAME, pkgName); args.putInt(AppInfoBase.ARG_PACKAGE_UID, appEntry.info.uid); - pref.setIntent(new SubSettingLauncher(mHost.getActivity()) .setDestination(AppNotificationSettings.class.getName()) .setTitleRes(R.string.notifications_title) .setArguments(args) + .setUserHandle(new UserHandle(UserHandle.getUserId(appEntry.info.uid))) .setSourceMetricsCategory( SettingsEnums.MANAGE_APPLICATIONS_NOTIFICATIONS) .toIntent()); @@ -301,11 +300,11 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC int count = 0; for (NotifyingApp app : mApps) { final ApplicationsState.AppEntry appEntry = mApplicationsState.getEntry( - app.getPackage(), mUserId); + app.getPackage(), app.getUserId()); if (appEntry == null) { continue; } - if (!shouldIncludePkgInRecents(app.getPackage())) { + if (!shouldIncludePkgInRecents(app.getPackage(), app.getUserId())) { continue; } displayableApps.add(app); @@ -321,14 +320,14 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC /** * Whether or not the app should be included in recent list. */ - private boolean shouldIncludePkgInRecents(String pkgName) { + private boolean shouldIncludePkgInRecents(String pkgName, int userId) { final Intent launchIntent = new Intent().addCategory(Intent.CATEGORY_LAUNCHER) .setPackage(pkgName); if (mPm.resolveActivity(launchIntent, 0) == null) { // Not visible on launcher -> likely not a user visible app, skip if non-instant. final ApplicationsState.AppEntry appEntry = - mApplicationsState.getEntry(pkgName, mUserId); + mApplicationsState.getEntry(pkgName, userId); if (appEntry == null || appEntry.info == null || !AppUtils.isInstant(appEntry.info)) { Log.d(TAG, "Not a user visible or instant app, skipping " + pkgName); return false; diff --git a/src/com/android/settings/widget/SwitchBar.java b/src/com/android/settings/widget/SwitchBar.java index f8743d1fa47..33413040e82 100644 --- a/src/com/android/settings/widget/SwitchBar.java +++ b/src/com/android/settings/widget/SwitchBar.java @@ -61,6 +61,16 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC void onSwitchChanged(Switch switchView, boolean isChecked); } + public interface LabelDelegate { + /** + * Called to create label and set the title with Accessibility + * service name to the textView of switchBar. + * + * @param isChecked The checked state of switchView. + */ + String createLabel(boolean isChecked); + } + private static final int[] XML_ATTRIBUTES = { R.attr.switchBarMarginStart, R.attr.switchBarMarginEnd, @@ -90,6 +100,7 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC private boolean mDisabledByAdmin; private EnforcedAdmin mEnforcedAdmin = null; private String mMetricsTag; + private LabelDelegate mLabelDelegate; public SwitchBar(Context context) { @@ -178,7 +189,11 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC } public void setTextViewLabelAndBackground(boolean isChecked) { - mLabel = getResources().getString(isChecked ? mOnTextId : mOffTextId); + if(mLabelDelegate != null) { + mLabel = mLabelDelegate.createLabel(isChecked); + } else { + mLabel = getResources().getString(isChecked ? mOnTextId : mOffTextId); + } setBackgroundColor(isChecked ? mBackgroundActivatedColor : mBackgroundColor); updateText(); } @@ -383,4 +398,9 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC requestLayout(); } + + public void setLabelDelegate(LabelDelegate labelDelegate) { + mLabelDelegate = labelDelegate; + setTextViewLabelAndBackground(isChecked()); + } } diff --git a/src/com/android/settings/widget/UsageGraph.java b/src/com/android/settings/widget/UsageGraph.java index 7cef66f79d2..505dc58b2cb 100644 --- a/src/com/android/settings/widget/UsageGraph.java +++ b/src/com/android/settings/widget/UsageGraph.java @@ -288,7 +288,11 @@ public class UsageGraph extends View { canvas.drawPath(mPath, paint); } - private void drawFilledPath(Canvas canvas, SparseIntArray localPaths, Paint paint) { + @VisibleForTesting + void drawFilledPath(Canvas canvas, SparseIntArray localPaths, Paint paint) { + if (localPaths.size() == 0) { + return; + } mPath.reset(); float lastStartX = localPaths.keyAt(0); mPath.moveTo(localPaths.keyAt(0), localPaths.valueAt(0)); diff --git a/tests/robotests/src/com/android/settings/display/DarkUIPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/DarkUIPreferenceControllerTest.java new file mode 100644 index 00000000000..3659803cc80 --- /dev/null +++ b/tests/robotests/src/com/android/settings/display/DarkUIPreferenceControllerTest.java @@ -0,0 +1,78 @@ +/* + * 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.display; + +import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import android.content.Context; +import android.os.Handler; +import android.os.IPowerManager; +import android.os.PowerManager; + +import androidx.fragment.app.Fragment; +import androidx.preference.PreferenceScreen; +import androidx.preference.SwitchPreference; + +import org.junit.Assert; +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; + +@RunWith(RobolectricTestRunner.class) +public class DarkUIPreferenceControllerTest { + + private DarkUIPreferenceController mController; + private Context mContext; + @Mock + private Fragment mFragment; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + mContext = spy(RuntimeEnvironment.application); + mController = spy(new DarkUIPreferenceController(mContext, "dark_ui_mode")); + mController.setParentFragment(mFragment); + mController.mPreference = new SwitchPreference(mContext); + mController.onStart(); + } + + @Test + public void batterySaverToggles_disabledStateUpdates() { + doReturn(true).when(mController).isPowerSaveMode(); + mController.updateEnabledStateIfNeeded(); + assertThat(mController.mPreference.isEnabled()).isFalse(); + + doReturn(false).when(mController).isPowerSaveMode(); + mController.updateEnabledStateIfNeeded(); + assertThat(mController.mPreference.isEnabled()).isTrue(); + + doReturn(true).when(mController).isPowerSaveMode(); + mController.updateEnabledStateIfNeeded(); + assertThat(mController.mPreference.isEnabled()).isFalse(); + } +} diff --git a/tests/robotests/src/com/android/settings/notification/RecentNotifyingAppsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/RecentNotifyingAppsPreferenceControllerTest.java index d47d1257816..93bd8dca7bc 100644 --- a/tests/robotests/src/com/android/settings/notification/RecentNotifyingAppsPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/RecentNotifyingAppsPreferenceControllerTest.java @@ -168,7 +168,6 @@ public class RecentNotifyingAppsPreferenceControllerTest { @Test public void display_showRecents() throws Exception { - List events = new ArrayList<>(); Event app = new Event(); app.mEventType = Event.NOTIFICATION_INTERRUPTION; @@ -262,8 +261,12 @@ public class RecentNotifyingAppsPreferenceControllerTest { ArgumentCaptor prefCaptor = ArgumentCaptor.forClass(Preference.class); verify(mCategory, times(2)).addPreference(prefCaptor.capture()); List prefs = prefCaptor.getAllValues(); - assertThat(prefs.get(1).getKey()).isEqualTo(app.getPackageName()); - assertThat(prefs.get(0).getKey()).isEqualTo(app1.getPackageName()); + assertThat(prefs.get(1).getKey()).isEqualTo( + RecentNotifyingAppsPreferenceController.getKey(UserHandle.myUserId(), + app.getPackageName())); + assertThat(prefs.get(0).getKey()).isEqualTo( + RecentNotifyingAppsPreferenceController.getKey(UserHandle.myUserId(), + app1.getPackageName())); } @Test diff --git a/tests/robotests/src/com/android/settings/widget/UsageGraphTest.java b/tests/robotests/src/com/android/settings/widget/UsageGraphTest.java index 7f09c3b88fb..ebb496c319a 100644 --- a/tests/robotests/src/com/android/settings/widget/UsageGraphTest.java +++ b/tests/robotests/src/com/android/settings/widget/UsageGraphTest.java @@ -24,6 +24,8 @@ import static org.mockito.Mockito.when; import android.content.Context; import android.content.res.Resources; +import android.graphics.Canvas; +import android.graphics.Paint; import android.util.SparseIntArray; import com.android.settingslib.R; @@ -177,4 +179,14 @@ public class UsageGraphTest { assertThat(localPaths.keyAt(5)).isEqualTo(1001); assertThat(localPaths.valueAt(5)).isEqualTo(-1); } + + @Test + public void drawFilledPath_emptyPath_shouldNotCrash() { + final Canvas canvas = new Canvas(); + final SparseIntArray localPaths = new SparseIntArray(); + final Paint paint = new Paint(); + + // Should not crash + mGraph.drawFilledPath(canvas, localPaths, paint); + } }