packages/apps/Settings
修訂 | d306e2419d5d5ce3498a6ba98d258d69eaf81e2f (tree) |
---|---|
時間 | 2020-11-19 21:40:57 |
作者 | Yi-yo Chiang <yochiang@goog...> |
Commiter | android-build-team Robot |
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)
@@ -104,9 +104,7 @@ | ||
104 | 104 | <uses-permission android:name="android.permission.INSTALL_DYNAMIC_SYSTEM" /> |
105 | 105 | <uses-permission android:name="android.permission.BIND_CELL_BROADCAST_SERVICE" /> |
106 | 106 | <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 | + | |
110 | 108 | <application android:label="@string/settings_label" |
111 | 109 | android:icon="@drawable/ic_launcher_settings" |
112 | 110 | android:theme="@style/Theme.Settings" |
@@ -12187,7 +12187,4 @@ | ||
12187 | 12187 | |
12188 | 12188 | <!-- Summary for see all preference when bluetooth is disable [CHAR LIMIT=none]--> |
12189 | 12189 | <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> | |
12193 | 12190 | </resources> |
@@ -16,17 +16,12 @@ | ||
16 | 16 | package com.android.settings.display; |
17 | 17 | |
18 | 18 | import android.content.Context; |
19 | -import android.content.pm.PackageManager; | |
20 | 19 | import android.hardware.display.AmbientDisplayConfiguration; |
21 | -import android.os.PowerManager; | |
22 | 20 | import android.os.SystemProperties; |
23 | 21 | import android.os.UserHandle; |
24 | 22 | import android.provider.Settings; |
25 | 23 | import android.text.TextUtils; |
26 | 24 | |
27 | -import androidx.preference.Preference; | |
28 | - | |
29 | -import com.android.settings.R; | |
30 | 25 | import com.android.settings.core.TogglePreferenceController; |
31 | 26 | |
32 | 27 | public class AmbientDisplayAlwaysOnPreferenceController extends TogglePreferenceController { |
@@ -36,9 +31,13 @@ public class AmbientDisplayAlwaysOnPreferenceController extends TogglePreference | ||
36 | 31 | |
37 | 32 | private static final int MY_USER = UserHandle.myUserId(); |
38 | 33 | private static final String PROP_AWARE_AVAILABLE = "ro.vendor.aware_available"; |
39 | - private static final String AOD_SUPPRESSED_TOKEN = "winddown"; | |
40 | 34 | |
41 | 35 | private AmbientDisplayConfiguration mConfig; |
36 | + private OnPreferenceChangedCallback mCallback; | |
37 | + | |
38 | + public interface OnPreferenceChangedCallback { | |
39 | + void onPreferenceChanged(); | |
40 | + } | |
42 | 41 | |
43 | 42 | public AmbientDisplayAlwaysOnPreferenceController(Context context, String key) { |
44 | 43 | super(context, key); |
@@ -52,12 +51,6 @@ public class AmbientDisplayAlwaysOnPreferenceController extends TogglePreference | ||
52 | 51 | } |
53 | 52 | |
54 | 53 | @Override |
55 | - public void updateState(Preference preference) { | |
56 | - super.updateState(preference); | |
57 | - refreshSummary(preference); | |
58 | - } | |
59 | - | |
60 | - @Override | |
61 | 54 | public boolean isSliceable() { |
62 | 55 | return TextUtils.equals(getPreferenceKey(), "ambient_display_always_on"); |
63 | 56 | } |
@@ -77,22 +70,24 @@ public class AmbientDisplayAlwaysOnPreferenceController extends TogglePreference | ||
77 | 70 | int enabled = isChecked ? ON : OFF; |
78 | 71 | Settings.Secure.putInt( |
79 | 72 | mContext.getContentResolver(), Settings.Secure.DOZE_ALWAYS_ON, enabled); |
73 | + if (mCallback != null) { | |
74 | + mCallback.onPreferenceChanged(); | |
75 | + } | |
80 | 76 | return true; |
81 | 77 | } |
82 | 78 | |
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 | - | |
90 | 79 | public AmbientDisplayAlwaysOnPreferenceController setConfig( |
91 | 80 | AmbientDisplayConfiguration config) { |
92 | 81 | mConfig = config; |
93 | 82 | return this; |
94 | 83 | } |
95 | 84 | |
85 | + public AmbientDisplayAlwaysOnPreferenceController setCallback( | |
86 | + OnPreferenceChangedCallback callback) { | |
87 | + mCallback = callback; | |
88 | + return this; | |
89 | + } | |
90 | + | |
96 | 91 | public static boolean isAvailable(AmbientDisplayConfiguration config) { |
97 | 92 | return config.alwaysOnAvailableForUser(MY_USER); |
98 | 93 | } |
@@ -103,25 +98,4 @@ public class AmbientDisplayAlwaysOnPreferenceController extends TogglePreference | ||
103 | 98 | } |
104 | 99 | return mConfig; |
105 | 100 | } |
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 | - } | |
127 | 101 | } |
@@ -88,7 +88,9 @@ public class LockscreenDashboardFragment extends DashboardFragment | ||
88 | 88 | @Override |
89 | 89 | public void onAttach(Context context) { |
90 | 90 | super.onAttach(context); |
91 | - use(AmbientDisplayAlwaysOnPreferenceController.class).setConfig(getConfig(context)); | |
91 | + use(AmbientDisplayAlwaysOnPreferenceController.class) | |
92 | + .setConfig(getConfig(context)) | |
93 | + .setCallback(this::updatePreferenceStates); | |
92 | 94 | use(AmbientDisplayNotificationsPreferenceController.class).setConfig(getConfig(context)); |
93 | 95 | use(DoubleTapScreenPreferenceController.class).setConfig(getConfig(context)); |
94 | 96 | use(PickupGesturePreferenceController.class).setConfig(getConfig(context)); |
@@ -19,20 +19,13 @@ package com.android.settings.display; | ||
19 | 19 | import static com.google.common.truth.Truth.assertThat; |
20 | 20 | |
21 | 21 | 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; | |
25 | 22 | import static org.mockito.Mockito.when; |
26 | 23 | |
27 | 24 | import android.content.ContentResolver; |
28 | 25 | import android.content.Context; |
29 | -import android.content.pm.ApplicationInfo; | |
30 | -import android.content.pm.PackageManager; | |
31 | 26 | import android.hardware.display.AmbientDisplayConfiguration; |
32 | -import android.os.PowerManager; | |
33 | 27 | import android.provider.Settings; |
34 | 28 | |
35 | -import com.android.internal.R; | |
36 | 29 | import com.android.settings.testutils.shadow.ShadowSecureSettings; |
37 | 30 | |
38 | 31 | import org.junit.Before; |
@@ -48,41 +41,24 @@ import org.robolectric.annotation.Config; | ||
48 | 41 | @Config(shadows = ShadowSecureSettings.class) |
49 | 42 | public class AmbientDisplayAlwaysOnPreferenceControllerTest { |
50 | 43 | |
51 | - private static final String TEST_PACKAGE = "com.android.test"; | |
52 | - | |
53 | 44 | @Mock |
54 | 45 | private AmbientDisplayConfiguration mConfig; |
55 | - @Mock | |
56 | - private PackageManager mPackageManager; | |
57 | - @Mock | |
58 | - private PowerManager mPowerManager; | |
59 | - @Mock | |
60 | - private ApplicationInfo mApplicationInfo; | |
61 | 46 | |
62 | 47 | private Context mContext; |
63 | 48 | |
64 | 49 | private ContentResolver mContentResolver; |
65 | 50 | |
66 | 51 | private AmbientDisplayAlwaysOnPreferenceController mController; |
52 | + private boolean mCallbackInvoked; | |
67 | 53 | |
68 | 54 | @Before |
69 | 55 | public void setUp() throws Exception { |
70 | 56 | MockitoAnnotations.initMocks(this); |
71 | - mContext = spy(RuntimeEnvironment.application); | |
57 | + mContext = RuntimeEnvironment.application; | |
72 | 58 | mContentResolver = mContext.getContentResolver(); |
73 | 59 | mController = new AmbientDisplayAlwaysOnPreferenceController(mContext, "key"); |
74 | 60 | 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); | |
86 | 62 | } |
87 | 63 | |
88 | 64 | @Test |
@@ -132,6 +108,13 @@ public class AmbientDisplayAlwaysOnPreferenceControllerTest { | ||
132 | 108 | } |
133 | 109 | |
134 | 110 | @Test |
111 | + public void onPreferenceChange_callback() { | |
112 | + assertThat(mCallbackInvoked).isFalse(); | |
113 | + mController.setChecked(true); | |
114 | + assertThat(mCallbackInvoked).isTrue(); | |
115 | + } | |
116 | + | |
117 | + @Test | |
135 | 118 | public void isSliceableCorrectKey_returnsTrue() { |
136 | 119 | final AmbientDisplayAlwaysOnPreferenceController controller = |
137 | 120 | new AmbientDisplayAlwaysOnPreferenceController(mContext, |
@@ -150,39 +133,4 @@ public class AmbientDisplayAlwaysOnPreferenceControllerTest { | ||
150 | 133 | public void isPublicSlice_returnTrue() { |
151 | 134 | assertThat(mController.isPublicSlice()).isTrue(); |
152 | 135 | } |
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 | - } | |
188 | 136 | } |
@@ -88,6 +88,7 @@ public class LockscreenDashboardFragmentTest { | ||
88 | 88 | |
89 | 89 | mTestFragment.onAttach(mContext); |
90 | 90 | verify(controller).setConfig(any()); |
91 | + verify(controller).setCallback(any()); | |
91 | 92 | } |
92 | 93 | |
93 | 94 | @Test |