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

Commit d53ce6f4 authored by Kweku Adams's avatar Kweku Adams
Browse files

Enable per-policy rewards.

Reserve 0 for the base policy event IDs so that individual policies can
create their own rewards without interference or confusion.

Bug: 243987091
Test: atest frameworks/base/services/tests/mockingservicestests/src/com/android/server/tare
Test: atest frameworks/base/services/tests/servicestests/src/com/android/server/tare
Change-Id: I96e092534996c27dc45981301de6bc368798f32a
parent b91f96a9
Loading
Loading
Loading
Loading
+6 −5
Original line number Original line Diff line number Diff line
@@ -55,12 +55,13 @@ public abstract class EconomicPolicy {
    static final int TYPE_ACTION = 1 << SHIFT_TYPE;
    static final int TYPE_ACTION = 1 << SHIFT_TYPE;
    static final int TYPE_REWARD = 2 << SHIFT_TYPE;
    static final int TYPE_REWARD = 2 << SHIFT_TYPE;


    private static final int SHIFT_POLICY = 29;
    private static final int SHIFT_POLICY = 28;
    static final int MASK_POLICY = 0b1 << SHIFT_POLICY;
    static final int MASK_POLICY = 0b11 << SHIFT_POLICY;
    static final int POLICY_AM = 0 << SHIFT_POLICY;
    // Reserve 0 for the base/common policy.
    static final int POLICY_JS = 1 << SHIFT_POLICY;
    static final int POLICY_AM = 1 << SHIFT_POLICY;
    static final int POLICY_JS = 2 << SHIFT_POLICY;


    static final int MASK_EVENT = ~0 - (0b111 << SHIFT_POLICY);
    static final int MASK_EVENT = -1 ^ (MASK_TYPE | MASK_POLICY);


    static final int REGULATION_BASIC_INCOME = TYPE_REGULATION | 0;
    static final int REGULATION_BASIC_INCOME = TYPE_REGULATION | 0;
    static final int REGULATION_BIRTHRIGHT = TYPE_REGULATION | 1;
    static final int REGULATION_BIRTHRIGHT = TYPE_REGULATION | 1;
+36 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2022 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.server.tare;

import static org.junit.Assert.assertEquals;

import androidx.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class EconomicPolicyTest {

    @Test
    public void testMasksDisjoint() {
        assertEquals(-1,
                (-1 & EconomicPolicy.MASK_TYPE)
                        + (-1 & EconomicPolicy.MASK_POLICY)
                        + (-1 & EconomicPolicy.MASK_EVENT));
    }
}