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.connecteddevice.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 /** 28 * Queries for associated device table. 29 */ 30 @Dao 31 public interface AssociatedDeviceDao { 32 33 /** Get an associated device based on device id. */ 34 @Query("SELECT * FROM associated_devices WHERE id LIKE :deviceId LIMIT 1") getAssociatedDevice(String deviceId)35 AssociatedDeviceEntity getAssociatedDevice(String deviceId); 36 37 /** Get all {@link AssociatedDeviceEntity}s associated with a user. */ 38 @Query("SELECT * FROM associated_devices WHERE userId LIKE :userId") getAssociatedDevicesForUser(int userId)39 List<AssociatedDeviceEntity> getAssociatedDevicesForUser(int userId); 40 41 /** 42 * Add a {@link AssociatedDeviceEntity}. Replace if a device already exists with the same 43 * device id. 44 */ 45 @Insert(onConflict = OnConflictStrategy.REPLACE) addOrReplaceAssociatedDevice(AssociatedDeviceEntity associatedDevice)46 void addOrReplaceAssociatedDevice(AssociatedDeviceEntity associatedDevice); 47 48 /** Remove a {@link AssociatedDeviceEntity}. */ 49 @Delete removeAssociatedDevice(AssociatedDeviceEntity connectedDevice)50 void removeAssociatedDevice(AssociatedDeviceEntity connectedDevice); 51 52 /** Get the key associated with a device id. */ 53 @Query("SELECT * FROM associated_device_keys WHERE id LIKE :deviceId LIMIT 1") getAssociatedDeviceKey(String deviceId)54 AssociatedDeviceKeyEntity getAssociatedDeviceKey(String deviceId); 55 56 /** 57 * Add a {@link AssociatedDeviceKeyEntity}. Replace if a device key already exists with the 58 * same device id. 59 */ 60 @Insert(onConflict = OnConflictStrategy.REPLACE) addOrReplaceAssociatedDeviceKey(AssociatedDeviceKeyEntity keyEntity)61 void addOrReplaceAssociatedDeviceKey(AssociatedDeviceKeyEntity keyEntity); 62 63 /** Remove a {@link AssociatedDeviceKeyEntity}. */ 64 @Delete removeAssociatedDeviceKey(AssociatedDeviceKeyEntity keyEntity)65 void removeAssociatedDeviceKey(AssociatedDeviceKeyEntity keyEntity); 66 } 67