Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
PathUtils.java
Go to the documentation of this file.
1// Copyright 2013 The Flutter 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 io.flutter.util;
6
7import static io.flutter.Build.API_LEVELS;
8
9import android.content.Context;
10import android.os.Build;
11import androidx.annotation.NonNull;
12import java.io.File;
13
14public final class PathUtils {
15 @NonNull
16 public static String getFilesDir(@NonNull Context applicationContext) {
17 File filesDir = applicationContext.getFilesDir();
18 if (filesDir == null) {
19 filesDir = new File(getDataDirPath(applicationContext), "files");
20 }
21 return filesDir.getPath();
22 }
23
24 @NonNull
25 public static String getDataDirectory(@NonNull Context applicationContext) {
26 final String name = "flutter";
27 File flutterDir = applicationContext.getDir(name, Context.MODE_PRIVATE);
28 if (flutterDir == null) {
29 flutterDir = new File(getDataDirPath(applicationContext), "app_" + name);
30 }
31 return flutterDir.getPath();
32 }
33
34 @NonNull
35 public static String getCacheDirectory(@NonNull Context applicationContext) {
36 File cacheDir;
37 cacheDir = applicationContext.getCodeCacheDir();
38 if (cacheDir == null) {
39 cacheDir = applicationContext.getCacheDir();
40 }
41 if (cacheDir == null) {
42 // This can happen if the disk is full. This code path is used to set up dart:io's
43 // `Directory.systemTemp`. It's unknown if the application will ever try to
44 // use that or not, so do not throw here. In this case, this directory does
45 // not exist because the disk is full, and the application will later get an
46 // exception when it tries to actually write.
47 cacheDir = new File(getDataDirPath(applicationContext), "cache");
48 }
49 return cacheDir.getPath();
50 }
51
52 private static String getDataDirPath(Context applicationContext) {
53 if (Build.VERSION.SDK_INT >= API_LEVELS.API_24) {
54 return applicationContext.getDataDir().getPath();
55 } else {
56 return applicationContext.getApplicationInfo().dataDir;
57 }
58 }
59}
static String getDataDirectory(@NonNull Context applicationContext)
static String getCacheDirectory(@NonNull Context applicationContext)
static String getFilesDir(@NonNull Context applicationContext)
const char * name
Definition fuchsia.cc:50