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