• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.model;
17 
18 import android.os.UserHandle;
19 
20 import com.android.launcher3.LauncherAppState;
21 import com.android.launcher3.model.data.AppInfo;
22 import com.android.launcher3.model.data.ItemInfoWithIcon;
23 import com.android.launcher3.model.data.WorkspaceItemInfo;
24 import com.android.launcher3.pm.PackageInstallInfo;
25 
26 import java.util.ArrayList;
27 import java.util.List;
28 
29 /**
30  * Handles updates due to incremental download progress updates.
31  */
32 public class PackageIncrementalDownloadUpdatedTask extends BaseModelUpdateTask {
33 
34     private final UserHandle mUser;
35     private final int mProgress;
36     private final String mPackageName;
37 
PackageIncrementalDownloadUpdatedTask( String packageName, UserHandle user, float progress)38     public PackageIncrementalDownloadUpdatedTask(
39             String packageName, UserHandle user, float progress) {
40         mUser = user;
41         mProgress = 1 - progress > 0.001 ? (int) (100 * progress) : 100;
42         mPackageName = packageName;
43     }
44 
45     @Override
execute(LauncherAppState app, BgDataModel dataModel, AllAppsList appsList)46     public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList appsList) {
47         PackageInstallInfo downloadInfo = new PackageInstallInfo(
48                 mPackageName,
49                 PackageInstallInfo.STATUS_INSTALLED_DOWNLOADING,
50                 mProgress,
51                 mUser);
52 
53         synchronized (appsList) {
54             List<AppInfo> updatedAppInfos = appsList.updatePromiseInstallInfo(downloadInfo);
55             if (!updatedAppInfos.isEmpty()) {
56                 for (AppInfo appInfo : updatedAppInfos) {
57                     appInfo.runtimeStatusFlags &= ~ItemInfoWithIcon.FLAG_INSTALL_SESSION_ACTIVE;
58                     scheduleCallbackTask(
59                             c -> c.bindIncrementalDownloadProgressUpdated(appInfo));
60                 }
61             }
62             bindApplicationsIfNeeded();
63         }
64 
65         final ArrayList<WorkspaceItemInfo> updatedWorkspaceItems = new ArrayList<>();
66         synchronized (dataModel) {
67             dataModel.forAllWorkspaceItemInfos(mUser, si -> {
68                 if (mPackageName.equals(si.getTargetPackage())) {
69                     si.runtimeStatusFlags &= ~ItemInfoWithIcon.FLAG_INSTALL_SESSION_ACTIVE;
70                     si.setProgressLevel(downloadInfo);
71                     updatedWorkspaceItems.add(si);
72                 }
73             });
74         }
75         bindUpdatedWorkspaceItems(updatedWorkspaceItems);
76     }
77 }
78