mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-01 08:16:49 +00:00
This would allow adding different source for model items without modifying every model task Bug: 160748731 Change-Id: I5a14dd761e2b8696c58dc8fec7b14077da0aced3
97 lines
3.8 KiB
Java
97 lines
3.8 KiB
Java
/*
|
|
* Copyright (C) 2016 The Android Open Source Project
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
package com.android.launcher3.model;
|
|
|
|
import android.content.ComponentName;
|
|
import android.content.pm.ApplicationInfo;
|
|
import android.content.pm.PackageManager;
|
|
|
|
import com.android.launcher3.LauncherAppState;
|
|
import com.android.launcher3.model.data.ItemInfo;
|
|
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
|
|
import com.android.launcher3.model.data.PromiseAppInfo;
|
|
import com.android.launcher3.model.data.WorkspaceItemInfo;
|
|
import com.android.launcher3.pm.PackageInstallInfo;
|
|
import com.android.launcher3.util.InstantAppResolver;
|
|
|
|
import java.util.HashSet;
|
|
|
|
/**
|
|
* Handles changes due to a sessions updates for a currently installing app.
|
|
*/
|
|
public class PackageInstallStateChangedTask extends BaseModelUpdateTask {
|
|
|
|
private final PackageInstallInfo mInstallInfo;
|
|
|
|
public PackageInstallStateChangedTask(PackageInstallInfo installInfo) {
|
|
mInstallInfo = installInfo;
|
|
}
|
|
|
|
@Override
|
|
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
|
|
if (mInstallInfo.state == PackageInstallInfo.STATUS_INSTALLED) {
|
|
try {
|
|
// For instant apps we do not get package-add. Use setting events to update
|
|
// any pinned icons.
|
|
ApplicationInfo ai = app.getContext()
|
|
.getPackageManager().getApplicationInfo(mInstallInfo.packageName, 0);
|
|
if (InstantAppResolver.newInstance(app.getContext()).isInstantApp(ai)) {
|
|
app.getModel().onPackageAdded(ai.packageName, mInstallInfo.user);
|
|
}
|
|
} catch (PackageManager.NameNotFoundException e) {
|
|
// Ignore
|
|
}
|
|
// Ignore install success events as they are handled by Package add events.
|
|
return;
|
|
}
|
|
|
|
synchronized (apps) {
|
|
PromiseAppInfo updated = apps.updatePromiseInstallInfo(mInstallInfo);
|
|
if (updated != null) {
|
|
scheduleCallbackTask(c -> c.bindPromiseAppProgressUpdated(updated));
|
|
}
|
|
bindApplicationsIfNeeded();
|
|
}
|
|
|
|
synchronized (dataModel) {
|
|
final HashSet<ItemInfo> updates = new HashSet<>();
|
|
dataModel.forAllWorkspaceItemInfos(mInstallInfo.user, si -> {
|
|
ComponentName cn = si.getTargetComponent();
|
|
if (si.hasPromiseIconUi() && (cn != null)
|
|
&& mInstallInfo.packageName.equals(cn.getPackageName())) {
|
|
si.setInstallProgress(mInstallInfo.progress);
|
|
if (mInstallInfo.state == PackageInstallInfo.STATUS_FAILED) {
|
|
// Mark this info as broken.
|
|
si.status &= ~WorkspaceItemInfo.FLAG_INSTALL_SESSION_ACTIVE;
|
|
}
|
|
updates.add(si);
|
|
}
|
|
});
|
|
|
|
for (LauncherAppWidgetInfo widget : dataModel.appWidgets) {
|
|
if (widget.providerName.getPackageName().equals(mInstallInfo.packageName)) {
|
|
widget.installProgress = mInstallInfo.progress;
|
|
updates.add(widget);
|
|
}
|
|
}
|
|
|
|
if (!updates.isEmpty()) {
|
|
scheduleCallbackTask(callbacks -> callbacks.bindRestoreItemsChange(updates));
|
|
}
|
|
}
|
|
}
|
|
}
|