• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

packages/apps/Settings


Commit MetaInfo

Revisiónd306e2419d5d5ce3498a6ba98d258d69eaf81e2f (tree)
Tiempo2020-11-19 21:40:57
AutorYi-yo Chiang <yochiang@goog...>
Commiterandroid-build-team Robot

Log Message

Revert "Update the summary of AoD when Bedtime mode is on"

Revert "Update the summary of Idle lock screen when Bedtime mode..."

Revert submission 13071396-cherrypick-cherrypick-bedtime-hpxwlbiuim-0q85x8kaar

Reason for revert: Broken test b/173663404

Reverted Changes:
Id2511cb0a:Update the summary of AoD when Bedtime mode is on
I041599b9c:Update the summary of Idle lock screen when Bedtim...

Bug: 173663404
Change-Id: I9bea7499393d3ab1733b82140942499dddd9a2aa
Merged-In: I3b7053ad752f548f421dcca10cc1203500b1220b
(cherry picked from commit cd4a35de8ef11074e89c978f840babe652d094b6)

Cambiar Resumen

Diferencia incremental

--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -104,9 +104,7 @@
104104 <uses-permission android:name="android.permission.INSTALL_DYNAMIC_SYSTEM" />
105105 <uses-permission android:name="android.permission.BIND_CELL_BROADCAST_SERVICE" />
106106 <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
107- <uses-permission android:name="android.permission.READ_DREAM_STATE" />
108- <uses-permission android:name="android.permission.READ_DREAM_SUPPRESSION" />
109-
107+
110108 <application android:label="@string/settings_label"
111109 android:icon="@drawable/ic_launcher_settings"
112110 android:theme="@style/Theme.Settings"
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -12187,7 +12187,4 @@
1218712187
1218812188 <!-- Summary for see all preference when bluetooth is disable [CHAR LIMIT=none]-->
1218912189 <string name="connected_device_see_all_summary">Bluetooth will turn on</string>
12190-
12191- <!-- Summary for preference when Bedtime mode is on [CHAR LIMIT=NONE] -->
12192- <string name="aware_summary_when_bedtime_on">Unavailable because bedtime mode is on</string>
1219312190 </resources>
--- a/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceController.java
+++ b/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceController.java
@@ -16,17 +16,12 @@
1616 package com.android.settings.display;
1717
1818 import android.content.Context;
19-import android.content.pm.PackageManager;
2019 import android.hardware.display.AmbientDisplayConfiguration;
21-import android.os.PowerManager;
2220 import android.os.SystemProperties;
2321 import android.os.UserHandle;
2422 import android.provider.Settings;
2523 import android.text.TextUtils;
2624
27-import androidx.preference.Preference;
28-
29-import com.android.settings.R;
3025 import com.android.settings.core.TogglePreferenceController;
3126
3227 public class AmbientDisplayAlwaysOnPreferenceController extends TogglePreferenceController {
@@ -36,9 +31,13 @@ public class AmbientDisplayAlwaysOnPreferenceController extends TogglePreference
3631
3732 private static final int MY_USER = UserHandle.myUserId();
3833 private static final String PROP_AWARE_AVAILABLE = "ro.vendor.aware_available";
39- private static final String AOD_SUPPRESSED_TOKEN = "winddown";
4034
4135 private AmbientDisplayConfiguration mConfig;
36+ private OnPreferenceChangedCallback mCallback;
37+
38+ public interface OnPreferenceChangedCallback {
39+ void onPreferenceChanged();
40+ }
4241
4342 public AmbientDisplayAlwaysOnPreferenceController(Context context, String key) {
4443 super(context, key);
@@ -52,12 +51,6 @@ public class AmbientDisplayAlwaysOnPreferenceController extends TogglePreference
5251 }
5352
5453 @Override
55- public void updateState(Preference preference) {
56- super.updateState(preference);
57- refreshSummary(preference);
58- }
59-
60- @Override
6154 public boolean isSliceable() {
6255 return TextUtils.equals(getPreferenceKey(), "ambient_display_always_on");
6356 }
@@ -77,22 +70,24 @@ public class AmbientDisplayAlwaysOnPreferenceController extends TogglePreference
7770 int enabled = isChecked ? ON : OFF;
7871 Settings.Secure.putInt(
7972 mContext.getContentResolver(), Settings.Secure.DOZE_ALWAYS_ON, enabled);
73+ if (mCallback != null) {
74+ mCallback.onPreferenceChanged();
75+ }
8076 return true;
8177 }
8278
83- @Override
84- public CharSequence getSummary() {
85- return mContext.getText(
86- isAodSuppressedByBedtime(mContext) ? R.string.aware_summary_when_bedtime_on
87- : R.string.doze_always_on_summary);
88- }
89-
9079 public AmbientDisplayAlwaysOnPreferenceController setConfig(
9180 AmbientDisplayConfiguration config) {
9281 mConfig = config;
9382 return this;
9483 }
9584
85+ public AmbientDisplayAlwaysOnPreferenceController setCallback(
86+ OnPreferenceChangedCallback callback) {
87+ mCallback = callback;
88+ return this;
89+ }
90+
9691 public static boolean isAvailable(AmbientDisplayConfiguration config) {
9792 return config.alwaysOnAvailableForUser(MY_USER);
9893 }
@@ -103,25 +98,4 @@ public class AmbientDisplayAlwaysOnPreferenceController extends TogglePreference
10398 }
10499 return mConfig;
105100 }
106-
107- /**
108- * Returns whether AOD is suppressed by Bedtime mode, a feature of Digital Wellbeing.
109- *
110- * We know that Bedtime mode suppresses AOD using {@link AOD_SUPPRESSED_TOKEN}. If the Digital
111- * Wellbeing app is suppressing AOD with {@link AOD_SUPPRESSED_TOKEN}, then we can infer that
112- * AOD is being suppressed by Bedtime mode.
113- */
114- public static boolean isAodSuppressedByBedtime(Context context) {
115- int uid;
116- final PowerManager powerManager = context.getSystemService(PowerManager.class);
117- final PackageManager packageManager = context.getPackageManager();
118- final String packageName = context.getString(
119- com.android.internal.R.string.config_defaultWellbeingPackage);
120- try {
121- uid = packageManager.getApplicationInfo(packageName, /* flags= */ 0).uid;
122- } catch (PackageManager.NameNotFoundException e) {
123- return false;
124- }
125- return powerManager.isAmbientDisplaySuppressedForTokenByApp(AOD_SUPPRESSED_TOKEN, uid);
126- }
127101 }
--- a/src/com/android/settings/security/LockscreenDashboardFragment.java
+++ b/src/com/android/settings/security/LockscreenDashboardFragment.java
@@ -88,7 +88,9 @@ public class LockscreenDashboardFragment extends DashboardFragment
8888 @Override
8989 public void onAttach(Context context) {
9090 super.onAttach(context);
91- use(AmbientDisplayAlwaysOnPreferenceController.class).setConfig(getConfig(context));
91+ use(AmbientDisplayAlwaysOnPreferenceController.class)
92+ .setConfig(getConfig(context))
93+ .setCallback(this::updatePreferenceStates);
9294 use(AmbientDisplayNotificationsPreferenceController.class).setConfig(getConfig(context));
9395 use(DoubleTapScreenPreferenceController.class).setConfig(getConfig(context));
9496 use(PickupGesturePreferenceController.class).setConfig(getConfig(context));
--- a/tests/robotests/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/AmbientDisplayAlwaysOnPreferenceControllerTest.java
@@ -19,20 +19,13 @@ package com.android.settings.display;
1919 import static com.google.common.truth.Truth.assertThat;
2020
2121 import static org.mockito.ArgumentMatchers.anyInt;
22-import static org.mockito.ArgumentMatchers.anyString;
23-import static org.mockito.Mockito.doReturn;
24-import static org.mockito.Mockito.spy;
2522 import static org.mockito.Mockito.when;
2623
2724 import android.content.ContentResolver;
2825 import android.content.Context;
29-import android.content.pm.ApplicationInfo;
30-import android.content.pm.PackageManager;
3126 import android.hardware.display.AmbientDisplayConfiguration;
32-import android.os.PowerManager;
3327 import android.provider.Settings;
3428
35-import com.android.internal.R;
3629 import com.android.settings.testutils.shadow.ShadowSecureSettings;
3730
3831 import org.junit.Before;
@@ -48,41 +41,24 @@ import org.robolectric.annotation.Config;
4841 @Config(shadows = ShadowSecureSettings.class)
4942 public class AmbientDisplayAlwaysOnPreferenceControllerTest {
5043
51- private static final String TEST_PACKAGE = "com.android.test";
52-
5344 @Mock
5445 private AmbientDisplayConfiguration mConfig;
55- @Mock
56- private PackageManager mPackageManager;
57- @Mock
58- private PowerManager mPowerManager;
59- @Mock
60- private ApplicationInfo mApplicationInfo;
6146
6247 private Context mContext;
6348
6449 private ContentResolver mContentResolver;
6550
6651 private AmbientDisplayAlwaysOnPreferenceController mController;
52+ private boolean mCallbackInvoked;
6753
6854 @Before
6955 public void setUp() throws Exception {
7056 MockitoAnnotations.initMocks(this);
71- mContext = spy(RuntimeEnvironment.application);
57+ mContext = RuntimeEnvironment.application;
7258 mContentResolver = mContext.getContentResolver();
7359 mController = new AmbientDisplayAlwaysOnPreferenceController(mContext, "key");
7460 mController.setConfig(mConfig);
75-
76- mApplicationInfo.uid = 1;
77- when(mContext.getString(R.string.config_defaultWellbeingPackage)).thenReturn(TEST_PACKAGE);
78-
79- when(mContext.getPackageManager()).thenReturn(mPackageManager);
80- doReturn(mApplicationInfo).when(mPackageManager).getApplicationInfo(
81- TEST_PACKAGE, /* flag= */0);
82-
83- doReturn(mPowerManager).when(mContext).getSystemService(PowerManager.class);
84- when(mPowerManager.isAmbientDisplaySuppressedForTokenByApp(anyString(), anyInt()))
85- .thenReturn(false);
61+ mController.setCallback(() -> mCallbackInvoked = true);
8662 }
8763
8864 @Test
@@ -132,6 +108,13 @@ public class AmbientDisplayAlwaysOnPreferenceControllerTest {
132108 }
133109
134110 @Test
111+ public void onPreferenceChange_callback() {
112+ assertThat(mCallbackInvoked).isFalse();
113+ mController.setChecked(true);
114+ assertThat(mCallbackInvoked).isTrue();
115+ }
116+
117+ @Test
135118 public void isSliceableCorrectKey_returnsTrue() {
136119 final AmbientDisplayAlwaysOnPreferenceController controller =
137120 new AmbientDisplayAlwaysOnPreferenceController(mContext,
@@ -150,39 +133,4 @@ public class AmbientDisplayAlwaysOnPreferenceControllerTest {
150133 public void isPublicSlice_returnTrue() {
151134 assertThat(mController.isPublicSlice()).isTrue();
152135 }
153-
154- @Test
155- public void isAodSuppressedByBedtime_bedTimeModeOn_returnTrue() {
156- when(mPowerManager.isAmbientDisplaySuppressedForTokenByApp(anyString(), anyInt()))
157- .thenReturn(true);
158-
159- assertThat(AmbientDisplayAlwaysOnPreferenceController
160- .isAodSuppressedByBedtime(mContext)).isTrue();
161- }
162-
163- @Test
164- public void isAodSuppressedByBedtime_bedTimeModeOff_returnFalse() {
165- assertThat(AmbientDisplayAlwaysOnPreferenceController
166- .isAodSuppressedByBedtime(mContext)).isFalse();
167- }
168-
169- @Test
170- public void isAodSuppressedByBedtime_notFoundWellbeingPackage_returnFalse()
171- throws PackageManager.NameNotFoundException {
172- when(mPackageManager.getApplicationInfo(TEST_PACKAGE, /* flag= */0)).thenThrow(
173- new PackageManager.NameNotFoundException());
174-
175- assertThat(AmbientDisplayAlwaysOnPreferenceController
176- .isAodSuppressedByBedtime(mContext)).isFalse();
177- }
178-
179- @Test
180- public void getSummary_bedTimeModeOn_shouldReturnUnavailableSummary() {
181- when(mPowerManager.isAmbientDisplaySuppressedForTokenByApp(anyString(), anyInt()))
182- .thenReturn(true);
183-
184- final CharSequence summary = mController.getSummary();
185- assertThat(summary).isEqualTo(mContext.getString(
186- com.android.settings.R.string.aware_summary_when_bedtime_on));
187- }
188136 }
--- a/tests/robotests/src/com/android/settings/security/LockscreenDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/security/LockscreenDashboardFragmentTest.java
@@ -88,6 +88,7 @@ public class LockscreenDashboardFragmentTest {
8888
8989 mTestFragment.onAttach(mContext);
9090 verify(controller).setConfig(any());
91+ verify(controller).setCallback(any());
9192 }
9293
9394 @Test