16fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz/*
26fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz * Copyright 2016, The Android Open Source Project
36fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz *
46fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz * Licensed under the Apache License, Version 2.0 (the "License");
56fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz * you may not use this file except in compliance with the License.
66fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz * You may obtain a copy of the License at
76fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz *
86fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz *     http://www.apache.org/licenses/LICENSE-2.0
96fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz *
106fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz * Unless required by applicable law or agreed to in writing, software
116fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz * distributed under the License is distributed on an "AS IS" BASIS,
126fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
136fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz * See the License for the specific language governing permissions and
146fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz * limitations under the License.
156fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz */
166fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz
176fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franzpackage com.android.managedprovisioning.provisioning;
186fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz
196fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franzimport android.content.Context;
206fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franzimport android.os.UserHandle;
216fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz
226fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franzimport com.android.internal.annotations.VisibleForTesting;
236fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franzimport com.android.managedprovisioning.common.Utils;
246fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franzimport com.android.managedprovisioning.model.ProvisioningParams;
256fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz
266fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz/**
276fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz * Factory class to create an {@link AbstractProvisioningController} from a set of
286fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz * {@link ProvisioningParams}.
296fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz */
306fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz@VisibleForTesting
316fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franzpublic class ProvisioningControllerFactory {
326fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz
336fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz    private final Utils mUtils = new Utils();
346fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz
356fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz    /**
366fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz     * This method constructs the controller used for the given type of provisioning.
376fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz     */
386fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz    @VisibleForTesting
396fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz    public AbstractProvisioningController createProvisioningController(
406fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz            Context context,
416fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz            ProvisioningParams params,
426fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz            ProvisioningControllerCallback callback) {
436fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz        if (mUtils.isDeviceOwnerAction(params.provisioningAction)) {
446fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz            return new DeviceOwnerProvisioningController(
456fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz                    context,
466fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz                    params,
476fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz                    UserHandle.myUserId(),
486fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz                    callback);
496fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz        } else {
506fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz            return new ProfileOwnerProvisioningController(
516fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz                    context,
526fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz                    params,
536fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz                    UserHandle.myUserId(),
546fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz                    callback);
556fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz        }
566fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz    }
576fb7161fc761c817cd3e708617ae3b3d331b1069Benjamin Franz}
58