Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 android.print; |
| 18 | |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Mathew Inwood | 06bf4b7 | 2018-07-31 16:36:56 +0100 | [diff] [blame] | 20 | import android.annotation.UnsupportedAppUsage; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 21 | import android.content.ComponentName; |
| 22 | import android.os.Parcel; |
| 23 | import android.os.Parcelable; |
Philip P. Moltmann | cdf2b40 | 2016-01-14 14:45:04 -0800 | [diff] [blame] | 24 | |
| 25 | import com.android.internal.util.Preconditions; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * This class represents the unique id of a printer. |
| 29 | */ |
| 30 | public final class PrinterId implements Parcelable { |
| 31 | |
Philip P. Moltmann | cdf2b40 | 2016-01-14 14:45:04 -0800 | [diff] [blame] | 32 | private final @NonNull ComponentName mServiceName; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 33 | |
Philip P. Moltmann | cdf2b40 | 2016-01-14 14:45:04 -0800 | [diff] [blame] | 34 | private final @NonNull String mLocalId; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * Creates a new instance. |
| 38 | * |
Svetoslav Ganov | 8c43376 | 2013-08-02 14:22:19 -0700 | [diff] [blame] | 39 | * @param serviceName The managing print service. |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 40 | * @param localId The locally unique id within the managing service. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 41 | * |
| 42 | * @hide |
| 43 | */ |
Philip P. Moltmann | cdf2b40 | 2016-01-14 14:45:04 -0800 | [diff] [blame] | 44 | public PrinterId(@NonNull ComponentName serviceName, @NonNull String localId) { |
Svetoslav Ganov | 8c43376 | 2013-08-02 14:22:19 -0700 | [diff] [blame] | 45 | mServiceName = serviceName; |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 46 | mLocalId = localId; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Philip P. Moltmann | cdf2b40 | 2016-01-14 14:45:04 -0800 | [diff] [blame] | 49 | private PrinterId(@NonNull Parcel parcel) { |
| 50 | mServiceName = Preconditions.checkNotNull((ComponentName) parcel.readParcelable(null)); |
| 51 | mLocalId = Preconditions.checkNotNull(parcel.readString()); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /** |
| 55 | * The id of the print service this printer is managed by. |
| 56 | * |
| 57 | * @return The print service component name. |
| 58 | * |
| 59 | * @hide |
| 60 | */ |
Mathew Inwood | 06bf4b7 | 2018-07-31 16:36:56 +0100 | [diff] [blame] | 61 | @UnsupportedAppUsage |
Philip P. Moltmann | cdf2b40 | 2016-01-14 14:45:04 -0800 | [diff] [blame] | 62 | public @NonNull ComponentName getServiceName() { |
Svetoslav Ganov | 8c43376 | 2013-08-02 14:22:19 -0700 | [diff] [blame] | 63 | return mServiceName; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | /** |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 67 | * Gets the id of this printer which is unique in the context |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 68 | * of the print service that manages it. |
| 69 | * |
Svetoslav Ganov | 8c43376 | 2013-08-02 14:22:19 -0700 | [diff] [blame] | 70 | * @return The printer name. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 71 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 72 | public @NonNull String getLocalId() { |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 73 | return mLocalId; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public int describeContents() { |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public void writeToParcel(Parcel parcel, int flags) { |
Svetoslav Ganov | 8c43376 | 2013-08-02 14:22:19 -0700 | [diff] [blame] | 83 | parcel.writeParcelable(mServiceName, flags); |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 84 | parcel.writeString(mLocalId); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public boolean equals(Object object) { |
| 89 | if (this == object) { |
| 90 | return true; |
| 91 | } |
| 92 | if (object == null) { |
| 93 | return false; |
| 94 | } |
| 95 | if (getClass() != object.getClass()) { |
| 96 | return false; |
| 97 | } |
| 98 | PrinterId other = (PrinterId) object; |
Philip P. Moltmann | cdf2b40 | 2016-01-14 14:45:04 -0800 | [diff] [blame] | 99 | if (!mServiceName.equals(other.mServiceName)) { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 100 | return false; |
| 101 | } |
Philip P. Moltmann | cdf2b40 | 2016-01-14 14:45:04 -0800 | [diff] [blame] | 102 | if (!mLocalId.equals(other.mLocalId)) { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 103 | return false; |
| 104 | } |
| 105 | return true; |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public int hashCode() { |
| 110 | final int prime = 31; |
| 111 | int hashCode = 1; |
Philip P. Moltmann | cdf2b40 | 2016-01-14 14:45:04 -0800 | [diff] [blame] | 112 | hashCode = prime * hashCode + mServiceName.hashCode(); |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 113 | hashCode = prime * hashCode + mLocalId.hashCode(); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 114 | return hashCode; |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public String toString() { |
| 119 | StringBuilder builder = new StringBuilder(); |
| 120 | builder.append("PrinterId{"); |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 121 | builder.append("serviceName=").append(mServiceName.flattenToString()); |
| 122 | builder.append(", localId=").append(mLocalId); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 123 | builder.append('}'); |
| 124 | return builder.toString(); |
| 125 | } |
| 126 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 127 | public static final @android.annotation.NonNull Parcelable.Creator<PrinterId> CREATOR = |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 128 | new Creator<PrinterId>() { |
| 129 | @Override |
| 130 | public PrinterId createFromParcel(Parcel parcel) { |
| 131 | return new PrinterId(parcel); |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public PrinterId[] newArray(int size) { |
| 136 | return new PrinterId[size]; |
| 137 | } |
| 138 | }; |
| 139 | } |