Home | History | Annotate | Download | only in model
      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.R;
     24 import com.android.managedprovisioning.common.Utils;
     25 
     26 /**
     27  * Captures parameters related to brand customization (e.g. tint color).
     28  */
     29 public class CustomizationParams {
     30     @VisibleForTesting public static final int DEFAULT_COLOR_ID_MP = R.color.gray_status_bar;
     31     @VisibleForTesting public static final int DEFAULT_COLOR_ID_DO = R.color.blue;
     32     @VisibleForTesting public static final int DEFAULT_COLOR_ID_BUTTON = R.color.blue;
     33     @VisibleForTesting public static final int DEFAULT_COLOR_ID_SWIPER = R.color.teal2;
     34 
     35     /** Status bar color */
     36     public final int statusBarColor;
     37 
     38     /** Animation swiper color */
     39     public final int swiperColor;
     40 
     41     /** 'Accept & Continue' button color */
     42     public final int buttonColor;
     43 
     44     /** Name of the organization where the device is being provisioned. */
     45     public final @Nullable String orgName;
     46 
     47     /** Support url of the organization where the device is being provisioned. */
     48     public final @Nullable String supportUrl;
     49 
     50     /**
     51      * Computes an instance from {@link ProvisioningParams} and required helper classes.
     52      * @param params {@link ProvisioningParams} instance to compute the values from
     53      * @param context {@link Context} instance to resolve color ids
     54      * @param utils {@link Utils} instance to determine the provisioning mode
     55      */
     56     public static CustomizationParams createInstance(ProvisioningParams params, Context context,
     57             Utils utils) {
     58         boolean isProfileOwner = utils.isProfileOwnerAction(params.provisioningAction);
     59 
     60         int statusBarColor, swiperColor, buttonColor;
     61         if (params.mainColor != null) {
     62             statusBarColor = swiperColor = buttonColor = params.mainColor;
     63         } else {
     64             statusBarColor = context.getColor(
     65                     isProfileOwner ? DEFAULT_COLOR_ID_MP : DEFAULT_COLOR_ID_DO);
     66             swiperColor = context.getColor(DEFAULT_COLOR_ID_SWIPER);
     67             buttonColor = context.getColor(DEFAULT_COLOR_ID_BUTTON);
     68         }
     69 
     70         String supportUrl = URLUtil.isNetworkUrl(params.supportUrl) ? params.supportUrl : null;
     71 
     72         return new CustomizationParams(statusBarColor, swiperColor, buttonColor,
     73                 params.organizationName, supportUrl);
     74     }
     75 
     76     private CustomizationParams(int statusBarColor, int swiperColor, int buttonColor,
     77             String orgName, String supportUrl) {
     78         this.statusBarColor = statusBarColor;
     79         this.swiperColor = swiperColor;
     80         this.buttonColor = buttonColor;
     81         this.orgName = orgName;
     82         this.supportUrl = supportUrl;
     83     }
     84 }