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.libraries.rcs.simpleclient.protocol.cpim;
18 
19 import java.time.ZoneId;
20 import java.time.ZonedDateTime;
21 import java.time.format.DateTimeFormatter;
22 import java.util.Random;
23 
24 /** Collections of utility functions for CPIM */
25 public class CpimUtils {
26     private static final String ANONYMOUS_URI = "<sip:anonymous@anonymous.invalid>";
27     public static final String CPIM_CONTENT_TYPE = "message/cpim";
28 
CpimUtils()29     private CpimUtils() {
30     }
31 
32     @SuppressWarnings("AndroidJdkLibsChecker")
createForText(String text)33     public static SimpleCpimMessage createForText(String text) {
34         return SimpleCpimMessage.newBuilder()
35                 .addNamespace("imdn", "urn:ietf:params:imdn")
36                 .addHeader("imdn.Message-ID", generateImdnMessageId())
37                 .addHeader("imdn.Disposition-Notification", "positive-delivery, display")
38                 .addHeader("To", ANONYMOUS_URI)
39                 .addHeader("From", ANONYMOUS_URI)
40                 .addHeader("DateTime", ZonedDateTime.now(ZoneId.systemDefault()).format(
41                         DateTimeFormatter.ISO_INSTANT))
42                 .setContentType("text/plain")
43                 .setContent(text)
44                 .build();
45     }
46 
generateImdnMessageId()47     private static String generateImdnMessageId() {
48         Random random = new Random();
49         return "Test_" + random.nextInt(1000000);
50     }
51 }
52