Java Code Examples for android.os.Environment#getUserSystemDirectory()

The following examples show how to use android.os.Environment#getUserSystemDirectory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InputMethodManagerService.java    From TvRemoteControl with Apache License 2.0 6 votes vote down vote up
public InputMethodFileManager(HashMap<String, InputMethodInfo> methodMap, int userId) {
    if (methodMap == null) {
        throw new NullPointerException("methodMap is null");
    }
    mMethodMap = methodMap;
    final File systemDir = userId == UserHandle.USER_OWNER
            ? new File(Environment.getDataDirectory(), SYSTEM_PATH)
            : Environment.getUserSystemDirectory(userId);
    final File inputMethodDir = new File(systemDir, INPUT_METHOD_PATH);
    if (!inputMethodDir.mkdirs()) {
        Slog.w(TAG, "Couldn't create dir.: " + inputMethodDir.getAbsolutePath());
    }
    final File subtypeFile = new File(inputMethodDir, ADDITIONAL_SUBTYPES_FILE_NAME);
    mAdditionalInputMethodSubtypeFile = new AtomicFile(subtypeFile);
    if (!subtypeFile.exists()) {
        // If "subtypes.xml" doesn't exist, create a blank file.
        writeAdditionalInputMethodSubtypes(
                mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, methodMap);
    } else {
        readAdditionalInputMethodSubtypes(
                mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile);
    }
}
 
Example 2
Source File: DatabaseHelper.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
static String dbNameForUser(final int userHandle) {
    // The owner gets the unadorned db name;
    if (userHandle == UserHandle.USER_SYSTEM) {
        return DATABASE_NAME;
    } else {
        // Place the database in the user-specific data tree so that it's
        // cleaned up automatically when the user is deleted.
        File databaseFile = new File(
                Environment.getUserSystemDirectory(userHandle), DATABASE_NAME);
        // If databaseFile doesn't exist, database can be kept in memory. It's safe because the
        // database will be migrated and disposed of immediately after onCreate finishes
        if (!databaseFile.exists()) {
            Log.i(TAG, "No previous database file exists - running in in-memory mode");
            return null;
        }
        return databaseFile.getPath();
    }
}
 
Example 3
Source File: PersistentDataStore.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public PersistentDataStore(Context context, int userId) {
    mContext = context;
    File userDir = Environment.getUserSystemDirectory(userId);
    if (!userDir.exists()) {
        if (!userDir.mkdirs()) {
            throw new IllegalStateException("User dir cannot be created: " + userDir);
        }
    }
    mAtomicFile = new AtomicFile(new File(userDir, "tv-input-manager-state.xml"), "tv-input-state");
}
 
Example 4
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Removes the app restrictions file for a specific package and user id, if it exists.
 */
private static void cleanAppRestrictionsForPackageLAr(String pkg, int userId) {
    File dir = Environment.getUserSystemDirectory(userId);
    File resFile = new File(dir, packageToRestrictionsFileName(pkg));
    if (resFile.exists()) {
        resFile.delete();
    }
}
 
Example 5
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@GuardedBy("mAppRestrictionsLock")
private static Bundle readApplicationRestrictionsLAr(String packageName, int userId) {
    AtomicFile restrictionsFile =
            new AtomicFile(new File(Environment.getUserSystemDirectory(userId),
                    packageToRestrictionsFileName(packageName)));
    return readApplicationRestrictionsLAr(restrictionsFile);
}
 
Example 6
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@GuardedBy("mAppRestrictionsLock")
private static void writeApplicationRestrictionsLAr(String packageName,
        Bundle restrictions, int userId) {
    AtomicFile restrictionsFile = new AtomicFile(
            new File(Environment.getUserSystemDirectory(userId),
                    packageToRestrictionsFileName(packageName)));
    writeApplicationRestrictionsLAr(restrictions, restrictionsFile);
}
 
Example 7
Source File: DatabaseHelper.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
static String dbNameForUser(final int userHandle) {
    // The owner gets the unadorned db name;
    if (userHandle == UserHandle.USER_OWNER) {
        return DATABASE_NAME;
    } else {
        // Place the database in the user-specific data tree so that it's
        // cleaned up automatically when the user is deleted.
        File databaseFile = new File(
                Environment.getUserSystemDirectory(userHandle), DATABASE_NAME);
        return databaseFile.getPath();
    }
}
 
Example 8
Source File: FingerprintsUserState.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private static File getFileForUser(int userId) {
    return new File(Environment.getUserSystemDirectory(userId), FINGERPRINT_FILE);
}
 
Example 9
Source File: WallpaperManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private static File getWallpaperDir(int userId) {
    return Environment.getUserSystemDirectory(userId);
}
 
Example 10
Source File: UserDataPreparer.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
protected File getUserSystemDirectory(int userId) {
    return Environment.getUserSystemDirectory(userId);
}
 
Example 11
Source File: InstantAppRegistry.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private static @NonNull File getInstantApplicationsDir(int userId) {
    return new File(Environment.getUserSystemDirectory(userId),
            INSTANT_APPS_FOLDER);
}
 
Example 12
Source File: RegisteredServicesCache.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
protected File getUserSystemDirectory(int userId) {
    return Environment.getUserSystemDirectory(userId);
}