1 /* 2 * Copyright (C) 2022 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 package com.google.android.iwlan; 17 18 import android.support.annotation.NonNull; 19 import android.support.annotation.Nullable; 20 21 import java.net.InetAddress; 22 import java.util.Objects; 23 24 public interface TunnelMetricsInterface { 25 class TunnelMetricsData { 26 private final String mApnName; 27 private final String mEpdgServerAddress; 28 private final int mEpdgServerSelectionDuration; 29 private final int mIkeTunnelEstablishmentDuration; 30 private final boolean mIsNetworkValidated; 31 TunnelMetricsData(Builder builder)32 protected TunnelMetricsData(Builder builder) { 33 this.mApnName = builder.mApnName; 34 this.mEpdgServerAddress = builder.mEpdgServerAddress; 35 this.mEpdgServerSelectionDuration = builder.mEpdgServerSelectionDuration; 36 this.mIkeTunnelEstablishmentDuration = builder.mIkeTunnelEstablishmentDuration; 37 this.mIsNetworkValidated = builder.mIsNetworkValidated; 38 } 39 40 @Nullable getApnName()41 public String getApnName() { 42 return mApnName; 43 } 44 45 @Nullable getEpdgServerAddress()46 public String getEpdgServerAddress() { 47 return mEpdgServerAddress; 48 } 49 getEpdgServerSelectionDuration()50 public int getEpdgServerSelectionDuration() { 51 return mEpdgServerSelectionDuration; 52 } 53 getIkeTunnelEstablishmentDuration()54 public int getIkeTunnelEstablishmentDuration() { 55 return mIkeTunnelEstablishmentDuration; 56 } 57 isNetworkValidated()58 public boolean isNetworkValidated() { 59 return mIsNetworkValidated; 60 } 61 62 public static class Builder<T extends Builder> { 63 @Nullable private String mApnName = null; 64 @Nullable private String mEpdgServerAddress = null; 65 private int mEpdgServerSelectionDuration = 0; 66 private int mIkeTunnelEstablishmentDuration = 0; 67 private boolean mIsNetworkValidated = false; 68 69 /** Default constructor for Builder. */ Builder()70 public Builder() {} 71 setApnName(@onNull String apnName)72 public T setApnName(@NonNull String apnName) { 73 mApnName = Objects.requireNonNull(apnName, "apnName must not be null"); 74 return (T) this; 75 } 76 setEpdgServerAddress(InetAddress epdgAddress)77 public T setEpdgServerAddress(InetAddress epdgAddress) { 78 mEpdgServerAddress = epdgAddress == null ? null : epdgAddress.getHostAddress(); 79 return (T) this; 80 } 81 setEpdgServerSelectionDuration(int epdgServerSelectionDuration)82 public T setEpdgServerSelectionDuration(int epdgServerSelectionDuration) { 83 mEpdgServerSelectionDuration = epdgServerSelectionDuration; 84 return (T) this; 85 } 86 setIkeTunnelEstablishmentDuration(int ikeTunnelEstablishmentDuration)87 public T setIkeTunnelEstablishmentDuration(int ikeTunnelEstablishmentDuration) { 88 mIkeTunnelEstablishmentDuration = ikeTunnelEstablishmentDuration; 89 return (T) this; 90 } 91 92 /** whether underlying network is validated */ setIsNetworkValidated(boolean isNetworkValidated)93 public T setIsNetworkValidated(boolean isNetworkValidated) { 94 mIsNetworkValidated = isNetworkValidated; 95 return (T) this; 96 } 97 build()98 public TunnelMetricsData build() { 99 if (mApnName == null) { 100 throw new IllegalArgumentException("Necessary parameter missing."); 101 } 102 return new TunnelMetricsData(this); 103 } 104 } 105 } 106 107 class OnOpenedMetrics extends TunnelMetricsData { 108 OnOpenedMetrics(Builder builder)109 protected OnOpenedMetrics(Builder builder) { 110 super(builder); 111 } 112 113 public static class Builder extends TunnelMetricsData.Builder<Builder> { 114 Builder()115 public Builder() {} 116 build()117 public OnOpenedMetrics build() { 118 return new OnOpenedMetrics(this); 119 } 120 } 121 } 122 123 class OnClosedMetrics extends TunnelMetricsData { 124 OnClosedMetrics(Builder builder)125 protected OnClosedMetrics(Builder builder) { 126 super(builder); 127 } 128 129 public static class Builder extends TunnelMetricsData.Builder<Builder> { 130 Builder()131 public Builder() {} 132 build()133 public OnClosedMetrics build() { 134 return new OnClosedMetrics(this); 135 } 136 } 137 } 138 } 139