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 import android.util.Log; 21 22 import com.android.server.wifi.hotspot2.soap.command.SppCommand; 23 24 import org.ksoap2.serialization.PropertyInfo; 25 import org.ksoap2.serialization.SoapObject; 26 27 import java.util.Objects; 28 29 /** 30 * Represents the sppPostDevDataResponse message sent by the server. 31 * For the details, refer to A.3.2 section in Hotspot2.0 rel2 specification. 32 */ 33 public class PostDevDataResponse extends SppResponseMessage { 34 private static final String TAG = "PasspointPostDevDataResponse"; 35 private static final int MAX_COMMAND_COUNT = 1; 36 private final SppCommand mSppCommand; 37 PostDevDataResponse(@onNull SoapObject response)38 private PostDevDataResponse(@NonNull SoapObject response) throws IllegalArgumentException { 39 super(response, MessageType.POST_DEV_DATA_RESPONSE); 40 if (getStatus() == SppConstants.SppStatus.ERROR) { 41 mSppCommand = null; 42 return; 43 } 44 45 PropertyInfo propertyInfo = new PropertyInfo(); 46 response.getPropertyInfo(0, propertyInfo); 47 // Get SPP(Subscription Provisioning Protocol) command from the original message. 48 mSppCommand = SppCommand.createInstance(propertyInfo); 49 } 50 51 /** 52 * create an instance of {@link PostDevDataResponse} 53 * 54 * @param response SOAP response message received from server. 55 * @return Instance of {@link PostDevDataResponse}, {@code null} in any failure. 56 */ createInstance(@onNull SoapObject response)57 public static PostDevDataResponse createInstance(@NonNull SoapObject response) { 58 if (response.getPropertyCount() != MAX_COMMAND_COUNT) { 59 Log.e(TAG, "max command count exceeds: " + response.getPropertyCount()); 60 return null; 61 } 62 63 PostDevDataResponse postDevDataResponse; 64 try { 65 postDevDataResponse = new PostDevDataResponse(response); 66 } catch (IllegalArgumentException e) { 67 Log.e(TAG, "fails to create an Instance: " + e); 68 return null; 69 } 70 71 return postDevDataResponse; 72 } 73 74 /** 75 * Get a SppCommand for the current {@code PostDevDataResponse} instance. 76 * 77 * @return {@link SppCommand} 78 */ getSppCommand()79 public SppCommand getSppCommand() { 80 return mSppCommand; 81 } 82 83 @Override hashCode()84 public int hashCode() { 85 return Objects.hash(super.hashCode(), mSppCommand); 86 } 87 88 @Override equals(Object thatObject)89 public boolean equals(Object thatObject) { 90 if (this == thatObject) return true; 91 if (!(thatObject instanceof PostDevDataResponse)) return false; 92 if (!super.equals(thatObject)) return false; 93 PostDevDataResponse that = (PostDevDataResponse) thatObject; 94 return Objects.equals(mSppCommand, that.getSppCommand()); 95 } 96 97 @Override toString()98 public String toString() { 99 return super.toString() + ", commands " + mSppCommand; 100 } 101 } 102