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

Commit e0dcd303 authored by Abhijeet Kaur's avatar Abhijeet Kaur Committed by Automerger Merge Worker
Browse files

Merge "Allow ExternalStorageProvider to access all Android/ dirs" into rvc-dev am: 51f5e20e

Change-Id: Ieeead3c693e49feeaf42fca06471d4094965e63b
parents 417f6f80 51f5e20e
Loading
Loading
Loading
Loading
+20 −10
Original line number Original line Diff line number Diff line
@@ -121,6 +121,7 @@ import android.os.storage.StorageVolume;
import android.os.storage.VolumeInfo;
import android.os.storage.VolumeInfo;
import android.os.storage.VolumeRecord;
import android.os.storage.VolumeRecord;
import android.provider.DeviceConfig;
import android.provider.DeviceConfig;
import android.provider.DocumentsContract;
import android.provider.Downloads;
import android.provider.Downloads;
import android.provider.MediaStore;
import android.provider.MediaStore;
import android.provider.Settings;
import android.provider.Settings;
@@ -432,6 +433,8 @@ class StorageManagerService extends IStorageManager.Stub


    private volatile int mDownloadsAuthorityAppId = -1;
    private volatile int mDownloadsAuthorityAppId = -1;


    private volatile int mExternalStorageAuthorityAppId = -1;

    private volatile int mCurrentUserId = UserHandle.USER_SYSTEM;
    private volatile int mCurrentUserId = UserHandle.USER_SYSTEM;


    private final Installer mInstaller;
    private final Installer mInstaller;
@@ -1923,24 +1926,22 @@ class StorageManagerService extends IStorageManager.Stub
        mIAppOpsService = IAppOpsService.Stub.asInterface(
        mIAppOpsService = IAppOpsService.Stub.asInterface(
                ServiceManager.getService(Context.APP_OPS_SERVICE));
                ServiceManager.getService(Context.APP_OPS_SERVICE));


        ProviderInfo provider = mPmInternal.resolveContentProvider(
        ProviderInfo provider = getProviderInfo(MediaStore.AUTHORITY);
                MediaStore.AUTHORITY, PackageManager.MATCH_DIRECT_BOOT_AWARE
                | PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
                UserHandle.getUserId(UserHandle.USER_SYSTEM));
        if (provider != null) {
        if (provider != null) {
            mMediaStoreAuthorityAppId = UserHandle.getAppId(provider.applicationInfo.uid);
            mMediaStoreAuthorityAppId = UserHandle.getAppId(provider.applicationInfo.uid);
            sMediaStoreAuthorityProcessName = provider.applicationInfo.processName;
            sMediaStoreAuthorityProcessName = provider.applicationInfo.processName;
        }
        }


        provider = mPmInternal.resolveContentProvider(
        provider = getProviderInfo(Downloads.Impl.AUTHORITY);
                Downloads.Impl.AUTHORITY, PackageManager.MATCH_DIRECT_BOOT_AWARE
                        | PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
                UserHandle.getUserId(UserHandle.USER_SYSTEM));

        if (provider != null) {
        if (provider != null) {
            mDownloadsAuthorityAppId = UserHandle.getAppId(provider.applicationInfo.uid);
            mDownloadsAuthorityAppId = UserHandle.getAppId(provider.applicationInfo.uid);
        }
        }


        provider = getProviderInfo(DocumentsContract.EXTERNAL_STORAGE_PROVIDER_AUTHORITY);
        if (provider != null) {
            mExternalStorageAuthorityAppId = UserHandle.getAppId(provider.applicationInfo.uid);
        }

        if (!mIsFuseEnabled) {
        if (!mIsFuseEnabled) {
            try {
            try {
                mIAppOpsService.startWatchingMode(OP_REQUEST_INSTALL_PACKAGES, null,
                mIAppOpsService.startWatchingMode(OP_REQUEST_INSTALL_PACKAGES, null,
@@ -1951,6 +1952,13 @@ class StorageManagerService extends IStorageManager.Stub
        }
        }
    }
    }


    private ProviderInfo getProviderInfo(String authority) {
        return mPmInternal.resolveContentProvider(
                authority, PackageManager.MATCH_DIRECT_BOOT_AWARE
                        | PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
                UserHandle.getUserId(UserHandle.USER_SYSTEM));
    }

    private void updateLegacyStorageApps(String packageName, int uid, boolean hasLegacy) {
    private void updateLegacyStorageApps(String packageName, int uid, boolean hasLegacy) {
        synchronized (mLock) {
        synchronized (mLock) {
            if (hasLegacy) {
            if (hasLegacy) {
@@ -4191,9 +4199,11 @@ class StorageManagerService extends IStorageManager.Stub
                return Zygote.MOUNT_EXTERNAL_PASS_THROUGH;
                return Zygote.MOUNT_EXTERNAL_PASS_THROUGH;
            }
            }


            if (mIsFuseEnabled && mDownloadsAuthorityAppId == UserHandle.getAppId(uid)) {
            if (mIsFuseEnabled && (mDownloadsAuthorityAppId == UserHandle.getAppId(uid)
                    || mExternalStorageAuthorityAppId == UserHandle.getAppId(uid))) {
                // DownloadManager can write in app-private directories on behalf of apps;
                // DownloadManager can write in app-private directories on behalf of apps;
                // give it write access to Android/
                // give it write access to Android/
                // ExternalStorageProvider can access Android/{data,obb} dirs in managed mode
                return Zygote.MOUNT_EXTERNAL_ANDROID_WRITABLE;
                return Zygote.MOUNT_EXTERNAL_ANDROID_WRITABLE;
            }
            }