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 return createInstance( 55 params.mainColor, params.organizationName, params.supportUrl, context, utils); 56 } 57 createInstance( @ullable Integer mainColor, @Nullable String orgName, @Nullable String supportUrl, Context context, Utils utils)58 private static CustomizationParams createInstance( 59 @Nullable Integer mainColor, 60 @Nullable String orgName, 61 @Nullable String supportUrl, 62 Context context, 63 Utils utils) { 64 int statusBarColor; 65 boolean useSetupStatusBarColor = false; 66 if (mainColor != null) { 67 statusBarColor = mainColor; 68 } else { 69 useSetupStatusBarColor = true; 70 statusBarColor = context.getColor(DEFAULT_STATUS_BAR_COLOR_ID); 71 mainColor = utils.getAccentColor(context); 72 } 73 74 supportUrl = URLUtil.isNetworkUrl(supportUrl) ? supportUrl : null; 75 76 return new CustomizationParams( 77 mainColor, statusBarColor, useSetupStatusBarColor, orgName, supportUrl); 78 } 79 CustomizationParams(int mainColor, int statusBarColor, boolean useSetupStatusBarColor, String orgName, String supportUrl)80 private CustomizationParams(int mainColor, int statusBarColor, boolean useSetupStatusBarColor, 81 String orgName, String supportUrl) { 82 this.mainColor = mainColor; 83 this.statusBarColor = statusBarColor; 84 this.useSetupStatusBarColor = useSetupStatusBarColor; 85 this.orgName = orgName; 86 this.supportUrl = supportUrl; 87 } 88 }