1 /*
2  * Copyright (C) 2022 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.settingslib.mobile.dataservice;
18 
19 import android.text.TextUtils;
20 
21 import androidx.annotation.NonNull;
22 import androidx.room.ColumnInfo;
23 import androidx.room.Entity;
24 import androidx.room.PrimaryKey;
25 
26 @Entity(tableName = DataServiceUtils.UiccInfoData.TABLE_NAME)
27 public class UiccInfoEntity {
28 
UiccInfoEntity(@onNull String subId, @NonNull String physicalSlotIndex, int logicalSlotIndex, int cardId, boolean isEuicc, boolean isMultipleEnabledProfilesSupported, int cardState, boolean isRemovable, boolean isActive, int portIndex)29     public UiccInfoEntity(@NonNull String subId, @NonNull String physicalSlotIndex,
30             int logicalSlotIndex, int cardId, boolean isEuicc,
31             boolean isMultipleEnabledProfilesSupported, int cardState, boolean isRemovable,
32             boolean isActive, int portIndex) {
33         this.subId = subId;
34         this.physicalSlotIndex = physicalSlotIndex;
35         this.logicalSlotIndex = logicalSlotIndex;
36         this.cardId = cardId;
37         this.isEuicc = isEuicc;
38         this.isMultipleEnabledProfilesSupported = isMultipleEnabledProfilesSupported;
39         this.cardState = cardState;
40         this.isRemovable = isRemovable;
41         this.isActive = isActive;
42         this.portIndex = portIndex;
43     }
44 
45     @PrimaryKey
46     @ColumnInfo(name = DataServiceUtils.UiccInfoData.COLUMN_ID, index = true)
47     @NonNull
48     public String subId;
49 
50     @ColumnInfo(name = DataServiceUtils.UiccInfoData.COLUMN_PHYSICAL_SLOT_INDEX)
51     @NonNull
52     public String physicalSlotIndex;
53 
54     @ColumnInfo(name = DataServiceUtils.UiccInfoData.COLUMN_LOGICAL_SLOT_INDEX)
55     public int logicalSlotIndex;
56 
57     @ColumnInfo(name = DataServiceUtils.UiccInfoData.COLUMN_CARD_ID)
58     public int cardId;
59 
60     @ColumnInfo(name = DataServiceUtils.UiccInfoData.COLUMN_IS_EUICC)
61     public boolean isEuicc;
62 
63     @ColumnInfo(name = DataServiceUtils.UiccInfoData.COLUMN_IS_MULTIPLE_ENABLED_PROFILES_SUPPORTED)
64     public boolean isMultipleEnabledProfilesSupported;
65 
66     @ColumnInfo(name = DataServiceUtils.UiccInfoData.COLUMN_CARD_STATE)
67     public int cardState;
68 
69     @ColumnInfo(name = DataServiceUtils.UiccInfoData.COLUMN_IS_REMOVABLE)
70     public boolean isRemovable;
71 
72     @ColumnInfo(name = DataServiceUtils.UiccInfoData.COLUMN_IS_ACTIVE)
73     public boolean isActive;
74 
75     @ColumnInfo(name = DataServiceUtils.UiccInfoData.COLUMN_PORT_INDEX)
76     public int portIndex;
77 
78 
79     @Override
hashCode()80     public int hashCode() {
81         int result = 17;
82         result = 31 * result + subId.hashCode();
83         result = 31 * result + physicalSlotIndex.hashCode();
84         result = 31 * result + logicalSlotIndex;
85         result = 31 * result + cardId;
86         result = 31 * result + Boolean.hashCode(isEuicc);
87         result = 31 * result + Boolean.hashCode(isMultipleEnabledProfilesSupported);
88         result = 31 * result + cardState;
89         result = 31 * result + Boolean.hashCode(isRemovable);
90         result = 31 * result + Boolean.hashCode(isActive);
91         result = 31 * result + portIndex;
92         return result;
93     }
94 
95     @Override
equals(Object obj)96     public boolean equals(Object obj) {
97         if (this == obj) {
98             return true;
99         }
100         if (!(obj instanceof UiccInfoEntity)) {
101             return false;
102         }
103 
104         UiccInfoEntity info = (UiccInfoEntity) obj;
105         return  TextUtils.equals(subId, info.subId)
106                 && TextUtils.equals(physicalSlotIndex, info.physicalSlotIndex)
107                 && logicalSlotIndex == info.logicalSlotIndex
108                 && cardId == info.cardId
109                 && isEuicc == info.isEuicc
110                 && isMultipleEnabledProfilesSupported == info.isMultipleEnabledProfilesSupported
111                 && cardState == info.cardState
112                 && isRemovable == info.isRemovable
113                 && isActive == info.isActive
114                 && portIndex == info.portIndex;
115     }
116 
toString()117     public String toString() {
118         StringBuilder builder = new StringBuilder();
119         builder.append(" {UiccInfoEntity(subId = ")
120                 .append(subId)
121                 .append(", logicalSlotIndex = ")
122                 .append(physicalSlotIndex)
123                 .append(", logicalSlotIndex = ")
124                 .append(logicalSlotIndex)
125                 .append(", cardId = ")
126                 .append(cardId)
127                 .append(", isEuicc = ")
128                 .append(isEuicc)
129                 .append(", isMultipleEnabledProfilesSupported = ")
130                 .append(isMultipleEnabledProfilesSupported)
131                 .append(", cardState = ")
132                 .append(cardState)
133                 .append(", isRemovable = ")
134                 .append(isRemovable)
135                 .append(", isActive = ")
136                 .append(isActive)
137                 .append(", portIndex = ")
138                 .append(portIndex)
139                 .append(")}");
140         return builder.toString();
141     }
142 }
143