• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2014, 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;
18 
19 import android.app.Dialog;
20 import android.app.DialogFragment;
21 import android.content.DialogInterface;
22 import android.content.Intent;
23 import android.net.Uri;
24 import android.os.Bundle;
25 import android.view.View;
26 import android.view.View.OnClickListener;
27 import android.widget.TextView;
28 import android.widget.Button;
29 
30 /**
31  * Dialog used to notify the user that the admin will have full control over the profile/device.
32  * Custom runnables can be passed that are run on consent or cancel.
33  */
34 public class UserConsentDialog extends DialogFragment {
35     public static final int PROFILE_OWNER = 1;
36     public static final int DEVICE_OWNER = 2;
37 
38     public static final String LEARN_MORE_URL_PROFILE_OWNER =
39             "https://support.google.com/android/work/answer/6090512";
40     // TODO: replace by the final device owner learn more link.
41     public static final String LEARN_MORE_URL_DEVICE_OWNER =
42             "https://support.google.com/android/work/answer/6090512";
43 
44     // Only urls starting with this base can be visisted in the device owner case.
45     public static final String LEARN_MORE_ALLOWED_BASE_URL =
46             "https://support.google.com/";
47 
48     private static final String KEY_OWNER_TYPE = "owner_type";
49 
newInstance(int ownerType)50     public static UserConsentDialog newInstance(int ownerType) {
51         UserConsentDialog dialog = new UserConsentDialog();
52         Bundle args = new Bundle();
53         args.putInt(KEY_OWNER_TYPE, ownerType);
54         dialog.setArguments(args);
55         return dialog;
56     }
57 
58     @Override
onCreateDialog(Bundle savedInstanceState)59     public Dialog onCreateDialog(Bundle savedInstanceState) {
60         int ownerType = getArguments().getInt(KEY_OWNER_TYPE);
61         if (ownerType != PROFILE_OWNER && ownerType != DEVICE_OWNER) {
62             throw new IllegalArgumentException("Illegal value for argument ownerType.");
63         }
64 
65         final Dialog dialog = new Dialog(getActivity(), R.style.ManagedProvisioningDialogTheme);
66         dialog.setContentView(R.layout.learn_more_dialog);
67         dialog.setCanceledOnTouchOutside(false);
68 
69         TextView text1 = (TextView) dialog.findViewById(R.id.learn_more_text1);
70         if (ownerType == PROFILE_OWNER) {
71             text1.setText(R.string.admin_has_ability_to_monitor_profile);
72         } else if (ownerType == DEVICE_OWNER) {
73             text1.setText(R.string.admin_has_ability_to_monitor_device);
74         }
75 
76         TextView textFrpWarning = (TextView) dialog.findViewById(R.id.learn_more_frp_warning);
77         if (ownerType == DEVICE_OWNER && Utils.isFrpSupported(getActivity())) {
78             textFrpWarning.setVisibility(View.VISIBLE);
79         } else {
80             textFrpWarning.setVisibility(View.GONE);
81         }
82 
83         TextView linkText = (TextView) dialog.findViewById(R.id.learn_more_link);
84         if (ownerType == PROFILE_OWNER) {
85             linkText.setOnClickListener(new OnClickListener() {
86                     @Override
87                     public void onClick(View v) {
88                         Intent browserIntent = new Intent(Intent.ACTION_VIEW,
89                                 Uri.parse(LEARN_MORE_URL_PROFILE_OWNER));
90                         getActivity().startActivity(browserIntent);
91                     }
92                 });
93         } else if (ownerType == DEVICE_OWNER) {
94             linkText.setOnClickListener(new OnClickListener() {
95                     @Override
96                     public void onClick(View v) {
97                         Intent webIntent = new Intent(getActivity(), WebActivity.class);
98                         webIntent.putExtra(WebActivity.EXTRA_URL, LEARN_MORE_URL_DEVICE_OWNER);
99                         webIntent.putExtra(WebActivity.EXTRA_ALLOWED_URL_BASE,
100                                 LEARN_MORE_ALLOWED_BASE_URL);
101                         getActivity().startActivity(webIntent);
102                     }
103                 });
104         }
105 
106         Button positiveButton = (Button) dialog.findViewById(R.id.positive_button);
107         positiveButton.setOnClickListener(new OnClickListener() {
108                 @Override
109                 public void onClick(View v) {
110                     dialog.dismiss();
111                     ((ConsentCallback) getActivity()).onDialogConsent();
112                 }
113             });
114 
115         Button negativeButton = (Button) dialog.findViewById(R.id.negative_button);
116         negativeButton.setOnClickListener(new OnClickListener() {
117                 @Override
118                 public void onClick(View v) {
119                     dialog.dismiss();
120                     ((ConsentCallback) getActivity()).onDialogCancel();
121                 }
122             });
123 
124         return dialog;
125     }
126 
127     @Override
onCancel(DialogInterface dialog)128     public void onCancel(DialogInterface dialog) {
129         ((ConsentCallback) getActivity()).onDialogCancel();
130     }
131 
132     public interface ConsentCallback {
onDialogConsent()133         public abstract void onDialogConsent();
onDialogCancel()134         public abstract void onDialogCancel();
135     }
136 }