1 package com.android.car.messenger; 2 3 4 import android.os.Parcel; 5 import android.os.Parcelable; 6 7 /** 8 * {@link CompositeKey} subclass used to identify Notification info for a sender; 9 * it uses a combination of senderContactUri and senderContactName as the secondary key. 10 */ 11 public class SenderKey extends CompositeKey implements Parcelable { 12 SenderKey(String deviceAddress, String key)13 private SenderKey(String deviceAddress, String key) { 14 super(deviceAddress, key); 15 } 16 SenderKey(MapMessage message)17 SenderKey(MapMessage message) { 18 // Use a combination of senderName and senderContactUri for key. Ideally we would use 19 // only senderContactUri (which is encoded phone no.). However since some phones don't 20 // provide these, we fall back to senderName. Since senderName may not be unique, we 21 // include senderContactUri also to provide uniqueness in cases it is available. 22 this(message.getDeviceAddress(), 23 message.getSenderName() + "/" + message.getSenderContactUri()); 24 } 25 26 @Override toString()27 public String toString() { 28 return String.format("SenderKey: %s -- %s", getDeviceAddress(), getSubKey()); 29 } 30 31 @Override describeContents()32 public int describeContents() { 33 return 0; 34 } 35 36 @Override writeToParcel(Parcel dest, int flags)37 public void writeToParcel(Parcel dest, int flags) { 38 dest.writeString(getDeviceAddress()); 39 dest.writeString(getSubKey()); 40 } 41 42 /** Creates {@link SenderKey} instances from {@link Parcel} sources. */ 43 public static final Parcelable.Creator<SenderKey> CREATOR = 44 new Parcelable.Creator<SenderKey>() { 45 @Override 46 public SenderKey createFromParcel(Parcel source) { 47 return new SenderKey(source.readString(), source.readString()); 48 } 49 50 @Override 51 public SenderKey[] newArray(int size) { 52 return new SenderKey[size]; 53 } 54 }; 55 56 } 57 58