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.adservices.cobalt; 18 19 import android.content.Context; 20 21 import androidx.annotation.NonNull; 22 23 import com.android.adservices.service.common.compat.FileCompatUtils; 24 import com.android.cobalt.data.CobaltDatabase; 25 import com.android.cobalt.data.DataService; 26 27 import java.util.Objects; 28 import java.util.concurrent.ExecutorService; 29 30 /** 31 * Static data and functions related to the Cobalt data service. 32 * 33 * <p>This may makes sense to have in the Cobalt library itself if manual migrations are needed, but 34 * it will be owned by AdServices for now to make the database name and destructive migration 35 * explicit. 36 */ 37 final class CobaltDataServiceFactory { 38 private static final String DB_NAME = FileCompatUtils.getAdservicesFilename("cobalt_db"); 39 createDataService( @onNull Context context, @NonNull ExecutorService executorService)40 static DataService createDataService( 41 @NonNull Context context, @NonNull ExecutorService executorService) { 42 Objects.requireNonNull(context); 43 Objects.requireNonNull(executorService); 44 45 CobaltDatabase cobaltDatabase = 46 FileCompatUtils.roomDatabaseBuilderHelper(context, CobaltDatabase.class, DB_NAME) 47 .fallbackToDestructiveMigration() 48 .build(); 49 return new DataService(executorService, cobaltDatabase); 50 } 51 } 52