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.admin.DevicePolicyManager; 21 import android.content.DialogInterface; 22 import android.content.DialogInterface.OnClickListener; 23 import android.content.DialogInterface.OnDismissListener; 24 import android.content.Intent; 25 import android.os.Bundle; 26 import android.os.UserHandle; 27 import android.provider.Settings; 28 29 import androidx.appcompat.app.AlertDialog; 30 31 import com.android.settingslib.RestrictedLockUtils; 32 33 /** 34 * Activity that shows a dialog explaining that a CA cert is allowing someone to monitor network 35 * traffic. This activity should be launched for the user into which the CA cert is installed 36 * unless Intent.EXTRA_USER_ID is provided. 37 */ 38 public class MonitoringCertInfoActivity extends Activity implements OnClickListener, 39 OnDismissListener { 40 41 private int mUserId; 42 43 @Override onCreate(Bundle savedStates)44 protected void onCreate(Bundle savedStates) { 45 super.onCreate(savedStates); 46 47 mUserId = getIntent().getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId()); 48 49 final UserHandle user; 50 if (mUserId == UserHandle.USER_NULL) { 51 user = null; 52 } else { 53 user = UserHandle.of(mUserId); 54 } 55 56 DevicePolicyManager dpm = getSystemService(DevicePolicyManager.class); 57 final int numberOfCertificates = getIntent().getIntExtra( 58 Settings.EXTRA_NUMBER_OF_CERTIFICATES, 1); 59 final int titleId = RestrictedLockUtils.getProfileOrDeviceOwner(this, user) != null 60 ? R.plurals.ssl_ca_cert_settings_button // Check certificate 61 : R.plurals.ssl_ca_cert_dialog_title; // Trust or remove certificate 62 final CharSequence title = getResources().getQuantityText(titleId, numberOfCertificates); 63 setTitle(title); 64 65 final AlertDialog.Builder builder = new AlertDialog.Builder(this); 66 builder.setTitle(title); 67 builder.setCancelable(true); 68 builder.setPositiveButton(getResources().getQuantityText( 69 R.plurals.ssl_ca_cert_settings_button, numberOfCertificates) , this); 70 builder.setNeutralButton(R.string.cancel, null); 71 builder.setOnDismissListener(this); 72 73 if (dpm.getProfileOwnerAsUser(mUserId) != null) { 74 builder.setMessage(getResources().getQuantityString(R.plurals.ssl_ca_cert_info_message, 75 numberOfCertificates, dpm.getProfileOwnerNameAsUser(mUserId))); 76 } else if (dpm.getDeviceOwnerComponentOnCallingUser() != null) { 77 builder.setMessage(getResources().getQuantityString( 78 R.plurals.ssl_ca_cert_info_message_device_owner, numberOfCertificates, 79 dpm.getDeviceOwnerNameOnAnyUser())); 80 } else { 81 // Consumer case. Show scary warning. 82 builder.setIcon(android.R.drawable.stat_notify_error); 83 builder.setMessage(R.string.ssl_ca_cert_warning_message); 84 } 85 86 builder.show(); 87 } 88 89 @Override onClick(DialogInterface dialog, int which)90 public void onClick(DialogInterface dialog, int which) { 91 Intent intent = new Intent(android.provider.Settings.ACTION_TRUSTED_CREDENTIALS_USER); 92 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); 93 intent.putExtra(TrustedCredentialsSettings.ARG_SHOW_NEW_FOR_USER, mUserId); 94 startActivity(intent); 95 finish(); 96 } 97 98 @Override onDismiss(DialogInterface dialogInterface)99 public void onDismiss(DialogInterface dialogInterface) { 100 finish(); 101 } 102 } 103