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

Commit 26b95bf6 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[Catalyst] Support float value type preference" into main

parents b11da57e d2e614e6
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -108,6 +108,7 @@ message PreferenceValueProto {
  oneof value {
    bool boolean_value = 1;
    int32 int_value = 2;
    float float_value = 3;
  }
}

@@ -116,6 +117,7 @@ message PreferenceValueDescriptorProto {
  oneof type {
    bool boolean_type = 1;
    RangeValueProto range_value = 2;
    bool float_type = 3;
  }
}

+7 −7
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import com.android.settingslib.graph.proto.PreferenceProto.ActionTarget
import com.android.settingslib.graph.proto.PreferenceScreenProto
import com.android.settingslib.graph.proto.TextProto
import com.android.settingslib.metadata.BooleanValue
import com.android.settingslib.metadata.FloatPersistentPreference
import com.android.settingslib.metadata.PersistentPreference
import com.android.settingslib.metadata.PreferenceAvailabilityProvider
import com.android.settingslib.metadata.PreferenceHierarchy
@@ -399,15 +400,13 @@ fun PreferenceMetadata.toProto(
                metadata is PersistentPreference<*> &&
                metadata.evalReadPermit(context, callingPid, callingUid) == ReadWritePermit.ALLOW
        ) {
            val storage = metadata.storage(context)
            value = preferenceValueProto {
                when (metadata) {
                    is BooleanValue ->
                        metadata.storage(context).getBoolean(metadata.key)?.let {
                            booleanValue = it
                        }
                    is RangeValue -> {
                        metadata.storage(context).getInt(metadata.key)?.let { intValue = it }
                    }
                    is BooleanValue -> storage.getBoolean(metadata.key)?.let { booleanValue = it }
                    is RangeValue -> storage.getInt(metadata.key)?.let { intValue = it }
                    is FloatPersistentPreference ->
                        storage.getFloat(metadata.key)?.let { floatValue = it }
                    else -> {}
                }
            }
@@ -421,6 +420,7 @@ fun PreferenceMetadata.toProto(
                            max = metadata.getMaxValue(context)
                            step = metadata.getIncrementStep(context)
                        }
                    is FloatPersistentPreference -> floatType = true
                    else -> {}
                }
            }
+6 −0
Original line number Diff line number Diff line
@@ -159,6 +159,12 @@ class PreferenceSetterApiHandler(
                }
                storage.setInt(key, intValue)
                return PreferenceSetterResult.OK
            } else if (value.hasFloatValue()) {
                val floatValue = value.floatValue
                val resultCode = metadata.checkWritePermit(floatValue)
                if (resultCode != PreferenceSetterResult.OK) return resultCode
                storage.setFloat(key, floatValue)
                return PreferenceSetterResult.OK
            }
        } catch (e: Exception) {
            return PreferenceSetterResult.INTERNAL_ERROR
+3 −0
Original line number Diff line number Diff line
@@ -201,3 +201,6 @@ interface RangeValue : ValueDescriptor {
    override fun isValidValue(context: Context, index: Int) =
        index in getMinValue(context)..getMaxValue(context)
}

/** A persistent preference that has a float value. */
interface FloatPersistentPreference : PersistentPreference<Float>