EMMA Coverage Report (generated Fri Aug 23 16:39:17 PDT 2013)
[all classes][org.chromium.base]

COVERAGE SUMMARY FOR SOURCE FILE [PathUtils.java]

nameclass, %method, %block, %line, %
PathUtils.java100% (1/1)75%  (6/8)54%  (43/79)55%  (11/20)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PathUtils100% (1/1)75%  (6/8)54%  (43/79)55%  (11/20)
PathUtils (): void 0%   (0/1)0%   (0/3)0%   (0/1)
setWebappDirectoryInfo (String, String): void 0%   (0/1)0%   (0/5)0%   (0/3)
getCacheDirectory (Context): String 100% (1/1)30%  (9/30)40%  (2/5)
getDataDirectory (Context): String 100% (1/1)62%  (8/13)67%  (2/3)
getNativeLibraryDirectory (Context): String 100% (1/1)89%  (16/18)75%  (3/4)
getDownloadsDirectory (Context): String 100% (1/1)100% (4/4)100% (1/1)
getExternalStorageDirectory (): String 100% (1/1)100% (3/3)100% (1/1)
setPrivateDataDirectorySuffix (String): void 100% (1/1)100% (3/3)100% (2/2)

1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4 
5package org.chromium.base;
6 
7import android.content.Context;
8import android.content.pm.ApplicationInfo;
9import android.os.Environment;
10 
11import java.io.File;
12 
13/**
14 * This class provides the path related methods for the native library.
15 */
16public abstract class PathUtils {
17 
18    private static String sDataDirectorySuffix;
19    private static String sWebappDirectorySuffix;
20    private static String sWebappCacheDirectory;
21 
22    // Prevent instantiation.
23    private PathUtils() {}
24 
25    /**
26     * Sets the suffix that should be used for the directory where private data is to be stored
27     * by the application.
28     * @param suffix The private data directory suffix.
29     * @see Context#getDir(String, int)
30     */
31    public static void setPrivateDataDirectorySuffix(String suffix) {
32        sDataDirectorySuffix = suffix;
33    }
34 
35    /**
36     * Sets the directory info used for chrome process running in application mode.
37     *
38     * @param webappSuffix The suffix of the directory used for storing webapp-specific profile
39     * @param cacheDir Cache directory name for web apps.
40     */
41    public static void setWebappDirectoryInfo(String webappSuffix, String cacheDir) {
42        sWebappDirectorySuffix = webappSuffix;
43        sWebappCacheDirectory = cacheDir;
44    }
45 
46    /**
47     * @return the private directory that is used to store application data.
48     */
49    @CalledByNative
50    public static String getDataDirectory(Context appContext) {
51        if (sDataDirectorySuffix == null) {
52            throw new IllegalStateException(
53                    "setDataDirectorySuffix must be called before getDataDirectory");
54        }
55        return appContext.getDir(sDataDirectorySuffix, Context.MODE_PRIVATE).getPath();
56    }
57 
58    /**
59     * @return the cache directory.
60     */
61    @SuppressWarnings("unused")
62    @CalledByNative
63    public static String getCacheDirectory(Context appContext) {
64        if (ContextTypes.getInstance().getType(appContext) == ContextTypes.CONTEXT_TYPE_NORMAL) {
65            return appContext.getCacheDir().getPath();
66        }
67        if (sWebappDirectorySuffix == null || sWebappCacheDirectory == null) {
68            throw new IllegalStateException(
69                    "setWebappDirectoryInfo must be called before getCacheDirectory");
70        }
71        return new File(appContext.getDir(sWebappDirectorySuffix, appContext.MODE_PRIVATE),
72                sWebappCacheDirectory).getPath();
73    }
74 
75    /**
76     * @return the public downloads directory.
77     */
78    @SuppressWarnings("unused")
79    @CalledByNative
80    private static String getDownloadsDirectory(Context appContext) {
81        return Environment.getExternalStoragePublicDirectory(
82                Environment.DIRECTORY_DOWNLOADS).getPath();
83    }
84 
85    /**
86     * @return the path to native libraries.
87     */
88    @SuppressWarnings("unused")
89    @CalledByNative
90    private static String getNativeLibraryDirectory(Context appContext) {
91        ApplicationInfo ai = appContext.getApplicationInfo();
92        if ((ai.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0 ||
93            (ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
94            return ai.nativeLibraryDir;
95        }
96 
97        return "/system/lib/";
98    }
99 
100    /**
101     * @return the external storage directory.
102     */
103    @SuppressWarnings("unused")
104    @CalledByNative
105    public static String getExternalStorageDirectory() {
106        return Environment.getExternalStorageDirectory().getAbsolutePath();
107    }
108}

[all classes][org.chromium.base]
EMMA 2.0.5312 (C) Vladimir Roubtsov