1/*
2 * Copyright (C) 2013 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.settings;
18
19import android.app.Activity;
20import android.app.AlertDialog;
21import android.app.Dialog;
22import android.app.admin.DevicePolicyManager;
23import android.content.Context;
24import android.content.DialogInterface;
25import android.content.DialogInterface.OnClickListener;
26import android.content.Intent;
27import android.os.Bundle;
28import android.os.RemoteException;
29import android.view.WindowManager;
30import android.view.WindowManagerGlobal;
31
32/**
33 * Activity that shows a dialog explaining that a CA cert is allowing someone to monitor network
34 * traffic.
35 */
36public class MonitoringCertInfoActivity extends Activity implements OnClickListener {
37
38    private boolean hasDeviceOwner = false;
39
40    @Override
41    protected void onCreate(Bundle savedStates) {
42        super.onCreate(savedStates);
43
44        DevicePolicyManager dpm =
45                (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
46
47        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
48        builder.setTitle(R.string.ssl_ca_cert_dialog_title);
49        builder.setCancelable(true);
50        hasDeviceOwner = dpm.getDeviceOwner() != null;
51        int buttonLabel;
52        if (hasDeviceOwner) {
53            // Institutional case.  Show informational message.
54            String message = this.getResources().getString(R.string.ssl_ca_cert_info_message,
55                    dpm.getDeviceOwnerName());
56            builder.setMessage(message);
57            buttonLabel = R.string.done_button;
58        } else {
59            // Consumer case.  Show scary warning.
60            builder.setIcon(android.R.drawable.stat_notify_error);
61            builder.setMessage(R.string.ssl_ca_cert_warning_message);
62            buttonLabel = R.string.ssl_ca_cert_settings_button;
63        }
64
65        builder.setPositiveButton(buttonLabel, this);
66
67        final Dialog dialog = builder.create();
68        dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
69        try {
70            WindowManagerGlobal.getWindowManagerService().dismissKeyguard();
71        } catch (RemoteException e) {
72        }
73        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
74            @Override public void onCancel(DialogInterface dialog) {
75                finish();
76            }
77        });
78
79        dialog.show();
80    }
81
82    @Override
83    public void onClick(DialogInterface dialog, int which) {
84        if (hasDeviceOwner) {
85            finish();
86        } else {
87            Intent intent =
88                    new Intent(android.provider.Settings.ACTION_TRUSTED_CREDENTIALS_USER);
89            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
90            startActivity(intent);
91            finish();
92        }
93    }
94}
95