Home | History | Annotate | Download | only in pm
      1 /*
      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 
     17 package com.android.server.pm;
     18 
     19 import android.util.ArraySet;
     20 
     21 /**
     22  * Settings data for a particular shared user ID we know about.
     23  */
     24 final class SharedUserSetting extends GrantedPermissions {
     25     final String name;
     26 
     27     int userId;
     28 
     29     // flags that are associated with this uid, regardless of any package flags
     30     int uidFlags;
     31 
     32     final ArraySet<PackageSetting> packages = new ArraySet<PackageSetting>();
     33 
     34     final PackageSignatures signatures = new PackageSignatures();
     35 
     36     SharedUserSetting(String _name, int _pkgFlags) {
     37         super(_pkgFlags);
     38         uidFlags =  _pkgFlags;
     39         name = _name;
     40     }
     41 
     42     @Override
     43     public String toString() {
     44         return "SharedUserSetting{" + Integer.toHexString(System.identityHashCode(this)) + " "
     45                 + name + "/" + userId + "}";
     46     }
     47 
     48     void removePackage(PackageSetting packageSetting) {
     49         if (packages.remove(packageSetting)) {
     50             // recalculate the pkgFlags for this shared user if needed
     51             if ((this.pkgFlags & packageSetting.pkgFlags) != 0) {
     52                 int aggregatedFlags = uidFlags;
     53                 for (PackageSetting ps : packages) {
     54                     aggregatedFlags |= ps.pkgFlags;
     55                 }
     56                 setFlags(aggregatedFlags);
     57             }
     58         }
     59     }
     60 
     61     void addPackage(PackageSetting packageSetting) {
     62         if (packages.add(packageSetting)) {
     63             setFlags(this.pkgFlags | packageSetting.pkgFlags);
     64         }
     65     }
     66 }
     67