Sander Alewijnse | 7a85694 | 2014-09-08 20:46:40 +0100 | [diff] [blame] | 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 | |
Sander Alewijnse | 7a85694 | 2014-09-08 20:46:40 +0100 | [diff] [blame] | 19 | import android.app.Dialog; |
| 20 | import android.app.DialogFragment; |
Sander Alewijnse | b86e89b | 2014-09-26 11:42:00 +0100 | [diff] [blame] | 21 | import android.content.DialogInterface; |
Sander Alewijnse | 7a85694 | 2014-09-08 20:46:40 +0100 | [diff] [blame] | 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; |
Sander Alewijnse | 7a85694 | 2014-09-08 20:46:40 +0100 | [diff] [blame] | 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"; |
Sander Alewijnse | 93476d6 | 2014-10-01 12:23:06 +0100 | [diff] [blame] | 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/"; |
Sander Alewijnse | 7a85694 | 2014-09-08 20:46:40 +0100 | [diff] [blame] | 47 | |
Sander Alewijnse | 3bad02d | 2014-10-02 14:57:05 +0100 | [diff] [blame] | 48 | private static final String KEY_OWNER_TYPE = "owner_type"; |
Sander Alewijnse | 7a85694 | 2014-09-08 20:46:40 +0100 | [diff] [blame] | 49 | |
Sander Alewijnse | 3bad02d | 2014-10-02 14:57:05 +0100 | [diff] [blame] | 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; |
Sander Alewijnse | 7a85694 | 2014-09-08 20:46:40 +0100 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
Sander Alewijnse | 3bad02d | 2014-10-02 14:57:05 +0100 | [diff] [blame] | 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); |
Sander Alewijnse | 7a85694 | 2014-09-08 20:46:40 +0100 | [diff] [blame] | 66 | dialog.setContentView(R.layout.learn_more_dialog); |
Sander Alewijnse | b86e89b | 2014-09-26 11:42:00 +0100 | [diff] [blame] | 67 | dialog.setCanceledOnTouchOutside(false); |
Sander Alewijnse | 7a85694 | 2014-09-08 20:46:40 +0100 | [diff] [blame] | 68 | |
| 69 | TextView text1 = (TextView) dialog.findViewById(R.id.learn_more_text1); |
Sander Alewijnse | 3bad02d | 2014-10-02 14:57:05 +0100 | [diff] [blame] | 70 | if (ownerType == PROFILE_OWNER) { |
Sander Alewijnse | 93476d6 | 2014-10-01 12:23:06 +0100 | [diff] [blame] | 71 | text1.setText(R.string.admin_has_ability_to_monitor_profile); |
Sander Alewijnse | 3bad02d | 2014-10-02 14:57:05 +0100 | [diff] [blame] | 72 | } else if (ownerType == DEVICE_OWNER) { |
Sander Alewijnse | 93476d6 | 2014-10-01 12:23:06 +0100 | [diff] [blame] | 73 | text1.setText(R.string.admin_has_ability_to_monitor_device); |
| 74 | } |
Sander Alewijnse | 7a85694 | 2014-09-08 20:46:40 +0100 | [diff] [blame] | 75 | |
Sander Alewijnse | 3bad02d | 2014-10-02 14:57:05 +0100 | [diff] [blame] | 76 | TextView linkText = (TextView) dialog.findViewById(R.id.learn_more_link); |
| 77 | if (ownerType == PROFILE_OWNER) { |
Sander Alewijnse | 7a85694 | 2014-09-08 20:46:40 +0100 | [diff] [blame] | 78 | linkText.setOnClickListener(new OnClickListener() { |
| 79 | @Override |
| 80 | public void onClick(View v) { |
Sander Alewijnse | 93476d6 | 2014-10-01 12:23:06 +0100 | [diff] [blame] | 81 | Intent browserIntent = new Intent(Intent.ACTION_VIEW, |
| 82 | Uri.parse(LEARN_MORE_URL_PROFILE_OWNER)); |
Sander Alewijnse | 3bad02d | 2014-10-02 14:57:05 +0100 | [diff] [blame] | 83 | getActivity().startActivity(browserIntent); |
Sander Alewijnse | 7a85694 | 2014-09-08 20:46:40 +0100 | [diff] [blame] | 84 | } |
| 85 | }); |
Sander Alewijnse | 3bad02d | 2014-10-02 14:57:05 +0100 | [diff] [blame] | 86 | } else if (ownerType == DEVICE_OWNER) { |
Sander Alewijnse | 93476d6 | 2014-10-01 12:23:06 +0100 | [diff] [blame] | 87 | linkText.setOnClickListener(new OnClickListener() { |
| 88 | @Override |
| 89 | public void onClick(View v) { |
Sander Alewijnse | 3bad02d | 2014-10-02 14:57:05 +0100 | [diff] [blame] | 90 | Intent webIntent = new Intent(getActivity(), WebActivity.class); |
Sander Alewijnse | 93476d6 | 2014-10-01 12:23:06 +0100 | [diff] [blame] | 91 | 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 Alewijnse | 3bad02d | 2014-10-02 14:57:05 +0100 | [diff] [blame] | 94 | getActivity().startActivity(webIntent); |
Sander Alewijnse | 93476d6 | 2014-10-01 12:23:06 +0100 | [diff] [blame] | 95 | } |
| 96 | }); |
Sander Alewijnse | 7a85694 | 2014-09-08 20:46:40 +0100 | [diff] [blame] | 97 | } |
| 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 Alewijnse | 3bad02d | 2014-10-02 14:57:05 +0100 | [diff] [blame] | 104 | ((ConsentCallback) getActivity()).onDialogConsent(); |
Sander Alewijnse | 7a85694 | 2014-09-08 20:46:40 +0100 | [diff] [blame] | 105 | } |
| 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 Alewijnse | 3bad02d | 2014-10-02 14:57:05 +0100 | [diff] [blame] | 113 | ((ConsentCallback) getActivity()).onDialogCancel(); |
Sander Alewijnse | 7a85694 | 2014-09-08 20:46:40 +0100 | [diff] [blame] | 114 | } |
| 115 | }); |
| 116 | |
Rubin Xu | 44cdbdf | 2014-11-28 15:19:14 +0000 | [diff] [blame] | 117 | 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 Alewijnse | 7a85694 | 2014-09-08 20:46:40 +0100 | [diff] [blame] | 120 | return dialog; |
| 121 | } |
Sander Alewijnse | b86e89b | 2014-09-26 11:42:00 +0100 | [diff] [blame] | 122 | |
| 123 | @Override |
| 124 | public void onCancel(DialogInterface dialog) { |
Sander Alewijnse | 3bad02d | 2014-10-02 14:57:05 +0100 | [diff] [blame] | 125 | ((ConsentCallback) getActivity()).onDialogCancel(); |
| 126 | } |
| 127 | |
| 128 | public interface ConsentCallback { |
| 129 | public abstract void onDialogConsent(); |
| 130 | public abstract void onDialogCancel(); |
Sander Alewijnse | b86e89b | 2014-09-26 11:42:00 +0100 | [diff] [blame] | 131 | } |
Sander Alewijnse | 7a85694 | 2014-09-08 20:46:40 +0100 | [diff] [blame] | 132 | } |