1 /*
2  * Copyright (C) 2020 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.model;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 
22 import java.util.Objects;
23 
24 /**
25  * View model representing a connected device.
26  */
27 public class ConnectedDevice {
28 
29     private final String mDeviceId;
30 
31     private final String mDeviceName;
32 
33     private final boolean mBelongsToActiveUser;
34 
35     private final boolean mHasSecureChannel;
36 
37     /**
38      * Create a new connected device.
39      *
40      * @param deviceId Id of the connected device.
41      * @param deviceName Name of the connected device. {@code null} if not known.
42      * @param belongsToActiveUser User associated with this device is currently in the foreground.
43      * @param hasSecureChannel {@code true} if a secure channel is available for this device.
44      */
ConnectedDevice(@onNull String deviceId, @Nullable String deviceName, boolean belongsToActiveUser, boolean hasSecureChannel)45     public ConnectedDevice(@NonNull String deviceId, @Nullable String deviceName,
46             boolean belongsToActiveUser, boolean hasSecureChannel) {
47         mDeviceId = deviceId;
48         mDeviceName = deviceName;
49         mBelongsToActiveUser = belongsToActiveUser;
50         mHasSecureChannel = hasSecureChannel;
51     }
52 
53     /** Returns the id for this device. */
54     @NonNull
getDeviceId()55     public String getDeviceId() {
56         return mDeviceId;
57     }
58 
59     /** Returns the name for this device or {@code null} if not known. */
60     @Nullable
getDeviceName()61     public String getDeviceName() {
62         return mDeviceName;
63     }
64 
65     /**
66      * Returns {@code true} if this device is associated with the user currently in the foreground.
67      */
isAssociatedWithActiveUser()68     public boolean isAssociatedWithActiveUser() {
69         return mBelongsToActiveUser;
70     }
71 
72     /** Returns {@code true} if this device has a secure channel available. */
hasSecureChannel()73     public boolean hasSecureChannel() {
74         return mHasSecureChannel;
75     }
76 
77     @Override
equals(Object obj)78     public boolean equals(Object obj) {
79         if (obj == this) {
80             return true;
81         }
82         if (!(obj instanceof ConnectedDevice)) {
83             return false;
84         }
85         ConnectedDevice connectedDevice = (ConnectedDevice) obj;
86         return Objects.equals(mDeviceId, connectedDevice.mDeviceId)
87                 && Objects.equals(mDeviceName, connectedDevice.mDeviceName)
88                 && mBelongsToActiveUser == connectedDevice.mBelongsToActiveUser
89                 && mHasSecureChannel == connectedDevice.mHasSecureChannel;
90     }
91 
92     @Override
hashCode()93     public int hashCode() {
94         return Objects.hash(mDeviceId, mDeviceName, mBelongsToActiveUser, mHasSecureChannel);
95     }
96 }
97