1 /* 2 * Copyright (C) 2023 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.devicelockcontroller.common; 18 19 import android.text.TextUtils; 20 21 import androidx.annotation.NonNull; 22 23 import com.android.devicelockcontroller.common.DeviceLockConstants.DeviceIdType; 24 25 /** 26 * A data structure class that is used to represent a device unique identifier such as IMEI, MEID, 27 * etc. 28 */ 29 public final class DeviceId { 30 31 /** Type of the identifier */ 32 @DeviceIdType 33 private final int mType; 34 /** Number of the identifier */ 35 private final String mId; 36 DeviceId(int type, @NonNull String id)37 public DeviceId(int type, @NonNull String id) { 38 mType = type; 39 mId = id; 40 } 41 42 /** 43 * @return Type of this unique identifier. 44 */ 45 @DeviceIdType getType()46 public int getType() { 47 return mType; 48 } 49 50 /** 51 * @return Number of this unique identifier. 52 */ 53 @NonNull getId()54 public String getId() { 55 return mId; 56 } 57 58 /** 59 * Check if the input DeviceId equals to this DeviceId. 60 * 61 * @return true if the input id has same type and number as this one; false otherwise. 62 */ 63 @Override equals(Object obj)64 public boolean equals(Object obj) { 65 if (!(obj instanceof DeviceId)) return false; 66 DeviceId deviceId = (DeviceId) obj; 67 return getType() == deviceId.getType() && TextUtils.equals(getId(), deviceId.getId()); 68 } 69 70 @Override hashCode()71 public int hashCode() { 72 return getType() * getId().hashCode(); 73 } 74 } 75