1 /* 2 * Copyright (C) 2019 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.security; 18 19 import android.annotation.Nullable; 20 import android.app.Activity; 21 import android.content.Intent; 22 import android.os.Bundle; 23 import android.security.Credentials; 24 import android.view.View; 25 import android.widget.Toast; 26 27 import com.android.settings.R; 28 import com.android.settings.SetupWizardUtils; 29 30 import com.google.android.setupcompat.template.FooterBarMixin; 31 import com.google.android.setupcompat.template.FooterButton; 32 import com.google.android.setupdesign.GlifLayout; 33 import com.google.android.setupdesign.util.ThemeHelper; 34 35 /** 36 * Creates a warning dialog explaining the consequences of installing a CA certificate 37 * This is displayed before a CA certificate can be installed from Settings. 38 */ 39 public class InstallCaCertificateWarning extends Activity { 40 41 @Override onCreate(@ullable Bundle savedInstanceState)42 public void onCreate(@Nullable Bundle savedInstanceState) { 43 super.onCreate(savedInstanceState); 44 45 setTheme(SetupWizardUtils.getTheme(this, getIntent())); 46 ThemeHelper.trySetDynamicColor(this); 47 setContentView(R.layout.ca_certificate_warning_dialog); 48 final GlifLayout layout = findViewById(R.id.setup_wizard_layout); 49 layout.setHeaderText(R.string.ca_certificate_warning_title); 50 51 final FooterBarMixin mixin = layout.getMixin(FooterBarMixin.class); 52 mixin.setSecondaryButton( 53 new FooterButton.Builder(this) 54 .setText(R.string.certificate_warning_install_anyway) 55 .setListener(installCaCertificate()) 56 .setButtonType(FooterButton.ButtonType.OTHER) 57 .setTheme(R.style.SudGlifButton_Secondary) 58 .build() 59 ); 60 61 mixin.setPrimaryButton( 62 new FooterButton.Builder(this) 63 .setText(R.string.certificate_warning_dont_install) 64 .setListener(returnToInstallCertificateFromStorage()) 65 .setButtonType(FooterButton.ButtonType.NEXT) 66 .setTheme(R.style.SudGlifButton_Primary) 67 .build() 68 ); 69 } 70 installCaCertificate()71 private View.OnClickListener installCaCertificate() { 72 return v -> { 73 final Intent intent = new Intent(); 74 intent.setAction(Credentials.INSTALL_ACTION); 75 intent.putExtra(Credentials.EXTRA_CERTIFICATE_USAGE, Credentials.CERTIFICATE_USAGE_CA); 76 startActivity(intent); 77 finish(); 78 }; 79 } 80 returnToInstallCertificateFromStorage()81 private View.OnClickListener returnToInstallCertificateFromStorage() { 82 return v -> { 83 Toast.makeText(this, R.string.cert_not_installed, Toast.LENGTH_SHORT).show(); 84 finish(); 85 }; 86 } 87 88 } 89