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

Commit 56d4c218 authored by Rhed Jao's avatar Rhed Jao Committed by Android (Google) Code Review
Browse files

Merge "Apply packages visibility to ContentResolver#getSyncAdapterTypes" into sc-dev

parents c04814ff 40e14f7a
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -706,6 +706,10 @@ package android.content {
    method public int getDisplayId();
  }

  public class SyncAdapterType implements android.os.Parcelable {
    method @Nullable public String getPackageName();
  }

}

package android.content.integrity {
+2 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.content;

import android.annotation.Nullable;
import android.annotation.TestApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.os.Build;
import android.os.Parcel;
@@ -168,6 +169,7 @@ public class SyncAdapterType implements Parcelable {
     *
     * @hide
     */
    @TestApi
    public @Nullable String getPackageName() {
        return packageName;
    }
+2 −1
Original line number Diff line number Diff line
@@ -791,12 +791,13 @@ public final class ContentService extends IContentService.Stub {
    public SyncAdapterType[] getSyncAdapterTypesAsUser(int userId) {
        enforceCrossUserPermission(userId,
                "no permission to read sync settings for user " + userId);
        final int callingUid = Binder.getCallingUid();
        // This makes it so that future permission checks will be in the context of this
        // process rather than the caller's process. We will restore this before returning.
        final long identityToken = clearCallingIdentity();
        try {
            SyncManager syncManager = getSyncManager();
            return syncManager.getSyncAdapterTypes(userId);
            return syncManager.getSyncAdapterTypes(callingUid, userId);
        } finally {
            restoreCallingIdentity(identityToken);
        }
+10 −6
Original line number Diff line number Diff line
@@ -89,6 +89,7 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.os.WorkSource;
import android.provider.Settings;
import android.text.TextUtils;
import android.text.format.TimeMigrationUtils;
import android.util.EventLog;
import android.util.Log;
@@ -1257,16 +1258,19 @@ public class SyncManager {
                syncExemptionFlag, callingUid, callingPid, callingPackage);
    }

    public SyncAdapterType[] getSyncAdapterTypes(int userId) {
    public SyncAdapterType[] getSyncAdapterTypes(int callingUid, int userId) {
        final Collection<RegisteredServicesCache.ServiceInfo<SyncAdapterType>> serviceInfos;
        serviceInfos = mSyncAdapters.getAllServices(userId);
        SyncAdapterType[] types = new SyncAdapterType[serviceInfos.size()];
        int i = 0;
        final List<SyncAdapterType> types = new ArrayList<>(serviceInfos.size());
        for (RegisteredServicesCache.ServiceInfo<SyncAdapterType> serviceInfo : serviceInfos) {
            types[i] = serviceInfo.type;
            ++i;
            final String packageName = serviceInfo.type.getPackageName();
            if (!TextUtils.isEmpty(packageName) && mPackageManagerInternal.filterAppAccess(
                    packageName, callingUid, userId)) {
                continue;
            }
            types.add(serviceInfo.type);
        }
        return types;
        return types.toArray(new SyncAdapterType[] {});
    }

    public String[] getSyncAdapterPackagesForAuthorityAsUser(String authority, int userId) {