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

Commit 72b91ddc authored by Pinyao Ting's avatar Pinyao Ting Committed by Automerger Merge Worker
Browse files

Merge "Allow settings app to request pin appwidgets from other apps." into...

Merge "Allow settings app to request pin appwidgets from other apps." into udc-qpr-dev am: 732bb20f am: 2bf9417a

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



Change-Id: I02c99e70f292818ba4cdf4b001b30356311c53a6
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 85a8b7c3 2bf9417a
Loading
Loading
Loading
Loading
+27 −5
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static android.provider.DeviceConfig.NAMESPACE_SYSTEMUI;

import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME;

import android.Manifest;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
@@ -1660,8 +1661,21 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
        synchronized (mLock) {
            ensureGroupStateLoadedLocked(userId);

            final String pkg = componentName.getPackageName();
            final ProviderId id;
            if (!mPackageManagerInternal.isSameApp(pkg, callingUid, userId)) {
                // If the calling process is requesting to pin appwidgets from another process,
                // check if the calling process has the necessary permission.
                if (!injectHasAccessWidgetsPermission(Binder.getCallingPid(), callingUid)) {
                    return false;
                }
                id = new ProviderId(mPackageManagerInternal.getPackageUid(
                        pkg, 0 /* flags */, userId), componentName);
            } else {
                id = new ProviderId(callingUid, componentName);
            }
            // Look for the widget associated with the caller.
            Provider provider = lookupProviderLocked(new ProviderId(callingUid, componentName));
            Provider provider = lookupProviderLocked(id);
            if (provider == null || provider.zombie) {
                return false;
            }
@@ -1675,6 +1689,14 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
                .requestPinAppWidget(callingPackage, info, extras, resultSender, userId);
    }

    /**
     * Returns true if the caller has the proper permission to access app widgets.
     */
    private boolean injectHasAccessWidgetsPermission(int callingPid, int callingUid) {
        return mContext.checkPermission(Manifest.permission.CLEAR_APP_USER_DATA,
                callingPid, callingUid) == PackageManager.PERMISSION_GRANTED;
    }

    @Override
    public ParceledListSlice<AppWidgetProviderInfo> getInstalledProvidersForProfile(int categoryFilter,
            int profileId, String packageName) {
@@ -4131,7 +4153,7 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
            return false;
        }

        @GuardedBy("mLock")
        @GuardedBy("AppWidgetServiceImpl.mLock")
        public AppWidgetProviderInfo getInfoLocked(Context context) {
            if (!mInfoParsed) {
                // parse
@@ -4159,18 +4181,18 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
         * be completely parsed and only contain placeHolder information like
         * {@link AppWidgetProviderInfo#providerInfo}
         */
        @GuardedBy("mLock")
        @GuardedBy("AppWidgetServiceImpl.mLock")
        public AppWidgetProviderInfo getPartialInfoLocked() {
            return info;
        }

        @GuardedBy("mLock")
        @GuardedBy("AppWidgetServiceImpl.mLock")
        public void setPartialInfoLocked(AppWidgetProviderInfo info) {
            this.info = info;
            mInfoParsed = false;
        }

        @GuardedBy("mLock")
        @GuardedBy("AppWidgetServiceImpl.mLock")
        public void setInfoLocked(AppWidgetProviderInfo info) {
            this.info = info;
            mInfoParsed = true;