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.compat; 18 19 import android.content.pm.ApplicationInfo; 20 21 class ApplicationInfoBuilder { 22 private boolean mIsDebuggable; 23 private int mTargetSdk; 24 private int mUid; 25 private String mPackageName; 26 private long mVersionCode; 27 private boolean mIsSystemApp; 28 ApplicationInfoBuilder()29 private ApplicationInfoBuilder() { 30 mTargetSdk = -1; 31 } 32 create()33 static ApplicationInfoBuilder create() { 34 return new ApplicationInfoBuilder(); 35 } 36 withTargetSdk(int targetSdk)37 ApplicationInfoBuilder withTargetSdk(int targetSdk) { 38 mTargetSdk = targetSdk; 39 return this; 40 } 41 debuggable()42 ApplicationInfoBuilder debuggable() { 43 mIsDebuggable = true; 44 return this; 45 } 46 systemApp()47 ApplicationInfoBuilder systemApp() { 48 mIsSystemApp = true; 49 return this; 50 } 51 withUid(int uid)52 ApplicationInfoBuilder withUid(int uid) { 53 mUid = uid; 54 return this; 55 } 56 withPackageName(String packageName)57 ApplicationInfoBuilder withPackageName(String packageName) { 58 mPackageName = packageName; 59 return this; 60 } 61 withVersionCode(Long versionCode)62 ApplicationInfoBuilder withVersionCode(Long versionCode) { 63 mVersionCode = versionCode; 64 return this; 65 } 66 build()67 ApplicationInfo build() { 68 final ApplicationInfo applicationInfo = new ApplicationInfo(); 69 if (mIsDebuggable) { 70 applicationInfo.flags |= ApplicationInfo.FLAG_DEBUGGABLE; 71 } 72 applicationInfo.packageName = mPackageName; 73 applicationInfo.targetSdkVersion = mTargetSdk; 74 applicationInfo.longVersionCode = mVersionCode; 75 applicationInfo.uid = mUid; 76 if (mIsSystemApp) { 77 applicationInfo.flags |= ApplicationInfo.FLAG_SYSTEM; 78 } 79 return applicationInfo; 80 } 81 } 82