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

Commit c25fd5ae authored by Dave Mankoff's avatar Dave Mankoff
Browse files

Add permissions to FeatureFlagService and override api.

This will allow flag flipper to change flags and prevent others
from doing so.

Bug: 279054964
Test: atest FrameworksServicesTests:com.android.server.flag
Change-Id: I6f2e2acecc202d3e24f94ef0801b98c2fd0aa456
parent 7c3cae6b
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -24,4 +24,8 @@ package android.flags;
 * @hide
 */
public interface DynamicFlag<T> extends Flag<T> {
    @Override
    default boolean isDynamic() {
        return true;
    }
}
+7 −1
Original line number Diff line number Diff line
@@ -250,7 +250,13 @@ public class FeatureFlags {
        return flag;
    }

    protected void sync() {
    /**
     * Sync any known flags that have not yet been synced.
     *
     * This is called implicitly when any flag is read, and is not generally needed except in
     * exceptional circumstances.
     */
    public void sync() {
        synchronized (FeatureFlags.class) {
            if (mDirtyFlags.isEmpty()) {
                return;
+5 −0
Original line number Diff line number Diff line
@@ -37,4 +37,9 @@ public interface Flag<T> {
    /** The value of this flag if no override has been set. Null values are not supported. */
    @NonNull
    T getDefault();

    /** Returns true if the value of this flag can change at runtime. */
    default boolean isDynamic() {
        return false;
    }
}
+24 −0
Original line number Diff line number Diff line
@@ -62,4 +62,28 @@ interface IFeatureFlags {
     * {@link #registerCallback}.
     */
    void unregisterCallback(IFeatureFlagsCallback callback);

    /**
     * Query the {@link com.android.server.flags.FeatureFlagsService} for flags, but don't
     * cache them. See {@link #syncFlags}.
     *
     * You almost certainly don't want this method. This is intended for the Flag Flipper
     * application that needs to query the state of system but doesn't want to affect it by
     * doing so. All other clients should use {@link syncFlags}.
     */
    List<SyncableFlag> queryFlags(in List<SyncableFlag> flagList);

    /**
     * Change a flags value in the system.
     *
     * This is intended for use by the Flag Flipper application.
     */
    void overrideFlag(in SyncableFlag flag);

    /**
     * Restore a flag to its default value.
     *
     * This is intended for use by the Flag Flipper application.
     */
    void resetFlag(in SyncableFlag flag);
}
 No newline at end of file
+22 −2
Original line number Diff line number Diff line
@@ -28,16 +28,28 @@ public final class SyncableFlag implements Parcelable {
    private final String mName;
    private final String mValue;
    private final boolean mDynamic;
    private final boolean mOverridden;

    public SyncableFlag(
            @NonNull String namespace,
            @NonNull String name,
            @NonNull String value,
            boolean dynamic) {
        this(namespace, name, value, dynamic, false);
    }

    public SyncableFlag(
            @NonNull String namespace,
            @NonNull String name,
            @NonNull String value,
            boolean dynamic,
            boolean overridden
    ) {
        mNamespace = namespace;
        mName = name;
        mValue = value;
        mDynamic = dynamic;
        mOverridden = overridden;
    }

    @NonNull
@@ -55,16 +67,23 @@ public final class SyncableFlag implements Parcelable {
        return mValue;
    }

    @NonNull
    public boolean isDynamic() {
        return mDynamic;
    }

    public boolean isOverridden() {
        return mOverridden;
    }

    @NonNull
    public static final Parcelable.Creator<SyncableFlag> CREATOR = new Parcelable.Creator<>() {
        public SyncableFlag createFromParcel(Parcel in) {
            return new SyncableFlag(
                    in.readString(), in.readString(), in.readString(), in.readBoolean());
                    in.readString(),
                    in.readString(),
                    in.readString(),
                    in.readBoolean(),
                    in.readBoolean());
        }

        public SyncableFlag[] newArray(int size) {
@@ -83,6 +102,7 @@ public final class SyncableFlag implements Parcelable {
        dest.writeString(mName);
        dest.writeString(mValue);
        dest.writeBoolean(mDynamic);
        dest.writeBoolean(mOverridden);
    }

    @Override
Loading