Search in sources :

Example 26 with SparseIntArray

use of android.util.SparseIntArray in project android_frameworks_base by ResurrectionRemix.

the class StreamConfigurationMap method getInternalFormatSizes.

private Size[] getInternalFormatSizes(int format, int dataspace, boolean output, boolean highRes) {
    // All depth formats are non-high-res.
    if (dataspace == HAL_DATASPACE_DEPTH && highRes) {
        return new Size[0];
    }
    SparseIntArray formatsMap = !output ? mInputFormats : dataspace == HAL_DATASPACE_DEPTH ? mDepthOutputFormats : highRes ? mHighResOutputFormats : mOutputFormats;
    int sizesCount = formatsMap.get(format);
    if (((!output || dataspace == HAL_DATASPACE_DEPTH) && sizesCount == 0) || (output && dataspace != HAL_DATASPACE_DEPTH && mAllOutputFormats.get(format) == 0)) {
        // Only throw if this is really not supported at all
        throw new IllegalArgumentException("format not available");
    }
    Size[] sizes = new Size[sizesCount];
    int sizeIndex = 0;
    StreamConfiguration[] configurations = (dataspace == HAL_DATASPACE_DEPTH) ? mDepthConfigurations : mConfigurations;
    StreamConfigurationDuration[] minFrameDurations = (dataspace == HAL_DATASPACE_DEPTH) ? mDepthMinFrameDurations : mMinFrameDurations;
    for (StreamConfiguration config : configurations) {
        int fmt = config.getFormat();
        if (fmt == format && config.isOutput() == output) {
            if (output && mListHighResolution) {
                // Filter slow high-res output formats; include for
                // highRes, remove for !highRes
                long duration = 0;
                for (int i = 0; i < minFrameDurations.length; i++) {
                    StreamConfigurationDuration d = minFrameDurations[i];
                    if (d.getFormat() == fmt && d.getWidth() == config.getSize().getWidth() && d.getHeight() == config.getSize().getHeight()) {
                        duration = d.getDuration();
                        break;
                    }
                }
                if (dataspace != HAL_DATASPACE_DEPTH && highRes != (duration > DURATION_20FPS_NS)) {
                    continue;
                }
            }
            sizes[sizeIndex++] = config.getSize();
        }
    }
    if (sizeIndex != sizesCount) {
        throw new AssertionError("Too few sizes (expected " + sizesCount + ", actual " + sizeIndex + ")");
    }
    return sizes;
}
Also used : SparseIntArray(android.util.SparseIntArray) Size(android.util.Size)

Example 27 with SparseIntArray

use of android.util.SparseIntArray in project android_frameworks_base by ResurrectionRemix.

the class StreamConfigurationMap method getPublicFormatCount.

/** Count the number of publicly-visible output formats */
private int getPublicFormatCount(boolean output) {
    SparseIntArray formatsMap = getFormatsMap(output);
    int size = formatsMap.size();
    if (output) {
        size += mDepthOutputFormats.size();
    }
    return size;
}
Also used : SparseIntArray(android.util.SparseIntArray)

Example 28 with SparseIntArray

use of android.util.SparseIntArray in project android_frameworks_base by ResurrectionRemix.

the class StreamConfigurationMap method getPublicFormats.

/** Get the list of publically visible output formats; does not include IMPL_DEFINED */
private int[] getPublicFormats(boolean output) {
    int[] formats = new int[getPublicFormatCount(output)];
    int i = 0;
    SparseIntArray map = getFormatsMap(output);
    for (int j = 0; j < map.size(); j++) {
        int format = map.keyAt(j);
        formats[i++] = imageFormatToPublic(format);
    }
    if (output) {
        for (int j = 0; j < mDepthOutputFormats.size(); j++) {
            formats[i++] = depthFormatToPublic(mDepthOutputFormats.keyAt(j));
        }
    }
    if (formats.length != i) {
        throw new AssertionError("Too few formats " + i + ", expected " + formats.length);
    }
    return formats;
}
Also used : SparseIntArray(android.util.SparseIntArray)

Example 29 with SparseIntArray

use of android.util.SparseIntArray in project android_frameworks_base by ResurrectionRemix.

the class CursorWindow method printStats.

private String printStats() {
    StringBuilder buff = new StringBuilder();
    int myPid = Process.myPid();
    int total = 0;
    SparseIntArray pidCounts = new SparseIntArray();
    synchronized (sWindowToPidMap) {
        int size = sWindowToPidMap.size();
        if (size == 0) {
            // this means we are not in the ContentProvider.
            return "";
        }
        for (int indx = 0; indx < size; indx++) {
            int pid = sWindowToPidMap.valueAt(indx);
            int value = pidCounts.get(pid);
            pidCounts.put(pid, ++value);
        }
    }
    int numPids = pidCounts.size();
    for (int i = 0; i < numPids; i++) {
        buff.append(" (# cursors opened by ");
        int pid = pidCounts.keyAt(i);
        if (pid == myPid) {
            buff.append("this proc=");
        } else {
            buff.append("pid " + pid + "=");
        }
        int num = pidCounts.get(pid);
        buff.append(num + ")");
        total += num;
    }
    // limit the returned string size to 1000
    String s = (buff.length() > 980) ? buff.substring(0, 980) : buff.toString();
    return "# Open Cursors=" + total + s;
}
Also used : SparseIntArray(android.util.SparseIntArray)

Example 30 with SparseIntArray

use of android.util.SparseIntArray in project android_frameworks_base by DirtyUnicorns.

the class AppOpsService method setUidMode.

@Override
public void setUidMode(int code, int uid, int mode) {
    if (Binder.getCallingPid() != Process.myPid()) {
        mContext.enforcePermission(android.Manifest.permission.UPDATE_APP_OPS_STATS, Binder.getCallingPid(), Binder.getCallingUid(), null);
    }
    verifyIncomingOp(code);
    code = AppOpsManager.opToSwitch(code);
    synchronized (this) {
        final int defaultMode = AppOpsManager.opToDefaultMode(code);
        UidState uidState = getUidStateLocked(uid, false);
        if (uidState == null) {
            if (mode == defaultMode) {
                return;
            }
            uidState = new UidState(uid);
            uidState.opModes = new SparseIntArray();
            uidState.opModes.put(code, mode);
            mUidStates.put(uid, uidState);
            scheduleWriteLocked();
        } else if (uidState.opModes == null) {
            if (mode != defaultMode) {
                uidState.opModes = new SparseIntArray();
                uidState.opModes.put(code, mode);
                scheduleWriteLocked();
            }
        } else {
            if (uidState.opModes.get(code) == mode) {
                return;
            }
            if (mode == defaultMode) {
                uidState.opModes.delete(code);
                if (uidState.opModes.size() <= 0) {
                    uidState.opModes = null;
                }
            } else {
                uidState.opModes.put(code, mode);
            }
            scheduleWriteLocked();
        }
    }
    String[] uidPackageNames = getPackagesForUid(uid);
    ArrayMap<Callback, ArraySet<String>> callbackSpecs = null;
    synchronized (this) {
        ArrayList<Callback> callbacks = mOpModeWatchers.get(code);
        if (callbacks != null) {
            final int callbackCount = callbacks.size();
            for (int i = 0; i < callbackCount; i++) {
                Callback callback = callbacks.get(i);
                ArraySet<String> changedPackages = new ArraySet<>();
                Collections.addAll(changedPackages, uidPackageNames);
                callbackSpecs = new ArrayMap<>();
                callbackSpecs.put(callback, changedPackages);
            }
        }
        for (String uidPackageName : uidPackageNames) {
            callbacks = mPackageModeWatchers.get(uidPackageName);
            if (callbacks != null) {
                if (callbackSpecs == null) {
                    callbackSpecs = new ArrayMap<>();
                }
                final int callbackCount = callbacks.size();
                for (int i = 0; i < callbackCount; i++) {
                    Callback callback = callbacks.get(i);
                    ArraySet<String> changedPackages = callbackSpecs.get(callback);
                    if (changedPackages == null) {
                        changedPackages = new ArraySet<>();
                        callbackSpecs.put(callback, changedPackages);
                    }
                    changedPackages.add(uidPackageName);
                }
            }
        }
    }
    if (callbackSpecs == null) {
        return;
    }
    // There are components watching for mode changes such as window manager
    // and location manager which are in our process. The callbacks in these
    // components may require permissions our remote caller does not have.
    final long identity = Binder.clearCallingIdentity();
    try {
        for (int i = 0; i < callbackSpecs.size(); i++) {
            Callback callback = callbackSpecs.keyAt(i);
            ArraySet<String> reportedPackageNames = callbackSpecs.valueAt(i);
            try {
                if (reportedPackageNames == null) {
                    callback.mCallback.opChanged(code, uid, null);
                } else {
                    final int reportedPackageCount = reportedPackageNames.size();
                    for (int j = 0; j < reportedPackageCount; j++) {
                        String reportedPackageName = reportedPackageNames.valueAt(j);
                        callback.mCallback.opChanged(code, uid, reportedPackageName);
                    }
                }
            } catch (RemoteException e) {
                Log.w(TAG, "Error dispatching op op change", e);
            }
        }
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
Also used : ArraySet(android.util.ArraySet) IAppOpsCallback(com.android.internal.app.IAppOpsCallback) SparseIntArray(android.util.SparseIntArray) RemoteException(android.os.RemoteException)

Aggregations

SparseIntArray (android.util.SparseIntArray)367 RemoteException (android.os.RemoteException)40 Test (org.junit.Test)35 ArrayList (java.util.ArrayList)32 HashMap (java.util.HashMap)22 Context (android.content.Context)19 IAppOpsCallback (com.android.internal.app.IAppOpsCallback)15 SparseArray (android.util.SparseArray)13 IOException (java.io.IOException)13 HistoryItem (android.os.BatteryStats.HistoryItem)12 UsageView (com.android.settings.graph.UsageView)12 Point (android.graphics.Point)11 Map (java.util.Map)11 UserInfo (android.content.pm.UserInfo)10 Paint (android.graphics.Paint)10 ArraySet (android.util.ArraySet)10 HashSet (java.util.HashSet)9 Cursor (android.database.Cursor)8 NetworkStatsHistory (android.net.NetworkStatsHistory)7 SparseBooleanArray (android.util.SparseBooleanArray)7