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