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

Commit 52b976d8 authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Android (Google) Code Review
Browse files

Merge "Update storage sandbox path translation methods."

parents 998b52ba 87915d66
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -285,4 +285,7 @@ public abstract class ActivityManagerInternal {
    */
    public abstract void setDebugFlagsForStartingActivity(ActivityInfo aInfo, int startFlags,
            ProfilerInfo profilerInfo, Object wmLock);

    /** Checks if process running with given pid has access to full external storage or not */
    public abstract boolean isAppStorageSandboxed(int pid, int uid);
}
+2 −2
Original line number Diff line number Diff line
@@ -188,6 +188,6 @@ interface IStorageManager {
    void allocateBytes(String volumeUuid, long bytes, int flags, String callingPackage) = 78;
    void runIdleMaintenance() = 79;
    void abortIdleMaintenance() = 80;
    String translateAppToSystem(String path, String packageName, int userId) = 81;
    String translateSystemToApp(String path, String packageName, int userId) = 82;
    String translateAppToSystem(String path, int pid, int uid) = 81;
    String translateSystemToApp(String path, int pid, int uid) = 82;
}
+4 −4
Original line number Diff line number Diff line
@@ -1548,13 +1548,13 @@ public class StorageManager {
     *
     * @hide
     */
    public File translateAppToSystem(File file, String packageName) {
    public File translateAppToSystem(File file, int pid, int uid) {
        // We can only translate absolute paths
        if (!file.isAbsolute()) return file;

        try {
            return new File(mStorageManager.translateAppToSystem(file.getAbsolutePath(),
                    packageName, mContext.getUserId()));
                    pid, uid));
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -1566,13 +1566,13 @@ public class StorageManager {
     *
     * @hide
     */
    public File translateSystemToApp(File file, String packageName) {
    public File translateSystemToApp(File file, int pid, int uid) {
        // We can only translate absolute paths
        if (!file.isAbsolute()) return file;

        try {
            return new File(mStorageManager.translateSystemToApp(file.getAbsolutePath(),
                    packageName, mContext.getUserId()));
                    pid, uid));
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+15 −11
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import static org.xmlpull.v1.XmlPullParser.START_TAG;
import android.Manifest;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.ActivityManagerInternal;
import android.app.AppOpsManager;
import android.app.IActivityManager;
import android.app.KeyguardManager;
@@ -450,6 +451,7 @@ class StorageManagerService extends IStorageManager.Stub

    private PackageManagerInternal mPmInternal;
    private UserManagerInternal mUmInternal;
    private ActivityManagerInternal mAmInternal;

    private final Callbacks mCallbacks;
    private final LockPatternUtils mLockPatternUtils;
@@ -1439,6 +1441,7 @@ class StorageManagerService extends IStorageManager.Stub

        mPmInternal = LocalServices.getService(PackageManagerInternal.class);
        mUmInternal = LocalServices.getService(UserManagerInternal.class);
        mAmInternal = LocalServices.getService(ActivityManagerInternal.class);

        HandlerThread hthread = new HandlerThread(TAG);
        hthread.start();
@@ -3060,25 +3063,25 @@ class StorageManagerService extends IStorageManager.Stub
            "(?i)^(/storage/[^/]+/(?:[0-9]+/)?)(.*)");

    @Override
    public String translateAppToSystem(String path, String packageName, int userId) {
        return translateInternal(path, packageName, userId, true);
    public String translateAppToSystem(String path, int pid, int uid) {
        return translateInternal(path, pid, uid, true);
    }

    @Override
    public String translateSystemToApp(String path, String packageName, int userId) {
        return translateInternal(path, packageName, userId, false);
    public String translateSystemToApp(String path, int pid, int uid) {
        return translateInternal(path, pid, uid, false);
    }

    private String translateInternal(String path, String packageName, int userId,
            boolean toSystem) {
    private String translateInternal(String path, int pid, int uid, boolean toSystem) {
        if (!ENABLE_ISOLATED_STORAGE) return path;

        if (path.contains("/../")) {
            throw new SecurityException("Shady looking path " + path);
        }

        final String sharedUserId = mPmInternal.getSharedUserIdForPackage(packageName);
        final String sandboxId = getSandboxId(packageName, sharedUserId);
        if (!mAmInternal.isAppStorageSandboxed(pid, uid)) {
            return path;
        }

        final Matcher m = PATTERN_TRANSLATE.matcher(path);
        if (m.matches()) {
@@ -3087,9 +3090,7 @@ class StorageManagerService extends IStorageManager.Stub

            // Does path belong to any packages belonging to this UID? If so,
            // they get to go straight through to legacy paths.
            final String[] pkgs = (sharedUserId == null)
                    ? new String[] {packageName}
                    : mPmInternal.getPackagesForSharedUserId(sharedUserId, userId);
            final String[] pkgs = mContext.getPackageManager().getPackagesForUid(uid);
            for (String pkg : pkgs) {
                if (devicePath.startsWith("Android/data/" + pkg + "/") ||
                        devicePath.startsWith("Android/media/" + pkg + "/") ||
@@ -3098,6 +3099,9 @@ class StorageManagerService extends IStorageManager.Stub
                }
            }

            final String sharedUserId = mPmInternal.getSharedUserIdForPackage(pkgs[0]);
            final String sandboxId = getSandboxId(pkgs[0], sharedUserId);

            if (toSystem) {
                // Everything else goes into sandbox.
                return device + "Android/sandbox/" + sandboxId + "/" + devicePath;
+12 −0
Original line number Diff line number Diff line
@@ -318,6 +318,7 @@ import com.android.internal.os.ByteTransferPipe;
import com.android.internal.os.IResultReceiver;
import com.android.internal.os.ProcessCpuTracker;
import com.android.internal.os.TransferPipe;
import com.android.internal.os.Zygote;
import com.android.internal.telephony.TelephonyIntents;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.DumpUtils;
@@ -19176,6 +19177,17 @@ public class ActivityManagerService extends IActivityManager.Stub
                }
            }
        }
        @Override
        public boolean isAppStorageSandboxed(int pid, int uid) {
            if (!SystemProperties.getBoolean(StorageManager.PROP_ISOLATED_STORAGE, false)) {
                return false;
            }
            synchronized (mPidsSelfLocked) {
                final ProcessRecord pr = mPidsSelfLocked.get(pid);
                return pr == null || pr.mountMode != Zygote.MOUNT_EXTERNAL_FULL;
            }
        }
    }
    long inputDispatchingTimedOut(int pid, final boolean aboveSystem, String reason) {
Loading