• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.preprovisioning.consent;
17 
18 import static java.util.Objects.requireNonNull;
19 
20 import android.app.Activity;
21 import android.text.SpannableString;
22 import android.text.style.UnderlineSpan;
23 import android.view.View;
24 import android.widget.TextView;
25 
26 import androidx.annotation.RawRes;
27 
28 import com.android.managedprovisioning.R;
29 import com.android.managedprovisioning.common.Lotties;
30 import com.android.managedprovisioning.common.ProvisionLogger;
31 import com.android.managedprovisioning.common.ThemeHelper;
32 import com.android.managedprovisioning.common.TouchTargetEnforcer;
33 import com.android.managedprovisioning.common.Utils;
34 import com.android.managedprovisioning.preprovisioning.PreProvisioningActivityBridgeCallbacks;
35 import com.android.managedprovisioning.preprovisioning.PreProvisioningActivityController.UiParams;
36 
37 import com.airbnb.lottie.LottieAnimationView;
38 import com.google.android.setupcompat.logging.ScreenKey;
39 import com.google.android.setupcompat.logging.SetupMetric;
40 import com.google.android.setupcompat.logging.SetupMetricsLogger;
41 import com.google.android.setupdesign.GlifLayout;
42 import com.google.android.setupdesign.util.DeviceHelper;
43 
44 /**
45  * Implements functionality for the consent screen.
46  */
47 class ConsentUiHelperImpl implements ConsentUiHelper {
48     private final Activity mActivity;
49     private final TouchTargetEnforcer mTouchTargetEnforcer;
50     private final ConsentUiHelperCallback mCallback;
51     private final Utils mUtils;
52     private final PreProvisioningActivityBridgeCallbacks mBridgeCallbacks;
53     private final ThemeHelper mThemeHelper;
54     private final ScreenKey mScreenKey;
55     private final String setupMetricScreenName;
56     private final Boolean mShouldApplyGlifExpressiveStyle;
57 
ConsentUiHelperImpl(Activity activity, ConsentUiHelperCallback callback, Utils utils, PreProvisioningActivityBridgeCallbacks bridgeCallbacks, ThemeHelper themeHelper, String setupMetricScreenName)58     ConsentUiHelperImpl(Activity activity, ConsentUiHelperCallback callback, Utils utils,
59             PreProvisioningActivityBridgeCallbacks bridgeCallbacks,
60             ThemeHelper themeHelper, String setupMetricScreenName) {
61         mActivity = requireNonNull(activity);
62         mCallback = requireNonNull(callback);
63         mTouchTargetEnforcer =
64             new TouchTargetEnforcer(activity.getResources().getDisplayMetrics().density);
65         mUtils = requireNonNull(utils);
66         mBridgeCallbacks = requireNonNull(bridgeCallbacks);
67         mThemeHelper = requireNonNull(themeHelper);
68         mScreenKey = ScreenKey.of(setupMetricScreenName, mActivity);
69         this.setupMetricScreenName = setupMetricScreenName;
70        mShouldApplyGlifExpressiveStyle =
71             ThemeHelper.shouldApplyGlifExpressiveStyle(mActivity.getApplicationContext());
72     }
73 
74     @Override
initiateUi(UiParams uiParams)75     public void initiateUi(UiParams uiParams) {
76         String title = "";
77         int headerResId = 0;
78         int animationResId = 0;
79         var context = mActivity.getApplicationContext();
80         if (mUtils.isProfileOwnerAction(uiParams.provisioningAction)) {
81             title = mActivity.getString(R.string.setup_profile);
82             headerResId = R.string.work_profile_provisioning_accept_header_post_suw;
83             animationResId =
84                 mShouldApplyGlifExpressiveStyle
85                     ? R.raw.lets_set_up_your_work_device_expressive
86                     : R.raw.consent_animation_po;
87         } else if (mUtils.isDeviceOwnerAction(uiParams.provisioningAction)) {
88             CharSequence deviceName = DeviceHelper.getDeviceName(context);
89             title = context.getString(R.string.setup_device, deviceName);
90             headerResId = R.string.fully_managed_device_provisioning_accept_header;
91             animationResId =
92                 mShouldApplyGlifExpressiveStyle
93                     ? R.raw.lets_set_up_your_work_device_expressive
94                     : R.raw.consent_animation_do;
95         }
96 
97         mCallback.onInitiateUi(R.layout.intro, headerResId);
98 
99         setupAnimation(animationResId);
100         setupAcceptAndContinueButton();
101 
102         // set the activity title
103         mActivity.setTitle(title);
104 
105         // set up terms headers
106         setupViewTermsButton();
107     }
108 
109     @Override
onStart()110     public void onStart() {}
111 
112     @Override
onStop()113     public void onStop() {}
114 
setupAnimation(@awRes int animationResId)115     private void setupAnimation(@RawRes int animationResId) {
116         final GlifLayout layout = mActivity.findViewById(R.id.setup_wizard_layout);
117         LottieAnimationView lottieAnimationView = layout.findViewById(R.id.animation);
118         lottieAnimationView.setAnimation(animationResId);
119         mThemeHelper.setupAnimationDynamicColors(
120                 mActivity, lottieAnimationView, mActivity.getIntent());
121         Lotties.applyColorMappingsIfGlifExpressive(lottieAnimationView);
122     }
123 
setupAcceptAndContinueButton()124     private void setupAcceptAndContinueButton() {
125         final GlifLayout layout = mActivity.findViewById(R.id.setup_wizard_layout);
126         Utils.addAcceptAndContinueButton(layout, v -> onNextButtonClicked());
127     }
128 
onNextButtonClicked()129     private void onNextButtonClicked() {
130         ProvisionLogger.logi("Next button (next_button) is clicked.");
131         SetupMetricsLogger.logMetrics(
132                 mActivity, mScreenKey, SetupMetric.ofOptIn(setupMetricScreenName, true));
133 
134         mBridgeCallbacks.onTermsAccepted();
135     }
136 
setupViewTermsButton()137     private void setupViewTermsButton() {
138         final GlifLayout layout = mActivity.findViewById(R.id.setup_wizard_layout);
139         layout.setDescriptionText(R.string.view_terms);
140         TextView subtitle = layout.findViewById(
141                 com.google.android.setupdesign.R.id.sud_layout_subtitle);
142         String descriptionText = mActivity.getString(R.string.view_terms);
143         SpannableString spannableString = new SpannableString(descriptionText);
144         spannableString.setSpan(new UnderlineSpan(), 0, descriptionText.length(), 0);
145         subtitle.setText(spannableString);
146         subtitle.setTextColor(mUtils.getAccentColor(mActivity));
147         subtitle.setOnClickListener(v -> mBridgeCallbacks.onTermsButtonClicked());
148         mTouchTargetEnforcer.enforce(subtitle, (View) subtitle.getParent());
149     }
150 }
151