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 String mPackageName; 25 private long mVersionCode; 26 ApplicationInfoBuilder()27 private ApplicationInfoBuilder() { 28 mTargetSdk = -1; 29 } 30 create()31 static ApplicationInfoBuilder create() { 32 return new ApplicationInfoBuilder(); 33 } 34 withTargetSdk(int targetSdk)35 ApplicationInfoBuilder withTargetSdk(int targetSdk) { 36 mTargetSdk = targetSdk; 37 return this; 38 } 39 debuggable()40 ApplicationInfoBuilder debuggable() { 41 mIsDebuggable = true; 42 return this; 43 } 44 withPackageName(String packageName)45 ApplicationInfoBuilder withPackageName(String packageName) { 46 mPackageName = packageName; 47 return this; 48 } 49 withVersionCode(Long versionCode)50 ApplicationInfoBuilder withVersionCode(Long versionCode) { 51 mVersionCode = versionCode; 52 return this; 53 } 54 build()55 ApplicationInfo build() { 56 final ApplicationInfo applicationInfo = new ApplicationInfo(); 57 if (mIsDebuggable) { 58 applicationInfo.flags |= ApplicationInfo.FLAG_DEBUGGABLE; 59 } 60 applicationInfo.packageName = mPackageName; 61 applicationInfo.targetSdkVersion = mTargetSdk; 62 applicationInfo.longVersionCode = mVersionCode; 63 return applicationInfo; 64 } 65 } 66