1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.os.profiling; 18 19 import android.util.ArrayMap; 20 import android.util.SparseArray; 21 22 /** 23 * This is a copy/paste of {@link com.android.internal.app.ProcessMap} with change: 24 * - remove does not return the removed object which leveraged a hidden SparseArray API. 25 */ 26 public class ProcessMap<E> { 27 final ArrayMap<String, SparseArray<E>> mMap = new ArrayMap<String, SparseArray<E>>(); 28 get(String name, int uid)29 public E get(String name, int uid) { 30 SparseArray<E> uids = mMap.get(name); 31 if (uids == null) return null; 32 return uids.get(uid); 33 } 34 put(String name, int uid, E value)35 public void put(String name, int uid, E value) { 36 SparseArray<E> uids = mMap.get(name); 37 if (uids == null) { 38 uids = new SparseArray<E>(1); 39 mMap.put(name, uids); 40 } 41 uids.put(uid, value); 42 } 43 remove(String name, int uid)44 public void remove(String name, int uid) { 45 SparseArray<E> uids = mMap.get(name); 46 if (uids != null) { 47 uids.remove(uid); 48 if (uids.size() == 0) { 49 mMap.remove(name); 50 } 51 } 52 } 53 getMap()54 public ArrayMap<String, SparseArray<E>> getMap() { 55 return mMap; 56 } 57 size()58 public int size() { 59 return mMap.size(); 60 } 61 } 62