Search in sources :

Example 56 with StorageManager

use of android.os.storage.StorageManager in project android_frameworks_base by crdroidandroid.

the class ApplicationPackageManager method getPrimaryStorageCandidateVolumes.

@Override
@NonNull
public List<VolumeInfo> getPrimaryStorageCandidateVolumes() {
    final StorageManager storage = mContext.getSystemService(StorageManager.class);
    final VolumeInfo currentVol = getPrimaryStorageCurrentVolume();
    final List<VolumeInfo> vols = storage.getVolumes();
    final List<VolumeInfo> candidates = new ArrayList<>();
    if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL, storage.getPrimaryStorageUuid()) && currentVol != null) {
        // TODO: support moving primary physical to emulated volume
        candidates.add(currentVol);
    } else {
        for (VolumeInfo vol : vols) {
            if (Objects.equals(vol, currentVol) || isPrimaryStorageCandidateVolume(vol)) {
                candidates.add(vol);
            }
        }
    }
    return candidates;
}
Also used : StorageManager(android.os.storage.StorageManager) ArrayList(java.util.ArrayList) VolumeInfo(android.os.storage.VolumeInfo) NonNull(android.annotation.NonNull)

Example 57 with StorageManager

use of android.os.storage.StorageManager in project android_frameworks_base by crdroidandroid.

the class UserManagerService method createUserInternalUnchecked.

private UserInfo createUserInternalUnchecked(String name, int flags, int parentId) {
    if (ActivityManager.isLowRamDeviceStatic()) {
        return null;
    }
    final boolean isGuest = (flags & UserInfo.FLAG_GUEST) != 0;
    final boolean isManagedProfile = (flags & UserInfo.FLAG_MANAGED_PROFILE) != 0;
    final boolean isRestricted = (flags & UserInfo.FLAG_RESTRICTED) != 0;
    final boolean isDemo = (flags & UserInfo.FLAG_DEMO) != 0;
    final long ident = Binder.clearCallingIdentity();
    UserInfo userInfo;
    UserData userData;
    final int userId;
    try {
        synchronized (mPackagesLock) {
            UserData parent = null;
            if (parentId != UserHandle.USER_NULL) {
                synchronized (mUsersLock) {
                    parent = getUserDataLU(parentId);
                }
                if (parent == null)
                    return null;
            }
            if (isManagedProfile && !canAddMoreManagedProfiles(parentId, false)) {
                Log.e(LOG_TAG, "Cannot add more managed profiles for user " + parentId);
                return null;
            }
            if (!isGuest && !isManagedProfile && !isDemo && isUserLimitReached()) {
                // been reached, cannot add a user.
                return null;
            }
            // If we're adding a guest and there already exists one, bail.
            if (isGuest && findCurrentGuestUser() != null) {
                return null;
            }
            // In legacy mode, restricted profile's parent can only be the owner user
            if (isRestricted && !UserManager.isSplitSystemUser() && (parentId != UserHandle.USER_SYSTEM)) {
                Log.w(LOG_TAG, "Cannot add restricted profile - parent user must be owner");
                return null;
            }
            if (isRestricted && UserManager.isSplitSystemUser()) {
                if (parent == null) {
                    Log.w(LOG_TAG, "Cannot add restricted profile - parent user must be " + "specified");
                    return null;
                }
                if (!parent.info.canHaveProfile()) {
                    Log.w(LOG_TAG, "Cannot add restricted profile - profiles cannot be " + "created for the specified parent user id " + parentId);
                    return null;
                }
            }
            if (!UserManager.isSplitSystemUser() && (flags & UserInfo.FLAG_EPHEMERAL) != 0 && (flags & UserInfo.FLAG_DEMO) == 0) {
                Log.e(LOG_TAG, "Ephemeral users are supported on split-system-user systems only.");
                return null;
            }
            // And if there is no device owner, we also assign the admin flag to primary user.
            if (UserManager.isSplitSystemUser() && !isGuest && !isManagedProfile && getPrimaryUser() == null) {
                flags |= UserInfo.FLAG_PRIMARY;
                synchronized (mUsersLock) {
                    if (!mIsDeviceManaged) {
                        flags |= UserInfo.FLAG_ADMIN;
                    }
                }
            }
            userId = getNextAvailableId();
            Environment.getUserSystemDirectory(userId).mkdirs();
            boolean ephemeralGuests = Resources.getSystem().getBoolean(com.android.internal.R.bool.config_guestUserEphemeral);
            synchronized (mUsersLock) {
                // Add ephemeral flag to guests/users if required. Also inherit it from parent.
                if ((isGuest && ephemeralGuests) || mForceEphemeralUsers || (parent != null && parent.info.isEphemeral())) {
                    flags |= UserInfo.FLAG_EPHEMERAL;
                }
                userInfo = new UserInfo(userId, name, null, flags);
                userInfo.serialNumber = mNextSerialNumber++;
                long now = System.currentTimeMillis();
                userInfo.creationTime = (now > EPOCH_PLUS_30_YEARS) ? now : 0;
                userInfo.partial = true;
                userInfo.lastLoggedInFingerprint = Build.FINGERPRINT;
                userData = new UserData();
                userData.info = userInfo;
                mUsers.put(userId, userData);
            }
            writeUserLP(userData);
            writeUserListLP();
            if (parent != null) {
                if (isManagedProfile) {
                    if (parent.info.profileGroupId == UserInfo.NO_PROFILE_GROUP_ID) {
                        parent.info.profileGroupId = parent.info.id;
                        writeUserLP(parent);
                    }
                    userInfo.profileGroupId = parent.info.profileGroupId;
                } else if (isRestricted) {
                    if (parent.info.restrictedProfileParentId == UserInfo.NO_PROFILE_GROUP_ID) {
                        parent.info.restrictedProfileParentId = parent.info.id;
                        writeUserLP(parent);
                    }
                    userInfo.restrictedProfileParentId = parent.info.restrictedProfileParentId;
                }
            }
        }
        final StorageManager storage = mContext.getSystemService(StorageManager.class);
        storage.createUserKey(userId, userInfo.serialNumber, userInfo.isEphemeral());
        mPm.prepareUserData(userId, userInfo.serialNumber, StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE);
        mPm.createNewUser(userId);
        userInfo.partial = false;
        synchronized (mPackagesLock) {
            writeUserLP(userData);
        }
        updateUserIds();
        Bundle restrictions = new Bundle();
        if (isGuest) {
            synchronized (mGuestRestrictions) {
                restrictions.putAll(mGuestRestrictions);
            }
        }
        synchronized (mRestrictionsLock) {
            mBaseUserRestrictions.append(userId, restrictions);
        }
        mPm.onNewUserCreated(userId);
        Intent addedIntent = new Intent(Intent.ACTION_USER_ADDED);
        addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
        mContext.sendBroadcastAsUser(addedIntent, UserHandle.ALL, android.Manifest.permission.MANAGE_USERS);
        MetricsLogger.count(mContext, isGuest ? TRON_GUEST_CREATED : TRON_USER_CREATED, 1);
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
    return userInfo;
}
Also used : Bundle(android.os.Bundle) PersistableBundle(android.os.PersistableBundle) StorageManager(android.os.storage.StorageManager) UserInfo(android.content.pm.UserInfo) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Example 58 with StorageManager

use of android.os.storage.StorageManager in project android_frameworks_base by crdroidandroid.

the class MountServiceTests method testMountAndUnmountObbNormal.

@LargeTest
public void testMountAndUnmountObbNormal() {
    StorageManager sm = getStorageManager();
    final File outFile = getFilePath("test1.obb");
    mountObb(sm, R.raw.test1, outFile, OnObbStateChangeListener.MOUNTED);
    mountObb(sm, R.raw.test1, outFile, OnObbStateChangeListener.ERROR_ALREADY_MOUNTED);
    final String mountPath = checkMountedPath(sm, outFile);
    final File mountDir = new File(mountPath);
    assertTrue("OBB mounted path should be a directory", mountDir.isDirectory());
    unmountObb(sm, outFile, OnObbStateChangeListener.UNMOUNTED);
}
Also used : StorageManager(android.os.storage.StorageManager) File(java.io.File) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 59 with StorageManager

use of android.os.storage.StorageManager in project android_frameworks_base by crdroidandroid.

the class AppFuseTest method testOpenFile.

public void testOpenFile() throws IOException {
    final StorageManager storageManager = getContext().getSystemService(StorageManager.class);
    final int INODE = 10;
    final AppFuse appFuse = new AppFuse("test", new TestCallback() {

        @Override
        public long getFileSize(int inode) throws FileNotFoundException {
            if (INODE == inode) {
                return 1024;
            }
            throw new FileNotFoundException();
        }
    });
    appFuse.mount(storageManager);
    final ParcelFileDescriptor fd = appFuse.openFile(INODE, ParcelFileDescriptor.MODE_READ_ONLY);
    fd.close();
    appFuse.close();
}
Also used : StorageManager(android.os.storage.StorageManager) FileNotFoundException(java.io.FileNotFoundException) ParcelFileDescriptor(android.os.ParcelFileDescriptor)

Example 60 with StorageManager

use of android.os.storage.StorageManager in project android_frameworks_base by crdroidandroid.

the class MtpDocumentsProviderTest method setupProvider.

private void setupProvider(int flag) {
    mDatabase = new MtpDatabase(getContext(), flag);
    mProvider = new MtpDocumentsProvider();
    final StorageManager storageManager = getContext().getSystemService(StorageManager.class);
    assertTrue(mProvider.onCreateForTesting(getContext(), mResources, mMtpManager, mResolver, mDatabase, storageManager, new TestServiceIntentSender()));
}
Also used : StorageManager(android.os.storage.StorageManager)

Aggregations

StorageManager (android.os.storage.StorageManager)161 File (java.io.File)43 IOException (java.io.IOException)42 VolumeInfo (android.os.storage.VolumeInfo)38 FileNotFoundException (java.io.FileNotFoundException)32 ParcelFileDescriptor (android.os.ParcelFileDescriptor)25 LargeTest (android.test.suitebuilder.annotation.LargeTest)20 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)17 RemoteException (android.os.RemoteException)14 ArrayList (java.util.ArrayList)14 Intent (android.content.Intent)13 Bundle (android.os.Bundle)13 StorageVolume (android.os.storage.StorageVolume)13 PackageParserException (android.content.pm.PackageParser.PackageParserException)12 NotFoundException (android.content.res.Resources.NotFoundException)12 StorageListener (android.os.storage.StorageListener)12 SettingNotFoundException (android.provider.Settings.SettingNotFoundException)12 ErrnoException (android.system.ErrnoException)12 NonNull (android.annotation.NonNull)10 ZipFile (java.util.zip.ZipFile)10