• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.cobalt.data;
18 
19 import androidx.annotation.NonNull;
20 import androidx.room.ColumnInfo;
21 import androidx.room.Entity;
22 import androidx.room.PrimaryKey;
23 
24 import com.google.auto.value.AutoValue;
25 import com.google.auto.value.AutoValue.CopyAnnotations;
26 
27 import java.time.Instant;
28 
29 /** Stores values used for features as string (key, value) pairs. */
30 @AutoValue
31 @CopyAnnotations
32 @Entity(tableName = "GlobalValues")
33 abstract class GlobalValueEntity {
34     enum Key {
35         INITIAL_ENABLED_TIME,
36         INITIAL_DISABLED_TIME,
37     }
38 
39     /** The feature's key. */
40     @CopyAnnotations
41     @ColumnInfo(name = "key")
42     @PrimaryKey
43     @NonNull
key()44     abstract Key key();
45 
46     /** The feature's value. */
47     @CopyAnnotations
48     @ColumnInfo(name = "value")
49     @NonNull
value()50     abstract String value();
51 
52     /**
53      * Creates a {@link GlobalValueEntity}.
54      *
55      * <p>Used by Room to instantiate objects.
56      */
create(Key key, String value)57     static GlobalValueEntity create(Key key, String value) {
58         return new AutoValue_GlobalValueEntity(key, value);
59     }
60 
timeFromDbString(String time)61     static Instant timeFromDbString(String time) {
62         return Instant.parse(time);
63     }
64 
timeToDbString(Instant time)65     static String timeToDbString(Instant time) {
66         return time.toString();
67     }
68 }
69