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

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

Merge "Fix Role direct boot awareness."

parents 700b554a f9ef6397
Loading
Loading
Loading
Loading
+16 −8
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.app.role.RoleManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.os.Process;
import android.os.UserHandle;
@@ -527,8 +528,8 @@ public class Role {
     * @return {@code true} iff the user selected the "none" role holder
     */
    private boolean isNoneHolderSelected(@NonNull Context context) {
        return context.getSharedPreferences(Constants.PREFERENCES_FILE, Context.MODE_PRIVATE)
                .getBoolean(Constants.IS_NONE_ROLE_HOLDER_SELECTED_KEY + mName, false);
        return getDeviceProtectedSharedPreferences(context).getBoolean(
                Constants.IS_NONE_ROLE_HOLDER_SELECTED_KEY + mName, false);
    }

    /**
@@ -538,9 +539,9 @@ public class Role {
     * @param user the user the role belongs to
     */
    public void onHolderSelectedAsUser(@NonNull Context context, @NonNull UserHandle user) {
        UserUtils.getUserContext(context, user)
                .getSharedPreferences(Constants.PREFERENCES_FILE, Context.MODE_PRIVATE)
                .edit().remove(Constants.IS_NONE_ROLE_HOLDER_SELECTED_KEY + mName).apply();
        getDeviceProtectedSharedPreferences(UserUtils.getUserContext(context, user)).edit()
                .remove(Constants.IS_NONE_ROLE_HOLDER_SELECTED_KEY + mName)
                .apply();
    }

    /**
@@ -550,12 +551,19 @@ public class Role {
     * @param user the user the role belongs to
     */
    public void onNoneHolderSelectedAsUser(@NonNull Context context, @NonNull UserHandle user) {
        UserUtils.getUserContext(context, user)
                .getSharedPreferences(Constants.PREFERENCES_FILE, Context.MODE_PRIVATE)
                .edit().putBoolean(Constants.IS_NONE_ROLE_HOLDER_SELECTED_KEY + mName, true)
        getDeviceProtectedSharedPreferences(UserUtils.getUserContext(context, user)).edit()
                .putBoolean(Constants.IS_NONE_ROLE_HOLDER_SELECTED_KEY + mName, true)
                .apply();
    }

    @NonNull
    private SharedPreferences getDeviceProtectedSharedPreferences(@NonNull Context context) {
        if (!context.isDeviceProtectedStorage()) {
            context = context.createDeviceProtectedStorageContext();
        }
        return context.getSharedPreferences(Constants.PREFERENCES_FILE, Context.MODE_PRIVATE);
    }

    @Override
    public String toString() {
        return "Role{"