Files
packages_apps_Settings/src/com/android/settings/security/CredentialManagementAppHeaderController.java
Alex Johnston 7db8142435 Credential management app UI tweaks
Credential management app Settings screen
* Add uninstall certificates button
* Reformat summary
* Remove dividing lines
Request manage credentials screen
* Make requesting app name bold

Manual testing
* Install TestDPC and select 'Request to
  manage credentials'
* Verify app name is bold and select allow
* Install a certificate as the cred mng app
  via TestDPC
* Go to Setting > Security > Encryption
  & Credentials > Credential Management App
* Verify screen looks like mocks
* Select 'Remove certificates' and
  verify all certificates installed by the
  cred mng app are removed
Settings screen: https://screenshot.googleplex.com/C6n9bnwkw843jgf
Request screen: https://screenshot.googleplex.com/5qH44NXKKGRsdHs

Bug: 189416800
Test: manual testing
      CredentialManagementAppControllerTest
      CredentialManagementAppFragmentTest
      CredentialManagementAppButtonsControllerTest
      CredentialManagementAppHeaderControllerTest
      RequestManageCredentialsTest
Change-Id: I71334b231ae7cefbc055e2575eda5418da2548b4
2021-06-09 10:13:53 +01:00

100 lines
3.8 KiB
Java

/*
* Copyright (C) 2020 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.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.os.Looper;
import android.os.RemoteException;
import android.security.IKeyChainService;
import android.security.KeyChain;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.widget.LayoutPreference;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* Controller that shows the header of the credential management app, which includes credential
* management app's name, icon and a description.
*/
public class CredentialManagementAppHeaderController extends BasePreferenceController {
private static final String TAG = "CredentialManagementApp";
private final ExecutorService mExecutor = Executors.newSingleThreadExecutor();
private final Handler mHandler = new Handler(Looper.getMainLooper());
public CredentialManagementAppHeaderController(Context context, String preferenceKey) {
super(context, preferenceKey);
mPackageManager = context.getPackageManager();
}
private final PackageManager mPackageManager;
private String mCredentialManagerPackageName;
@Override
public int getAvailabilityStatus() {
return AVAILABLE_UNSEARCHABLE;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mExecutor.execute(() -> {
try {
IKeyChainService service = KeyChain.bind(mContext).getService();
mCredentialManagerPackageName = service.getCredentialManagementAppPackageName();
} catch (InterruptedException | RemoteException e) {
Log.e(TAG, "Unable to display credential management app header");
}
mHandler.post(() -> displayHeader(screen));
});
}
private void displayHeader(PreferenceScreen screen) {
LayoutPreference headerPref = screen.findPreference(getPreferenceKey());
ImageView appIconView = headerPref.findViewById(R.id.entity_header_icon);
TextView titleView = headerPref.findViewById(R.id.entity_header_title);
TextView summary1 = headerPref.findViewById(R.id.entity_header_summary);
TextView summary2 = headerPref.findViewById(R.id.entity_header_second_summary);
summary2.setVisibility(View.GONE);
try {
ApplicationInfo applicationInfo =
mPackageManager.getApplicationInfo(mCredentialManagerPackageName, 0);
appIconView.setImageDrawable(mPackageManager.getApplicationIcon(applicationInfo));
titleView.setText(applicationInfo.loadLabel(mPackageManager));
summary1.setText(R.string.certificate_management_app_description);
} catch (PackageManager.NameNotFoundException e) {
appIconView.setImageDrawable(null);
titleView.setText(mCredentialManagerPackageName);
}
}
}