1 /* 2 * Copyright (C) 2018 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.server.wifi.hotspot2.soap; 18 19 import android.annotation.NonNull; 20 21 import org.ksoap2.SoapEnvelope; 22 import org.ksoap2.serialization.SoapObject; 23 import org.ksoap2.serialization.SoapSerializationEnvelope; 24 25 /** 26 * This class represents sppUpdateResponse message, as part of the 27 * Subscription Provisioning Protocol. 28 * For the detail, refer to the Hotspot 2.0 rel2 specification. 29 */ 30 public class UpdateResponseMessage { 31 32 /** 33 * Serialize the given request to a SOAP envelope. 34 * 35 * @param sessionId session id generated by the server to identify the session between device 36 * and server. 37 * @param isError {@code true} if the error happens during updating or installing PPS MO. 38 * @return {@link SoapSerializationEnvelope} 39 */ serializeToSoapEnvelope(@onNull String sessionId, boolean isError)40 public static SoapSerializationEnvelope serializeToSoapEnvelope(@NonNull String sessionId, 41 boolean isError) { 42 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12); 43 envelope.implicitTypes = true; // Do not include type in element attribute 44 envelope.setAddAdornments(false); // Do not generate/include IDs for each element 45 46 SoapObject requestObject = 47 new SoapObject(SoapEnvelope.NS20, SppConstants.METHOD_UPDATE_RESPONSE); 48 requestObject.addAttribute(SoapEnvelope.NS20, SppConstants.ATTRIBUTE_SPP_VERSION, 49 SppConstants.SUPPORTED_SPP_VERSION); 50 requestObject.addAttribute(SoapEnvelope.NS20, SppConstants.ATTRIBUTE_SESSION_ID, sessionId); 51 if (isError) { 52 requestObject.addAttribute(SoapEnvelope.NS20, SppConstants.ATTRIBUTE_SPP_STATUS, 53 SppConstants.mapStatusIntToString(SppConstants.SppStatus.ERROR)); 54 SoapObject sppError = 55 new SoapObject(SoapEnvelope.NS20, SppConstants.PROPERTY_SPP_ERROR); 56 sppError.addAttribute(SppConstants.ATTRIBUTE_ERROR_CODE, 57 SppConstants.mapErrorIntToString( 58 SppConstants.SppError.MO_ADD_OR_UPDATE_FAILED)); 59 requestObject.addProperty(SoapEnvelope.NS20, SppConstants.PROPERTY_SPP_ERROR, sppError); 60 } else { 61 requestObject.addAttribute(SoapEnvelope.NS20, SppConstants.ATTRIBUTE_SPP_STATUS, 62 SppConstants.mapStatusIntToString(SppConstants.SppStatus.OK)); 63 } 64 65 envelope.setOutputSoapObject(requestObject); 66 return envelope; 67 } 68 } 69