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

Commit a02b8b05 authored by Kenny Root's avatar Kenny Root
Browse files

Move OBB file reading to DefaultContainerService

The system_server shouldn't touch files on the SD card. This change
moves the things that touch the SD card out to the
DefaultContainerService so that it will get killed if the SD card goes
away instead of the system_server.

Change-Id: I0aefa085be4b194768527195532ee6dddc801cfc
parent 9902196f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -121,6 +121,7 @@ LOCAL_SRC_FILES += \
	core/java/android/os/storage/IMountService.aidl \
	core/java/android/os/storage/IMountServiceListener.aidl \
	core/java/android/os/storage/IMountShutdownObserver.aidl \
	core/java/android/os/storage/IObbActionListener.aidl \
	core/java/android/os/INetworkManagementService.aidl \
	core/java/android/os/INetStatService.aidl \
	core/java/android/os/IPermissionController.aidl \
+4 −0
Original line number Diff line number Diff line
@@ -129531,6 +129531,8 @@
>
<parameter name="filename" type="java.lang.String">
</parameter>
<exception name="IllegalArgumentException" type="java.lang.IllegalArgumentException">
</exception>
</method>
<method name="mountObb"
 return="boolean"
@@ -129561,6 +129563,8 @@
</parameter>
<parameter name="force" type="boolean">
</parameter>
<exception name="IllegalArgumentException" type="java.lang.IllegalArgumentException">
</exception>
</method>
</class>
</package>
+9 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.os.storage;

import android.os.storage.IMountServiceListener;
import android.os.storage.IMountShutdownObserver;
import android.os.storage.IObbActionListener;

/** WARNING! Update IMountService.h and IMountService.cpp if you change this file.
 * In particular, the ordering of the methods below must match the 
@@ -156,14 +157,20 @@ interface IMountService
    /**
     * Mounts an Opaque Binary Blob (OBB) with the specified decryption key and only
     * allows the calling process's UID access to the contents.
     *
     * MountService will call back to the supplied IObbActionListener to inform
     * it of the terminal state of the call.
     */
    int mountObb(String filename, String key);
    void mountObb(String filename, String key, IObbActionListener token);

    /**
     * Unmounts an Opaque Binary Blob (OBB). When the force flag is specified, any
     * program using it will be forcibly killed to unmount the image.
     *
     * MountService will call back to the supplied IObbActionListener to inform
     * it of the terminal state of the call.
     */
    int unmountObb(String filename, boolean force);
    void unmountObb(String filename, boolean force, IObbActionListener token);

    /**
     * Checks whether the specified Opaque Binary Blob (OBB) is mounted somewhere.
+34 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.os.storage;

/**
 * Callback class for receiving events from MountService about
 * Opaque Binary Blobs (OBBs).
 *
 * @hide - Applications should use android.os.storage.StorageManager
 * to interact with OBBs.
 */
interface IObbActionListener {
    /**
     * Return from an OBB action result.
     *
     * @param filename the path to the OBB the operation was performed on
     * @param returnCode status of the operation
     */
    void onObbResult(String filename, String status);
}
+59 −25
Original line number Diff line number Diff line
@@ -16,28 +16,14 @@

package android.os.storage;

import android.content.Context;
import android.os.Binder;
import android.os.Bundle;
import android.os.Looper;
import android.os.Parcelable;
import android.os.ParcelFileDescriptor;
import android.os.Process;
import android.os.RemoteException;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.storage.IMountService;
import android.os.storage.IMountServiceListener;
import android.util.Log;
import android.util.SparseArray;

import java.io.FileDescriptor;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

/**
 * StorageManager is the interface to the systems storage service.
@@ -86,6 +72,17 @@ public class StorageManager
        }
    }

    /**
     * Binder listener for OBB action results.
     */
    private final ObbActionBinderListener mObbActionListener = new ObbActionBinderListener();
    private class ObbActionBinderListener extends IObbActionListener.Stub {
        @Override
        public void onObbResult(String filename, String status) throws RemoteException {
            Log.i(TAG, "filename = " + filename + ", result = " + status);
        }
    }

    /**
     * Private base class for messages sent between the callback thread
     * and the target looper handler.
@@ -299,12 +296,23 @@ public class StorageManager
    }

    /**
     * Mount an OBB file.
     * Mount an Opaque Binary Blob (OBB) file. If a <code>key</code> is
     * specified, it is supplied to the mounting process to be used in any
     * encryption used in the OBB.
     * <p>
     * <em>Note:</em> you can only mount OBB files for which the OBB tag on the
     * file matches a package ID that is owned by the calling program's UID.
     * That is, shared UID applications can obtain access to any other
     * application's OBB that shares its UID.
     * 
     * @param filename the path to the OBB file
     * @param key decryption key
     * @return whether the mount call was successfully queued or not
     */
    public boolean mountObb(String filename, String key) {
        try {
            return mMountService.mountObb(filename, key)
                    == StorageResultCode.OperationSucceeded;
            mMountService.mountObb(filename, key, mObbActionListener);
            return true;
        } catch (RemoteException e) {
            Log.e(TAG, "Failed to mount OBB", e);
        }
@@ -313,12 +321,24 @@ public class StorageManager
    }

    /**
     * Mount an OBB file.
     * Unmount an Opaque Binary Blob (OBB) file. If the <code>force</code> flag
     * is true, it will kill any application needed to unmount the given OBB.
     * <p>
     * <em>Note:</em> you can only mount OBB files for which the OBB tag on the
     * file matches a package ID that is owned by the calling program's UID.
     * That is, shared UID applications can obtain access to any other
     * application's OBB that shares its UID.
     * 
     * @param filename path to the OBB file
     * @param force whether to kill any programs using this in order to unmount
     *            it
     * @return whether the unmount call was successfully queued or not
     * @throws IllegalArgumentException when OBB is not already mounted
     */
    public boolean unmountObb(String filename, boolean force) {
    public boolean unmountObb(String filename, boolean force) throws IllegalArgumentException {
        try {
            return mMountService.unmountObb(filename, force)
                    == StorageResultCode.OperationSucceeded;
            mMountService.unmountObb(filename, force, mObbActionListener);
            return true;
        } catch (RemoteException e) {
            Log.e(TAG, "Failed to mount OBB", e);
        }
@@ -326,7 +346,13 @@ public class StorageManager
        return false;
    }

    public boolean isObbMounted(String filename) {
    /**
     * Check whether an Opaque Binary Blob (OBB) is mounted or not.
     * 
     * @param filename path to OBB image
     * @return true if OBB is mounted; false if not mounted or on error
     */
    public boolean isObbMounted(String filename) throws IllegalArgumentException {
        try {
            return mMountService.isObbMounted(filename);
        } catch (RemoteException e) {
@@ -337,13 +363,21 @@ public class StorageManager
    }

    /**
     * Check the mounted path of an OBB file.
     * Check the mounted path of an Opaque Binary Blob (OBB) file. This will
     * give you the path to where you can obtain access to the internals of the
     * OBB.
     * 
     * @param filename path to OBB image
     * @return absolute path to mounted OBB image data or <code>null</code> if
     *         not mounted or exception encountered trying to read status
     */
    public String getMountedObbPath(String filename) {
        try {
            return mMountService.getMountedObbPath(filename);
        } catch (RemoteException e) {
            Log.e(TAG, "Failed to find mounted path for OBB", e);
        } catch (IllegalArgumentException e) {
            Log.d(TAG, "Couldn't read OBB file", e);
        }

        return null;
Loading