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