Search in sources :

Example 26 with StorageManager

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

the class AppFuseTest method testWriteFile_writeError.

public void testWriteFile_writeError() 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) {
                throw new FileNotFoundException();
            }
            return 5;
        }
    });
    appFuse.mount(storageManager);
    final ParcelFileDescriptor fd = appFuse.openFile(INODE, ParcelFileDescriptor.MODE_WRITE_ONLY | ParcelFileDescriptor.MODE_TRUNCATE);
    try (final ParcelFileDescriptor.AutoCloseOutputStream stream = new ParcelFileDescriptor.AutoCloseOutputStream(fd)) {
        stream.write('a');
        fail();
    } catch (IOException e) {
    }
    appFuse.close();
}
Also used : StorageManager(android.os.storage.StorageManager) FileNotFoundException(java.io.FileNotFoundException) ParcelFileDescriptor(android.os.ParcelFileDescriptor) IOException(java.io.IOException)

Example 27 with StorageManager

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

the class AppFuseTest method testMount.

public void testMount() throws ErrnoException, IOException {
    final StorageManager storageManager = getContext().getSystemService(StorageManager.class);
    final AppFuse appFuse = new AppFuse("test", new TestCallback());
    appFuse.mount(storageManager);
    final File file = appFuse.getMountPoint();
    assertTrue(file.isDirectory());
    assertEquals(1, Os.stat(file.getPath()).st_ino);
    appFuse.close();
    assertTrue(1 != Os.stat(file.getPath()).st_ino);
}
Also used : StorageManager(android.os.storage.StorageManager) File(java.io.File)

Example 28 with StorageManager

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

the class PackageManagerService method systemReady.

@Override
public void systemReady() {
    mSystemReady = true;
    // Disable any carrier apps. We do this very early in boot to prevent the apps from being
    // disabled after already being started.
    CarrierAppUtils.disableCarrierAppsUntilPrivileged(mContext.getOpPackageName(), this, mContext.getContentResolver(), UserHandle.USER_SYSTEM);
    // Read the compatibilty setting when the system is ready.
    boolean compatibilityModeEnabled = android.provider.Settings.Global.getInt(mContext.getContentResolver(), android.provider.Settings.Global.COMPATIBILITY_MODE, 1) == 1;
    PackageParser.setCompatibilityModeEnabled(compatibilityModeEnabled);
    if (DEBUG_SETTINGS) {
        Log.d(TAG, "compatibility mode:" + compatibilityModeEnabled);
    }
    int[] grantPermissionsUserIds = EMPTY_INT_ARRAY;
    synchronized (mPackages) {
        // Verify that all of the preferred activity components actually
        // exist.  It is possible for applications to be updated and at
        // that point remove a previously declared activity component that
        // had been set as a preferred activity.  We try to clean this up
        // the next time we encounter that preferred activity, but it is
        // possible for the user flow to never be able to return to that
        // situation so here we do a sanity check to make sure we haven't
        // left any junk around.
        ArrayList<PreferredActivity> removed = new ArrayList<PreferredActivity>();
        for (int i = 0; i < mSettings.mPreferredActivities.size(); i++) {
            PreferredIntentResolver pir = mSettings.mPreferredActivities.valueAt(i);
            removed.clear();
            for (PreferredActivity pa : pir.filterSet()) {
                if (mActivities.mActivities.get(pa.mPref.mComponent) == null) {
                    removed.add(pa);
                }
            }
            if (removed.size() > 0) {
                for (int r = 0; r < removed.size(); r++) {
                    PreferredActivity pa = removed.get(r);
                    Slog.w(TAG, "Removing dangling preferred activity: " + pa.mPref.mComponent);
                    pir.removeFilter(pa);
                }
                mSettings.writePackageRestrictionsLPr(mSettings.mPreferredActivities.keyAt(i));
            }
        }
        for (int userId : UserManagerService.getInstance().getUserIds()) {
            if (!mSettings.areDefaultRuntimePermissionsGrantedLPr(userId)) {
                grantPermissionsUserIds = ArrayUtils.appendInt(grantPermissionsUserIds, userId);
            }
        }
    }
    sUserManager.systemReady();
    // If we upgraded grant all default permissions before kicking off.
    for (int userId : grantPermissionsUserIds) {
        mDefaultPermissionPolicy.grantDefaultPermissions(userId);
    }
    // disk on a new user creation.
    if (grantPermissionsUserIds == EMPTY_INT_ARRAY) {
        mDefaultPermissionPolicy.scheduleReadDefaultPermissionExceptions();
    }
    // Kick off any messages waiting for system ready
    if (mPostSystemReadyMessages != null) {
        for (Message msg : mPostSystemReadyMessages) {
            msg.sendToTarget();
        }
        mPostSystemReadyMessages = null;
    }
    // Watch for external volumes that come and go over time
    final StorageManager storage = mContext.getSystemService(StorageManager.class);
    storage.registerListener(mStorageListener);
    mInstallerService.systemReady();
    mPackageDexOptimizer.systemReady();
    MountServiceInternal mountServiceInternal = LocalServices.getService(MountServiceInternal.class);
    mountServiceInternal.addExternalStoragePolicy(new MountServiceInternal.ExternalStorageMountPolicy() {

        @Override
        public int getMountMode(int uid, String packageName) {
            if (Process.isIsolated(uid)) {
                return Zygote.MOUNT_EXTERNAL_NONE;
            }
            if (checkUidPermission(WRITE_MEDIA_STORAGE, uid) == PERMISSION_GRANTED) {
                return Zygote.MOUNT_EXTERNAL_DEFAULT;
            }
            if (checkUidPermission(READ_EXTERNAL_STORAGE, uid) == PERMISSION_DENIED) {
                return Zygote.MOUNT_EXTERNAL_DEFAULT;
            }
            if (checkUidPermission(WRITE_EXTERNAL_STORAGE, uid) == PERMISSION_DENIED) {
                return Zygote.MOUNT_EXTERNAL_READ;
            }
            return Zygote.MOUNT_EXTERNAL_WRITE;
        }

        @Override
        public boolean hasExternalStorage(int uid, String packageName) {
            return true;
        }
    });
    // Now that we're mostly running, clean up stale users and apps
    reconcileUsers(StorageManager.UUID_PRIVATE_INTERNAL);
    reconcileApps(StorageManager.UUID_PRIVATE_INTERNAL);
}
Also used : Message(android.os.Message) MountServiceInternal(android.os.storage.MountServiceInternal) ArrayList(java.util.ArrayList) StorageManager(android.os.storage.StorageManager)

Example 29 with StorageManager

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

the class PackageManagerService method destroyUserDataLI.

private void destroyUserDataLI(String volumeUuid, int userId, int flags) {
    final StorageManager storage = mContext.getSystemService(StorageManager.class);
    try {
        // Clean up app data, profile data, and media data
        mInstaller.destroyUserData(volumeUuid, userId, flags);
        // Clean up system data
        if (Objects.equals(volumeUuid, StorageManager.UUID_PRIVATE_INTERNAL)) {
            if ((flags & StorageManager.FLAG_STORAGE_DE) != 0) {
                FileUtils.deleteContentsAndDir(Environment.getUserSystemDirectory(userId));
                FileUtils.deleteContentsAndDir(Environment.getDataSystemDeDirectory(userId));
            }
            if ((flags & StorageManager.FLAG_STORAGE_CE) != 0) {
                FileUtils.deleteContentsAndDir(Environment.getDataSystemCeDirectory(userId));
            }
        }
        // Data with special labels is now gone, so finish the job
        storage.destroyUserStorage(volumeUuid, userId, flags);
    } catch (Exception e) {
        logCriticalInfo(Log.WARN, "Failed to destroy user " + userId + " on volume " + volumeUuid + ": " + e);
    }
}
Also used : StorageManager(android.os.storage.StorageManager) CertificateEncodingException(java.security.cert.CertificateEncodingException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) ErrnoException(android.system.ErrnoException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) PackageParserException(android.content.pm.PackageParser.PackageParserException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SendIntentException(android.content.IntentSender.SendIntentException) FileNotFoundException(java.io.FileNotFoundException) InstallerException(com.android.internal.os.InstallerConnection.InstallerException) CertificateException(java.security.cert.CertificateException)

Example 30 with StorageManager

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

the class PackageManagerService method movePrimaryStorage.

@Override
public int movePrimaryStorage(String volumeUuid) throws RemoteException {
    mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MOVE_PACKAGE, null);
    final int realMoveId = mNextMoveId.getAndIncrement();
    final Bundle extras = new Bundle();
    extras.putString(VolumeRecord.EXTRA_FS_UUID, volumeUuid);
    mMoveCallbacks.notifyCreated(realMoveId, extras);
    final IPackageMoveObserver callback = new IPackageMoveObserver.Stub() {

        @Override
        public void onCreated(int moveId, Bundle extras) {
        // Ignored
        }

        @Override
        public void onStatusChanged(int moveId, int status, long estMillis) {
            mMoveCallbacks.notifyStatusChanged(realMoveId, status, estMillis);
        }
    };
    final StorageManager storage = mContext.getSystemService(StorageManager.class);
    storage.setPrimaryStorageUuid(volumeUuid, callback);
    return realMoveId;
}
Also used : Bundle(android.os.Bundle) StorageManager(android.os.storage.StorageManager) IPackageMoveObserver(android.content.pm.IPackageMoveObserver)

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