Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 71e6090f authored by Sihua Ma's avatar Sihua Ma
Browse files

Return widget uid only when it is bound to screen

This fixes NPE that could happen when we call stopListening before the
widget id is deleted or bound to the screen.

Test: N/A
Fix: 212651639
Change-Id: Id4f1a7c112c29a8c058e70de51ac75d02908530c
parent b638b557
Loading
Loading
Loading
Loading
+7 −9
Original line number Diff line number Diff line
@@ -817,7 +817,8 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
            if (host != null) {
                host.callbacks = null;
                pruneHostLocked(host);
                mAppOpsManagerInternal.updateAppWidgetVisibility(host.getWidgetUids(), false);
                mAppOpsManagerInternal.updateAppWidgetVisibility(host.getWidgetUidsIfBound(),
                        false);
            }
        }
    }
@@ -888,12 +889,8 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
            Host host = lookupHostLocked(id);

            if (host != null) {
                try {
                    mAppOpsManagerInternal.updateAppWidgetVisibility(host.getWidgetUids(), false);
                } catch (NullPointerException e) {
                    Slog.e(TAG, "setAppWidgetHidden(): Getting host uids: " + host.toString(), e);
                    throw e;
                }
                mAppOpsManagerInternal.updateAppWidgetVisibility(host.getWidgetUidsIfBound(),
                        false);
            }
        }
    }
@@ -4345,14 +4342,15 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
                    PendingHostUpdate.appWidgetRemoved(appWidgetId));
        }

        public SparseArray<String> getWidgetUids() {
        public SparseArray<String> getWidgetUidsIfBound() {
            final SparseArray<String> uids = new SparseArray<>();
            for (int i = widgets.size() - 1; i >= 0; i--) {
                final Widget widget = widgets.get(i);
                if (widget.provider == null) {
                    if (DEBUG) {
                        Slog.e(TAG, "Widget with no provider " + widget.toString());
                        Slog.d(TAG, "Widget with no provider " + widget.toString());
                    }
                    continue;
                }
                final ProviderId providerId = widget.provider.id;
                uids.put(providerId.uid, providerId.componentName.getPackageName());