Merge "Avoid potential deadlock" into sc-dev am: f9cd67b01e

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14888574

Change-Id: I7c2553cbff8cbde02c659d93d2d406533ef487a8
This commit is contained in:
TreeHugger Robot
2021-06-09 17:08:10 +00:00
committed by Automerger Merge Worker
2 changed files with 7 additions and 19 deletions

View File

@@ -61,7 +61,7 @@ public class ShortcutBitmapSaver {
* Before saving shortcuts.xml, and returning icons to the launcher, we wait for all pending * Before saving shortcuts.xml, and returning icons to the launcher, we wait for all pending
* saves to finish. However if it takes more than this long, we just give up and proceed. * saves to finish. However if it takes more than this long, we just give up and proceed.
*/ */
private final long SAVE_WAIT_TIMEOUT_MS = 30 * 1000; private final long SAVE_WAIT_TIMEOUT_MS = 5 * 1000;
private final ShortcutService mService; private final ShortcutService mService;
@@ -281,7 +281,7 @@ public class ShortcutBitmapSaver {
} }
final String path = file.getAbsolutePath(); final String path = file.getAbsolutePath();
mService.postValue(shortcut, si -> si.setBitmapPath(path)); shortcut.setBitmapPath(path);
} catch (IOException | RuntimeException e) { } catch (IOException | RuntimeException e) {
Slog.e(ShortcutService.TAG, "Unable to write bitmap to file", e); Slog.e(ShortcutService.TAG, "Unable to write bitmap to file", e);
@@ -296,14 +296,12 @@ public class ShortcutBitmapSaver {
Slog.d(TAG, "Saved bitmap."); Slog.d(TAG, "Saved bitmap.");
} }
if (shortcut != null) { if (shortcut != null) {
mService.postValue(shortcut, si -> { if (shortcut.getBitmapPath() == null) {
if (si.getBitmapPath() == null) { removeIcon(shortcut);
removeIcon(si);
} }
// Whatever happened, remove this flag. // Whatever happened, remove this flag.
si.clearFlags(ShortcutInfo.FLAG_ICON_FILE_PENDING_SAVE); shortcut.clearFlags(ShortcutInfo.FLAG_ICON_FILE_PENDING_SAVE);
});
} }
} }
return true; return true;

View File

@@ -1208,16 +1208,6 @@ public class ShortcutService extends IShortcutService.Stub {
} }
} }
void postValue(@NonNull final ShortcutInfo shortcutInfo,
@NonNull final Consumer<ShortcutInfo> cb) {
final String pkg = shortcutInfo.getPackage();
final int userId = shortcutInfo.getUserId();
final String id = shortcutInfo.getId();
synchronized (mLock) {
getPackageShortcutsLocked(pkg, userId).mutateShortcut(id, shortcutInfo, cb);
}
}
/** Return the last reset time. */ /** Return the last reset time. */
@GuardedBy("mLock") @GuardedBy("mLock")
long getLastResetTimeLocked() { long getLastResetTimeLocked() {