1 /*
2  * Copyright (C) 2015 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 
17 package android.os.storage;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.UserIdInt;
22 import android.os.IVold;
23 
24 import java.util.List;
25 import java.util.Set;
26 
27 /**
28  * Mount service local interface.
29  *
30  * @hide Only for use within the system server.
31  */
32 public abstract class StorageManagerInternal {
33     /**
34      * Gets the mount mode to use for a given UID
35      *
36      * @param uid The UID for which to get mount mode.
37      * @param packageName The package in the UID for making the call.
38      * @return The mount mode.
39      */
getExternalStorageMountMode(int uid, String packageName)40     public abstract int getExternalStorageMountMode(int uid, String packageName);
41 
42     /**
43      * Checks whether the {@code packageName} with {@code uid} has full external storage access via
44      * the {@link MANAGE_EXTERNAL_STORAGE} permission.
45      *
46      * @param uid the UID for which to check access.
47      * @param packageName the package in the UID for making the call.
48      * @return whether the {@code packageName} has full external storage access.
49      * Returns {@code true} if it has access, {@code false} otherwise.
50      */
hasExternalStorageAccess(int uid, String packageName)51     public abstract boolean hasExternalStorageAccess(int uid, String packageName);
52 
53     /**
54      * A listener for reset events in the StorageManagerService.
55      */
56     public interface ResetListener {
57         /**
58          * A method that should be triggered internally by StorageManagerInternal
59          * when StorageManagerService reset happens.
60          *
61          * @param vold The binder object to vold.
62          */
onReset(IVold vold)63         void onReset(IVold vold);
64     }
65 
66     /**
67      * Return true if fuse is mounted.
68      */
isFuseMounted(int userId)69     public abstract boolean isFuseMounted(int userId);
70 
71     /**
72      * Create storage directories if it does not exist.
73      * Return true if the directories were setup correctly, otherwise false.
74      */
prepareStorageDirs(int userId, Set<String> packageList, String processName)75     public abstract boolean prepareStorageDirs(int userId, Set<String> packageList,
76             String processName);
77 
78     /**
79      * Add a listener to listen to reset event in StorageManagerService.
80      *
81      * @param listener The listener that will be notified on reset events.
82      */
addResetListener(ResetListener listener)83     public abstract void addResetListener(ResetListener listener);
84 
85     /**
86      * Notified when any app op changes so that storage mount points can be updated if the app op
87      * affects them.
88      */
onAppOpsChanged(int code, int uid, @Nullable String packageName, int mode, int previousMode)89     public abstract void onAppOpsChanged(int code, int uid,
90             @Nullable String packageName, int mode, int previousMode);
91 
92     /**
93      * Asks the StorageManager to reset all state for the provided user; this will result
94      * in the unmounting for all volumes of the user, and, if the user is still running, the
95      * volumes will be re-mounted as well.
96      *
97      * @param userId the userId for which to reset storage
98      */
resetUser(int userId)99     public abstract void resetUser(int userId);
100 
101     /**
102      * Returns {@code true} if the immediate last installed version of an app with {@code uid} had
103      * legacy storage, {@code false} otherwise.
104      */
hasLegacyExternalStorage(int uid)105     public abstract boolean hasLegacyExternalStorage(int uid);
106 
107     /**
108      * Makes sure app-private data directories on external storage are setup correctly
109      * after an application is installed or upgraded. The main use for this is OBB dirs,
110      * which can be created/modified by the installer.
111      *
112      * @param packageName the package name of the package
113      * @param uid the uid of the package
114      */
prepareAppDataAfterInstall(@onNull String packageName, int uid)115     public abstract void prepareAppDataAfterInstall(@NonNull String packageName, int uid);
116 
117 
118     /**
119      * Return true if uid is external storage service.
120      */
isExternalStorageService(int uid)121     public abstract boolean isExternalStorageService(int uid);
122 
123     /**
124      * Frees cache held by ExternalStorageService.
125      *
126      * <p> Blocks until the service frees the cache or fails in doing so.
127      *
128      * @param volumeUuid uuid of the {@link StorageVolume} from which cache needs to be freed,
129      *                   null value indicates private internal volume.
130      * @param bytes number of bytes which need to be freed
131      */
freeCache(@ullable String volumeUuid, long bytes)132     public abstract void freeCache(@Nullable String volumeUuid, long bytes);
133 
134     /**
135      * Returns the {@link VolumeInfo#getId()} values for the volumes matching
136      * {@link VolumeInfo#isPrimary()}
137      */
getPrimaryVolumeIds()138     public abstract List<String> getPrimaryVolumeIds();
139 
140     /**
141      * Tells StorageManager that CE storage for this user has been prepared.
142      *
143      * @param userId userId for which CE storage has been prepared
144      */
markCeStoragePrepared(@serIdInt int userId)145     public abstract void markCeStoragePrepared(@UserIdInt int userId);
146 
147     /**
148      * Returns true when CE storage for this user has been prepared.
149      *
150      * When the user key is unlocked and CE storage has been prepared,
151      * it's ok to access and modify CE directories on volumes for this user.
152      */
isCeStoragePrepared(@serIdInt int userId)153     public abstract boolean isCeStoragePrepared(@UserIdInt int userId);
154 }
155