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.command;
18 
19 import android.text.TextUtils;
20 import android.util.Log;
21 
22 import org.ksoap2.serialization.PropertyInfo;
23 
24 import java.util.Objects;
25 
26 /**
27  * Represents URI of LaunchBrowser command defined by SPP (Subscription Provisioning Protocol).
28  */
29 public class BrowserUri implements SppCommand.SppCommandData {
30     private static final String TAG = "PasspointBrowserUri";
31     private final String mUri;
32 
BrowserUri(PropertyInfo command)33     private BrowserUri(PropertyInfo command) {
34         mUri = command.getValue().toString();
35     }
36 
37     /**
38      * Create an instance of {@link BrowserUri}
39      *
40      * @param command command message embedded in SOAP sppPostDevDataResponse.
41      * @return instance of {@link BrowserUri}, {@code null} in any failure.
42      */
createInstance(PropertyInfo command)43     public static BrowserUri createInstance(PropertyInfo command) {
44         if (!TextUtils.equals(command.getName(), "launchBrowserToURI")) {
45             Log.e(TAG, "received wrong command : " + ((command == null) ? "" : command.getName()));
46             return null;
47         }
48         return new BrowserUri(command);
49     }
50 
getUri()51     public String getUri() {
52         return mUri;
53     }
54 
55     @Override
equals(Object thatObject)56     public boolean equals(Object thatObject) {
57         if (this == thatObject) return true;
58         if (!(thatObject instanceof BrowserUri)) return false;
59         BrowserUri that = (BrowserUri) thatObject;
60         return TextUtils.equals(mUri, that.mUri);
61     }
62 
63     @Override
hashCode()64     public int hashCode() {
65         return Objects.hash(mUri);
66     }
67 
68     @Override
toString()69     public String toString() {
70         return "BrowserUri{mUri: " + mUri + "}";
71     }
72 }
73