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.FlaggedApi;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.annotation.UserIdInt;
23 import android.content.pm.UserInfo;
24 import android.multiuser.Flags;
25 import android.os.IInstalld;
26 import android.os.IVold;
27 import android.os.ParcelFileDescriptor;
28 
29 import java.io.IOException;
30 import java.util.List;
31 import java.util.Set;
32 
33 /**
34  * Mount service local interface.
35  *
36  * @hide Only for use within the system server.
37  */
38 public abstract class StorageManagerInternal {
39     /**
40      * Gets the mount mode to use for a given UID
41      *
42      * @param uid The UID for which to get mount mode.
43      * @param packageName The package in the UID for making the call.
44      * @return The mount mode.
45      */
getExternalStorageMountMode(int uid, String packageName)46     public abstract int getExternalStorageMountMode(int uid, String packageName);
47 
48     /**
49      * Checks whether the {@code packageName} with {@code uid} has full external storage access via
50      * the {@link MANAGE_EXTERNAL_STORAGE} permission.
51      *
52      * @param uid the UID for which to check access.
53      * @param packageName the package in the UID for making the call.
54      * @return whether the {@code packageName} has full external storage access.
55      * Returns {@code true} if it has access, {@code false} otherwise.
56      */
hasExternalStorageAccess(int uid, String packageName)57     public abstract boolean hasExternalStorageAccess(int uid, String packageName);
58 
59     /**
60      * A listener for reset events in the StorageManagerService.
61      */
62     public interface ResetListener {
63         /**
64          * A method that should be triggered internally by StorageManagerInternal
65          * when StorageManagerService reset happens.
66          *
67          * @param vold The binder object to vold.
68          */
onReset(IVold vold)69         void onReset(IVold vold);
70     }
71 
72     /**
73      * Return true if fuse is mounted.
74      */
isFuseMounted(int userId)75     public abstract boolean isFuseMounted(int userId);
76 
77     /**
78      * Create storage directories if it does not exist.
79      * Return true if the directories were setup correctly, otherwise false.
80      */
prepareStorageDirs(int userId, Set<String> packageList, String processName)81     public abstract boolean prepareStorageDirs(int userId, Set<String> packageList,
82             String processName);
83 
84     /**
85      * Add a listener to listen to reset event in StorageManagerService.
86      *
87      * @param listener The listener that will be notified on reset events.
88      */
addResetListener(ResetListener listener)89     public abstract void addResetListener(ResetListener listener);
90 
91     /**
92      * Notified when any app op changes so that storage mount points can be updated if the app op
93      * affects them.
94      */
onAppOpsChanged(int code, int uid, @Nullable String packageName, int mode, int previousMode)95     public abstract void onAppOpsChanged(int code, int uid,
96             @Nullable String packageName, int mode, int previousMode);
97 
98     /**
99      * Asks the StorageManager to reset all state for the provided user; this will result
100      * in the unmounting for all volumes of the user, and, if the user is still running, the
101      * volumes will be re-mounted as well.
102      *
103      * @param userId the userId for which to reset storage
104      */
resetUser(int userId)105     public abstract void resetUser(int userId);
106 
107     /**
108      * Returns {@code true} if the immediate last installed version of an app with {@code uid} had
109      * legacy storage, {@code false} otherwise.
110      */
hasLegacyExternalStorage(int uid)111     public abstract boolean hasLegacyExternalStorage(int uid);
112 
113     /**
114      * Makes sure app-private data directories on external storage are setup correctly
115      * after an application is installed or upgraded. The main use for this is OBB dirs,
116      * which can be created/modified by the installer.
117      *
118      * @param packageName the package name of the package
119      * @param uid the uid of the package
120      */
prepareAppDataAfterInstall(@onNull String packageName, int uid)121     public abstract void prepareAppDataAfterInstall(@NonNull String packageName, int uid);
122 
123     /**
124      * Return true if uid is external storage service.
125      */
isExternalStorageService(int uid)126     public abstract boolean isExternalStorageService(int uid);
127 
128     /**
129      * Frees cache held by ExternalStorageService.
130      *
131      * <p> Blocks until the service frees the cache or fails in doing so.
132      *
133      * @param volumeUuid uuid of the {@link StorageVolume} from which cache needs to be freed,
134      *                   null value indicates private internal volume.
135      * @param bytes number of bytes which need to be freed
136      */
freeCache(@ullable String volumeUuid, long bytes)137     public abstract void freeCache(@Nullable String volumeUuid, long bytes);
138 
139     /**
140      * Returns the {@link VolumeInfo#getId()} values for the volumes matching
141      * {@link VolumeInfo#isPrimary()}
142      */
getPrimaryVolumeIds()143     public abstract List<String> getPrimaryVolumeIds();
144 
145     /**
146      * Tells StorageManager that CE storage for this user has been prepared.
147      *
148      * @param userId userId for which CE storage has been prepared
149      */
markCeStoragePrepared(@serIdInt int userId)150     public abstract void markCeStoragePrepared(@UserIdInt int userId);
151 
152     /**
153      * Returns true when CE storage for this user has been prepared.
154      *
155      * When the user key is unlocked and CE storage has been prepared,
156      * it's ok to access and modify CE directories on volumes for this user.
157      */
isCeStoragePrepared(@serIdInt int userId)158     public abstract boolean isCeStoragePrepared(@UserIdInt int userId);
159 
160     /**
161      * A listener for changes to the cloud provider.
162      */
163     public interface CloudProviderChangeListener {
164         /**
165          * Triggered when the cloud provider changes. A {@code null} value means there's currently
166          * no cloud provider.
167          */
onCloudProviderChanged(int userId, @Nullable String authority)168         void onCloudProviderChanged(int userId, @Nullable String authority);
169     }
170 
171     /**
172      * Register a {@link CloudProviderChangeListener} to be notified when a cloud media provider
173      * changes. The listener will be called after registration with any currently set cloud media
174      * providers.
175      */
registerCloudProviderChangeListener( @onNull CloudProviderChangeListener listener)176     public abstract void registerCloudProviderChangeListener(
177             @NonNull CloudProviderChangeListener listener);
178 
179     /**
180      * Prepares user data directories before moving storage or apps. This is required as adoptable
181      * storage unlock is tied to the prepare user data and storage needs to be unlocked before
182      * performing any operations on it. This will also create user data directories before
183      * initiating the move operations, which essential for ensuring the directories to have correct
184      * SELinux labels and permissions.
185      *
186      * @param fromVolumeUuid the source volume UUID from which content needs to be transferred
187      * @param toVolumeUuid the destination volume UUID to which contents are to be transferred
188      * @param users a list of users for whom to prepare storage
189      */
prepareUserStorageForMove(String fromVolumeUuid, String toVolumeUuid, List<UserInfo> users)190     public abstract void prepareUserStorageForMove(String fromVolumeUuid, String toVolumeUuid,
191             List<UserInfo> users);
192 
193     /**
194      * A proxy call to the corresponding method in Installer.
195      * @see com.android.server.pm.Installer#createFsveritySetupAuthToken()
196      */
createFsveritySetupAuthToken( ParcelFileDescriptor authFd, int uid)197     public abstract IInstalld.IFsveritySetupAuthToken createFsveritySetupAuthToken(
198             ParcelFileDescriptor authFd, int uid) throws IOException;
199 
200     /**
201      * A proxy call to the corresponding method in Installer.
202      * @see com.android.server.pm.Installer#enableFsverity()
203      */
enableFsverity(IInstalld.IFsveritySetupAuthToken authToken, String filePath, String packageName)204     public abstract int enableFsverity(IInstalld.IFsveritySetupAuthToken authToken, String filePath,
205             String packageName) throws IOException;
206 
207     /**
208      * Registers a {@link ICeStorageLockEventListener} for receiving CE storage lock events.
209      */
210     @FlaggedApi(Flags.FLAG_ENABLE_BIOMETRICS_TO_UNLOCK_PRIVATE_SPACE)
registerStorageLockEventListener( @onNull ICeStorageLockEventListener listener)211     public abstract void registerStorageLockEventListener(
212             @NonNull ICeStorageLockEventListener listener);
213 
214     /**
215      * Unregisters the {@link ICeStorageLockEventListener} which was registered previously
216      */
217     @FlaggedApi(Flags.FLAG_ENABLE_BIOMETRICS_TO_UNLOCK_PRIVATE_SPACE)
unregisterStorageLockEventListener( @onNull ICeStorageLockEventListener listener)218     public abstract void unregisterStorageLockEventListener(
219             @NonNull ICeStorageLockEventListener listener);
220 }
221