1 /*
2  * Copyright (C) 2024 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.ondevicepersonalization.services.reset;
18 
19 import android.content.Context;
20 
21 import com.android.ondevicepersonalization.internal.util.LoggerFactory;
22 import com.android.ondevicepersonalization.services.OnDevicePersonalizationApplication;
23 import com.android.ondevicepersonalization.services.data.events.EventsDao;
24 import com.android.ondevicepersonalization.services.data.vendor.OnDevicePersonalizationVendorDataDao;
25 
26 import java.util.Collections;
27 
28 /** API to handle a user reset */
29 class ResetDataTask {
30     private static final String TAG = ResetDataTask.class.getSimpleName();
31     private static final LoggerFactory.Logger sLogger = LoggerFactory.getLogger();
32 
33     /** Delete measurement data. */
deleteMeasurementData()34     static void deleteMeasurementData() {
35         sLogger.i(TAG + ": deleting measurement data.");
36         Context context = OnDevicePersonalizationApplication.getAppContext();
37         try {
38             OnDevicePersonalizationVendorDataDao.deleteVendorTables(
39                     context, Collections.emptyList());
40         } catch (Exception e) {
41             sLogger.e(e, TAG + ": failed to delete vendor tables");
42         }
43         try {
44             EventsDao eventsDao = EventsDao.getInstance(context);
45             eventsDao.deleteEventsAndQueries(System.currentTimeMillis());
46         } catch (Exception e) {
47             sLogger.e(e, TAG + ": failed to delete event tables");
48         }
49     }
50 }
51