1 /* 2 * Copyright 2016, 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.parser; 18 19 import static com.android.internal.util.Preconditions.checkNotNull; 20 21 import android.content.Context; 22 import android.content.Intent; 23 24 import androidx.annotation.VisibleForTesting; 25 26 import com.android.managedprovisioning.common.IllegalProvisioningArgumentException; 27 import com.android.managedprovisioning.common.SettingsFacade; 28 import com.android.managedprovisioning.common.Utils; 29 import com.android.managedprovisioning.model.ProvisioningParams; 30 31 /** 32 * This class can initialize a {@link ProvisioningParams} object from an intent. 33 * 34 * <p>A {@link ProvisioningParams} object stores various parameters both for the device owner 35 * provisioning and profile owner provisioning. 36 */ 37 public class MessageParser implements ProvisioningDataParser { 38 39 private final Utils mUtils; 40 private final ParserUtils mParserUtils; 41 private final SettingsFacade mSettingsFacade; 42 private final Context mContext; 43 MessageParser(Context context, Utils utils)44 public MessageParser(Context context, Utils utils) { 45 this(context, utils, new ParserUtils(), new SettingsFacade()); 46 } 47 48 @VisibleForTesting MessageParser(Context context, Utils utils, ParserUtils parserUtils, SettingsFacade settingsFacade)49 MessageParser(Context context, Utils utils, ParserUtils parserUtils, 50 SettingsFacade settingsFacade) { 51 mContext = checkNotNull(context); 52 mUtils = checkNotNull(utils); 53 mParserUtils = checkNotNull(parserUtils); 54 mSettingsFacade = checkNotNull(settingsFacade); 55 } 56 57 @Override parse(Intent provisioningIntent)58 public ProvisioningParams parse(Intent provisioningIntent) 59 throws IllegalProvisioningArgumentException { 60 return getParser().parse(provisioningIntent); 61 } 62 63 @VisibleForTesting getParser()64 ProvisioningDataParser getParser() { 65 return new ExtrasProvisioningDataParser(mContext, mUtils, mParserUtils, mSettingsFacade); 66 } 67 } 68