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 package com.android.car.occupantconnection; 17 18 import android.annotation.NonNull; 19 import android.car.CarOccupantZoneManager.OccupantZoneInfo; 20 import android.text.TextUtils; 21 22 import java.util.Objects; 23 24 /** A class used to identify a client. */ 25 final class ClientId { 26 27 /** The occupant zone that the client runs in. */ 28 public final OccupantZoneInfo occupantZone; 29 /** The user ID of the client. */ 30 public final int userId; 31 /** The package name of the client. */ 32 public final String packageName; 33 34 // TODO(b/275370184): use factory method pattern. ClientId(@onNull OccupantZoneInfo occupantZone, int userId, @NonNull String packageName)35 public ClientId(@NonNull OccupantZoneInfo occupantZone, int userId, 36 @NonNull String packageName) { 37 this.occupantZone = Objects.requireNonNull(occupantZone, "occupantZone cannot be null"); 38 this.userId = userId; 39 this.packageName = Objects.requireNonNull(packageName, "packageName cannot be null"); 40 } 41 42 @Override equals(Object o)43 public boolean equals(Object o) { 44 if (this == o) { 45 return true; 46 } 47 if (!(o instanceof ClientId)) { 48 return false; 49 } 50 ClientId other = (ClientId) o; 51 return occupantZone.equals(other.occupantZone) && userId == other.userId 52 && TextUtils.equals(packageName, other.packageName); 53 54 } 55 56 @Override hashCode()57 public int hashCode() { 58 return Objects.hash(occupantZone, userId, packageName); 59 } 60 61 @Override toString()62 public String toString() { 63 return "ClientId[occupantZone=" + occupantZone + ", userId=" + userId 64 + ", packageName=" + packageName + "]"; 65 } 66 } 67