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.os.IVold; 22 23 import java.util.Set; 24 25 /** 26 * Mount service local interface. 27 * 28 * @hide Only for use within the system server. 29 */ 30 public abstract class StorageManagerInternal { 31 32 /** 33 * Policy that influences how external storage is mounted and reported. 34 */ 35 public interface ExternalStorageMountPolicy { 36 /** 37 * Gets the external storage mount mode for the given uid. 38 * 39 * @param uid The UID for which to determine mount mode. 40 * @param packageName The package in the UID for making the call. 41 * @return The mount mode. 42 * 43 * @see com.android.internal.os.Zygote#MOUNT_EXTERNAL_NONE 44 * @see com.android.internal.os.Zygote#MOUNT_EXTERNAL_DEFAULT 45 * @see com.android.internal.os.Zygote#MOUNT_EXTERNAL_READ 46 * @see com.android.internal.os.Zygote#MOUNT_EXTERNAL_WRITE 47 */ getMountMode(int uid, String packageName)48 public int getMountMode(int uid, String packageName); 49 50 /** 51 * Gets whether external storage should be reported to the given UID. 52 * 53 * @param uid The UID for which to determine whether it has external storage. 54 * @param packageName The package in the UID for making the call. 55 * @return Weather to report external storage. 56 * @return True to report the state of external storage, false to 57 * report it as unmounted. 58 */ hasExternalStorage(int uid, String packageName)59 public boolean hasExternalStorage(int uid, String packageName); 60 } 61 62 /** 63 * Adds a policy for determining how external storage is mounted and reported. 64 * The mount mode is the most conservative result from querying all registered 65 * policies. Similarly, the reported state is the most conservative result from 66 * querying all registered policies. 67 * 68 * @param policy The policy to add. 69 */ addExternalStoragePolicy(ExternalStorageMountPolicy policy)70 public abstract void addExternalStoragePolicy(ExternalStorageMountPolicy policy); 71 72 /** 73 * Notify the mount service that the mount policy for a UID changed. 74 * @param uid The UID for which policy changed. 75 * @param packageName The package in the UID for making the call. 76 */ onExternalStoragePolicyChanged(int uid, String packageName)77 public abstract void onExternalStoragePolicyChanged(int uid, String packageName); 78 79 /** 80 * Gets the mount mode to use for a given UID as determined by consultin all 81 * policies. 82 * 83 * @param uid The UID for which to get mount mode. 84 * @param packageName The package in the UID for making the call. 85 * @return The mount mode. 86 */ getExternalStorageMountMode(int uid, String packageName)87 public abstract int getExternalStorageMountMode(int uid, String packageName); 88 89 /** 90 * A listener for reset events in the StorageManagerService. 91 */ 92 public interface ResetListener { 93 /** 94 * A method that should be triggered internally by StorageManagerInternal 95 * when StorageManagerService reset happens. 96 * 97 * @param vold The binder object to vold. 98 */ onReset(IVold vold)99 void onReset(IVold vold); 100 } 101 102 /** 103 * Create storage directories if it does not exist. 104 * Return true if the directories were setup correctly, otherwise false. 105 */ prepareStorageDirs(int userId, Set<String> packageList, String processName)106 public abstract boolean prepareStorageDirs(int userId, Set<String> packageList, 107 String processName); 108 109 /** 110 * Add a listener to listen to reset event in StorageManagerService. 111 * 112 * @param listener The listener that will be notified on reset events. 113 */ addResetListener(ResetListener listener)114 public abstract void addResetListener(ResetListener listener); 115 116 /** 117 * Notified when any app op changes so that storage mount points can be updated if the app op 118 * affects them. 119 */ onAppOpsChanged(int code, int uid, @Nullable String packageName, int mode)120 public abstract void onAppOpsChanged(int code, int uid, 121 @Nullable String packageName, int mode); 122 123 /** 124 * Asks the StorageManager to reset all state for the provided user; this will result 125 * in the unmounting for all volumes of the user, and, if the user is still running, the 126 * volumes will be re-mounted as well. 127 * 128 * @param userId the userId for which to reset storage 129 */ resetUser(int userId)130 public abstract void resetUser(int userId); 131 132 /** 133 * Returns {@code true} if the immediate last installed version of an app with {@code uid} had 134 * legacy storage, {@code false} otherwise. 135 */ hasLegacyExternalStorage(int uid)136 public abstract boolean hasLegacyExternalStorage(int uid); 137 138 /** 139 * Makes sure app-private data directories on external storage are setup correctly 140 * after an application is installed or upgraded. The main use for this is OBB dirs, 141 * which can be created/modified by the installer. 142 * 143 * @param packageName the package name of the package 144 * @param uid the uid of the package 145 */ prepareAppDataAfterInstall(@onNull String packageName, int uid)146 public abstract void prepareAppDataAfterInstall(@NonNull String packageName, int uid); 147 148 149 /** 150 * Return true if uid is external storage service. 151 */ isExternalStorageService(int uid)152 public abstract boolean isExternalStorageService(int uid); 153 } 154