Support adding icon after launcher changed (#1497)

This commit is contained in:
LoveSy 2021-12-28 23:39:23 +08:00 committed by GitHub
parent 1975718d3d
commit e829bdd15d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 4 deletions

View File

@ -34,6 +34,7 @@ import android.content.AttributionSource;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.LauncherApps;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
@ -307,10 +308,16 @@ public class LSPManagerService extends ILSPManagerService.Stub {
.build();
for (var shortcutInfo : sm.getPinnedShortcuts()) {
if (SHORTCUT_ID.equals(shortcutInfo.getId())) {
Log.d(TAG, "shortcut exists, updating");
sm.updateShortcuts(Collections.singletonList(shortcut));
return;
if (SHORTCUT_ID.equals(shortcutInfo.getId()) && shortcutInfo.isPinned()) {
var shortcutIntent = sm.createShortcutResultIntent(shortcutInfo);
var request = (LauncherApps.PinItemRequest)shortcutIntent.getParcelableExtra(LauncherApps.EXTRA_PIN_ITEM_REQUEST);
var requestInfo = request.getShortcutInfo();
// https://cs.android.com/android/platform/superproject/+/android-8.1.0_r1:frameworks/base/services/core/java/com/android/server/pm/ShortcutRequestPinProcessor.java;drc=4ad6b57700bef4c484021f49e018117046562e6b;l=337
if (requestInfo.isPinned()) {
Log.d(TAG, "shortcut exists, updating");
sm.updateShortcuts(Collections.singletonList(shortcut));
return;
}
}
}
var configManager = ConfigManager.getInstance();