public E put(String name, int uid, E value) { SparseArray<E> uids = mMap.get(name); if (uids == null) { uids = new SparseArray<E>(2); mMap.put(name, uids); } uids.put(uid, value); return value; }
/** * Alias for {@link #delete(int)}. */ public void remove(int key) { delete(key); }
@Override public void writePersistenceData(Parcel p) { mGlobalConfig.writeToParcel(p, 0); p.writeInt(mLocConfigs.size()); for (int i = 0; i < mLocConfigs.size(); i++) { int userId = mLocConfigs.keyAt(i); Map<String, VLocConfig> pkgs = mLocConfigs.valueAt(i); p.writeInt(userId); p.writeMap(pkgs); } }
private VLocConfig getOrCreateConfig(int userId, String pkg) { Map<String, VLocConfig> pkgs = mLocConfigs.get(userId); if (pkgs == null) { pkgs = new HashMap<>(); mLocConfigs.put(userId, pkgs); } VLocConfig config = pkgs.get(pkg); if (config == null) { config = new VLocConfig(); config.mode = MODE_CLOSE; pkgs.put(pkg, config); } return config; }
@Override public String getAppProcessName(int pid) { synchronized (mPidsSelfLocked) { ProcessRecord r = mPidsSelfLocked.get(pid); if (r != null) { return r.processName; } } return null; }
/** * Given an index in the range <code>0...size()-1</code>, returns * the key from the <code>index</code>th key-value mapping that this * SparseArray stores. */ public int keyAt(int index) { if (mGarbage) { gc(); } return mKeys[index]; }
public E remove(String name, int uid) { SparseArray<E> uids = mMap.get(name); if (uids != null) { final E old = uids.removeReturnOld(uid); if (uids.size() == 0) { mMap.remove(name); } return old; } return null; }
/** * Puts a key/value pair into the array, optimizing for the case where * the key is greater than all existing keys in the array. */ public void append(int key, E value) { if (mSize != 0 && key <= mKeys[mSize - 1]) { put(key, value); return; } if (mGarbage && mSize >= mKeys.length) { gc(); } int pos = mSize; if (pos >= mKeys.length) { int n = ContainerHelpers.idealIntArraySize(pos + 1); int[] nkeys = new int[n]; Object[] nvalues = new Object[n]; // Log.e("SparseArray", "grow " + mKeys.length + " to " + n); System.arraycopy(mKeys, 0, nkeys, 0, mKeys.length); System.arraycopy(mValues, 0, nvalues, 0, mValues.length); mKeys = nkeys; mValues = nvalues; } mKeys[pos] = key; mValues[pos] = value; mSize = pos + 1; }
void stopSession() { if (clientJobService != null) { try { clientJobService.stopJob(jobParams); } catch (RemoteException e) { e.printStackTrace(); } } mJobSessions.remove(jobId); unbindService(this); } }
@Override public void updateDeviceInfo(int userId, VDeviceInfo info) throws RemoteException { synchronized (mDeviceInfos) { if (info != null) { mDeviceInfos.put(userId, info); mPersistenceLayer.save(); } } }
/** * Remove a range of mappings as a batch. * * @param index Index to begin at * @param size Number of mappings to remove */ public void removeAtRange(int index, int size) { final int end = Math.min(mSize, index + size); for (int i = index; i < end; i++) { removeAt(i); } }
@Override public void writePersistenceData(Parcel p) { SparseArray<VDeviceInfo> infos = mService.getDeviceInfos(); int size = infos.size(); p.writeInt(size); for (int i = 0; i < size; i++) { int userId = infos.keyAt(i); VDeviceInfo info = infos.valueAt(i); p.writeInt(userId); info.writeToParcel(p, 0); } }
@Override public String getInitialPackage(int pid) { synchronized (mPidsSelfLocked) { ProcessRecord r = mPidsSelfLocked.get(pid); if (r != null) { return r.info.packageName; } return null; } }
/** * Returns the number of key-value mappings that this SparseArray * currently stores. */ public int size() { if (mGarbage) { gc(); } return mSize; }
public E remove(String name, int uid) { SparseArray<E> uids = mMap.get(name); if (uids != null) { final E old = uids.removeReturnOld(uid); if (uids.size() == 0) { mMap.remove(name); } return old; } return null; }
/** * Puts a key/value pair into the array, optimizing for the case where * the key is greater than all existing keys in the array. */ public void append(int key, E value) { if (mSize != 0 && key <= mKeys[mSize - 1]) { put(key, value); return; } if (mGarbage && mSize >= mKeys.length) { gc(); } int pos = mSize; if (pos >= mKeys.length) { int n = ContainerHelpers.idealIntArraySize(pos + 1); int[] nkeys = new int[n]; Object[] nvalues = new Object[n]; // Log.e("SparseArray", "grow " + mKeys.length + " to " + n); System.arraycopy(mKeys, 0, nkeys, 0, mKeys.length); System.arraycopy(mValues, 0, nvalues, 0, mValues.length); mKeys = nkeys; mValues = nvalues; } mKeys[pos] = key; mValues[pos] = value; mSize = pos + 1; }
private void onProcessDead(ProcessRecord record) { mProcessNames.remove(record.processName, record.vuid); mPidsSelfLocked.remove(record.pid); processDead(record); record.lock.open(); }
synchronized (mProcessNames) { mProcessNames.put(app.processName, app.vuid, app); mPidsSelfLocked.put(app.pid, app);