The new certificate can be installed from Settings ("Install a certificate > App Source certificate"). The installation flow includes a warning with user authorization to proceed, then a prompt for reboot (now or later). Installed certificate can be managed in "User credentials". The name is currently a hash of hex numbers. Upon deletion, there will also be a promot for reboot (now or later). Test: Only see the new setting entry if feature is enabled Test: Install from Settings, see the expected file name in /data/misc/keysetore/user_0. Reboot also works. Test: Able to see the certificate in Settings after installed Test: Able to delete the certificate, which triggers confirmation dialog to reboot. Reboot works. Test: add certificate, see dialog, "not now" / tapping elsewhere does nothing Test: atest RestrictedEncryptionPreferenceControllerTest Bug: 112038744 Change-Id: I7a4494ea0f243730df2212076588074d8774ae23
84 lines
3.0 KiB
Java
84 lines
3.0 KiB
Java
/*
|
|
* Copyright (C) 2019 The Android Open Source Project
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
package com.android.settings.security;
|
|
|
|
import android.annotation.Nullable;
|
|
import android.app.Activity;
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.security.Credentials;
|
|
import android.view.View;
|
|
import android.widget.Toast;
|
|
|
|
import com.android.settings.R;
|
|
|
|
import com.google.android.setupcompat.template.FooterBarMixin;
|
|
import com.google.android.setupcompat.template.FooterButton;
|
|
import com.google.android.setupdesign.GlifLayout;
|
|
|
|
/**
|
|
* Creates a warning dialog explaining the consequences of installing a certificate
|
|
* This is displayed before an app source certificate can be installed from Settings.
|
|
*/
|
|
public class InstallAppSourceCertificateWarning extends Activity {
|
|
@Override
|
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.app_source_certificate_warning_dialog);
|
|
final GlifLayout layout = findViewById(R.id.setup_wizard_layout);
|
|
|
|
final FooterBarMixin mixin = layout.getMixin(FooterBarMixin.class);
|
|
mixin.setSecondaryButton(
|
|
new FooterButton.Builder(this)
|
|
.setText(R.string.certificate_warning_install_anyway)
|
|
.setListener(installCertificate())
|
|
.setButtonType(FooterButton.ButtonType.OTHER)
|
|
.setTheme(R.style.SudGlifButton_Secondary)
|
|
.build()
|
|
);
|
|
|
|
mixin.setPrimaryButton(
|
|
new FooterButton.Builder(this)
|
|
.setText(R.string.certificate_warning_dont_install)
|
|
.setListener(returnToInstallCertificateFromStorage())
|
|
.setButtonType(FooterButton.ButtonType.NEXT)
|
|
.setTheme(R.style.SudGlifButton_Primary)
|
|
.build()
|
|
);
|
|
}
|
|
|
|
private View.OnClickListener installCertificate() {
|
|
return v -> {
|
|
final Intent intent = new Intent();
|
|
intent.setAction(Credentials.INSTALL_ACTION);
|
|
intent.putExtra(Credentials.EXTRA_CERTIFICATE_USAGE,
|
|
Credentials.CERTIFICATE_USAGE_APP_SOURCE);
|
|
startActivity(intent);
|
|
finish();
|
|
};
|
|
}
|
|
|
|
private View.OnClickListener returnToInstallCertificateFromStorage() {
|
|
return v -> {
|
|
Toast.makeText(this, R.string.cert_not_installed, Toast.LENGTH_SHORT).show();
|
|
finish();
|
|
};
|
|
}
|
|
|
|
}
|