Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6f7a0d67 authored by Dave Mankoff's avatar Dave Mankoff Committed by Automerger Merge Worker
Browse files

Merge "Add a shared library for setting flags in SysUI." into sc-v2-dev am:...

Merge "Add a shared library for setting flags in SysUI." into sc-v2-dev am: fdb01b63 am: abef1d3d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16092692

Change-Id: I2debaf6ed83b2cbf72bbb1b578c8b30a8a58a4da
parents b3a3869f abef1d3d
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -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",
+3 −0
Original line number Diff line number Diff line
<<<<<<< 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)
+31 −0
Original line number Diff line number Diff line
@@ -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",
+64 −0
Original line number Diff line number Diff line
/*
 * 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<Collection<Flag<*>>> {
        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<Collection<Flag<*>>> ->
                completer.set(knownFlagMap.values as Collection<Flag<*>>)
                "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
Loading