• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019, 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.app.Activity;
20 import android.content.Context;
21 import android.os.Bundle;
22 
23 import androidx.annotation.VisibleForTesting;
24 
25 import com.android.managedprovisioning.R;
26 import com.android.managedprovisioning.common.ProvisionLogger;
27 import com.android.managedprovisioning.common.SettingsFacade;
28 import com.android.managedprovisioning.common.ThemeHelper;
29 import com.android.managedprovisioning.common.ThemeHelper.DefaultNightModeChecker;
30 import com.android.managedprovisioning.common.ThemeHelper.DefaultSetupWizardBridge;
31 import com.android.managedprovisioning.common.Utils;
32 import com.android.managedprovisioning.model.CustomizationParams;
33 import com.android.managedprovisioning.model.ProvisioningParams;
34 
35 /**
36  * Progress activity shown whilst network setup, downloading, verifying and installing the
37  * admin package is ongoing.
38  *
39  * <p>This activity registers for updates of the provisioning process from the
40  * {@link AdminIntegratedFlowPrepareManager}. It shows progress updates as provisioning
41  * progresses and handles showing of cancel and error dialogs.</p>
42  */
43 public class AdminIntegratedFlowPrepareActivity extends AbstractProvisioningActivity {
44 
45     private AdminIntegratedFlowPrepareManager mProvisioningManager;
46 
AdminIntegratedFlowPrepareActivity()47     public AdminIntegratedFlowPrepareActivity() {
48         this(new Utils(), new SettingsFacade(),
49                 new ThemeHelper(new DefaultNightModeChecker(), new DefaultSetupWizardBridge()));
50     }
51 
shouldRunPrepareActivity( Utils utils, Context context, ProvisioningParams params)52     public static boolean shouldRunPrepareActivity(
53             Utils utils, Context context, ProvisioningParams params) {
54         // TODO(b/177849035): Remove NFC-specific logic
55         if (params.isNfc) {
56             return false;
57         }
58         if (params.wifiInfo != null) {
59             return true;
60         }
61         if (params.useMobileData) {
62             return true;
63         }
64         if (params.deviceAdminDownloadInfo != null) {
65             // Only prepare if a download is actually required
66             if (utils.packageRequiresUpdate(
67                     params.inferDeviceAdminPackageName(),
68                     params.deviceAdminDownloadInfo.minVersion,
69                     context)) {
70                 return true;
71             }
72         }
73         return false;
74     }
75 
76     @VisibleForTesting
AdminIntegratedFlowPrepareActivity( Utils utils, SettingsFacade settingsFacade, ThemeHelper themeHelper)77     protected AdminIntegratedFlowPrepareActivity(
78             Utils utils, SettingsFacade settingsFacade, ThemeHelper themeHelper) {
79         super(utils, settingsFacade, themeHelper);
80     }
81 
82     @Override
onCreate(Bundle savedInstanceState)83     protected void onCreate(Bundle savedInstanceState) {
84         super.onCreate(savedInstanceState);
85         initializeUi(mParams);
86     }
87 
getProvisioningManager()88     protected ProvisioningManagerInterface getProvisioningManager() {
89         if (mProvisioningManager == null) {
90             mProvisioningManager = AdminIntegratedFlowPrepareManager.getInstance(this);
91         }
92         return mProvisioningManager;
93     }
94 
95     @Override
preFinalizationCompleted()96     public void preFinalizationCompleted() {
97         ProvisionLogger.logi("AdminIntegratedFlowPrepareActivity pre-finalization completed");
98         setResult(Activity.RESULT_OK);
99         getTransitionHelper().finishActivity(this);
100     }
101 
102     @Override
decideCancelProvisioningDialog()103     protected void decideCancelProvisioningDialog() {
104         showCancelProvisioningDialog(/* resetRequired = */true);
105     }
106 
initializeUi(ProvisioningParams params)107     private void initializeUi(ProvisioningParams params) {
108         final int headerResId = R.string.downloading_administrator_header;
109         final int titleResId = R.string.setup_device_progress;
110         final CustomizationParams customizationParams =
111                 CustomizationParams.createInstance(mParams, this, mUtils);
112         initializeLayoutParams(R.layout.empty_loading_layout, headerResId, customizationParams);
113         setTitle(titleResId);
114     }
115 
116     @Override
isWaitingScreen()117     protected boolean isWaitingScreen() {
118         return true;
119     }
120 }