blob: 5a982cf8440e12456d2fa254689aa2be7562ee81 [file] [log] [blame]
Sander Alewijnse7a856942014-09-08 20:46:40 +01001/*
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
17package com.android.managedprovisioning;
18
Sander Alewijnse7a856942014-09-08 20:46:40 +010019import android.app.Dialog;
20import android.app.DialogFragment;
Sander Alewijnseb86e89b2014-09-26 11:42:00 +010021import android.content.DialogInterface;
Sander Alewijnse7a856942014-09-08 20:46:40 +010022import android.content.Intent;
23import android.net.Uri;
24import android.os.Bundle;
25import android.view.View;
26import android.view.View.OnClickListener;
Sander Alewijnse7a856942014-09-08 20:46:40 +010027import android.widget.TextView;
28import 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 */
34public 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";
Sander Alewijnse93476d62014-10-01 12:23:06 +010040 // 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/";
Sander Alewijnse7a856942014-09-08 20:46:40 +010047
Sander Alewijnse3bad02d2014-10-02 14:57:05 +010048 private static final String KEY_OWNER_TYPE = "owner_type";
Sander Alewijnse7a856942014-09-08 20:46:40 +010049
Sander Alewijnse3bad02d2014-10-02 14:57:05 +010050 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;
Sander Alewijnse7a856942014-09-08 20:46:40 +010056 }
57
58 @Override
59 public Dialog onCreateDialog(Bundle savedInstanceState) {
Sander Alewijnse3bad02d2014-10-02 14:57:05 +010060 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);
Sander Alewijnse7a856942014-09-08 20:46:40 +010066 dialog.setContentView(R.layout.learn_more_dialog);
Sander Alewijnseb86e89b2014-09-26 11:42:00 +010067 dialog.setCanceledOnTouchOutside(false);
Sander Alewijnse7a856942014-09-08 20:46:40 +010068
69 TextView text1 = (TextView) dialog.findViewById(R.id.learn_more_text1);
Sander Alewijnse3bad02d2014-10-02 14:57:05 +010070 if (ownerType == PROFILE_OWNER) {
Sander Alewijnse93476d62014-10-01 12:23:06 +010071 text1.setText(R.string.admin_has_ability_to_monitor_profile);
Sander Alewijnse3bad02d2014-10-02 14:57:05 +010072 } else if (ownerType == DEVICE_OWNER) {
Sander Alewijnse93476d62014-10-01 12:23:06 +010073 text1.setText(R.string.admin_has_ability_to_monitor_device);
74 }
Sander Alewijnse7a856942014-09-08 20:46:40 +010075
Sander Alewijnse3bad02d2014-10-02 14:57:05 +010076 TextView linkText = (TextView) dialog.findViewById(R.id.learn_more_link);
77 if (ownerType == PROFILE_OWNER) {
Sander Alewijnse7a856942014-09-08 20:46:40 +010078 linkText.setOnClickListener(new OnClickListener() {
79 @Override
80 public void onClick(View v) {
Sander Alewijnse93476d62014-10-01 12:23:06 +010081 Intent browserIntent = new Intent(Intent.ACTION_VIEW,
82 Uri.parse(LEARN_MORE_URL_PROFILE_OWNER));
Sander Alewijnse3bad02d2014-10-02 14:57:05 +010083 getActivity().startActivity(browserIntent);
Sander Alewijnse7a856942014-09-08 20:46:40 +010084 }
85 });
Sander Alewijnse3bad02d2014-10-02 14:57:05 +010086 } else if (ownerType == DEVICE_OWNER) {
Sander Alewijnse93476d62014-10-01 12:23:06 +010087 linkText.setOnClickListener(new OnClickListener() {
88 @Override
89 public void onClick(View v) {
Sander Alewijnse3bad02d2014-10-02 14:57:05 +010090 Intent webIntent = new Intent(getActivity(), WebActivity.class);
Sander Alewijnse93476d62014-10-01 12:23:06 +010091 webIntent.putExtra(WebActivity.EXTRA_URL, LEARN_MORE_URL_DEVICE_OWNER);
92 webIntent.putExtra(WebActivity.EXTRA_ALLOWED_URL_BASE,
93 LEARN_MORE_ALLOWED_BASE_URL);
Sander Alewijnse3bad02d2014-10-02 14:57:05 +010094 getActivity().startActivity(webIntent);
Sander Alewijnse93476d62014-10-01 12:23:06 +010095 }
96 });
Sander Alewijnse7a856942014-09-08 20:46:40 +010097 }
98
99 Button positiveButton = (Button) dialog.findViewById(R.id.positive_button);
100 positiveButton.setOnClickListener(new OnClickListener() {
101 @Override
102 public void onClick(View v) {
103 dialog.dismiss();
Sander Alewijnse3bad02d2014-10-02 14:57:05 +0100104 ((ConsentCallback) getActivity()).onDialogConsent();
Sander Alewijnse7a856942014-09-08 20:46:40 +0100105 }
106 });
107
108 Button negativeButton = (Button) dialog.findViewById(R.id.negative_button);
109 negativeButton.setOnClickListener(new OnClickListener() {
110 @Override
111 public void onClick(View v) {
112 dialog.dismiss();
Sander Alewijnse3bad02d2014-10-02 14:57:05 +0100113 ((ConsentCallback) getActivity()).onDialogCancel();
Sander Alewijnse7a856942014-09-08 20:46:40 +0100114 }
115 });
116
Rubin Xu44cdbdf2014-11-28 15:19:14 +0000117 dialog.getWindow().getDecorView().setSystemUiVisibility(
118 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
119 View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
Sander Alewijnse7a856942014-09-08 20:46:40 +0100120 return dialog;
121 }
Sander Alewijnseb86e89b2014-09-26 11:42:00 +0100122
123 @Override
124 public void onCancel(DialogInterface dialog) {
Sander Alewijnse3bad02d2014-10-02 14:57:05 +0100125 ((ConsentCallback) getActivity()).onDialogCancel();
126 }
127
128 public interface ConsentCallback {
129 public abstract void onDialogConsent();
130 public abstract void onDialogCancel();
Sander Alewijnseb86e89b2014-09-26 11:42:00 +0100131 }
Sander Alewijnse7a856942014-09-08 20:46:40 +0100132}