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