1 /* 2 * Copyright (C) 2020 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.car.messenger.core.models; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 22 import androidx.annotation.NonNull; 23 import androidx.annotation.Nullable; 24 25 import java.time.Instant; 26 27 /** 28 * A user account can represent a bluetooth connection to a phone sim or a user account. There can 29 * be more than one user accounts during a drive. The user id can be used to retrieve data for that 30 * specific account. The user name can be used to display the user the name of the account/account. 31 */ 32 public class UserAccount implements Parcelable { 33 private final int mId; 34 @Nullable private final String mIccId; 35 @NonNull private final String mName; 36 @NonNull private final Instant mConnectionTime; 37 UserAccount( int id, @NonNull String name, @Nullable String iccId, @NonNull Instant connectionTime)38 public UserAccount( 39 int id, @NonNull String name, @Nullable String iccId, @NonNull Instant connectionTime) { 40 mId = id; 41 mIccId = iccId; 42 mName = name; 43 mConnectionTime = connectionTime; 44 } 45 UserAccount(Parcel in)46 protected UserAccount(Parcel in) { 47 this.mId = in.readInt(); 48 this.mIccId = in.readString(); 49 this.mName = in.readString(); 50 this.mConnectionTime = (Instant) in.readSerializable(); 51 } 52 53 @NonNull 54 public static final Creator<UserAccount> CREATOR = 55 new Creator<UserAccount>() { 56 @Override 57 public UserAccount createFromParcel(@NonNull Parcel source) { 58 return new UserAccount(source); 59 } 60 61 @Override 62 public UserAccount[] newArray(int size) { 63 return new UserAccount[size]; 64 } 65 }; 66 67 /** 68 * The user id can be used to retrieve data for that specific account. 69 * 70 * @return the unique identifier for the user account 71 */ getId()72 public int getId() { 73 return mId; 74 } 75 76 /** 77 * The IccId is a globally unique serial number—a one-of-a-kind signature that identifies the 78 * SIM card itself or bluetooth address of the account. 79 * 80 * <p>For device/account disambiguation for Contact db queries, this field maps to {@link 81 * android.provider.ContactsContract.RawContacts#ACCOUNT_NAME} in the Contacts database. 82 * 83 * @return The id or null, if not set 84 */ 85 @Nullable getIccId()86 public String getIccId() { 87 return mIccId; 88 } 89 90 /** The display name for the account or account. */ 91 @NonNull getName()92 public String getName() { 93 return mName; 94 } 95 96 /** Returns the {@link Instant} the car was connected to this {@link UserAccount} */ 97 @NonNull getConnectionTime()98 public Instant getConnectionTime() { 99 return mConnectionTime; 100 } 101 102 @Override describeContents()103 public int describeContents() { 104 return 0; 105 } 106 107 @Override writeToParcel(Parcel dest, int flags)108 public void writeToParcel(Parcel dest, int flags) { 109 dest.writeInt(this.mId); 110 dest.writeString(mIccId); 111 dest.writeString(this.mName); 112 dest.writeSerializable(this.mConnectionTime); 113 } 114 } 115