1 /*
2  * Copyright 2016, 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 
17 package com.android.managedprovisioning.provisioning;
18 
19 import android.annotation.IntDef;
20 import android.annotation.Nullable;
21 import android.app.admin.DevicePolicyManager;
22 import android.content.ComponentName;
23 import android.content.Context;
24 import android.content.Intent;
25 
26 import com.android.managedprovisioning.common.Globals;
27 
28 import java.io.File;
29 import java.lang.annotation.Retention;
30 import java.lang.annotation.RetentionPolicy;
31 import java.util.HashMap;
32 import java.util.Set;
33 
34 /**
35  * Constants used for communication between service and activity.
36  */
37 public final class Constants {
38     // Intents sent by the activity to the service
39     /**
40      * Intent action sent to the {@link ProvisioningService} to indicate that provisioning should be
41      * started.
42      */
43     public static final String ACTION_START_PROVISIONING =
44             "com.android.managedprovisioning.START_PROVISIONING";
45 
46     public static final int COLOR_TYPE_ACCENT = 1;
47     public static final int COLOR_TYPE_PRIMARY_TEXT = 2;
48     public static final int COLOR_TYPE_SECONDARY_TEXT = 3;
49     public static final int COLOR_TYPE_BACKGROUND_SURFACE = 4;
50     public static final int COLOR_TYPE_NOTIFICATION_BACKGROUND = 5;
51     public static final int COLOR_TYPE_NAVIGATION_BAR_COLOR = 6;
52     public static final int COLOR_TYPE_NAVIGATION_BAR_DIVIDER_COLOR = 7;
53     public static final int COLOR_TYPE_IS_NIGHT_MODE_ACTIVE = 8;
54 
55     @IntDef(prefix = {"COLOR_PALETTE_"}, value = {
56         COLOR_TYPE_ACCENT,
57         COLOR_TYPE_PRIMARY_TEXT,
58         COLOR_TYPE_SECONDARY_TEXT,
59         COLOR_TYPE_BACKGROUND_SURFACE,
60         COLOR_TYPE_NOTIFICATION_BACKGROUND,
61         COLOR_TYPE_NAVIGATION_BAR_COLOR,
62         COLOR_TYPE_NAVIGATION_BAR_DIVIDER_COLOR,
63         COLOR_TYPE_IS_NIGHT_MODE_ACTIVE
64     })
65     @Retention(RetentionPolicy.SOURCE)
66     public @interface ColorType {}
67 
68     /**
69      * A {@link HashMap} extra that maps colors from {@link ColorType} to an {@link Integer} color
70      */
71     public static final String EXTRA_PROVISIONING_COLOR_PALETTE =
72             "android.app.extra.PROVISIONING_COLOR_PALETTE";
73 
getDeferredMetricsFile(Context context)74     public static File getDeferredMetricsFile(Context context) {
75         return new File(context.getFilesDir(), "deferred_metrics");
76     }
77 
78     public static boolean FLAG_ENABLE_LIGHT_DARK_MODE = true;
79 
80     /**
81      * A boolean flag to indicate whether to lock the orientation to portrait mode.
82      * <p>This is a temporary feature flag until the setup wizard library support is implemented.
83      */
84     public static final boolean LOCK_TO_PORTRAIT_MODE = false;
85 
86     /**
87      * A boolean flag to indicate whether to enable custom activity start gestures.
88      */
89     public static boolean ENABLE_CUSTOM_TRANSITIONS = true;
90 
91     public static final Intent PROVISIONING_SERVICE_INTENT = new Intent().setComponent(
92             new ComponentName(
93                     Globals.MANAGED_PROVISIONING_PACKAGE_NAME,
94                     ProvisioningService.class.getName()));
95 
96     private static final Set<String> sManagedProvisioningProvisioningActions =
97             Set.of(DevicePolicyManager.ACTION_PROVISION_MANAGED_DEVICE_FROM_TRUSTED_SOURCE,
98                     DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE);
99 
100     /**
101      * Returns whether the supplied provisioning action is supported for role holder-driven
102      * provisioning.
103      */
isRoleHolderProvisioningAllowedForAction( @ullable String managedProvisioningAction)104     public static boolean isRoleHolderProvisioningAllowedForAction(
105             @Nullable String managedProvisioningAction) {
106         if (managedProvisioningAction == null) {
107             return false;
108         }
109         return sManagedProvisioningProvisioningActions.contains(managedProvisioningAction);
110     }
111 
Constants()112     private Constants() {
113         // Do not instantiate
114     }
115 }
116