1 /*
2  * Copyright (C) 2019 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.content.pm.PackageParser;
20 import android.os.UserHandle;
21 
22 class ScanRequestBuilder {
23     private final PackageParser.Package mPkg;
24     private PackageParser.Package mOldPkg;
25     private SharedUserSetting mSharedUserSetting;
26     private PackageSetting mPkgSetting;
27     private PackageSetting mDisabledPkgSetting;
28     private PackageSetting mOriginalPkgSetting;
29     private String mRealPkgName;
30     private int mParseFlags;
31     private int mScanFlags;
32     private UserHandle mUser;
33     private boolean mIsPlatformPackage;
34 
ScanRequestBuilder(PackageParser.Package pkg)35     ScanRequestBuilder(PackageParser.Package pkg) {
36         this.mPkg = pkg;
37     }
38 
setOldPkg(PackageParser.Package oldPkg)39     public ScanRequestBuilder setOldPkg(PackageParser.Package oldPkg) {
40         this.mOldPkg = oldPkg;
41         return this;
42     }
43 
setSharedUserSetting(SharedUserSetting sharedUserSetting)44     public ScanRequestBuilder setSharedUserSetting(SharedUserSetting sharedUserSetting) {
45         this.mSharedUserSetting = sharedUserSetting;
46         return this;
47     }
48 
setPkgSetting(PackageSetting pkgSetting)49     public ScanRequestBuilder setPkgSetting(PackageSetting pkgSetting) {
50         this.mPkgSetting = pkgSetting;
51         return this;
52     }
53 
setDisabledPkgSetting(PackageSetting disabledPkgSetting)54     public ScanRequestBuilder setDisabledPkgSetting(PackageSetting disabledPkgSetting) {
55         this.mDisabledPkgSetting = disabledPkgSetting;
56         return this;
57     }
58 
setOriginalPkgSetting(PackageSetting originalPkgSetting)59     public ScanRequestBuilder setOriginalPkgSetting(PackageSetting originalPkgSetting) {
60         this.mOriginalPkgSetting = originalPkgSetting;
61         return this;
62     }
63 
setRealPkgName(String realPkgName)64     public ScanRequestBuilder setRealPkgName(String realPkgName) {
65         this.mRealPkgName = realPkgName;
66         return this;
67     }
68 
setParseFlags(int parseFlags)69     public ScanRequestBuilder setParseFlags(int parseFlags) {
70         this.mParseFlags = parseFlags;
71         return this;
72     }
73 
addParseFlag(int parseFlag)74     public ScanRequestBuilder addParseFlag(int parseFlag) {
75         this.mParseFlags |= parseFlag;
76         return this;
77     }
78 
setScanFlags(int scanFlags)79     public ScanRequestBuilder setScanFlags(int scanFlags) {
80         this.mScanFlags = scanFlags;
81         return this;
82     }
83 
addScanFlag(int scanFlag)84     public ScanRequestBuilder addScanFlag(int scanFlag) {
85         this.mScanFlags |= scanFlag;
86         return this;
87     }
88 
setUser(UserHandle user)89     public ScanRequestBuilder setUser(UserHandle user) {
90         this.mUser = user;
91         return this;
92     }
93 
setIsPlatformPackage(boolean isPlatformPackage)94     public ScanRequestBuilder setIsPlatformPackage(boolean isPlatformPackage) {
95         this.mIsPlatformPackage = isPlatformPackage;
96         return this;
97     }
98 
build()99     PackageManagerService.ScanRequest build() {
100         return new PackageManagerService.ScanRequest(
101                 mPkg, mSharedUserSetting, mOldPkg, mPkgSetting, mDisabledPkgSetting,
102                 mOriginalPkgSetting, mRealPkgName, mParseFlags, mScanFlags, mIsPlatformPackage,
103                 mUser);
104     }
105 }
106