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.annotation.NonNull; 20 import androidx.annotation.Nullable; 21 import androidx.room.Entity; 22 import androidx.room.PrimaryKey; 23 24 import com.android.car.connecteddevice.model.AssociatedDevice; 25 26 /** Table entity representing an associated device. */ 27 @Entity(tableName = "associated_devices") 28 public class AssociatedDeviceEntity { 29 30 /** Id of the device. */ 31 @PrimaryKey 32 @NonNull 33 public String id; 34 35 /** Id of user associated with this device. */ 36 public int userId; 37 38 /** Bluetooth address of the device. */ 39 @Nullable 40 public String address; 41 42 /** Bluetooth device name. */ 43 @Nullable 44 public String name; 45 46 /** {@code true} if the connection is enabled for this device.*/ 47 public boolean isConnectionEnabled; 48 AssociatedDeviceEntity()49 public AssociatedDeviceEntity() { } 50 AssociatedDeviceEntity(int userId, AssociatedDevice associatedDevice, boolean isConnectionEnabled)51 public AssociatedDeviceEntity(int userId, AssociatedDevice associatedDevice, 52 boolean isConnectionEnabled) { 53 this.userId = userId; 54 id = associatedDevice.getDeviceId(); 55 address = associatedDevice.getDeviceAddress(); 56 name = associatedDevice.getDeviceName(); 57 this.isConnectionEnabled = isConnectionEnabled; 58 } 59 60 /** Return a new {@link AssociatedDevice} of this entity. */ toAssociatedDevice()61 public AssociatedDevice toAssociatedDevice() { 62 return new AssociatedDevice(id, address, name, isConnectionEnabled); 63 } 64 } 65