1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content.res;
18
19import java.io.File;
20import java.io.IOException;
21
22/**
23 * Class to scan Opaque Binary Blob (OBB) files. Use this to get information
24 * about an OBB file for use in a program via {@link ObbInfo}.
25 */
26public class ObbScanner {
27    // Don't allow others to instantiate this class
28    private ObbScanner() {}
29
30    /**
31     * Scan a file for OBB information.
32     *
33     * @param filePath path to the OBB file to be scanned.
34     * @return ObbInfo object information corresponding to the file path
35     * @throws IllegalArgumentException if the OBB file couldn't be found
36     * @throws IOException if the OBB file couldn't be read
37     */
38    public static ObbInfo getObbInfo(String filePath) throws IOException {
39        if (filePath == null) {
40            throw new IllegalArgumentException("file path cannot be null");
41        }
42
43        final File obbFile = new File(filePath);
44        if (!obbFile.exists()) {
45            throw new IllegalArgumentException("OBB file does not exist: " + filePath);
46        }
47
48        /*
49         * XXX This will fail to find the real canonical path if bind mounts are
50         * used, but we don't use any bind mounts right now.
51         */
52        final String canonicalFilePath = obbFile.getCanonicalPath();
53
54        ObbInfo obbInfo = new ObbInfo();
55        obbInfo.filename = canonicalFilePath;
56        getObbInfo_native(canonicalFilePath, obbInfo);
57
58        return obbInfo;
59    }
60
61    private native static void getObbInfo_native(String filePath, ObbInfo obbInfo)
62            throws IOException;
63}
64