chore(#AlwaysOnMagnifier): Support feature flag flips observation
In AlwaysOnMagnificationFeatureFlag, support adding listener to DeviceConfig to
observe the feature flag flips. If the flag value is changed, notify
AccessibilityManagerService to enable/disable the feature.
Bug: 269414499
Test: manually set flag value with adb shell
atest MagnificationControllerTest
atest AccessibilityManagerServiceTest
Change-Id: Ie66972ae8a3ac0ebda2b888bf7265ec1360b6a40
This commit is contained in:
@@ -4567,6 +4567,17 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when always on magnification feature flag flips to check if the feature should be
|
||||
* enabled for current user state.
|
||||
*/
|
||||
public void updateAlwaysOnMagnification() {
|
||||
synchronized (mLock) {
|
||||
readAlwaysOnMagnificationLocked(getCurrentUserState());
|
||||
}
|
||||
}
|
||||
|
||||
@GuardedBy("mLock")
|
||||
boolean readAlwaysOnMagnificationLocked(AccessibilityUserState userState) {
|
||||
final boolean isSettingsAlwaysOnEnabled = Settings.Secure.getIntForUser(
|
||||
mContext.getContentResolver(),
|
||||
|
||||
@@ -16,10 +16,13 @@
|
||||
|
||||
package com.android.server.accessibility.magnification;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.provider.DeviceConfig;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* Encapsulates the feature flags for always on magnification. {@see DeviceConfig}
|
||||
*
|
||||
@@ -50,4 +53,39 @@ public class AlwaysOnMagnificationFeatureFlag {
|
||||
Boolean.toString(isEnabled),
|
||||
/* makeDefault= */ false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a listener for when the feature flag changes.
|
||||
*
|
||||
* <p>{@see DeviceConfig#addOnPropertiesChangedListener(
|
||||
* String, Executor, DeviceConfig.OnPropertiesChangedListener)}
|
||||
*/
|
||||
@NonNull
|
||||
public static DeviceConfig.OnPropertiesChangedListener addOnChangedListener(
|
||||
@NonNull Executor executor, @NonNull Runnable listener) {
|
||||
DeviceConfig.OnPropertiesChangedListener onChangedListener =
|
||||
properties -> {
|
||||
if (properties.getKeyset().contains(
|
||||
FEATURE_NAME_ENABLE_ALWAYS_ON_MAGNIFICATION)) {
|
||||
listener.run();
|
||||
}
|
||||
};
|
||||
DeviceConfig.addOnPropertiesChangedListener(
|
||||
NAMESPACE,
|
||||
executor,
|
||||
onChangedListener);
|
||||
|
||||
return onChangedListener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a listener for when the feature flag changes.
|
||||
*
|
||||
* <p>{@see DeviceConfig#addOnPropertiesChangedListener(String, Executor,
|
||||
* DeviceConfig.OnPropertiesChangedListener)}
|
||||
*/
|
||||
public static void removeOnChangedListener(
|
||||
@NonNull DeviceConfig.OnPropertiesChangedListener onChangedListener) {
|
||||
DeviceConfig.removeOnPropertiesChangedListener(onChangedListener);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ import android.view.accessibility.MagnificationAnimationCallback;
|
||||
import com.android.internal.accessibility.util.AccessibilityStatsLogUtils;
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.ConcurrentUtils;
|
||||
import com.android.server.LocalServices;
|
||||
import com.android.server.accessibility.AccessibilityManagerService;
|
||||
import com.android.server.wm.WindowManagerInternal;
|
||||
@@ -149,6 +150,9 @@ public class MagnificationController implements WindowMagnificationManager.Callb
|
||||
.getAccessibilityController().setUiChangesForAccessibilityCallbacks(this);
|
||||
mSupportWindowMagnification = context.getPackageManager().hasSystemFeature(
|
||||
FEATURE_WINDOW_MAGNIFICATION);
|
||||
|
||||
AlwaysOnMagnificationFeatureFlag.addOnChangedListener(
|
||||
ConcurrentUtils.DIRECT_EXECUTOR, mAms::updateAlwaysOnMagnification);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
||||
Reference in New Issue
Block a user