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 package com.android.managedprovisioning.provisioning; 17 18 import android.app.Activity; 19 import android.content.Intent; 20 import android.os.Bundle; 21 import android.widget.TextView; 22 23 import com.android.internal.annotations.VisibleForTesting; 24 import com.android.managedprovisioning.R; 25 import com.android.managedprovisioning.common.AccessibilityContextMenuMaker; 26 import com.android.managedprovisioning.common.ClickableSpanFactory; 27 import com.android.managedprovisioning.common.SetupGlifLayoutActivity; 28 import com.android.managedprovisioning.common.Utils; 29 import com.android.managedprovisioning.model.CustomizationParams; 30 import com.android.managedprovisioning.model.ProvisioningParams; 31 import com.google.android.setupcompat.util.WizardManagerHelper; 32 import com.google.android.setupdesign.GlifLayout; 33 34 /** 35 * The first activity shown during provisioning. 36 */ 37 public class LandingActivity extends SetupGlifLayoutActivity { 38 private static final int ADMIN_INTEGRATED_FLOW_PREPARE_REQUEST_CODE = 1; 39 private final AccessibilityContextMenuMaker mContextMenuMaker; 40 LandingActivity()41 public LandingActivity() { 42 this(new Utils(), null); 43 } 44 45 @VisibleForTesting LandingActivity(Utils utils, AccessibilityContextMenuMaker contextMenuMaker)46 LandingActivity(Utils utils, AccessibilityContextMenuMaker contextMenuMaker) { 47 super(utils); 48 mContextMenuMaker = contextMenuMaker != null 49 ? contextMenuMaker 50 : new AccessibilityContextMenuMaker(this); 51 } 52 53 @Override onCreate(Bundle savedInstanceState)54 protected void onCreate(Bundle savedInstanceState) { 55 super.onCreate(savedInstanceState); 56 final ProvisioningParams params = 57 getIntent().getParcelableExtra(ProvisioningParams.EXTRA_PROVISIONING_PARAMS); 58 initializeUi(params); 59 } 60 initializeUi(ProvisioningParams params)61 private void initializeUi(ProvisioningParams params) { 62 final int headerResId = R.string.brand_screen_header; 63 final int titleResId = R.string.setup_device_progress; 64 65 final CustomizationParams customizationParams = 66 CustomizationParams.createInstance(params, this, mUtils); 67 initializeLayoutParams(R.layout.landing_screen, headerResId, customizationParams); 68 setTitle(titleResId); 69 70 handleSupportUrl(customizationParams); 71 final GlifLayout layout = findViewById(R.id.setup_wizard_layout); 72 Utils.addNextButton(layout, v -> onNextButtonClicked(params)); 73 74 if (Utils.isSilentProvisioning(this, params)) { 75 onNextButtonClicked(params); 76 } 77 } 78 onNextButtonClicked(ProvisioningParams params)79 private void onNextButtonClicked(ProvisioningParams params) { 80 if (AdminIntegratedFlowPrepareActivity.shouldRunPrepareActivity(mUtils, this, params)) { 81 final Intent intent = new Intent(this, AdminIntegratedFlowPrepareActivity.class); 82 WizardManagerHelper.copyWizardManagerExtras(getIntent(), intent); 83 intent.putExtra(ProvisioningParams.EXTRA_PROVISIONING_PARAMS, params); 84 startActivityForResult(intent, ADMIN_INTEGRATED_FLOW_PREPARE_REQUEST_CODE); 85 } else { 86 setResult(Activity.RESULT_OK); 87 finish(); 88 } 89 } 90 handleSupportUrl(CustomizationParams customizationParams)91 private void handleSupportUrl(CustomizationParams customizationParams) { 92 final TextView info = findViewById(R.id.provider_info); 93 final String deviceProvider = getString(R.string.organization_admin); 94 final String contactDeviceProvider = 95 getString(R.string.contact_device_provider, deviceProvider); 96 final ClickableSpanFactory clickableSpanFactory = 97 new ClickableSpanFactory(getColor(R.color.blue_text)); 98 mUtils.handleSupportUrl(this, customizationParams, clickableSpanFactory, 99 mContextMenuMaker, info, deviceProvider, contactDeviceProvider); 100 } 101 102 @Override onActivityResult(int requestCode, int resultCode, Intent data)103 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 104 if (requestCode == ADMIN_INTEGRATED_FLOW_PREPARE_REQUEST_CODE) { 105 setResult(resultCode); 106 finish(); 107 } 108 } 109 } 110