Home | History | Annotate | Download | only in settings
      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 
     17 package com.android.settings;
     18 
     19 import android.app.Activity;
     20 import android.app.AlertDialog;
     21 import android.app.Dialog;
     22 import android.app.admin.DevicePolicyManager;
     23 import android.content.Context;
     24 import android.content.DialogInterface;
     25 import android.content.DialogInterface.OnClickListener;
     26 import android.content.Intent;
     27 import android.os.Bundle;
     28 import android.os.RemoteException;
     29 import android.view.WindowManager;
     30 import 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  */
     36 public 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