• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.internal.annotations.VisibleForTesting;
23 import com.android.managedprovisioning.common.Utils;
24 
25 /**
26  * Captures parameters related to brand customization (e.g. tint color).
27  */
28 public class CustomizationParams {
29     @VisibleForTesting
30     public static final int DEFAULT_STATUS_BAR_COLOR_ID = android.R.color.white;
31 
32     /** Status bar color */
33     public final int statusBarColor;
34 
35     /** Use Status bar color from SUW partner configuration */
36     public final boolean useSetupStatusBarColor;
37 
38     /** Color used in everywhere else */
39     public final int mainColor;
40 
41     /** Name of the organization where the device is being provisioned. */
42     public final @Nullable String orgName;
43 
44     /** Support url of the organization where the device is being provisioned. */
45     public final @Nullable String supportUrl;
46 
47     /**
48      * Computes an instance from {@link ProvisioningParams} and required helper classes.
49      * @param params {@link ProvisioningParams} instance to compute the values from
50      * @param context {@link Context} instance to resolve color ids
51      */
createInstance( ProvisioningParams params, Context context, Utils utils)52     public static CustomizationParams createInstance(
53             ProvisioningParams params, Context context, Utils utils) {
54         int statusBarColor, mainColor;
55         boolean useSetupStatusBarColor = false;
56         if (params.mainColor != null) {
57             statusBarColor = mainColor = params.mainColor;
58         } else {
59             useSetupStatusBarColor = true;
60             statusBarColor = context.getColor(DEFAULT_STATUS_BAR_COLOR_ID);
61             mainColor = utils.getAccentColor(context);
62         }
63 
64         String supportUrl = URLUtil.isNetworkUrl(params.supportUrl) ? params.supportUrl : null;
65 
66         return new CustomizationParams(mainColor, statusBarColor, useSetupStatusBarColor,
67                 params.organizationName, supportUrl);
68     }
69 
CustomizationParams(int mainColor, int statusBarColor, boolean useSetupStatusBarColor, String orgName, String supportUrl)70     private CustomizationParams(int mainColor, int statusBarColor, boolean useSetupStatusBarColor,
71             String orgName, String supportUrl) {
72         this.mainColor = mainColor;
73         this.statusBarColor = statusBarColor;
74         this.useSetupStatusBarColor = useSetupStatusBarColor;
75         this.orgName = orgName;
76         this.supportUrl = supportUrl;
77     }
78 }