blob: 27bfc58b701286bac64ecedde78637aebeb51a68 [file]
/*
* Copyright 2019, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.managedprovisioning.finalization;
import android.content.Intent;
import com.android.managedprovisioning.analytics.MetricsWriterFactory;
import com.android.managedprovisioning.analytics.ProvisioningAnalyticsTracker;
import com.android.managedprovisioning.common.ManagedProvisioningSharedPreferences;
import com.android.managedprovisioning.common.ProvisionLogger;
import com.android.managedprovisioning.common.SettingsFacade;
import com.android.managedprovisioning.common.TransitionHelper;
/**
* This class is used to start the Device Policy Controller app while the Setup Wizard is still
* running. It listens for a result from any child activity that is started, and returns its own
* result code when all child activities have completed.
*/
public class FinalizationInsideSuwActivity extends FinalizationActivityBase {
private static final int DPC_SETUP_REQUEST_CODE = 1;
private static final int FINAL_SCREEN_REQUEST_CODE = 2;
public FinalizationInsideSuwActivity() {
super(new TransitionHelper());
}
@Override
protected FinalizationController createFinalizationController() {
return new FinalizationController(this, new FinalizationInsideSuwControllerLogic(this));
}
@Override
protected void onFinalizationCompletedWithChildActivityLaunched() {
// Don't commit finalized state until child activity completes.
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
// We use FINAL_SCREEN_REQUEST_CODE in the admin-integrated flow, because the DPC has
// already run earlier, so we don't run it again during finalization. Instead, we show
// a generic UI indicating that provisioning is done. In other flows, we start up the
// DPC during finalization, using DPC_SETUP_REQUEST_CODE.
case DPC_SETUP_REQUEST_CODE:
logDpcSetupCompleted(resultCode);
// Fall through; code below this applies to both request codes
case FINAL_SCREEN_REQUEST_CODE:
ProvisionLogger.logi("onActivityResult: received "
+ "requestCode = " + requestCode + ", resultCode = " + resultCode);
// Inside of SUW, if this activity returns RESULT_CANCELED, we will go back to
// the previous SUW action. Don't finalize the user provisioning state in that
// case, so that we run finalization again when the user goes forward again in SUW.
if (resultCode != RESULT_CANCELED) {
getFinalizationController().commitFinalizedState();
}
setResult(resultCode);
getTransitionHelper().finishActivity(this);
break;
default:
ProvisionLogger.logw("onActivityResult: Unknown request code: " + requestCode);
break;
}
}
private void logDpcSetupCompleted(int resultCode) {
final ProvisioningAnalyticsTracker provisioningAnalyticsTracker =
new ProvisioningAnalyticsTracker(
MetricsWriterFactory.getMetricsWriter(this, new SettingsFacade()),
new ManagedProvisioningSharedPreferences(this));
provisioningAnalyticsTracker.logDpcSetupCompleted(this, resultCode);
}
}