blob: 5f0c8d729e74699c54b5ab453b7aa690fda084cb [file] [log] [blame]
Sailesh Nepale7ef59a2014-07-08 21:48:22 -07001/*
2 * Copyright (C) 2014 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
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070018
Pranav Madapurmathac29a0c2023-05-25 21:58:19 +000019import android.annotation.Nullable;
Ihab Awada7684ed2015-05-13 11:34:53 -070020import android.annotation.SystemApi;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070021import android.content.ComponentName;
22import android.content.Context;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070023import android.graphics.drawable.Drawable;
Ihab Awada7684ed2015-05-13 11:34:53 -070024import android.graphics.drawable.Icon;
Pranav Madapurmathac29a0c2023-05-25 21:58:19 +000025import android.os.Binder;
Sailesh Nepal61203862014-07-11 14:50:13 -070026import android.os.Bundle;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070027import android.os.Parcel;
28import android.os.Parcelable;
Pranav Madapurmathac29a0c2023-05-25 21:58:19 +000029import android.os.UserHandle;
30
31import com.android.internal.annotations.VisibleForTesting;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070032
Sailesh Nepalf20b9162014-08-12 11:53:32 -070033import java.util.Objects;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070034
35/**
36 * Contains status label and icon displayed in the in-call UI.
37 */
38public final class StatusHints implements Parcelable {
39
Santos Cordon146a3e32014-07-21 00:00:44 -070040 private final CharSequence mLabel;
Pranav Madapurmathac29a0c2023-05-25 21:58:19 +000041 private Icon mIcon;
Sailesh Nepal61203862014-07-11 14:50:13 -070042 private final Bundle mExtras;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070043
Ihab Awada7684ed2015-05-13 11:34:53 -070044 /**
45 * @hide
46 */
47 @SystemApi @Deprecated
Nancy Chenea38cca2014-09-05 16:38:49 -070048 public StatusHints(ComponentName packageName, CharSequence label, int iconResId,
49 Bundle extras) {
Sailesh Nepald9be9cf2015-05-14 18:28:10 -070050 this(label, iconResId == 0 ? null : Icon.createWithResource(packageName.getPackageName(),
51 iconResId), extras);
Ihab Awada7684ed2015-05-13 11:34:53 -070052 }
53
54 public StatusHints(CharSequence label, Icon icon, Bundle extras) {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070055 mLabel = label;
Pranav Madapurmathac29a0c2023-05-25 21:58:19 +000056 mIcon = validateAccountIconUserBoundary(icon, Binder.getCallingUserHandle());
Sailesh Nepal61203862014-07-11 14:50:13 -070057 mExtras = extras;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070058 }
59
60 /**
Pranav Madapurmathac29a0c2023-05-25 21:58:19 +000061 * @param icon
62 * @hide
63 */
64 @VisibleForTesting
65 public StatusHints(@Nullable Icon icon) {
66 mLabel = null;
67 mExtras = null;
68 mIcon = icon;
69 }
70
71 /**
72 *
73 * @param icon
74 * @hide
75 */
76 public void setIcon(@Nullable Icon icon) {
77 mIcon = icon;
78 }
79
80 /**
Nancy Chenea38cca2014-09-05 16:38:49 -070081 * @return A package used to load the icon.
Ihab Awada7684ed2015-05-13 11:34:53 -070082 *
83 * @hide
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070084 */
Ihab Awada7684ed2015-05-13 11:34:53 -070085 @SystemApi @Deprecated
Nancy Chenea38cca2014-09-05 16:38:49 -070086 public ComponentName getPackageName() {
Ihab Awada7684ed2015-05-13 11:34:53 -070087 // Minimal compatibility shim for legacy apps' tests
88 return new ComponentName("", "");
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070089 }
90
91 /**
92 * @return The label displayed in the in-call UI.
93 */
Santos Cordon146a3e32014-07-21 00:00:44 -070094 public CharSequence getLabel() {
Sailesh Nepale7ef59a2014-07-08 21:48:22 -070095 return mLabel;
96 }
97
98 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070099 * The icon resource ID for the icon to show.
100 *
101 * @return A resource ID.
Ihab Awada7684ed2015-05-13 11:34:53 -0700102 *
103 * @hide
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700104 */
Ihab Awada7684ed2015-05-13 11:34:53 -0700105 @SystemApi @Deprecated
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700106 public int getIconResId() {
Ihab Awada7684ed2015-05-13 11:34:53 -0700107 // Minimal compatibility shim for legacy apps' tests
108 return 0;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700109 }
110
111 /**
112 * @return An icon displayed in the in-call UI.
Ihab Awada7684ed2015-05-13 11:34:53 -0700113 *
114 * @hide
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700115 */
Ihab Awada7684ed2015-05-13 11:34:53 -0700116 @SystemApi @Deprecated
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700117 public Drawable getIcon(Context context) {
Ihab Awada7684ed2015-05-13 11:34:53 -0700118 return mIcon.loadDrawable(context);
119 }
120
121 /**
122 * @return An icon depicting the status.
123 */
124 public Icon getIcon() {
125 return mIcon;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700126 }
127
Sailesh Nepal61203862014-07-11 14:50:13 -0700128 /**
129 * @return Extra data used to display status.
130 */
131 public Bundle getExtras() {
132 return mExtras;
133 }
134
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700135 @Override
136 public int describeContents() {
137 return 0;
138 }
139
Pranav Madapurmathac29a0c2023-05-25 21:58:19 +0000140 /**
141 * Validates the StatusHints image icon to see if it's not in the calling user space.
142 * Invalidates the icon if so, otherwise returns back the original icon.
143 *
144 * @param icon
145 * @return icon (validated)
146 * @hide
147 */
148 public static Icon validateAccountIconUserBoundary(Icon icon, UserHandle callingUserHandle) {
149 // Refer to Icon#getUriString for context. The URI string is invalid for icons of
150 // incompatible types.
151 if (icon != null && (icon.getType() == Icon.TYPE_URI
152 || icon.getType() == Icon.TYPE_URI_ADAPTIVE_BITMAP)) {
153 String encodedUser = icon.getUri().getEncodedUserInfo();
154 // If there is no encoded user, the URI is calling into the calling user space
155 if (encodedUser != null) {
156 int userId = Integer.parseInt(encodedUser);
157 // Do not try to save the icon if the user id isn't in the calling user space.
158 if (userId != callingUserHandle.getIdentifier()) return null;
159 }
160 }
161 return icon;
162 }
163
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700164 @Override
165 public void writeToParcel(Parcel out, int flags) {
Santos Cordon146a3e32014-07-21 00:00:44 -0700166 out.writeCharSequence(mLabel);
Ihab Awada7684ed2015-05-13 11:34:53 -0700167 out.writeParcelable(mIcon, 0);
Sailesh Nepal61203862014-07-11 14:50:13 -0700168 out.writeParcelable(mExtras, 0);
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700169 }
170
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700171 public static final @android.annotation.NonNull Creator<StatusHints> CREATOR
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700172 = new Creator<StatusHints>() {
173 public StatusHints createFromParcel(Parcel in) {
174 return new StatusHints(in);
175 }
176
177 public StatusHints[] newArray(int size) {
178 return new StatusHints[size];
179 }
180 };
181
182 private StatusHints(Parcel in) {
Santos Cordon146a3e32014-07-21 00:00:44 -0700183 mLabel = in.readCharSequence();
Bernardo Rufino1a5cb382022-01-14 17:35:36 +0000184 mIcon = in.readParcelable(getClass().getClassLoader(), android.graphics.drawable.Icon.class);
185 mExtras = in.readParcelable(getClass().getClassLoader(), android.os.Bundle.class);
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700186 }
187
Sailesh Nepalf20b9162014-08-12 11:53:32 -0700188 @Override
189 public boolean equals(Object other) {
190 if (other != null && other instanceof StatusHints) {
191 StatusHints otherHints = (StatusHints) other;
Ihab Awada7684ed2015-05-13 11:34:53 -0700192 return Objects.equals(otherHints.getLabel(), getLabel()) &&
193 Objects.equals(otherHints.getIcon(), getIcon()) &&
Sailesh Nepalf20b9162014-08-12 11:53:32 -0700194 Objects.equals(otherHints.getExtras(), getExtras());
195 }
196 return false;
197 }
198
199 @Override
200 public int hashCode() {
Ihab Awada7684ed2015-05-13 11:34:53 -0700201 return Objects.hashCode(mLabel) + Objects.hashCode(mIcon) + Objects.hashCode(mExtras);
Sailesh Nepalf20b9162014-08-12 11:53:32 -0700202 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700203}