1 /*
2  * Copyright 2017, 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.android.managedprovisioning.model;
17 
18 import android.annotation.Nullable;
19 import android.content.Context;
20 import android.webkit.URLUtil;
21 
22 import com.android.managedprovisioning.common.Utils;
23 
24 /**
25  * Captures parameters related to brand customization (e.g. tint color).
26  */
27 public class CustomizationParams {
28     /** Color used in everywhere else */
29     public final int logoColor;
30 
31     /** Support url of the organization where the device is being provisioned. */
32     public final @Nullable String supportUrl;
33 
34     /**
35      * Computes an instance from {@link ProvisioningParams} and required helper classes.
36      * @param params {@link ProvisioningParams} instance to compute the values from
37      * @param context {@link Context} instance to resolve color ids
38      */
createInstance( ProvisioningParams params, Context context, Utils utils)39     public static CustomizationParams createInstance(
40             ProvisioningParams params, Context context, Utils utils) {
41         return createInstance(params.supportUrl, context, utils);
42     }
43 
createInstance( @ullable String supportUrl, Context context, Utils utils)44     private static CustomizationParams createInstance(
45             @Nullable String supportUrl,
46             Context context,
47             Utils utils) {
48         int logoColor = utils.getAccentColor(context);
49         supportUrl = URLUtil.isNetworkUrl(supportUrl) ? supportUrl : null;
50         return new CustomizationParams(logoColor, supportUrl);
51     }
52 
CustomizationParams(int logoColor, String supportUrl)53     private CustomizationParams(int logoColor, String supportUrl) {
54         this.logoColor = logoColor;
55         this.supportUrl = supportUrl;
56     }
57 }