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

Commit d3bee4d9 authored by Pinyao Ting's avatar Pinyao Ting Committed by Android (Google) Code Review
Browse files

Merge "Prevent unintentional removal of widgets pinned by another host" into main

parents ff4d832c 931b3043
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -5666,6 +5666,13 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
        }

        public boolean canAccessAppWidget(Widget widget, int uid, String packageName) {
            if (isDifferentPackageFromHost(widget.host, packageName)
                    && isDifferentPackageFromProvider(widget.provider, packageName)) {
                // Apps providing AppWidget are only allowed to access widgets provided by the
                // same package. Similarly, apps hosting AppWidget are only allowed to access
                // widgets hosted by the same package.
                return false;
            }
            if (isHostInPackageForUid(widget.host, uid, packageName)) {
                // Apps hosting the AppWidget have access to it.
                return true;
@@ -5768,6 +5775,19 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
                    && provider.id.componentName.getPackageName().equals(packageName);
        }

        private boolean isDifferentPackageFromHost(
                @Nullable final Host host, @Nullable final String packageName) {
            return packageName == null || host == null || host.id == null
                || !packageName.equals(host.id.packageName);
        }

        private boolean isDifferentPackageFromProvider(
                @Nullable final Provider provider, @Nullable final String packageName) {
            return packageName == null || provider == null || provider.id == null
                    || provider.id.componentName == null
                    || !packageName.equals(provider.id.componentName.getPackageName());
        }

        private boolean isProfileEnabled(int profileId) {
            final long identity = Binder.clearCallingIdentity();
            try {