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 SettingBase {
     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     int uidPrivateFlags;
     32 
     33     final ArraySet<PackageSetting> packages = new ArraySet<PackageSetting>();
     34 
     35     final PackageSignatures signatures = new PackageSignatures();
     36 
     37     SharedUserSetting(String _name, int _pkgFlags, int _pkgPrivateFlags) {
     38         super(_pkgFlags, _pkgPrivateFlags);
     39         uidFlags =  _pkgFlags;
     40         uidPrivateFlags = _pkgPrivateFlags;
     41         name = _name;
     42     }
     43 
     44     @Override
     45     public String toString() {
     46         return "SharedUserSetting{" + Integer.toHexString(System.identityHashCode(this)) + " "
     47                 + name + "/" + userId + "}";
     48     }
     49 
     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             }
     60             if ((this.pkgPrivateFlags & packageSetting.pkgPrivateFlags) != 0) {
     61                 int aggregatedPrivateFlags = uidPrivateFlags;
     62                 for (PackageSetting ps : packages) {
     63                     aggregatedPrivateFlags |= ps.pkgPrivateFlags;
     64                 }
     65                 setPrivateFlags(aggregatedPrivateFlags);
     66             }
     67         }
     68     }
     69 
     70     void addPackage(PackageSetting packageSetting) {
     71         if (packages.add(packageSetting)) {
     72             setFlags(this.pkgFlags | packageSetting.pkgFlags);
     73             setPrivateFlags(this.pkgPrivateFlags | packageSetting.pkgPrivateFlags);
     74         }
     75     }
     76 }
     77