Remove the server side flag of clockface blacklist
Bug: 136090066 Test: atest com.android.keyguard.clock.ClockManagerTest Change-Id: I7aa2c2deb690a3c8a5648754eeb6ae10ed0af0d8
This commit is contained in:
@@ -145,13 +145,6 @@ public final class SystemUiDeviceConfigFlags {
|
|||||||
*/
|
*/
|
||||||
public static final String ASSIST_HANDLES_SHOWN_FREQUENCY_THRESHOLD_MS =
|
public static final String ASSIST_HANDLES_SHOWN_FREQUENCY_THRESHOLD_MS =
|
||||||
"assist_handles_shown_frequency_threshold_ms";
|
"assist_handles_shown_frequency_threshold_ms";
|
||||||
// Flag related to clock face
|
|
||||||
|
|
||||||
/**
|
|
||||||
* (String) Contains the clock plugin service names that are not allow to be shown.
|
|
||||||
* Each service name is seperated by a comma(",") in the string.
|
|
||||||
*/
|
|
||||||
public static final String CLOCK_FACE_BLACKLIST = "clock_face_blacklist";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (long) How long, in milliseconds, for teaching behaviors to wait before considering the user
|
* (long) How long, in milliseconds, for teaching behaviors to wait before considering the user
|
||||||
|
|||||||
@@ -15,8 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.keyguard.clock;
|
package com.android.keyguard.clock;
|
||||||
|
|
||||||
import static com.android.internal.config.sysui.SystemUiDeviceConfigFlags.CLOCK_FACE_BLACKLIST;
|
|
||||||
|
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -26,12 +24,9 @@ import android.net.Uri;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.provider.DeviceConfig;
|
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
import android.util.ArraySet;
|
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
@@ -47,12 +42,10 @@ import com.android.systemui.shared.plugins.PluginManager;
|
|||||||
import com.android.systemui.util.InjectionInflationController;
|
import com.android.systemui.util.InjectionInflationController;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
@@ -74,8 +67,6 @@ public final class ClockManager {
|
|||||||
private final Handler mMainHandler = new Handler(Looper.getMainLooper());
|
private final Handler mMainHandler = new Handler(Looper.getMainLooper());
|
||||||
private final CurrentUserObservable mCurrentUserObservable;
|
private final CurrentUserObservable mCurrentUserObservable;
|
||||||
|
|
||||||
private final ArraySet<String> mBlacklistedClockPlugins = new ArraySet<>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Observe settings changes to know when to switch the clock face.
|
* Observe settings changes to know when to switch the clock face.
|
||||||
*/
|
*/
|
||||||
@@ -164,41 +155,6 @@ public final class ClockManager {
|
|||||||
DisplayMetrics dm = res.getDisplayMetrics();
|
DisplayMetrics dm = res.getDisplayMetrics();
|
||||||
mWidth = dm.widthPixels;
|
mWidth = dm.widthPixels;
|
||||||
mHeight = dm.heightPixels;
|
mHeight = dm.heightPixels;
|
||||||
|
|
||||||
updateBlackList();
|
|
||||||
registerDeviceConfigListener();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateBlackList() {
|
|
||||||
String blacklist = getBlackListFromConfig();
|
|
||||||
|
|
||||||
mBlacklistedClockPlugins.clear();
|
|
||||||
if (blacklist != null && !blacklist.isEmpty()) {
|
|
||||||
mBlacklistedClockPlugins.addAll(Arrays.asList(blacklist.split(",")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String getBlackListFromConfig() {
|
|
||||||
return DeviceConfig.getString(
|
|
||||||
DeviceConfig.NAMESPACE_SYSTEMUI, CLOCK_FACE_BLACKLIST, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerDeviceConfigListener() {
|
|
||||||
DeviceConfig.addOnPropertiesChangedListener(
|
|
||||||
DeviceConfig.NAMESPACE_SYSTEMUI,
|
|
||||||
r -> mMainHandler.post(r),
|
|
||||||
properties -> onDeviceConfigPropertiesChanged(properties.getNamespace()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void onDeviceConfigPropertiesChanged(String namespace) {
|
|
||||||
if (!DeviceConfig.NAMESPACE_SYSTEMUI.equals(namespace)) {
|
|
||||||
Log.e(TAG, "Received update from DeviceConfig for unrelated namespace: "
|
|
||||||
+ namespace);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
updateBlackList();
|
|
||||||
reload();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -350,12 +306,10 @@ public final class ClockManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get information about clock faces which are available and not in blacklist.
|
* Get information about available clock faces.
|
||||||
*/
|
*/
|
||||||
List<ClockInfo> getInfo() {
|
List<ClockInfo> getInfo() {
|
||||||
return mClockInfo.stream()
|
return mClockInfo;
|
||||||
.filter(info -> !mBlacklistedClockPlugins.contains(info.getId()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -407,7 +361,7 @@ public final class ClockManager {
|
|||||||
if (ClockManager.this.isDocked()) {
|
if (ClockManager.this.isDocked()) {
|
||||||
final String name = mSettingsWrapper.getDockedClockFace(
|
final String name = mSettingsWrapper.getDockedClockFace(
|
||||||
mCurrentUserObservable.getCurrentUser().getValue());
|
mCurrentUserObservable.getCurrentUser().getValue());
|
||||||
if (name != null && !mBlacklistedClockPlugins.contains(name)) {
|
if (name != null) {
|
||||||
plugin = mClocks.get(name);
|
plugin = mClocks.get(name);
|
||||||
if (plugin != null) {
|
if (plugin != null) {
|
||||||
return plugin;
|
return plugin;
|
||||||
@@ -416,7 +370,7 @@ public final class ClockManager {
|
|||||||
}
|
}
|
||||||
final String name = mSettingsWrapper.getLockScreenCustomClockFace(
|
final String name = mSettingsWrapper.getLockScreenCustomClockFace(
|
||||||
mCurrentUserObservable.getCurrentUser().getValue());
|
mCurrentUserObservable.getCurrentUser().getValue());
|
||||||
if (name != null && !mBlacklistedClockPlugins.contains(name)) {
|
if (name != null) {
|
||||||
plugin = mClocks.get(name);
|
plugin = mClocks.get(name);
|
||||||
}
|
}
|
||||||
return plugin;
|
return plugin;
|
||||||
|
|||||||
@@ -20,14 +20,12 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.Mockito.reset;
|
import static org.mockito.Mockito.reset;
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.DeviceConfig;
|
|
||||||
import android.test.suitebuilder.annotation.SmallTest;
|
import android.test.suitebuilder.annotation.SmallTest;
|
||||||
import android.testing.AndroidTestingRunner;
|
import android.testing.AndroidTestingRunner;
|
||||||
import android.testing.TestableLooper.RunWithLooper;
|
import android.testing.TestableLooper.RunWithLooper;
|
||||||
@@ -52,8 +50,6 @@ import org.mockito.ArgumentCaptor;
|
|||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
@RunWith(AndroidTestingRunner.class)
|
@RunWith(AndroidTestingRunner.class)
|
||||||
// Need to run tests on main looper because LiveData operations such as setData, observe,
|
// Need to run tests on main looper because LiveData operations such as setData, observe,
|
||||||
@@ -67,7 +63,7 @@ public final class ClockManagerTest extends SysuiTestCase {
|
|||||||
private static final int SECONDARY_USER_ID = 11;
|
private static final int SECONDARY_USER_ID = 11;
|
||||||
private static final Uri SETTINGS_URI = null;
|
private static final Uri SETTINGS_URI = null;
|
||||||
|
|
||||||
ClockManager mClockManager;
|
private ClockManager mClockManager;
|
||||||
private ContentObserver mContentObserver;
|
private ContentObserver mContentObserver;
|
||||||
private DockManagerFake mFakeDockManager;
|
private DockManagerFake mFakeDockManager;
|
||||||
private MutableLiveData<Integer> mCurrentUser;
|
private MutableLiveData<Integer> mCurrentUser;
|
||||||
@@ -143,33 +139,6 @@ public final class ClockManagerTest extends SysuiTestCase {
|
|||||||
assertThat(mClockManager.getCurrentClock()).isInstanceOf(BUBBLE_CLOCK_CLASS);
|
assertThat(mClockManager.getCurrentClock()).isInstanceOf(BUBBLE_CLOCK_CLASS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getCurrentClock_inBlackList() {
|
|
||||||
mClockManager = spy(mClockManager);
|
|
||||||
// GIVEN that settings is set to the bubble clock face
|
|
||||||
when(mMockSettingsWrapper.getLockScreenCustomClockFace(anyInt())).thenReturn(BUBBLE_CLOCK);
|
|
||||||
// WHEN settings change event is fired
|
|
||||||
mContentObserver.onChange(false, SETTINGS_URI, MAIN_USER_ID);
|
|
||||||
// GIVEN that bubble clock is in blacklist
|
|
||||||
when(mClockManager.getBlackListFromConfig()).thenReturn(BUBBLE_CLOCK);
|
|
||||||
// WHEN device config change of systemui is fired
|
|
||||||
mClockManager.onDeviceConfigPropertiesChanged(DeviceConfig.NAMESPACE_SYSTEMUI);
|
|
||||||
// THEN the result is null, indicated the current clock should be reset to the default one.
|
|
||||||
assertThat(mClockManager.getCurrentClock()).isNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getClockInfo_inBlackList() {
|
|
||||||
mClockManager = spy(mClockManager);
|
|
||||||
// GIVEN that bubble clock is in blacklist
|
|
||||||
when(mClockManager.getBlackListFromConfig()).thenReturn(BUBBLE_CLOCK);
|
|
||||||
// WHEN device config change of systemui is fired
|
|
||||||
mClockManager.onDeviceConfigPropertiesChanged(DeviceConfig.NAMESPACE_SYSTEMUI);
|
|
||||||
// THEN the ClockInfo should not contain bubble clock
|
|
||||||
List<ClockInfo> clocks = mClockManager.getClockInfos();
|
|
||||||
assertThat(clocks.stream().anyMatch(info -> BUBBLE_CLOCK.equals(info.getId()))).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onClockChanged_customClock() {
|
public void onClockChanged_customClock() {
|
||||||
// GIVEN that settings is set to the bubble clock face
|
// GIVEN that settings is set to the bubble clock face
|
||||||
|
|||||||
Reference in New Issue
Block a user