1 /* 2 * Copyright (C) 2022 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.server.healthconnect.permission; 18 19 import android.annotation.IntDef; 20 import android.os.UserHandle; 21 22 import java.io.File; 23 import java.lang.annotation.Retention; 24 import java.lang.annotation.RetentionPolicy; 25 26 /** 27 * Class for managing health permissions first grant time datastore. 28 * 29 * @hide 30 */ 31 public interface FirstGrantTimeDatastore { 32 33 @Retention(RetentionPolicy.SOURCE) 34 @IntDef({DATA_TYPE_CURRENT, DATA_TYPE_STAGED}) 35 public @interface DataType {} 36 37 /* Type used for storing general grant time */ 38 int DATA_TYPE_CURRENT = 0; 39 40 /* Type used for applying backup data when it's needed. */ 41 int DATA_TYPE_STAGED = 1; 42 43 /** 44 * Read {@link UserGrantTimeState for given user}. 45 * 46 * @hide 47 */ readForUser(UserHandle user, @DataType int dataType)48 UserGrantTimeState readForUser(UserHandle user, @DataType int dataType); 49 50 /** 51 * Write {@link UserGrantTimeState for given user}. 52 * 53 * @hide 54 */ writeForUser(UserGrantTimeState grantTimesState, UserHandle user, @DataType int dataType)55 void writeForUser(UserGrantTimeState grantTimesState, UserHandle user, @DataType int dataType); 56 57 /** 58 * Returns the name of the files used by the store for the given user. 59 * 60 * @hide 61 */ getFile(UserHandle user, @DataType int dataType)62 File getFile(UserHandle user, @DataType int dataType); 63 64 /** 65 * Create instance of the datastore class. 66 * 67 * @hide 68 */ createInstance(File environmentDataDirectory)69 static FirstGrantTimeDatastore createInstance(File environmentDataDirectory) { 70 return new FirstGrantTimeDatastoreXmlPersistence(environmentDataDirectory); 71 } 72 } 73