blob: 06e020a056fd85d1980e39bc3b87a737556abbbf [file] [log] [blame]
Kenny Rootcf0b38c2011-03-22 14:17:59 -07001/*
2 * Copyright (C) 2011 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
17package com.android.server.pm;
18
Jeff Sharkey9f837a92014-10-24 12:07:24 -070019import android.util.ArraySet;
Kenny Rootcf0b38c2011-03-22 14:17:59 -070020
21/**
22 * Settings data for a particular shared user ID we know about.
23 */
Svetoslavc6d1c342015-02-26 14:44:43 -080024final class SharedUserSetting extends SettingBase {
Kenny Rootcf0b38c2011-03-22 14:17:59 -070025 final String name;
26
27 int userId;
28
Ben Gruverdd72c9e2013-08-06 12:34:17 -070029 // flags that are associated with this uid, regardless of any package flags
30 int uidFlags;
Alex Klyubinb9f8a522015-02-03 11:12:59 -080031 int uidPrivateFlags;
Ben Gruverdd72c9e2013-08-06 12:34:17 -070032
Jeff Sharkey9f837a92014-10-24 12:07:24 -070033 final ArraySet<PackageSetting> packages = new ArraySet<PackageSetting>();
Kenny Rootcf0b38c2011-03-22 14:17:59 -070034
35 final PackageSignatures signatures = new PackageSignatures();
36
Alex Klyubinb9f8a522015-02-03 11:12:59 -080037 SharedUserSetting(String _name, int _pkgFlags, int _pkgPrivateFlags) {
38 super(_pkgFlags, _pkgPrivateFlags);
Ben Gruverdd72c9e2013-08-06 12:34:17 -070039 uidFlags = _pkgFlags;
Alex Klyubinb9f8a522015-02-03 11:12:59 -080040 uidPrivateFlags = _pkgPrivateFlags;
Kenny Rootcf0b38c2011-03-22 14:17:59 -070041 name = _name;
42 }
43
44 @Override
45 public String toString() {
46 return "SharedUserSetting{" + Integer.toHexString(System.identityHashCode(this)) + " "
47 + name + "/" + userId + "}";
48 }
Ben Gruverdd72c9e2013-08-06 12:34:17 -070049
50 void removePackage(PackageSetting packageSetting) {
51 if (packages.remove(packageSetting)) {
52 // recalculate the pkgFlags for this shared user if needed
53 if ((this.pkgFlags & packageSetting.pkgFlags) != 0) {
54 int aggregatedFlags = uidFlags;
55 for (PackageSetting ps : packages) {
56 aggregatedFlags |= ps.pkgFlags;
57 }
58 setFlags(aggregatedFlags);
59 }
Alex Klyubinb9f8a522015-02-03 11:12:59 -080060 if ((this.pkgPrivateFlags & packageSetting.pkgPrivateFlags) != 0) {
61 int aggregatedPrivateFlags = uidPrivateFlags;
62 for (PackageSetting ps : packages) {
63 aggregatedPrivateFlags |= ps.pkgPrivateFlags;
64 }
65 setPrivateFlags(aggregatedPrivateFlags);
66 }
Ben Gruverdd72c9e2013-08-06 12:34:17 -070067 }
68 }
69
70 void addPackage(PackageSetting packageSetting) {
71 if (packages.add(packageSetting)) {
72 setFlags(this.pkgFlags | packageSetting.pkgFlags);
Alex Klyubinb9f8a522015-02-03 11:12:59 -080073 setPrivateFlags(this.pkgPrivateFlags | packageSetting.pkgPrivateFlags);
Ben Gruverdd72c9e2013-08-06 12:34:17 -070074 }
75 }
Kenny Rootcf0b38c2011-03-22 14:17:59 -070076}