1 /* 2 * Copyright (C) 2021 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.libraries.entitlement; 18 19 import android.net.Network; 20 21 import androidx.annotation.Nullable; 22 23 import com.google.auto.value.AutoValue; 24 25 /** 26 * Carrier specific customization to be used in the service entitlement queries and operations. 27 * 28 * @see #ServiceEntitlement 29 */ 30 @AutoValue 31 public abstract class CarrierConfig { 32 /** Default value of {@link #timeoutInSec} if not set. */ 33 public static final int DEFAULT_TIMEOUT_IN_SEC = 30; 34 35 /** The carrier's entitlement server URL. See {@link Builder#setServerUrl}. */ serverUrl()36 public abstract String serverUrl(); 37 38 /** Client side timeout for HTTP connection. See {@link Builder#setTimeoutInSec}. */ timeoutInSec()39 public abstract int timeoutInSec(); 40 41 /** The {@link Network} used for HTTP connection. See {@link Builder#setNetwork}. */ 42 @Nullable network()43 public abstract Network network(); 44 45 /** Returns a new {@link Builder} object. */ builder()46 public static Builder builder() { 47 return new AutoValue_CarrierConfig.Builder() 48 .setServerUrl("") 49 .setTimeoutInSec(DEFAULT_TIMEOUT_IN_SEC); 50 } 51 52 /** Builder. */ 53 @AutoValue.Builder 54 public abstract static class Builder { build()55 public abstract CarrierConfig build(); 56 57 /** 58 * Sets the carrier's entitlement server URL. If not set, will use {@code 59 * https://aes.mnc<MNC>.mcc<MCC>.pub.3gppnetwork.org} as defined in GSMA TS.43 section 2.1. 60 */ setServerUrl(String url)61 public abstract Builder setServerUrl(String url); 62 63 /** 64 * Sets the client side timeout for HTTP connection. Default to 65 * {@link DEFAULT_TIMEOUT_IN_SEC}. 66 * 67 * <p>This timeout is used by both {@link java.net.URLConnection#setConnectTimeout} and 68 * {@link java.net.URLConnection#setReadTimeout}. 69 */ setTimeoutInSec(int timeoutInSec)70 public abstract Builder setTimeoutInSec(int timeoutInSec); 71 72 /** 73 * Sets the {@link Network} used for HTTP connection. If not set, the device default network 74 * is used. 75 */ setNetwork(Network network)76 public abstract Builder setNetwork(Network network); 77 } 78 } 79