• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.common;
18 
19 import static java.util.Objects.requireNonNull;
20 
21 import android.content.Intent;
22 
23 /**
24  * Utilities related to error dialogs, such as constructing a resulting {@link Intent} that
25  * describes a dialog.
26  */
27 public final class ErrorDialogUtils {
28     public static final String EXTRA_DIALOG_TITLE_ID = "dialog_title_id";
29     public static final String EXTRA_ERROR_MESSAGE_RES_ID =
30             "dialog_error_message_res_id";
31     public static final String EXTRA_FACTORY_RESET_REQUIRED =
32             "factory_reset_required";
33 
ErrorDialogUtils()34     private ErrorDialogUtils() {}
35 
36     /**
37      * Creates a resulting intent to be returned as a result that describes an error.
38      */
createResultIntent(ErrorWrapper error)39     public static Intent createResultIntent(ErrorWrapper error) {
40         requireNonNull(error);
41         Intent intent = new Intent();
42         if (error.dialogTitleId != 0) {
43             intent.putExtra(EXTRA_DIALOG_TITLE_ID, error.dialogTitleId);
44         }
45         if (error.errorMessageResId != 0) {
46             intent.putExtra(EXTRA_ERROR_MESSAGE_RES_ID, error.errorMessageResId);
47         }
48         intent.putExtra(EXTRA_FACTORY_RESET_REQUIRED, error.factoryResetRequired);
49         return intent;
50     }
51 }
52