• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.car.settingslib.applications;
18 
19 import android.content.pm.ApplicationInfo;
20 import android.content.pm.UserInfo;
21 import android.text.TextUtils;
22 
23 import java.util.Objects;
24 
25 /**
26  * Simple class for bringing together information about application and user for which it was
27  * installed.
28  */
29 // TODO(b/208511815): copied from Settings mostly "as-is"; ideally should be move to SettingsLib,
30 // but if not, we should copy the unit tests as well.
31 public final class UserAppInfo {
32     public final UserInfo userInfo;
33     public final ApplicationInfo appInfo;
34 
UserAppInfo(UserInfo mUserInfo, ApplicationInfo mAppInfo)35     public UserAppInfo(UserInfo mUserInfo, ApplicationInfo mAppInfo) {
36         this.userInfo = mUserInfo;
37         this.appInfo = mAppInfo;
38     }
39 
40     @Override
equals(Object other)41     public boolean equals(Object other) {
42         if (other == this) {
43             return true;
44         }
45         if (other == null || getClass() != other.getClass()) {
46             return false;
47         }
48         final UserAppInfo that = (UserAppInfo) other;
49 
50         // As UserInfo and AppInfo do not support hashcode/equals contract, assume
51         // equality based on corresponding identity fields.
52         return that.userInfo.id == userInfo.id && TextUtils.equals(that.appInfo.packageName,
53                 appInfo.packageName);
54     }
55 
56     @Override
hashCode()57     public int hashCode() {
58         return Objects.hash(userInfo.id, appInfo.packageName);
59     }
60 
61     // TODO(b/208511815): added in this class
62     @Override
toString()63     public String toString() {
64         return getClass().getSimpleName() + "[user=" + userInfo.id + ", pkg=" + appInfo.packageName
65                 + "]";
66     }
67 }
68