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 package com.android.launcher3.pm; 17 18 import android.content.ComponentName; 19 import android.content.pm.PackageInstaller; 20 import android.os.UserHandle; 21 22 import androidx.annotation.NonNull; 23 24 public final class PackageInstallInfo { 25 26 public static final int STATUS_INSTALLED = 0; 27 public static final int STATUS_INSTALLING = 1; 28 public static final int STATUS_INSTALLED_DOWNLOADING = 2; 29 public static final int STATUS_FAILED = 3; 30 31 public final ComponentName componentName; 32 public final String packageName; 33 public final int state; 34 public final int progress; 35 public final UserHandle user; 36 PackageInstallInfo(@onNull PackageInstaller.SessionInfo info)37 private PackageInstallInfo(@NonNull PackageInstaller.SessionInfo info) { 38 this.state = STATUS_INSTALLING; 39 this.packageName = info.getAppPackageName(); 40 this.componentName = new ComponentName(packageName, ""); 41 this.progress = (int) (info.getProgress() * 100f); 42 this.user = InstallSessionHelper.getUserHandle(info); 43 } 44 PackageInstallInfo(String packageName, int state, int progress, UserHandle user)45 public PackageInstallInfo(String packageName, int state, int progress, UserHandle user) { 46 this.state = state; 47 this.packageName = packageName; 48 this.componentName = new ComponentName(packageName, ""); 49 this.progress = progress; 50 this.user = user; 51 } 52 fromInstallingState(PackageInstaller.SessionInfo info)53 public static PackageInstallInfo fromInstallingState(PackageInstaller.SessionInfo info) { 54 return new PackageInstallInfo(info); 55 } 56 fromState(int state, String packageName, UserHandle user)57 public static PackageInstallInfo fromState(int state, String packageName, UserHandle user) { 58 return new PackageInstallInfo(packageName, state, 0 /* progress */, user); 59 } 60 } 61