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.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.os.UserHandle; 22 23 import com.android.internal.pm.parsing.pkg.ParsedPackage; 24 import com.android.server.pm.pkg.AndroidPackage; 25 26 class ScanRequestBuilder { 27 private final ParsedPackage mPkg; 28 private AndroidPackage mOldPkg; 29 private SharedUserSetting mOldSharedUserSetting; 30 private SharedUserSetting mSharedUserSetting; 31 private PackageSetting mPkgSetting; 32 private PackageSetting mDisabledPkgSetting; 33 private PackageSetting mOriginalPkgSetting; 34 private String mRealPkgName; 35 private int mParseFlags; 36 private int mScanFlags; 37 private UserHandle mUser; 38 private boolean mIsPlatformPackage; 39 @Nullable 40 private String mCpuAbiOverride; 41 ScanRequestBuilder(ParsedPackage pkg)42 ScanRequestBuilder(ParsedPackage pkg) { 43 this.mPkg = pkg; 44 } 45 setOldPkg(AndroidPackage oldPkg)46 public ScanRequestBuilder setOldPkg(AndroidPackage oldPkg) { 47 this.mOldPkg = oldPkg; 48 return this; 49 } 50 setSharedUserSetting(SharedUserSetting sharedUserSetting)51 public ScanRequestBuilder setSharedUserSetting(SharedUserSetting sharedUserSetting) { 52 this.mSharedUserSetting = sharedUserSetting; 53 return this; 54 } 55 setOldSharedUserSetting(SharedUserSetting oldSharedUserSetting)56 public ScanRequestBuilder setOldSharedUserSetting(SharedUserSetting oldSharedUserSetting) { 57 this.mOldSharedUserSetting = oldSharedUserSetting; 58 return this; 59 } 60 setPkgSetting(PackageSetting pkgSetting)61 public ScanRequestBuilder setPkgSetting(PackageSetting pkgSetting) { 62 this.mPkgSetting = pkgSetting; 63 return this; 64 } 65 setDisabledPkgSetting(PackageSetting disabledPkgSetting)66 public ScanRequestBuilder setDisabledPkgSetting(PackageSetting disabledPkgSetting) { 67 this.mDisabledPkgSetting = disabledPkgSetting; 68 return this; 69 } 70 setOriginalPkgSetting(PackageSetting originalPkgSetting)71 public ScanRequestBuilder setOriginalPkgSetting(PackageSetting originalPkgSetting) { 72 this.mOriginalPkgSetting = originalPkgSetting; 73 return this; 74 } 75 setRealPkgName(String realPkgName)76 public ScanRequestBuilder setRealPkgName(String realPkgName) { 77 this.mRealPkgName = realPkgName; 78 return this; 79 } 80 setParseFlags(int parseFlags)81 public ScanRequestBuilder setParseFlags(int parseFlags) { 82 this.mParseFlags = parseFlags; 83 return this; 84 } 85 addParseFlag(int parseFlag)86 public ScanRequestBuilder addParseFlag(int parseFlag) { 87 this.mParseFlags |= parseFlag; 88 return this; 89 } 90 setScanFlags(int scanFlags)91 public ScanRequestBuilder setScanFlags(int scanFlags) { 92 this.mScanFlags = scanFlags; 93 return this; 94 } 95 addScanFlag(int scanFlag)96 public ScanRequestBuilder addScanFlag(int scanFlag) { 97 this.mScanFlags |= scanFlag; 98 return this; 99 } 100 setUser(UserHandle user)101 public ScanRequestBuilder setUser(UserHandle user) { 102 this.mUser = user; 103 return this; 104 } 105 setIsPlatformPackage(boolean isPlatformPackage)106 public ScanRequestBuilder setIsPlatformPackage(boolean isPlatformPackage) { 107 this.mIsPlatformPackage = isPlatformPackage; 108 return this; 109 } 110 111 @NonNull setCpuAbiOverride(@ullable String cpuAbiOverride)112 public ScanRequestBuilder setCpuAbiOverride(@Nullable String cpuAbiOverride) { 113 this.mCpuAbiOverride = cpuAbiOverride; 114 return this; 115 } 116 build()117 ScanRequest build() { 118 return new ScanRequest( 119 mPkg, mOldSharedUserSetting, mOldPkg, mPkgSetting, mSharedUserSetting, 120 mDisabledPkgSetting, mOriginalPkgSetting, mRealPkgName, mParseFlags, mScanFlags, 121 mIsPlatformPackage, mUser, mCpuAbiOverride); 122 } 123 } 124