• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.role.persistence;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.SystemApi;
22 import android.annotation.SystemApi.Client;
23 
24 import java.util.Map;
25 import java.util.Objects;
26 import java.util.Set;
27 
28 /**
29  * State of all roles.
30  *
31  * TODO(b/147914847): Remove @hide when it becomes the default.
32  * @hide
33  */
34 @SystemApi(client = Client.SYSTEM_SERVER)
35 public final class RolesState {
36 
37     /**
38      * The version of the roles.
39      */
40     private final int mVersion;
41 
42     /**
43      * The hash of all packages in the system.
44      */
45     @Nullable
46     private final String mPackagesHash;
47 
48     /**
49      * The roles.
50      */
51     @NonNull
52     private final Map<String, Set<String>> mRoles;
53 
54     /**
55      * Create a new instance of this class.
56      *
57      * @param version the version of the roles
58      * @param packagesHash the hash of all packages in the system
59      * @param roles the roles
60      */
RolesState(int version, @Nullable String packagesHash, @NonNull Map<String, Set<String>> roles)61     public RolesState(int version, @Nullable String packagesHash,
62             @NonNull Map<String, Set<String>> roles) {
63         mVersion = version;
64         mPackagesHash = packagesHash;
65         mRoles = roles;
66     }
67 
68     /**
69      * Get the version of the roles.
70      *
71      * @return the version of the roles
72      */
getVersion()73     public int getVersion() {
74         return mVersion;
75     }
76 
77     /**
78      * Get the hash of all packages in the system.
79      *
80      * @return the hash of all packages in the system
81      */
82     @Nullable
getPackagesHash()83     public String getPackagesHash() {
84         return mPackagesHash;
85     }
86 
87     /**
88      * Get the roles.
89      *
90      * @return the roles
91      */
92     @NonNull
getRoles()93     public Map<String, Set<String>> getRoles() {
94         return mRoles;
95     }
96 
97     @Override
equals(Object object)98     public boolean equals(Object object) {
99         if (this == object) {
100             return true;
101         }
102         if (object == null || getClass() != object.getClass()) {
103             return false;
104         }
105         RolesState that = (RolesState) object;
106         return mVersion == that.mVersion
107                 && Objects.equals(mPackagesHash, that.mPackagesHash)
108                 && Objects.equals(mRoles, that.mRoles);
109     }
110 
111     @Override
hashCode()112     public int hashCode() {
113         return Objects.hash(mVersion, mPackagesHash, mRoles);
114     }
115 }
116