Loading src/java/com/android/ims/rcs/uce/presence/pidfparser/ElementBase.java 0 → 100644 +47 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.ims.rcs.uce.presence.pidfparser; import org.xmlpull.v1.XmlSerializer; import java.io.IOException; /** * The base class of the pidf element. */ public abstract class ElementBase { private String mNamespace; private String mElementName; public ElementBase() { mNamespace = initNamespace(); mElementName = initElementName(); } protected abstract String initNamespace(); protected abstract String initElementName(); protected String getNamespace() { return mNamespace; } protected String getElementName() { return mElementName; } public abstract void serialize(XmlSerializer serializer) throws IOException; } src/java/com/android/ims/rcs/uce/presence/pidfparser/PidfParser.java 0 → 100644 +90 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.ims.rcs.uce.presence.pidfparser; import android.telephony.ims.RcsContactUceCapability; import com.android.ims.rcs.uce.presence.pidfparser.capabilities.CapsConstant; import com.android.ims.rcs.uce.presence.pidfparser.omapres.OmaPresConstant; import com.android.ims.rcs.uce.presence.pidfparser.pidf.PidfConstant; import com.android.ims.rcs.uce.presence.pidfparser.pidf.Presence; import com.android.ims.rcs.uce.presence.pidfparser.pidf.Tuple; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserFactory; import org.xmlpull.v1.XmlSerializer; import java.io.IOException; import java.io.StringWriter; /** * The pidf parser class */ public class PidfParser { /** * Convert the RcsContactUceCapability to the string of pidf. */ public static String convertToPidf(RcsContactUceCapability capabilities) { StringWriter pidfWriter = new StringWriter(); try { // Init the instance of the XmlSerializer. XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); XmlSerializer serializer = factory.newSerializer(); // setup output and namespace serializer.setOutput(pidfWriter); serializer.setPrefix("", PidfConstant.NAMESPACE); serializer.setPrefix("op", OmaPresConstant.NAMESPACE); serializer.setPrefix("caps", CapsConstant.NAMESPACE); // Get the Presence element Presence presence = getPresence(capabilities); // Start serializing. serializer.startDocument(PidfParserConstant.ENCODING_UTF_8, true); presence.serialize(serializer); serializer.endDocument(); serializer.flush(); } catch (XmlPullParserException parserEx) { parserEx.printStackTrace(); return null; } catch (IOException ioException) { ioException.printStackTrace(); return null; } return pidfWriter.toString(); } private static Presence getPresence(RcsContactUceCapability capabilities) { // Create "presence" element which is the root element of the pidf Presence presence = new Presence(capabilities); // Add the Capabilities discovery via Presence tuple. Tuple capsDiscoveryTuple = TupleFactory.getCapabilityDiscoveryTuple(capabilities); if (capsDiscoveryTuple != null) { presence.addTuple(capsDiscoveryTuple); } // Add the VoLTE voice/video tuple. Tuple ipCallTuple = TupleFactory.getIpCallTuple(capabilities); if (ipCallTuple != null) { presence.addTuple(ipCallTuple); } return presence; } } src/java/com/android/ims/rcs/uce/presence/pidfparser/PidfParserConstant.java 0 → 100644 +39 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.ims.rcs.uce.presence.pidfparser; /** * The constant of the pidf */ public class PidfParserConstant { /** * The UTF-8 encoding format */ public static final String ENCODING_UTF_8 = "utf-8"; /** * The service id of the capabilities discovery via presence. */ public static final String SERVICE_ID_CAPS_DISCOVERY = "org.3gpp.urn:urn-7:3gpp-application.ims.iari.rcse.dp"; /** * The service id of the VoLTE voice and video call. */ public static final String SERVICE_ID_IpCall = "org.3gpp.urn:urn-7:3gpp-service.ims.icsi.mmtel"; } src/java/com/android/ims/rcs/uce/presence/pidfparser/TupleFactory.java 0 → 100644 +108 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.ims.rcs.uce.presence.pidfparser; import static android.telephony.ims.RcsContactUceCapability.CAPABILITY_DISCOVERY_VIA_PRESENCE; import static android.telephony.ims.RcsContactUceCapability.CAPABILITY_IP_VIDEO_CALL; import static android.telephony.ims.RcsContactUceCapability.CAPABILITY_IP_VOICE_CALL; import android.telephony.ims.RcsContactUceCapability; import com.android.ims.rcs.uce.presence.pidfparser.capabilities.Audio; import com.android.ims.rcs.uce.presence.pidfparser.capabilities.Duplex; import com.android.ims.rcs.uce.presence.pidfparser.capabilities.ServiceCaps; import com.android.ims.rcs.uce.presence.pidfparser.capabilities.Video; import com.android.ims.rcs.uce.presence.pidfparser.omapres.Description; import com.android.ims.rcs.uce.presence.pidfparser.omapres.ServiceDescription; import com.android.ims.rcs.uce.presence.pidfparser.omapres.ServiceId; import com.android.ims.rcs.uce.presence.pidfparser.omapres.Version; import com.android.ims.rcs.uce.presence.pidfparser.pidf.Basic; import com.android.ims.rcs.uce.presence.pidfparser.pidf.Contact; import com.android.ims.rcs.uce.presence.pidfparser.pidf.Status; import com.android.ims.rcs.uce.presence.pidfparser.pidf.Tuple; public class TupleFactory { /** * Get the Capability discovery by Presence tuple. */ public static Tuple getCapabilityDiscoveryTuple(RcsContactUceCapability contactCaps) { // Return directly if it is not supported. if (!contactCaps.isCapable(CAPABILITY_DISCOVERY_VIA_PRESENCE)) { return null; } Tuple tuple = new Tuple(); // The status element has a basic element with the value "open". Basic basic = new Basic(Basic.OPEN); Status status = new Status(); status.setBasic(basic); tuple.setStatus(status); // Describe the capability discovery via presence is supported. ServiceDescription serviceDescription = new ServiceDescription(); serviceDescription.setServiceId(new ServiceId(PidfParserConstant.SERVICE_ID_CAPS_DISCOVERY)); serviceDescription.setVersion(new Version(1, 0)); serviceDescription.setDescription(new Description("Capabilities Discovery")); tuple.addElement(serviceDescription); // The "contact" element Contact contact = new Contact(); contact.setContact(contactCaps.getContactUri().toString()); tuple.setContact(contact); return tuple; } /** * Get the VoLTE Voice and Video call tuple. */ public static Tuple getIpCallTuple(RcsContactUceCapability contactCaps) { Tuple tuple = new Tuple(); // The status element has a basic element with the value "open". Basic basic = new Basic(Basic.OPEN); Status status = new Status(); status.setBasic(basic); tuple.setStatus(status); // Describe the VoLTE voice and video. ServiceDescription serviceDescription = new ServiceDescription(); serviceDescription.setServiceId(new ServiceId(PidfParserConstant.SERVICE_ID_IpCall)); serviceDescription.setVersion(new Version(1, 0)); serviceDescription.setDescription(new Description("VoLTE Voice/Video service")); tuple.addElement(serviceDescription); // The service capabilities element ServiceCaps serviceCaps = new ServiceCaps(); Audio audio = new Audio(contactCaps.isCapable(CAPABILITY_IP_VOICE_CALL)); Video video = new Video(contactCaps.isCapable(CAPABILITY_IP_VIDEO_CALL)); Duplex duplex = new Duplex(); duplex.setSupportedType(Duplex.DUPLEX_FULL); serviceCaps.addElement(audio); serviceCaps.addElement(video); serviceCaps.addElement(duplex); tuple.addElement(serviceCaps); // The "contact" element Contact contact = new Contact(); contact.setContact(contactCaps.getContactUri().toString()); tuple.setContact(contact); return tuple; } } src/java/com/android/ims/rcs/uce/presence/pidfparser/capabilities/Audio.java 0 → 100644 +57 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.ims.rcs.uce.presence.pidfparser.capabilities; import com.android.ims.rcs.uce.presence.pidfparser.ElementBase; import org.xmlpull.v1.XmlSerializer; import java.io.IOException; /** * The "audio" element of the Capabilities namespace. */ public class Audio extends ElementBase { private boolean mSupported; public Audio(boolean supported) { mSupported = supported; } @Override protected String initNamespace() { return CapsConstant.NAMESPACE; } @Override protected String initElementName() { return "audio"; } @Override public void serialize(XmlSerializer serializer) throws IOException { String namespace = getNamespace(); String elementName = getElementName(); serializer.startTag(namespace, elementName); serializer.text(getValue()); serializer.endTag(namespace, elementName); } private String getValue() { return (mSupported) ? "true" : "false"; } } Loading
src/java/com/android/ims/rcs/uce/presence/pidfparser/ElementBase.java 0 → 100644 +47 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.ims.rcs.uce.presence.pidfparser; import org.xmlpull.v1.XmlSerializer; import java.io.IOException; /** * The base class of the pidf element. */ public abstract class ElementBase { private String mNamespace; private String mElementName; public ElementBase() { mNamespace = initNamespace(); mElementName = initElementName(); } protected abstract String initNamespace(); protected abstract String initElementName(); protected String getNamespace() { return mNamespace; } protected String getElementName() { return mElementName; } public abstract void serialize(XmlSerializer serializer) throws IOException; }
src/java/com/android/ims/rcs/uce/presence/pidfparser/PidfParser.java 0 → 100644 +90 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.ims.rcs.uce.presence.pidfparser; import android.telephony.ims.RcsContactUceCapability; import com.android.ims.rcs.uce.presence.pidfparser.capabilities.CapsConstant; import com.android.ims.rcs.uce.presence.pidfparser.omapres.OmaPresConstant; import com.android.ims.rcs.uce.presence.pidfparser.pidf.PidfConstant; import com.android.ims.rcs.uce.presence.pidfparser.pidf.Presence; import com.android.ims.rcs.uce.presence.pidfparser.pidf.Tuple; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserFactory; import org.xmlpull.v1.XmlSerializer; import java.io.IOException; import java.io.StringWriter; /** * The pidf parser class */ public class PidfParser { /** * Convert the RcsContactUceCapability to the string of pidf. */ public static String convertToPidf(RcsContactUceCapability capabilities) { StringWriter pidfWriter = new StringWriter(); try { // Init the instance of the XmlSerializer. XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); XmlSerializer serializer = factory.newSerializer(); // setup output and namespace serializer.setOutput(pidfWriter); serializer.setPrefix("", PidfConstant.NAMESPACE); serializer.setPrefix("op", OmaPresConstant.NAMESPACE); serializer.setPrefix("caps", CapsConstant.NAMESPACE); // Get the Presence element Presence presence = getPresence(capabilities); // Start serializing. serializer.startDocument(PidfParserConstant.ENCODING_UTF_8, true); presence.serialize(serializer); serializer.endDocument(); serializer.flush(); } catch (XmlPullParserException parserEx) { parserEx.printStackTrace(); return null; } catch (IOException ioException) { ioException.printStackTrace(); return null; } return pidfWriter.toString(); } private static Presence getPresence(RcsContactUceCapability capabilities) { // Create "presence" element which is the root element of the pidf Presence presence = new Presence(capabilities); // Add the Capabilities discovery via Presence tuple. Tuple capsDiscoveryTuple = TupleFactory.getCapabilityDiscoveryTuple(capabilities); if (capsDiscoveryTuple != null) { presence.addTuple(capsDiscoveryTuple); } // Add the VoLTE voice/video tuple. Tuple ipCallTuple = TupleFactory.getIpCallTuple(capabilities); if (ipCallTuple != null) { presence.addTuple(ipCallTuple); } return presence; } }
src/java/com/android/ims/rcs/uce/presence/pidfparser/PidfParserConstant.java 0 → 100644 +39 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.ims.rcs.uce.presence.pidfparser; /** * The constant of the pidf */ public class PidfParserConstant { /** * The UTF-8 encoding format */ public static final String ENCODING_UTF_8 = "utf-8"; /** * The service id of the capabilities discovery via presence. */ public static final String SERVICE_ID_CAPS_DISCOVERY = "org.3gpp.urn:urn-7:3gpp-application.ims.iari.rcse.dp"; /** * The service id of the VoLTE voice and video call. */ public static final String SERVICE_ID_IpCall = "org.3gpp.urn:urn-7:3gpp-service.ims.icsi.mmtel"; }
src/java/com/android/ims/rcs/uce/presence/pidfparser/TupleFactory.java 0 → 100644 +108 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.ims.rcs.uce.presence.pidfparser; import static android.telephony.ims.RcsContactUceCapability.CAPABILITY_DISCOVERY_VIA_PRESENCE; import static android.telephony.ims.RcsContactUceCapability.CAPABILITY_IP_VIDEO_CALL; import static android.telephony.ims.RcsContactUceCapability.CAPABILITY_IP_VOICE_CALL; import android.telephony.ims.RcsContactUceCapability; import com.android.ims.rcs.uce.presence.pidfparser.capabilities.Audio; import com.android.ims.rcs.uce.presence.pidfparser.capabilities.Duplex; import com.android.ims.rcs.uce.presence.pidfparser.capabilities.ServiceCaps; import com.android.ims.rcs.uce.presence.pidfparser.capabilities.Video; import com.android.ims.rcs.uce.presence.pidfparser.omapres.Description; import com.android.ims.rcs.uce.presence.pidfparser.omapres.ServiceDescription; import com.android.ims.rcs.uce.presence.pidfparser.omapres.ServiceId; import com.android.ims.rcs.uce.presence.pidfparser.omapres.Version; import com.android.ims.rcs.uce.presence.pidfparser.pidf.Basic; import com.android.ims.rcs.uce.presence.pidfparser.pidf.Contact; import com.android.ims.rcs.uce.presence.pidfparser.pidf.Status; import com.android.ims.rcs.uce.presence.pidfparser.pidf.Tuple; public class TupleFactory { /** * Get the Capability discovery by Presence tuple. */ public static Tuple getCapabilityDiscoveryTuple(RcsContactUceCapability contactCaps) { // Return directly if it is not supported. if (!contactCaps.isCapable(CAPABILITY_DISCOVERY_VIA_PRESENCE)) { return null; } Tuple tuple = new Tuple(); // The status element has a basic element with the value "open". Basic basic = new Basic(Basic.OPEN); Status status = new Status(); status.setBasic(basic); tuple.setStatus(status); // Describe the capability discovery via presence is supported. ServiceDescription serviceDescription = new ServiceDescription(); serviceDescription.setServiceId(new ServiceId(PidfParserConstant.SERVICE_ID_CAPS_DISCOVERY)); serviceDescription.setVersion(new Version(1, 0)); serviceDescription.setDescription(new Description("Capabilities Discovery")); tuple.addElement(serviceDescription); // The "contact" element Contact contact = new Contact(); contact.setContact(contactCaps.getContactUri().toString()); tuple.setContact(contact); return tuple; } /** * Get the VoLTE Voice and Video call tuple. */ public static Tuple getIpCallTuple(RcsContactUceCapability contactCaps) { Tuple tuple = new Tuple(); // The status element has a basic element with the value "open". Basic basic = new Basic(Basic.OPEN); Status status = new Status(); status.setBasic(basic); tuple.setStatus(status); // Describe the VoLTE voice and video. ServiceDescription serviceDescription = new ServiceDescription(); serviceDescription.setServiceId(new ServiceId(PidfParserConstant.SERVICE_ID_IpCall)); serviceDescription.setVersion(new Version(1, 0)); serviceDescription.setDescription(new Description("VoLTE Voice/Video service")); tuple.addElement(serviceDescription); // The service capabilities element ServiceCaps serviceCaps = new ServiceCaps(); Audio audio = new Audio(contactCaps.isCapable(CAPABILITY_IP_VOICE_CALL)); Video video = new Video(contactCaps.isCapable(CAPABILITY_IP_VIDEO_CALL)); Duplex duplex = new Duplex(); duplex.setSupportedType(Duplex.DUPLEX_FULL); serviceCaps.addElement(audio); serviceCaps.addElement(video); serviceCaps.addElement(duplex); tuple.addElement(serviceCaps); // The "contact" element Contact contact = new Contact(); contact.setContact(contactCaps.getContactUri().toString()); tuple.setContact(contact); return tuple; } }
src/java/com/android/ims/rcs/uce/presence/pidfparser/capabilities/Audio.java 0 → 100644 +57 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.ims.rcs.uce.presence.pidfparser.capabilities; import com.android.ims.rcs.uce.presence.pidfparser.ElementBase; import org.xmlpull.v1.XmlSerializer; import java.io.IOException; /** * The "audio" element of the Capabilities namespace. */ public class Audio extends ElementBase { private boolean mSupported; public Audio(boolean supported) { mSupported = supported; } @Override protected String initNamespace() { return CapsConstant.NAMESPACE; } @Override protected String initElementName() { return "audio"; } @Override public void serialize(XmlSerializer serializer) throws IOException { String namespace = getNamespace(); String elementName = getElementName(); serializer.startTag(namespace, elementName); serializer.text(getValue()); serializer.endTag(namespace, elementName); } private String getValue() { return (mSupported) ? "true" : "false"; } }