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 21 import com.android.internal.util.ArrayUtils; 22 23 class PackageBuilder { 24 final PackageParser.Package mPkg; 25 PackageBuilder(String packageName)26 PackageBuilder(String packageName) { 27 mPkg = new PackageParser.Package(packageName); 28 } 29 setApplicationInfoCodePath(String codePath)30 PackageBuilder setApplicationInfoCodePath(String codePath) { 31 mPkg.applicationInfo.setCodePath(codePath); 32 return this; 33 } 34 setApplicationInfoResourcePath(String resourcePath)35 PackageBuilder setApplicationInfoResourcePath(String resourcePath) { 36 mPkg.applicationInfo.setResourcePath(resourcePath); 37 return this; 38 } 39 setCodePath(String codePath)40 PackageBuilder setCodePath(String codePath) { 41 mPkg.codePath = codePath; 42 return this; 43 } 44 setBaseCodePath(String baseCodePath)45 PackageBuilder setBaseCodePath(String baseCodePath) { 46 mPkg.baseCodePath = baseCodePath; 47 return this; 48 } 49 addUsesStaticLibrary(String name, long version)50 PackageBuilder addUsesStaticLibrary(String name, long version) { 51 mPkg.usesStaticLibraries = ArrayUtils.add(mPkg.usesStaticLibraries, name); 52 mPkg.usesStaticLibrariesVersions = 53 ArrayUtils.appendLong(mPkg.usesStaticLibrariesVersions, version); 54 return this; 55 } 56 setApplicationInfoNativeLibraryRootDir(String dir)57 PackageBuilder setApplicationInfoNativeLibraryRootDir(String dir) { 58 mPkg.applicationInfo.nativeLibraryRootDir = dir; 59 return this; 60 } 61 setStaticSharedLib(String staticSharedLibName, long staticSharedLibVersion)62 PackageBuilder setStaticSharedLib(String staticSharedLibName, long staticSharedLibVersion) { 63 mPkg.staticSharedLibVersion = staticSharedLibVersion; 64 mPkg.staticSharedLibName = staticSharedLibName; 65 return this; 66 } 67 setManifestPackageName(String manifestPackageName)68 PackageBuilder setManifestPackageName(String manifestPackageName) { 69 mPkg.manifestPackageName = manifestPackageName; 70 return this; 71 } 72 setVersionCodeMajor(int versionCodeMajor)73 PackageBuilder setVersionCodeMajor(int versionCodeMajor) { 74 mPkg.mVersionCodeMajor = versionCodeMajor; 75 return this; 76 } 77 setVersionCode(int versionCode)78 PackageBuilder setVersionCode(int versionCode) { 79 mPkg.mVersionCode = versionCode; 80 return this; 81 } 82 addSplitCodePath(String splitCodePath)83 PackageBuilder addSplitCodePath(String splitCodePath) { 84 mPkg.splitCodePaths = 85 ArrayUtils.appendElement(String.class, mPkg.splitCodePaths, splitCodePath); 86 return this; 87 } 88 setApplicationInfoVolumeUuid(String volumeUuid)89 PackageBuilder setApplicationInfoVolumeUuid(String volumeUuid) { 90 mPkg.applicationInfo.volumeUuid = volumeUuid; 91 return this; 92 } 93 addLibraryName(String libraryName)94 PackageBuilder addLibraryName(String libraryName) { 95 mPkg.libraryNames = ArrayUtils.add(mPkg.libraryNames, libraryName); 96 return this; 97 } 98 setRealPackageName(String realPackageName)99 PackageBuilder setRealPackageName(String realPackageName) { 100 mPkg.mRealPackage = realPackageName; 101 return this; 102 } 103 setCpuAbiOVerride(String cpuAbiOverride)104 PackageBuilder setCpuAbiOVerride(String cpuAbiOverride) { 105 mPkg.cpuAbiOverride = cpuAbiOverride; 106 return this; 107 } 108 addPermissionRequest(String permissionName)109 PackageBuilder addPermissionRequest(String permissionName) { 110 mPkg.requestedPermissions.add(permissionName); 111 return this; 112 } 113 build()114 PackageParser.Package build() { 115 return mPkg; 116 } 117 addApplicationInfoFlag(int flag)118 public PackageBuilder addApplicationInfoFlag(int flag) { 119 mPkg.applicationInfo.flags |= flag; 120 return this; 121 } 122 } 123