1 /* 2 * Copyright (C) 2023 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.devicelockcontroller.activities; 18 19 import static com.android.devicelockcontroller.common.DeviceLockConstants.ProvisionFailureReason.UNKNOWN_REASON; 20 21 import com.android.devicelockcontroller.R; 22 import com.android.devicelockcontroller.common.DeviceLockConstants.ProvisionFailureReason; 23 24 import java.util.Objects; 25 26 /** 27 * Different stages of the provisioning progress. 28 */ 29 public final class ProvisioningProgress { 30 31 public static final ProvisioningProgress GETTING_DEVICE_READY = new ProvisioningProgress( 32 R.drawable.ic_smartphone_24px, R.string.getting_device_ready, 33 R.string.this_may_take_a_few_minutes); 34 public static final ProvisioningProgress INSTALLING_KIOSK_APP = new ProvisioningProgress( 35 R.drawable.ic_downloading_24px, R.string.installing_kiosk_app); 36 public static final ProvisioningProgress OPENING_KIOSK_APP = new ProvisioningProgress( 37 R.drawable.ic_open_in_new_24px, R.string.opening_kiosk_app); 38 39 final int mIconId; 40 final int mHeaderId; 41 final int mSubheaderId; 42 final boolean mProgressBarVisible; 43 final boolean mBottomViewVisible; 44 45 final boolean mCountDownTimerVisible; 46 47 @ProvisionFailureReason 48 final int mFailureReason; 49 ProvisioningProgress(int iconId, int headerId)50 private ProvisioningProgress(int iconId, int headerId) { 51 this(iconId, headerId, 0); 52 } 53 ProvisioningProgress(int iconId, int headerId, int subheaderId)54 ProvisioningProgress(int iconId, int headerId, int subheaderId) { 55 this(iconId, headerId, subheaderId, /* progressBarVisible= */ true, 56 /* bottomViewVisible= */ false, /* countDownTimerVisible= */ false, UNKNOWN_REASON); 57 } 58 ProvisioningProgress(boolean bottomViewVisible, boolean countDownTimerVisible, @ProvisionFailureReason int failureReason)59 ProvisioningProgress(boolean bottomViewVisible, boolean countDownTimerVisible, 60 @ProvisionFailureReason int failureReason) { 61 this(R.drawable.ic_warning_24px, R.string.provisioning_failed, 62 R.string.click_to_contact_financier, /* progressBarVisible=*/ false, 63 bottomViewVisible, countDownTimerVisible, failureReason); 64 } 65 ProvisioningProgress(int iconId, int headerId, int subheaderId, boolean progressBarVisible, boolean bottomViewVisible, boolean countDownTimerVisible, @ProvisionFailureReason int failureReason)66 ProvisioningProgress(int iconId, int headerId, int subheaderId, boolean progressBarVisible, 67 boolean bottomViewVisible, boolean countDownTimerVisible, 68 @ProvisionFailureReason int failureReason) { 69 mHeaderId = headerId; 70 mIconId = iconId; 71 mSubheaderId = subheaderId; 72 mProgressBarVisible = progressBarVisible; 73 mBottomViewVisible = bottomViewVisible; 74 mCountDownTimerVisible = countDownTimerVisible; 75 mFailureReason = failureReason; 76 } 77 78 /** 79 * Get the provision failure progress item for mandatory case with the failure reason. 80 * 81 * @param failureReason one of {@link ProvisionFailureReason} The reason why provision failed. 82 */ getMandatoryProvisioningFailedProgress( @rovisionFailureReason int failureReason)83 public static ProvisioningProgress getMandatoryProvisioningFailedProgress( 84 @ProvisionFailureReason int failureReason) { 85 return new ProvisioningProgress( 86 /* bottomViewVisible= */ false, /* countDownTimerVisible= */ true, failureReason); 87 } 88 89 /** 90 * Get the provision failure progress item for non-mandatory case with the failure reason. 91 * 92 * @param failureReason one of {@link ProvisionFailureReason} The reason why provision failed. 93 */ getNonMandatoryProvisioningFailedProgress( @rovisionFailureReason int failureReason)94 public static ProvisioningProgress getNonMandatoryProvisioningFailedProgress( 95 @ProvisionFailureReason int failureReason) { 96 return new ProvisioningProgress( 97 /* bottomViewVisible= */ true, /* countDownTimerVisible= */ false, failureReason); 98 } 99 100 @Override equals(Object o)101 public boolean equals(Object o) { 102 if (this == o) return true; 103 if (o == null || getClass() != o.getClass()) return false; 104 ProvisioningProgress that = (ProvisioningProgress) o; 105 return mIconId == that.mIconId && mHeaderId == that.mHeaderId 106 && mSubheaderId == that.mSubheaderId 107 && mProgressBarVisible == that.mProgressBarVisible 108 && mBottomViewVisible == that.mBottomViewVisible 109 && mCountDownTimerVisible == that.mCountDownTimerVisible 110 && mFailureReason == that.mFailureReason; 111 } 112 113 @Override hashCode()114 public int hashCode() { 115 return Objects.hash(mIconId, mHeaderId, mSubheaderId, mProgressBarVisible, 116 mBottomViewVisible, 117 mCountDownTimerVisible, mFailureReason); 118 } 119 120 @Override toString()121 public String toString() { 122 return "ProvisioningProgress{" 123 + "mIconId=" + mIconId 124 + ", mHeaderId=" + mHeaderId 125 + ", mSubheaderId=" + mSubheaderId 126 + ", mProgressBarVisible=" + mProgressBarVisible 127 + ", mBottomViewVisible=" + mBottomViewVisible 128 + ", mCountDownTimerVisible=" + mCountDownTimerVisible 129 + ", mFailureReason=" + mFailureReason 130 + '}'; 131 } 132 } 133