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

Commit 0a6779ab authored by wwtbuaa01's avatar wwtbuaa01 Committed by Wentao Wang
Browse files

Add additional arguments to PackagesHash.

RetailDemo role depends on additional states of the device. Adding those to the package hash
as well.

Security approved for design: go/retail-demo-role-fr

Bug: 274132354
Change-Id: I3da2f2ae64a190ead57967cce0f81db3020426b5
Test: manual
parent 59f9d24c
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.server.policy.role;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.app.admin.DevicePolicyManagerInternal;
import android.app.role.RoleManager;
import android.content.ComponentName;
import android.content.ContentResolver;
@@ -303,6 +304,8 @@ public class RoleServicePlatformHelperImpl implements RoleServicePlatformHelper
    public String computePackageStateHash(@UserIdInt int userId) {
        PackageManagerInternal packageManagerInternal = LocalServices.getService(
                PackageManagerInternal.class);
        DevicePolicyManagerInternal devicePolicyManagerInternal = LocalServices.getService(
                DevicePolicyManagerInternal.class);
        final MessageDigestOutputStream mdos = new MessageDigestOutputStream();

        DataOutputStream dataOutputStream = new DataOutputStream(new BufferedOutputStream(mdos));
@@ -342,6 +345,30 @@ public class RoleServicePlatformHelperImpl implements RoleServicePlatformHelper
                throw new AssertionError(e);
            }
        }, userId);
        try {
            String deviceOwner= "";
            if (devicePolicyManagerInternal.getDeviceOwnerUserId() == userId) {
                ComponentName deviceOwnerComponent =
                    devicePolicyManagerInternal.getDeviceOwnerComponent(false);
                if (deviceOwnerComponent != null) {
                    deviceOwner = deviceOwnerComponent.getPackageName();
                }
            }
            dataOutputStream.writeUTF(deviceOwner);
            String profileOwner = "";
            ComponentName profileOwnerComponent =
                devicePolicyManagerInternal.getProfileOwnerAsUser(userId);
            if (profileOwnerComponent != null) {
                profileOwner = profileOwnerComponent.getPackageName();
            }
            dataOutputStream.writeUTF(profileOwner);
            dataOutputStream.writeInt(Settings.Global.getInt(mContext.getContentResolver(),
                    Settings.Global.DEVICE_DEMO_MODE, 0));
            dataOutputStream.flush();
        } catch (IOException e) {
            // Never happens for MessageDigestOutputStream and DataOutputStream.
            throw new AssertionError(e);
        }
        return mdos.getDigestAsString();
    }