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.permissioncontroller.role.model; 18 19 import android.content.Context; 20 import android.content.pm.ApplicationInfo; 21 import android.util.Log; 22 23 import androidx.annotation.NonNull; 24 import androidx.annotation.Nullable; 25 26 import com.android.permissioncontroller.R; 27 import com.android.permissioncontroller.role.utils.PackageUtils; 28 29 /** 30 * Mixin for {@link RoleBehavior#getConfirmationMessage(Role, String, Context)} 31 * that returns a confirmation message when the application is not direct boot aware. 32 */ 33 public class EncryptionUnawareConfirmationMixin { 34 35 private static final String LOG_TAG = EncryptionUnawareConfirmationMixin.class.getSimpleName(); 36 37 /** 38 * @see RoleBehavior#getConfirmationMessage(Role, String, Context) 39 */ 40 @Nullable getConfirmationMessage(@onNull Role role, @NonNull String packageName, @NonNull Context context)41 public static CharSequence getConfirmationMessage(@NonNull Role role, 42 @NonNull String packageName, @NonNull Context context) { 43 ApplicationInfo applicationInfo = PackageUtils.getApplicationInfo(packageName, context); 44 if (applicationInfo == null) { 45 Log.w(LOG_TAG, "Cannot get ApplicationInfo for application, package name: " 46 + packageName); 47 return null; 48 } 49 if (applicationInfo.isEncryptionAware()) { 50 return null; 51 } 52 return context.getString(R.string.encryption_unaware_confirmation_message); 53 } 54 } 55