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.car.companiondevicesupport.feature.trust.storage;
18 
19 import androidx.room.Dao;
20 import androidx.room.Delete;
21 import androidx.room.Insert;
22 import androidx.room.OnConflictStrategy;
23 import androidx.room.Query;
24 
25 import java.util.List;
26 
27 /** Queries for trusted device table. */
28 @Dao
29 public interface TrustedDeviceDao {
30 
31     /** Get a {@link TrustedDeviceEntity} based on device id. */
32     @Query("SELECT * FROM trusted_devices WHERE id LIKE :deviceId LIMIT 1")
getTrustedDevice(String deviceId)33     TrustedDeviceEntity getTrustedDevice(String deviceId);
34 
35     /** Get all {@link TrustedDeviceEntity}s associated with a user. */
36     @Query("SELECT * FROM trusted_devices WHERE userId LIKE :userId")
getTrustedDevicesForUser(int userId)37     List<TrustedDeviceEntity> getTrustedDevicesForUser(int userId);
38 
39     /**
40      * Add a {@link TrustedDeviceEntity}. Replace if a device already exists with the same
41      * device id.
42      */
43     @Insert(onConflict = OnConflictStrategy.REPLACE)
addOrReplaceTrustedDevice(TrustedDeviceEntity trustedDevice)44     void addOrReplaceTrustedDevice(TrustedDeviceEntity trustedDevice);
45 
46     /** Remove a {@link TrustedDeviceEntity}. */
47     @Delete
removeTrustedDevice(TrustedDeviceEntity trustedDevice)48     void removeTrustedDevice(TrustedDeviceEntity trustedDevice);
49 }
50