diff --git a/packages/SystemUI/Android.bp b/packages/SystemUI/Android.bp index ae8439f75f199..f6b35238433ea 100644 --- a/packages/SystemUI/Android.bp +++ b/packages/SystemUI/Android.bp @@ -50,6 +50,17 @@ java_library { srcs: ["src/com/android/systemui/EventLogTags.logtags"], } +java_library { + name: "SystemUI-flags", + srcs: [ + "src/com/android/systemui/flags/Flags.java", + ], + libs: [ + "SystemUI-flag-types", + ], + static_kotlin_stdlib: false, +} + filegroup { name: "ReleaseJavaFiles", srcs: [ @@ -117,6 +128,7 @@ android_library { "iconloader_base", "SystemUI-tags", "SystemUI-proto", + "SystemUI-flags", "monet", "dagger2", "jsr330", diff --git a/packages/SystemUI/plugin/src/com/android/systemui/flags/Flags.java b/packages/SystemUI/plugin/src/com/android/systemui/flags/Flags.java index fa60bc9d747dd..51441db1861ea 100644 --- a/packages/SystemUI/plugin/src/com/android/systemui/flags/Flags.java +++ b/packages/SystemUI/plugin/src/com/android/systemui/flags/Flags.java @@ -1,3 +1,4 @@ +<<<<<<< TARGET BRANCH (b3a386 Merge "Update package data API docs") /* * Copyright (C) 2021 The Android Open Source Project * @@ -126,3 +127,5 @@ public class Flags { // \_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/ } +======= +>>>>>>> SOURCE BRANCH (abef1d Merge "Add a shared library for setting flags in SysUI." int) diff --git a/packages/SystemUI/shared/Android.bp b/packages/SystemUI/shared/Android.bp index 23307de519c86..7cf22a38837b2 100644 --- a/packages/SystemUI/shared/Android.bp +++ b/packages/SystemUI/shared/Android.bp @@ -45,9 +45,40 @@ android_library { ":wm_shell-aidls", ":wm_shell_util-sources", ], + libs: [ + "SystemUI-flags", + ], static_libs: [ "PluginCoreLib", "androidx.dynamicanimation_dynamicanimation", + "androidx.concurrent_concurrent-futures", + ], + java_version: "1.8", + min_sdk_version: "current", +} + +java_library { + name: "SystemUI-flag-types", + srcs: [ + "src/com/android/systemui/flags/Flag.kt", + ], + static_kotlin_stdlib: false, + java_version: "1.8", + min_sdk_version: "current", +} + +java_library { + name: "SystemUIFlagsLib", + srcs: [ + "src/com/android/systemui/flags/**/*.kt", + ], + static_kotlin_stdlib: false, + libs: [ + "androidx.concurrent_concurrent-futures", + "SystemUI-flags", + ], + static_libs: [ + "SystemUI-flag-types", ], java_version: "1.8", min_sdk_version: "current", diff --git a/packages/SystemUI/plugin/src/com/android/systemui/flags/Flag.kt b/packages/SystemUI/shared/src/com/android/systemui/flags/Flag.kt similarity index 100% rename from packages/SystemUI/plugin/src/com/android/systemui/flags/Flag.kt rename to packages/SystemUI/shared/src/com/android/systemui/flags/Flag.kt diff --git a/packages/SystemUI/shared/src/com/android/systemui/flags/FlagManager.kt b/packages/SystemUI/shared/src/com/android/systemui/flags/FlagManager.kt new file mode 100644 index 0000000000000..89fee7084332a --- /dev/null +++ b/packages/SystemUI/shared/src/com/android/systemui/flags/FlagManager.kt @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2021 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.systemui.flags + +import android.content.Context +import android.content.Intent +import androidx.concurrent.futures.CallbackToFutureAdapter +import com.google.common.util.concurrent.ListenableFuture + +class FlagManager constructor(val context: Context) { + companion object { + const val RECEIVING_PACKAGE = "com.android.systemui" + const val ACTION_SET_FLAG = "com.android.systemui.action.SET_FLAG" + const val FLAGS_PERMISSION = "com.android.systemui.permission.FLAGS" + const val FIELD_ID = "id" + const val FIELD_VALUE = "value" + } + + fun getFlagsFuture(): ListenableFuture>> { + val knownFlagMap = Flags.collectFlags() + // Possible todo in the future: query systemui async to actually get the known flag ids. + return CallbackToFutureAdapter.getFuture( + CallbackToFutureAdapter.Resolver { + completer: CallbackToFutureAdapter.Completer>> -> + completer.set(knownFlagMap.values as Collection>) + "Retrieving Flags" + }) + } + + fun setFlagValue(id: Int, enabled: Boolean) { + val intent = createIntent(id) + intent.putExtra(FIELD_VALUE, enabled) + + context.sendBroadcast(intent) + } + + fun eraseFlag(id: Int) { + val intent = createIntent(id) + + context.sendBroadcast(intent) + } + + private fun createIntent(id: Int): Intent { + val intent = Intent(ACTION_SET_FLAG) + intent.setPackage(RECEIVING_PACKAGE) + intent.putExtra(FIELD_ID, id) + + return intent + } +} \ No newline at end of file diff --git a/packages/SystemUI/src-debug/com/android/systemui/flags/FeatureFlagManager.java b/packages/SystemUI/src-debug/com/android/systemui/flags/FeatureFlagManager.java index 1eeb51601682d..c2ed1ac6f0e87 100644 --- a/packages/SystemUI/src-debug/com/android/systemui/flags/FeatureFlagManager.java +++ b/packages/SystemUI/src-debug/com/android/systemui/flags/FeatureFlagManager.java @@ -16,6 +16,11 @@ package com.android.systemui.flags; +import static com.android.systemui.flags.FlagManager.ACTION_SET_FLAG; +import static com.android.systemui.flags.FlagManager.FIELD_ID; +import static com.android.systemui.flags.FlagManager.FIELD_VALUE; +import static com.android.systemui.flags.FlagManager.FLAGS_PERMISSION; + import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -55,11 +60,7 @@ public class FeatureFlagManager implements FlagReader, FlagWriter, Dumpable { private static final String SYSPROP_PREFIX = "persist.systemui.flag_"; private static final String FIELD_TYPE = "type"; - private static final String FIELD_ID = "id"; - private static final String FIELD_VALUE = "value"; private static final String TYPE_BOOLEAN = "boolean"; - private static final String ACTION_SET_FLAG = "com.android.systemui.action.SET_FLAG"; - private static final String FLAGS_PERMISSION = "com.android.systemui.permission.FLAGS"; private final SystemPropertiesHelper mSystemPropertiesHelper; private final Map mBooleanFlagCache = new HashMap<>(); diff --git a/packages/SystemUI/src/com/android/systemui/flags/Flags.java b/packages/SystemUI/src/com/android/systemui/flags/Flags.java new file mode 100644 index 0000000000000..3761d42ae98c7 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/flags/Flags.java @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2021 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.systemui.flags; + +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; + +/** + * List of {@link Flag} objects for use in SystemUI. + * + * Flag Ids are integers. + * Ids must be unique. This is enforced in a unit test. + * Ids need not be sequential. Flags can "claim" a chunk of ids for flags in related featurs with + * a comment. This is purely for organizational purposes. + * + * On public release builds, flags will always return their default value. There is no way to + * change their value on release builds. + * + * See {@link FeatureFlagManager} for instructions on flipping the flags via adb. + */ +public class Flags { + public static final BooleanFlag TEAMFOOD = new BooleanFlag(1, false); + + /***************************************/ + // 100 - notification + public static final BooleanFlag NEW_NOTIFICATION_PIPELINE = + new BooleanFlag(100, true); + + public static final BooleanFlag NEW_NOTIFICATION_PIPELINE_RENDERING = + new BooleanFlag(101, false); + + public static final BooleanFlag NOTIFICATION_UPDATES = + new BooleanFlag(102, true); + + + /***************************************/ + // 200 - keyguard/lockscreen + public static final BooleanFlag KEYGUARD_LAYOUT = + new BooleanFlag(200, true); + + public static final BooleanFlag LOCKSCREEN_ANIMATIONS = + new BooleanFlag(201, true); + + public static final BooleanFlag NEW_UNLOCK_SWIPE_ANIMATION = + new BooleanFlag(202, true); + + /***************************************/ + // 300 - power menu + public static final BooleanFlag POWER_MENU_LITE = + new BooleanFlag(300, true); + + /***************************************/ + // 400 - smartspace + public static final BooleanFlag SMARTSPACE_DEDUPING = + new BooleanFlag(400, true); + + public static final BooleanFlag SMARTSPACE_SHARED_ELEMENT_TRANSITION_ENABLED = + new BooleanFlag(401, false); + + /***************************************/ + // 500 - quick settings + public static final BooleanFlag NEW_USER_SWITCHER = + new BooleanFlag(500, true); + + /***************************************/ + // 600- status bar + public static final BooleanFlag COMBINED_STATUS_BAR_SIGNAL_ICONS = + new BooleanFlag(501, false); + + /***************************************/ + // 700 - dialer/calls + public static final BooleanFlag ONGOING_CALL_STATUS_BAR_CHIP = + new BooleanFlag(600, true); + + public static final BooleanFlag ONGOING_CALL_IN_IMMERSIVE = + new BooleanFlag(601, true); + + public static final BooleanFlag ONGOING_CALL_IN_IMMERSIVE_CHIP_TAP = + new BooleanFlag(602, true); + + // Pay no attention to the reflection behind the curtain. + // ========================== Curtain ========================== + // | | + // | . . . . . . . . . . . . . . . . . . . | + private static Map> sFlagMap; + static Map> collectFlags() { + if (sFlagMap != null) { + return sFlagMap; + } + Map> flags = new HashMap<>(); + + Field[] fields = Flags.class.getFields(); + + for (Field field : fields) { + Class t = field.getType(); + if (Flag.class.isAssignableFrom(t)) { + try { + Flag flag = (Flag) field.get(null); + flags.put(flag.getId(), flag); + } catch (IllegalAccessException e) { + // no-op + } + } + } + + sFlagMap = flags; + + return sFlagMap; + } + // | . . . . . . . . . . . . . . . . . . . | + // | | + // \_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/ + +}