Search in sources :

Example 11 with StorageManager

use of android.os.storage.StorageManager in project platform_frameworks_base by android.

the class DeviceStorageMonitorService method onStart.

/**
    * Initializes the disk space threshold value and posts an empty message to
    * kickstart the process.
    */
@Override
public void onStart() {
    // cache storage thresholds
    final StorageManager sm = StorageManager.from(getContext());
    mMemLowThreshold = sm.getStorageLowBytes(DATA_PATH);
    mMemFullThreshold = sm.getStorageFullBytes(DATA_PATH);
    mMemCacheStartTrimThreshold = ((mMemLowThreshold * 3) + mMemFullThreshold) / 4;
    mMemCacheTrimToThreshold = mMemLowThreshold + ((mMemLowThreshold - mMemCacheStartTrimThreshold) * 2);
    mFreeMemAfterLastCacheClear = mTotalMemory;
    checkMemory(true);
    mCacheFileDeletedObserver = new CacheFileDeletedObserver();
    mCacheFileDeletedObserver.startWatching();
    publishBinderService(SERVICE, mRemoteService);
    publishLocalService(DeviceStorageMonitorInternal.class, mLocalService);
}
Also used : StorageManager(android.os.storage.StorageManager)

Example 12 with StorageManager

use of android.os.storage.StorageManager in project platform_frameworks_base by android.

the class PackageManagerService method loadPrivatePackagesInner.

private void loadPrivatePackagesInner(VolumeInfo vol) {
    final String volumeUuid = vol.fsUuid;
    if (TextUtils.isEmpty(volumeUuid)) {
        Slog.e(TAG, "Loading internal storage is probably a mistake; ignoring");
        return;
    }
    final ArrayList<PackageFreezer> freezers = new ArrayList<>();
    final ArrayList<ApplicationInfo> loaded = new ArrayList<>();
    final int parseFlags = mDefParseFlags | PackageParser.PARSE_EXTERNAL_STORAGE;
    final VersionInfo ver;
    final List<PackageSetting> packages;
    synchronized (mPackages) {
        ver = mSettings.findOrCreateVersion(volumeUuid);
        packages = mSettings.getVolumePackagesLPr(volumeUuid);
    }
    for (PackageSetting ps : packages) {
        freezers.add(freezePackage(ps.name, "loadPrivatePackagesInner"));
        synchronized (mInstallLock) {
            final PackageParser.Package pkg;
            try {
                pkg = scanPackageTracedLI(ps.codePath, parseFlags, SCAN_INITIAL, 0, null);
                loaded.add(pkg.applicationInfo);
            } catch (PackageManagerException e) {
                Slog.w(TAG, "Failed to scan " + ps.codePath + ": " + e.getMessage());
            }
            if (!Build.FINGERPRINT.equals(ver.fingerprint)) {
                clearAppDataLIF(ps.pkg, UserHandle.USER_ALL, StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE | Installer.FLAG_CLEAR_CODE_CACHE_ONLY);
            }
        }
    }
    // Reconcile app data for all started/unlocked users
    final StorageManager sm = mContext.getSystemService(StorageManager.class);
    final UserManager um = mContext.getSystemService(UserManager.class);
    UserManagerInternal umInternal = getUserManagerInternal();
    for (UserInfo user : um.getUsers()) {
        final int flags;
        if (umInternal.isUserUnlockingOrUnlocked(user.id)) {
            flags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE;
        } else if (umInternal.isUserRunning(user.id)) {
            flags = StorageManager.FLAG_STORAGE_DE;
        } else {
            continue;
        }
        try {
            sm.prepareUserStorage(volumeUuid, user.id, user.serialNumber, flags);
            synchronized (mInstallLock) {
                reconcileAppsDataLI(volumeUuid, user.id, flags);
            }
        } catch (IllegalStateException e) {
            // Device was probably ejected, and we'll process that event momentarily
            Slog.w(TAG, "Failed to prepare storage: " + e);
        }
    }
    synchronized (mPackages) {
        int updateFlags = UPDATE_PERMISSIONS_ALL;
        if (ver.sdkVersion != mSdkVersion) {
            logCriticalInfo(Log.INFO, "Platform changed from " + ver.sdkVersion + " to " + mSdkVersion + "; regranting permissions for " + volumeUuid);
            updateFlags |= UPDATE_PERMISSIONS_REPLACE_PKG | UPDATE_PERMISSIONS_REPLACE_ALL;
        }
        updatePermissionsLPw(null, null, volumeUuid, updateFlags);
        // Yay, everything is now upgraded
        ver.forceCurrent();
        mSettings.writeLPr();
    }
    for (PackageFreezer freezer : freezers) {
        freezer.close();
    }
    if (DEBUG_INSTALL)
        Slog.d(TAG, "Loaded packages " + loaded);
    sendResourcesChangedBroadcast(true, false, loaded, null);
}
Also used : ArrayList(java.util.ArrayList) EphemeralApplicationInfo(android.content.pm.EphemeralApplicationInfo) ApplicationInfo(android.content.pm.ApplicationInfo) StorageManager(android.os.storage.StorageManager) UserInfo(android.content.pm.UserInfo) VersionInfo(com.android.server.pm.Settings.VersionInfo) PackageParser(android.content.pm.PackageParser) UserManagerInternal(android.os.UserManagerInternal) UserManager(android.os.UserManager)

Example 13 with StorageManager

use of android.os.storage.StorageManager in project platform_frameworks_base by android.

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 14 with StorageManager

use of android.os.storage.StorageManager in project platform_frameworks_base by android.

the class PackageManagerService method destroyUserData.

/**
     * Destroy storage areas for given user on all mounted devices.
     */
void destroyUserData(int userId, int flags) {
    synchronized (mInstallLock) {
        final StorageManager storage = mContext.getSystemService(StorageManager.class);
        for (VolumeInfo vol : storage.getWritablePrivateVolumes()) {
            final String volumeUuid = vol.getFsUuid();
            destroyUserDataLI(volumeUuid, userId, flags);
        }
    }
}
Also used : StorageManager(android.os.storage.StorageManager) VolumeInfo(android.os.storage.VolumeInfo)

Example 15 with StorageManager

use of android.os.storage.StorageManager in project platform_frameworks_base by android.

the class MountServiceTests method testAttemptMountObbWrongPackage.

@LargeTest
public void testAttemptMountObbWrongPackage() {
    StorageManager sm = getStorageManager();
    final File outFile = getFilePath("test1_wrongpackage.obb");
    mountObb(sm, R.raw.test1_wrongpackage, outFile, OnObbStateChangeListener.ERROR_PERMISSION_DENIED);
    assertFalse("OBB should not be mounted", sm.isObbMounted(outFile.getPath()));
    assertNull("OBB's mounted path should be null", sm.getMountedObbPath(outFile.getPath()));
}
Also used : StorageManager(android.os.storage.StorageManager) File(java.io.File) LargeTest(android.test.suitebuilder.annotation.LargeTest)

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