Search in sources :

Example 61 with ArrayMap

use of android.util.ArrayMap in project platform_frameworks_base by android.

the class ShortcutPackage method enforceShortcutCountsBeforeOperation.

/**
     * Called by
     * {@link android.content.pm.ShortcutManager#setDynamicShortcuts},
     * {@link android.content.pm.ShortcutManager#addDynamicShortcuts}, and
     * {@link android.content.pm.ShortcutManager#updateShortcuts} before actually performing
     * the operation to make sure the operation wouldn't result in the target activities having
     * more than the allowed number of dynamic/manifest shortcuts.
     *
     * @param newList shortcut list passed to set, add or updateShortcuts().
     * @param operation add, set or update.
     * @throws IllegalArgumentException if the operation would result in going over the max
     *                                  shortcut count for any activity.
     */
public void enforceShortcutCountsBeforeOperation(List<ShortcutInfo> newList, @ShortcutOperation int operation) {
    final ShortcutService service = mShortcutUser.mService;
    // Current # of dynamic / manifest shortcuts for each activity.
    // (If it's for update, then don't count dynamic shortcuts, since they'll be replaced
    // anyway.)
    final ArrayMap<ComponentName, Integer> counts = new ArrayMap<>(4);
    for (int i = mShortcuts.size() - 1; i >= 0; i--) {
        final ShortcutInfo shortcut = mShortcuts.valueAt(i);
        if (shortcut.isManifestShortcut()) {
            incrementCountForActivity(counts, shortcut.getActivity(), 1);
        } else if (shortcut.isDynamic() && (operation != ShortcutService.OPERATION_SET)) {
            incrementCountForActivity(counts, shortcut.getActivity(), 1);
        }
    }
    for (int i = newList.size() - 1; i >= 0; i--) {
        final ShortcutInfo newShortcut = newList.get(i);
        final ComponentName newActivity = newShortcut.getActivity();
        if (newActivity == null) {
            if (operation != ShortcutService.OPERATION_UPDATE) {
                service.wtf("Activity must not be null at this point");
                // Just ignore this invalid case.
                continue;
            }
            // Activity can be null for update.
            continue;
        }
        final ShortcutInfo original = mShortcuts.get(newShortcut.getId());
        if (original == null) {
            if (operation == ShortcutService.OPERATION_UPDATE) {
                // When updating, ignore if there's no target.
                continue;
            }
            // Add() or set(), and there's no existing shortcut with the same ID.  We're
            // simply publishing (as opposed to updating) this shortcut, so just +1.
            incrementCountForActivity(counts, newActivity, 1);
            continue;
        }
        if (original.isFloating() && (operation == ShortcutService.OPERATION_UPDATE)) {
            // Updating floating shortcuts doesn't affect the count, so ignore.
            continue;
        }
        // dynamic shortcuts in the first loop.
        if (operation != ShortcutService.OPERATION_SET) {
            final ComponentName oldActivity = original.getActivity();
            if (!original.isFloating()) {
                incrementCountForActivity(counts, oldActivity, -1);
            }
        }
        incrementCountForActivity(counts, newActivity, 1);
    }
    // Then make sure none of the activities have more than the max number of shortcuts.
    for (int i = counts.size() - 1; i >= 0; i--) {
        service.enforceMaxActivityShortcuts(counts.valueAt(i));
    }
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ArrayMap(android.util.ArrayMap) ComponentName(android.content.ComponentName)

Example 62 with ArrayMap

use of android.util.ArrayMap in project platform_frameworks_base by android.

the class FullBackup method getBackupSchemeForTest.

public static BackupScheme getBackupSchemeForTest(Context context) {
    BackupScheme testing = new BackupScheme(context);
    testing.mExcludes = new ArraySet();
    testing.mIncludes = new ArrayMap();
    return testing;
}
Also used : ArraySet(android.util.ArraySet) ArrayMap(android.util.ArrayMap)

Example 63 with ArrayMap

use of android.util.ArrayMap in project platform_frameworks_base by android.

the class ScanRecord method parseFromBytes.

/**
     * Parse scan record bytes to {@link ScanRecord}.
     * <p>
     * The format is defined in Bluetooth 4.1 specification, Volume 3, Part C, Section 11 and 18.
     * <p>
     * All numerical multi-byte entities and values shall use little-endian <strong>byte</strong>
     * order.
     *
     * @param scanRecord The scan record of Bluetooth LE advertisement and/or scan response.
     * @hide
     */
public static ScanRecord parseFromBytes(byte[] scanRecord) {
    if (scanRecord == null) {
        return null;
    }
    int currentPos = 0;
    int advertiseFlag = -1;
    List<ParcelUuid> serviceUuids = new ArrayList<ParcelUuid>();
    String localName = null;
    int txPowerLevel = Integer.MIN_VALUE;
    SparseArray<byte[]> manufacturerData = new SparseArray<byte[]>();
    Map<ParcelUuid, byte[]> serviceData = new ArrayMap<ParcelUuid, byte[]>();
    try {
        while (currentPos < scanRecord.length) {
            // length is unsigned int.
            int length = scanRecord[currentPos++] & 0xFF;
            if (length == 0) {
                break;
            }
            // Note the length includes the length of the field type itself.
            int dataLength = length - 1;
            // fieldType is unsigned int.
            int fieldType = scanRecord[currentPos++] & 0xFF;
            switch(fieldType) {
                case DATA_TYPE_FLAGS:
                    advertiseFlag = scanRecord[currentPos] & 0xFF;
                    break;
                case DATA_TYPE_SERVICE_UUIDS_16_BIT_PARTIAL:
                case DATA_TYPE_SERVICE_UUIDS_16_BIT_COMPLETE:
                    parseServiceUuid(scanRecord, currentPos, dataLength, BluetoothUuid.UUID_BYTES_16_BIT, serviceUuids);
                    break;
                case DATA_TYPE_SERVICE_UUIDS_32_BIT_PARTIAL:
                case DATA_TYPE_SERVICE_UUIDS_32_BIT_COMPLETE:
                    parseServiceUuid(scanRecord, currentPos, dataLength, BluetoothUuid.UUID_BYTES_32_BIT, serviceUuids);
                    break;
                case DATA_TYPE_SERVICE_UUIDS_128_BIT_PARTIAL:
                case DATA_TYPE_SERVICE_UUIDS_128_BIT_COMPLETE:
                    parseServiceUuid(scanRecord, currentPos, dataLength, BluetoothUuid.UUID_BYTES_128_BIT, serviceUuids);
                    break;
                case DATA_TYPE_LOCAL_NAME_SHORT:
                case DATA_TYPE_LOCAL_NAME_COMPLETE:
                    localName = new String(extractBytes(scanRecord, currentPos, dataLength));
                    break;
                case DATA_TYPE_TX_POWER_LEVEL:
                    txPowerLevel = scanRecord[currentPos];
                    break;
                case DATA_TYPE_SERVICE_DATA:
                    // The first two bytes of the service data are service data UUID in little
                    // endian. The rest bytes are service data.
                    int serviceUuidLength = BluetoothUuid.UUID_BYTES_16_BIT;
                    byte[] serviceDataUuidBytes = extractBytes(scanRecord, currentPos, serviceUuidLength);
                    ParcelUuid serviceDataUuid = BluetoothUuid.parseUuidFrom(serviceDataUuidBytes);
                    byte[] serviceDataArray = extractBytes(scanRecord, currentPos + serviceUuidLength, dataLength - serviceUuidLength);
                    serviceData.put(serviceDataUuid, serviceDataArray);
                    break;
                case DATA_TYPE_MANUFACTURER_SPECIFIC_DATA:
                    // The first two bytes of the manufacturer specific data are
                    // manufacturer ids in little endian.
                    int manufacturerId = ((scanRecord[currentPos + 1] & 0xFF) << 8) + (scanRecord[currentPos] & 0xFF);
                    byte[] manufacturerDataBytes = extractBytes(scanRecord, currentPos + 2, dataLength - 2);
                    manufacturerData.put(manufacturerId, manufacturerDataBytes);
                    break;
                default:
                    // Just ignore, we don't handle such data type.
                    break;
            }
            currentPos += dataLength;
        }
        if (serviceUuids.isEmpty()) {
            serviceUuids = null;
        }
        return new ScanRecord(serviceUuids, manufacturerData, serviceData, advertiseFlag, txPowerLevel, localName, scanRecord);
    } catch (Exception e) {
        Log.e(TAG, "unable to parse scan record: " + Arrays.toString(scanRecord));
        // and return an empty record with raw scanRecord bytes in results
        return new ScanRecord(null, null, null, -1, Integer.MIN_VALUE, null, scanRecord);
    }
}
Also used : ParcelUuid(android.os.ParcelUuid) SparseArray(android.util.SparseArray) ArrayList(java.util.ArrayList) ArrayMap(android.util.ArrayMap)

Example 64 with ArrayMap

use of android.util.ArrayMap in project platform_frameworks_base by android.

the class BlobBackupHelper method readOldState.

// Internal implementation
/*
     * State on-disk format:
     * [Int]    : overall blob version number
     * [Int=N] : number of keys represented in the state blob
     * N* :
     *     [String] key
     *     [Long]   blob checksum, calculated after compression
     */
@SuppressWarnings("resource")
private ArrayMap<String, Long> readOldState(ParcelFileDescriptor oldStateFd) {
    final ArrayMap<String, Long> state = new ArrayMap<String, Long>();
    FileInputStream fis = new FileInputStream(oldStateFd.getFileDescriptor());
    DataInputStream in = new DataInputStream(fis);
    try {
        int version = in.readInt();
        if (version <= mCurrentBlobVersion) {
            final int numKeys = in.readInt();
            if (DEBUG) {
                Log.i(TAG, "  " + numKeys + " keys in state record");
            }
            for (int i = 0; i < numKeys; i++) {
                String key = in.readUTF();
                long checksum = in.readLong();
                if (DEBUG) {
                    Log.i(TAG, "  key '" + key + "' checksum is " + checksum);
                }
                state.put(key, checksum);
            }
        } else {
            Log.w(TAG, "Prior state from unrecognized version " + version);
        }
    } catch (EOFException e) {
        // is truncated we just treat it the same way.
        if (DEBUG) {
            Log.i(TAG, "Hit EOF reading prior state");
        }
        state.clear();
    } catch (Exception e) {
        Log.e(TAG, "Error examining prior backup state " + e.getMessage());
        state.clear();
    }
    return state;
}
Also used : EOFException(java.io.EOFException) ArrayMap(android.util.ArrayMap) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) EOFException(java.io.EOFException)

Example 65 with ArrayMap

use of android.util.ArrayMap in project platform_frameworks_base by android.

the class VpnTest method setMockedUsers.

/**
     * Populate {@link #mUserManager} with a list of fake users.
     */
private void setMockedUsers(UserInfo... users) {
    final Map<Integer, UserInfo> userMap = new ArrayMap<>();
    for (UserInfo user : users) {
        userMap.put(user.id, user);
    }
    /**
         * @see UserManagerService#getUsers(boolean)
         */
    doAnswer(invocation -> {
        final boolean excludeDying = (boolean) invocation.getArguments()[0];
        final ArrayList<UserInfo> result = new ArrayList<>(users.length);
        for (UserInfo ui : users) {
            if (!excludeDying || (ui.isEnabled() && !ui.partial)) {
                result.add(ui);
            }
        }
        return result;
    }).when(mUserManager).getUsers(anyBoolean());
    doAnswer(invocation -> {
        final int id = (int) invocation.getArguments()[0];
        return userMap.get(id);
    }).when(mUserManager).getUserInfo(anyInt());
    doAnswer(invocation -> {
        final int id = (int) invocation.getArguments()[0];
        return (userMap.get(id).flags & UserInfo.FLAG_ADMIN) != 0;
    }).when(mUserManager).canHaveRestrictedProfile(anyInt());
}
Also used : ArrayList(java.util.ArrayList) ArrayMap(android.util.ArrayMap) UserInfo(android.content.pm.UserInfo)

Aggregations

ArrayMap (android.util.ArrayMap)365 ArraySet (android.util.ArraySet)77 ArrayList (java.util.ArrayList)75 PublicKey (java.security.PublicKey)49 HashMap (java.util.HashMap)32 Preference (android.support.v7.preference.Preference)30 IOException (java.io.IOException)30 Map (java.util.Map)29 HashSet (java.util.HashSet)28 Intent (android.content.Intent)24 Test (org.junit.Test)24 ComponentName (android.content.ComponentName)22 RemoteException (android.os.RemoteException)22 Field (java.lang.reflect.Field)21 Activity (android.app.Activity)20 SparseArray (android.util.SparseArray)18 List (java.util.List)18 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)18 Point (android.graphics.Point)17 Method (java.lang.reflect.Method)17