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