Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5a678395 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add confirmation message support for roles."

parents 408b0505 48e51b10
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@
}
-dontwarn androidx.core.**

# Keep classes that implements RoleAvailabilityProvider, which are used by reflection.
-keep class * implements com.android.packageinstaller.role.model.RoleAvailabilityProvider {
# Keep classes that implements RoleBehavior, which are used by reflection.
-keep class * implements com.android.packageinstaller.role.model.RoleBehavior {
    *;
}
+3 −0
Original line number Diff line number Diff line
@@ -537,4 +537,7 @@
    <string name="role_label_gallery">Gallery app</string>
    <!-- Label for the music player role. [CHAR LIMIT=30] -->
    <string name="role_label_music">Music app</string>

    <!-- [CHAR LIMIT=NONE] Dialog body explaining that the app just selected by the user will not work after a reboot until the user enters their credentials, such as a PIN or password. -->
    <string name="encryption_unaware_confirmation_message">Note: If you restart your device and have a screen lock set, this app can\u2019t start until you unlock your device.</string>
</resources>
+2 −2
Original line number Diff line number Diff line
@@ -149,7 +149,7 @@
    <!--- @see android.telecom.DefaultDialerManager -->
    <role
        name="android.app.role.DIALER"
        availabilityProvider="DialerRoleAvailabilityProvider"
        behavior="DialerRoleBehavior"
        exclusive="true"
        label="@string/role_label_dialer">
        <required-components>
@@ -212,7 +212,7 @@
    <!--- @see com.android.internal.telephony.SmsApplication -->
    <role
        name="android.app.role.SMS"
        availabilityProvider="SmsRoleAvailabilityProvider"
        behavior="SmsRoleBehavior"
        exclusive="true"
        label="@string/role_label_sms">
        <required-components>
+15 −4
Original line number Diff line number Diff line
@@ -21,18 +21,29 @@ import android.os.UserHandle;
import android.telephony.TelephonyManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
 * Class for determining whether the dialer role is available.
 * Class for behavior of the dialer role.
 *
 * @see com.android.settings.applications.DefaultAppSettings
 * @see com.android.settings.applications.defaultapps.DefaultPhonePreferenceController#isAvailable()
 * @see com.android.settings.applications.defaultapps.DefaultPhonePreferenceController
 * @see com.android.settings.applications.defaultapps.DefaultPhonePicker
 */
public class DialerRoleAvailabilityProvider implements RoleAvailabilityProvider {
public class DialerRoleBehavior implements RoleBehavior {

    @Override
    public boolean isRoleAvailableAsUser(@NonNull UserHandle user, @NonNull Context context) {
    public boolean isAvailableAsUser(@NonNull UserHandle user,
            @NonNull Context context) {
        TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class);
        return telephonyManager.isVoiceCapable();
    }

    @Nullable
    @Override
    public CharSequence getConfirmationMessage(@NonNull String packageName,
            @NonNull Context context) {
        return EncryptionUnawareConfirmationMixin.getConfirmationMessage(packageName,
                context);
    }
}
+54 −0
Original line number Diff line number Diff line
/*
 * 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.packageinstaller.role.model;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.packageinstaller.role.utils.PackageUtils;
import com.android.permissioncontroller.R;

/**
 * Mixin for {@link RoleBehavior#getConfirmationMessage(String, Context)}
 * that returns a confirmation message when the application is not direct boot aware.
 */
public class EncryptionUnawareConfirmationMixin {

    private static final String LOG_TAG = EncryptionUnawareConfirmationMixin.class.getSimpleName();

    /**
     * @see RoleBehavior#getConfirmationMessage(String, Context)
     */
    @Nullable
    public static CharSequence getConfirmationMessage(@NonNull String packageName,
            @NonNull Context context) {
        ApplicationInfo applicationInfo = PackageUtils.getApplicationInfo(packageName, context);
        if (applicationInfo == null) {
            Log.w(LOG_TAG, "Cannot get ApplicationInfo for application, package name: "
                    + packageName);
            return null;
        }
        if (applicationInfo.isEncryptionAware()) {
            return null;
        }
        return context.getString(R.string.encryption_unaware_confirmation_message);
    }
}
Loading