Search in sources :

Example 11 with MountServiceInternal

use of android.os.storage.MountServiceInternal in project android_frameworks_base by AOSPA.

the class AppOpsService method systemReady.

public void systemReady() {
    synchronized (this) {
        boolean changed = false;
        for (int i = mUidStates.size() - 1; i >= 0; i--) {
            UidState uidState = mUidStates.valueAt(i);
            String[] packageNames = getPackagesForUid(uidState.uid);
            if (ArrayUtils.isEmpty(packageNames)) {
                uidState.clear();
                mUidStates.removeAt(i);
                changed = true;
                continue;
            }
            ArrayMap<String, Ops> pkgs = uidState.pkgOps;
            if (pkgs == null) {
                continue;
            }
            Iterator<Ops> it = pkgs.values().iterator();
            while (it.hasNext()) {
                Ops ops = it.next();
                int curUid = -1;
                try {
                    curUid = AppGlobals.getPackageManager().getPackageUid(ops.packageName, PackageManager.MATCH_UNINSTALLED_PACKAGES, UserHandle.getUserId(ops.uidState.uid));
                } catch (RemoteException ignored) {
                }
                if (curUid != ops.uidState.uid) {
                    Slog.i(TAG, "Pruning old package " + ops.packageName + "/" + ops.uidState + ": new uid=" + curUid);
                    it.remove();
                    changed = true;
                }
            }
            if (uidState.isDefault()) {
                mUidStates.removeAt(i);
            }
        }
        if (changed) {
            scheduleFastWriteLocked();
        }
    }
    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 (noteOperation(AppOpsManager.OP_READ_EXTERNAL_STORAGE, uid, packageName) != AppOpsManager.MODE_ALLOWED) {
                return Zygote.MOUNT_EXTERNAL_NONE;
            }
            if (noteOperation(AppOpsManager.OP_WRITE_EXTERNAL_STORAGE, uid, packageName) != AppOpsManager.MODE_ALLOWED) {
                return Zygote.MOUNT_EXTERNAL_READ;
            }
            return Zygote.MOUNT_EXTERNAL_WRITE;
        }

        @Override
        public boolean hasExternalStorage(int uid, String packageName) {
            final int mountMode = getMountMode(uid, packageName);
            return mountMode == Zygote.MOUNT_EXTERNAL_READ || mountMode == Zygote.MOUNT_EXTERNAL_WRITE;
        }
    });
}
Also used : MountServiceInternal(android.os.storage.MountServiceInternal) RemoteException(android.os.RemoteException)

Aggregations

MountServiceInternal (android.os.storage.MountServiceInternal)11 RemoteException (android.os.RemoteException)7 Message (android.os.Message)4 IntentFilter (android.content.IntentFilter)2 IPackageManager (android.content.pm.IPackageManager)2 PackageParser (android.content.pm.PackageParser)2 Point (android.graphics.Point)2 Process (android.os.Process)2 StorageManager (android.os.storage.StorageManager)2 ArrayList (java.util.ArrayList)2 AtomicFile (android.util.AtomicFile)1 File (java.io.File)1