1 /*
2  * Copyright (C) 2019 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.managedprovisioning.finalization;
18 
19 import static java.util.Objects.requireNonNull;
20 
21 import android.content.Context;
22 
23 import java.io.File;
24 import java.util.function.Function;
25 
26 /**
27  * Class containing utility methods for working with stored provisioning parameters.
28  */
29 class ProvisioningParamsUtils {
30 
31     private static final String PROVISIONING_PARAMS_FILE_NAME =
32             "finalization_activity_provisioning_params.xml";
33 
34     public static Function<Context, File> DEFAULT_PROVISIONING_PARAMS_FILE_PROVIDER =
35             context -> new File(context.getFilesDir(), PROVISIONING_PARAMS_FILE_NAME);
36 
37     private final Function<Context, File> mProvisioningParamsFileProvider;
38 
ProvisioningParamsUtils(Function<Context, File> provisioningParamsFileProvider)39     ProvisioningParamsUtils(Function<Context, File> provisioningParamsFileProvider) {
40         mProvisioningParamsFileProvider = requireNonNull(provisioningParamsFileProvider);
41     }
42 
43     /**
44      * Returns a handle to the provisioning params file, which is used to store the params
45      * for use during provisioning finalization.
46      */
getProvisioningParamsFile(Context context)47     File getProvisioningParamsFile(Context context) {
48         return mProvisioningParamsFileProvider.apply(context);
49     }
50 }
51