1e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/*
2e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Copyright (C) 2010 The Android Open Source Project
3e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian *
4e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Licensed under the Apache License, Version 2.0 (the "License");
5e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * you may not use this file except in compliance with the License.
6e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * You may obtain a copy of the License at
7e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian *
8e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian *      http://www.apache.org/licenses/LICENSE-2.0
9e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian *
10e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Unless required by applicable law or agreed to in writing, software
11e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * distributed under the License is distributed on an "AS IS" BASIS,
12e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * See the License for the specific language governing permissions and
14e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * limitations under the License.
15e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */
16e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
17bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/**
18bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * @addtogroup Storage
19bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * @{
20bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine */
21bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine
22bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/**
23bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * @file storage_manager.h
24bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine */
25e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
26e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#ifndef ANDROID_STORAGE_MANAGER_H
27e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#define ANDROID_STORAGE_MANAGER_H
28e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
29e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#include <stdint.h>
30e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
31e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#ifdef __cplusplus
32e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianextern "C" {
33e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#endif
34e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
35e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianstruct AStorageManager;
36bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/**
37bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * {@link AStorageManager} manages application OBB storage, a pointer
38bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * can be obtained with AStorageManager_new().
39bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine */
40e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopiantypedef struct AStorageManager AStorageManager;
41e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
42bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/**
43bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * The different states of a OBB storage passed to AStorageManager_obbCallbackFunc().
44bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine */
45e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianenum {
46bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine    /**
47e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     * The OBB container is now mounted and ready for use. Can be returned
48e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     * as the status for callbacks made during asynchronous OBB actions.
49e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     */
50e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    AOBB_STATE_MOUNTED = 1,
51e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
52bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine    /**
53e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     * The OBB container is now unmounted and not usable. Can be returned
54e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     * as the status for callbacks made during asynchronous OBB actions.
55e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     */
56e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    AOBB_STATE_UNMOUNTED = 2,
57e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
58bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine    /**
59e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     * There was an internal system error encountered while trying to
60e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     * mount the OBB. Can be returned as the status for callbacks made
61e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     * during asynchronous OBB actions.
62e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     */
63e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    AOBB_STATE_ERROR_INTERNAL = 20,
64e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
65bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine    /**
66e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     * The OBB could not be mounted by the system. Can be returned as the
67e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     * status for callbacks made during asynchronous OBB actions.
68e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     */
69e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    AOBB_STATE_ERROR_COULD_NOT_MOUNT = 21,
70e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
71bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine    /**
72e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     * The OBB could not be unmounted. This most likely indicates that a
73e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     * file is in use on the OBB. Can be returned as the status for
74e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     * callbacks made during asynchronous OBB actions.
75e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     */
76e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    AOBB_STATE_ERROR_COULD_NOT_UNMOUNT = 22,
77e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
78bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine    /**
79e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     * A call was made to unmount the OBB when it was not mounted. Can be
80e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     * returned as the status for callbacks made during asynchronous OBB
81e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     * actions.
82e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     */
83e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    AOBB_STATE_ERROR_NOT_MOUNTED = 23,
84e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
85bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine    /**
86e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     * The OBB has already been mounted. Can be returned as the status for
87e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     * callbacks made during asynchronous OBB actions.
88e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     */
89e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    AOBB_STATE_ERROR_ALREADY_MOUNTED = 24,
90e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
91bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine    /**
92e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     * The current application does not have permission to use this OBB.
93e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     * This could be because the OBB indicates it's owned by a different
94e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     * package. Can be returned as the status for callbacks made during
95e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     * asynchronous OBB actions.
96e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian     */
97e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    AOBB_STATE_ERROR_PERMISSION_DENIED = 25,
98e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian};
99e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
100e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/**
101e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Obtains a new instance of AStorageManager.
102e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */
103e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias AgopianAStorageManager* AStorageManager_new();
104e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
105e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/**
106e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Release AStorageManager instance.
107e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */
108e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianvoid AStorageManager_delete(AStorageManager* mgr);
109e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
110e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/**
111e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Callback function for asynchronous calls made on OBB files.
112bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine *
113bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * "state" is one of the following constants:
114bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * - {@link AOBB_STATE_MOUNTED}
115bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * - {@link AOBB_STATE_UNMOUNTED}
116bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * - {@link AOBB_STATE_ERROR_INTERNAL}
117bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * - {@link AOBB_STATE_ERROR_COULD_NOT_MOUNT}
118bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * - {@link AOBB_STATE_ERROR_COULD_NOT_UNMOUNT}
119bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * - {@link AOBB_STATE_ERROR_NOT_MOUNTED}
120bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * - {@link AOBB_STATE_ERROR_ALREADY_MOUNTED}
121bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * - {@link AOBB_STATE_ERROR_PERMISSION_DENIED}
122e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */
123e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopiantypedef void (*AStorageManager_obbCallbackFunc)(const char* filename, const int32_t state, void* data);
124e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
125e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/**
126e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Attempts to mount an OBB file. This is an asynchronous operation.
127e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */
128e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianvoid AStorageManager_mountObb(AStorageManager* mgr, const char* filename, const char* key,
129e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian        AStorageManager_obbCallbackFunc cb, void* data);
130e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
131e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/**
132e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Attempts to unmount an OBB file. This is an asynchronous operation.
133e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */
134e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianvoid AStorageManager_unmountObb(AStorageManager* mgr, const char* filename, const int force,
135e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian        AStorageManager_obbCallbackFunc cb, void* data);
136e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
137e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/**
138e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Check whether an OBB is mounted.
139e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */
140e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianint AStorageManager_isObbMounted(AStorageManager* mgr, const char* filename);
141e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
142e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/**
143e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Get the mounted path for an OBB.
144e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */
145e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianconst char* AStorageManager_getMountedObbPath(AStorageManager* mgr, const char* filename);
146e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
147e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
148e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#ifdef __cplusplus
149e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian};
150e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#endif
151e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
152e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#endif      // ANDROID_STORAGE_MANAGER_H
153bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine
154bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/** @} */
155