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 /** Color used in everywhere else */ 36 public final int mainColor; 37 38 /** Name of the organization where the device is being provisioned. */ 39 public final @Nullable String orgName; 40 41 /** Support url of the organization where the device is being provisioned. */ 42 public final @Nullable String supportUrl; 43 44 /** 45 * Computes an instance from {@link ProvisioningParams} and required helper classes. 46 * @param params {@link ProvisioningParams} instance to compute the values from 47 * @param context {@link Context} instance to resolve color ids 48 */ createInstance( ProvisioningParams params, Context context, Utils utils)49 public static CustomizationParams createInstance( 50 ProvisioningParams params, Context context, Utils utils) { 51 int statusBarColor, mainColor; 52 if (params.mainColor != null) { 53 statusBarColor = mainColor = params.mainColor; 54 } else { 55 statusBarColor = context.getColor(DEFAULT_STATUS_BAR_COLOR_ID); 56 mainColor = utils.getAccentColor(context); 57 } 58 59 String supportUrl = URLUtil.isNetworkUrl(params.supportUrl) ? params.supportUrl : null; 60 61 return new CustomizationParams(mainColor, statusBarColor, params.organizationName, 62 supportUrl); 63 } 64 CustomizationParams(int mainColor, int statusBarColor, String orgName, String supportUrl)65 private CustomizationParams(int mainColor, int statusBarColor, 66 String orgName, String supportUrl) { 67 this.mainColor = mainColor; 68 this.statusBarColor = statusBarColor; 69 this.orgName = orgName; 70 this.supportUrl = supportUrl; 71 } 72 }