Fix crash when pulling certain atoms
IonMemoryUtil and ProcFsMemoryUtil were package-private classes loaded in the system server class loader and had the same package as StatsCompanionService, which is loaded in a separate class loader for statsd. This caused a crash when statsd tried to access either. This cl moves IonMemoryUtil and ProcFsMemoryUtil along with StatsPullAtomService to a separate package so that no classes are shared in the same package. Bug: 147792532 Test: pulled all relevant atoms and make sure they worked Test: adb shell cmd stats pull-source 10064 Test: adb shell cmd stats pull-source 10061 Test: adb shell cmd stats pull-source 10042 Test: adb shell cmd stats pull-source 10056 Change-Id: I5107aa47045321e84549a7f2d55d0ee27f0d080e
This commit is contained in:
@@ -24,11 +24,11 @@ import static android.os.storage.VolumeInfo.TYPE_PRIVATE;
|
||||
import static android.os.storage.VolumeInfo.TYPE_PUBLIC;
|
||||
|
||||
import static com.android.server.am.MemoryStatUtil.readMemoryStatFromFilesystem;
|
||||
import static com.android.server.stats.IonMemoryUtil.readProcessSystemIonHeapSizesFromDebugfs;
|
||||
import static com.android.server.stats.IonMemoryUtil.readSystemIonHeapSizeFromDebugfs;
|
||||
import static com.android.server.stats.ProcfsMemoryUtil.forEachPid;
|
||||
import static com.android.server.stats.ProcfsMemoryUtil.readCmdlineFromProcfs;
|
||||
import static com.android.server.stats.ProcfsMemoryUtil.readMemorySnapshotFromProcfs;
|
||||
import static com.android.server.stats.pull.IonMemoryUtil.readProcessSystemIonHeapSizesFromDebugfs;
|
||||
import static com.android.server.stats.pull.IonMemoryUtil.readSystemIonHeapSizeFromDebugfs;
|
||||
import static com.android.server.stats.pull.ProcfsMemoryUtil.forEachPid;
|
||||
import static com.android.server.stats.pull.ProcfsMemoryUtil.readCmdlineFromProcfs;
|
||||
import static com.android.server.stats.pull.ProcfsMemoryUtil.readMemorySnapshotFromProcfs;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
@@ -135,8 +135,8 @@ import com.android.server.SystemServiceManager;
|
||||
import com.android.server.am.MemoryStatUtil.MemoryStat;
|
||||
import com.android.server.notification.NotificationManagerService;
|
||||
import com.android.server.role.RoleManagerInternal;
|
||||
import com.android.server.stats.IonMemoryUtil.IonAllocations;
|
||||
import com.android.server.stats.ProcfsMemoryUtil.MemorySnapshot;
|
||||
import com.android.server.stats.pull.IonMemoryUtil.IonAllocations;
|
||||
import com.android.server.stats.pull.ProcfsMemoryUtil.MemorySnapshot;
|
||||
import com.android.server.storage.DiskStatsFileLogger;
|
||||
import com.android.server.storage.DiskStatsLoggingService;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.server.stats;
|
||||
package com.android.server.stats.pull;
|
||||
|
||||
import android.os.FileUtils;
|
||||
import android.util.Slog;
|
||||
@@ -30,8 +30,11 @@ import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** Utility methods for reading ion memory stats. */
|
||||
final class IonMemoryUtil {
|
||||
/**
|
||||
* Utility methods for reading ion memory stats.
|
||||
* TODO: Consider making package private after puller migration
|
||||
*/
|
||||
public final class IonMemoryUtil {
|
||||
private static final String TAG = "IonMemoryUtil";
|
||||
|
||||
/** Path to debugfs file for the system ion heap. */
|
||||
@@ -50,7 +53,7 @@ final class IonMemoryUtil {
|
||||
* Returns value of the total size in bytes of the system ion heap from
|
||||
* /sys/kernel/debug/ion/heaps/system.
|
||||
*/
|
||||
static long readSystemIonHeapSizeFromDebugfs() {
|
||||
public static long readSystemIonHeapSizeFromDebugfs() {
|
||||
return parseIonHeapSizeFromDebugfs(readFile(DEBUG_SYSTEM_ION_HEAP_FILE));
|
||||
}
|
||||
|
||||
@@ -78,7 +81,7 @@ final class IonMemoryUtil {
|
||||
* Returns values of allocation sizes in bytes on the system ion heap from
|
||||
* /sys/kernel/debug/ion/heaps/system.
|
||||
*/
|
||||
static List<IonAllocations> readProcessSystemIonHeapSizesFromDebugfs() {
|
||||
public static List<IonAllocations> readProcessSystemIonHeapSizesFromDebugfs() {
|
||||
return parseProcessIonHeapSizesFromDebugfs(readFile(DEBUG_SYSTEM_ION_HEAP_FILE));
|
||||
}
|
||||
|
||||
@@ -130,7 +133,7 @@ final class IonMemoryUtil {
|
||||
}
|
||||
|
||||
/** Summary information about process ion allocations. */
|
||||
static final class IonAllocations {
|
||||
public static final class IonAllocations {
|
||||
/** PID these allocations belong to. */
|
||||
public int pid;
|
||||
/** Size of all individual allocations added together. */
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.server.stats;
|
||||
package com.android.server.stats.pull;
|
||||
|
||||
import static android.os.Process.PROC_OUT_STRING;
|
||||
|
||||
@@ -22,7 +22,7 @@ import android.os.Process;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
final class ProcfsMemoryUtil {
|
||||
public final class ProcfsMemoryUtil {
|
||||
private static final int[] CMDLINE_OUT = new int[] { PROC_OUT_STRING };
|
||||
private static final String[] STATUS_KEYS = new String[] {
|
||||
"Uid:",
|
||||
@@ -39,7 +39,7 @@ final class ProcfsMemoryUtil {
|
||||
* VmSwap fields in /proc/pid/status in kilobytes or null if not available.
|
||||
*/
|
||||
@Nullable
|
||||
static MemorySnapshot readMemorySnapshotFromProcfs(int pid) {
|
||||
public static MemorySnapshot readMemorySnapshotFromProcfs(int pid) {
|
||||
long[] output = new long[STATUS_KEYS.length];
|
||||
output[0] = -1;
|
||||
Process.readProcLines("/proc/" + pid + "/status", STATUS_KEYS, output);
|
||||
@@ -63,7 +63,7 @@ final class ProcfsMemoryUtil {
|
||||
* Returns content of /proc/pid/cmdline (e.g. /system/bin/statsd) or an empty string
|
||||
* if the file is not available.
|
||||
*/
|
||||
static String readCmdlineFromProcfs(int pid) {
|
||||
public static String readCmdlineFromProcfs(int pid) {
|
||||
String[] cmdline = new String[1];
|
||||
if (!Process.readProcFile("/proc/" + pid + "/cmdline", CMDLINE_OUT, cmdline, null, null)) {
|
||||
return "";
|
||||
@@ -71,7 +71,7 @@ final class ProcfsMemoryUtil {
|
||||
return cmdline[0];
|
||||
}
|
||||
|
||||
static void forEachPid(BiConsumer<Integer, String> func) {
|
||||
public static void forEachPid(BiConsumer<Integer, String> func) {
|
||||
int[] pids = new int[1024];
|
||||
pids = Process.getPids("/proc", pids);
|
||||
for (int pid : pids) {
|
||||
@@ -86,7 +86,7 @@ final class ProcfsMemoryUtil {
|
||||
}
|
||||
}
|
||||
|
||||
static final class MemorySnapshot {
|
||||
public static final class MemorySnapshot {
|
||||
public int uid;
|
||||
public int rssHighWaterMarkInKilobytes;
|
||||
public int rssInKilobytes;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.server.stats;
|
||||
package com.android.server.stats.pull;
|
||||
|
||||
import static android.app.AppOpsManager.OP_FLAGS_ALL_TRUSTED;
|
||||
import static android.content.pm.PackageInfo.REQUESTED_PERMISSION_GRANTED;
|
||||
@@ -26,11 +26,11 @@ import static android.os.storage.VolumeInfo.TYPE_PRIVATE;
|
||||
import static android.os.storage.VolumeInfo.TYPE_PUBLIC;
|
||||
|
||||
import static com.android.server.am.MemoryStatUtil.readMemoryStatFromFilesystem;
|
||||
import static com.android.server.stats.IonMemoryUtil.readProcessSystemIonHeapSizesFromDebugfs;
|
||||
import static com.android.server.stats.IonMemoryUtil.readSystemIonHeapSizeFromDebugfs;
|
||||
import static com.android.server.stats.ProcfsMemoryUtil.forEachPid;
|
||||
import static com.android.server.stats.ProcfsMemoryUtil.readCmdlineFromProcfs;
|
||||
import static com.android.server.stats.ProcfsMemoryUtil.readMemorySnapshotFromProcfs;
|
||||
import static com.android.server.stats.pull.IonMemoryUtil.readProcessSystemIonHeapSizesFromDebugfs;
|
||||
import static com.android.server.stats.pull.IonMemoryUtil.readSystemIonHeapSizeFromDebugfs;
|
||||
import static com.android.server.stats.pull.ProcfsMemoryUtil.forEachPid;
|
||||
import static com.android.server.stats.pull.ProcfsMemoryUtil.readCmdlineFromProcfs;
|
||||
import static com.android.server.stats.pull.ProcfsMemoryUtil.readMemorySnapshotFromProcfs;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
@@ -142,8 +142,8 @@ import com.android.server.SystemServiceManager;
|
||||
import com.android.server.am.MemoryStatUtil.MemoryStat;
|
||||
import com.android.server.notification.NotificationManagerService;
|
||||
import com.android.server.role.RoleManagerInternal;
|
||||
import com.android.server.stats.IonMemoryUtil.IonAllocations;
|
||||
import com.android.server.stats.ProcfsMemoryUtil.MemorySnapshot;
|
||||
import com.android.server.stats.pull.IonMemoryUtil.IonAllocations;
|
||||
import com.android.server.stats.pull.ProcfsMemoryUtil.MemorySnapshot;
|
||||
import com.android.server.storage.DiskStatsFileLogger;
|
||||
import com.android.server.storage.DiskStatsLoggingService;
|
||||
|
||||
@@ -218,7 +218,7 @@ public final class SystemServer {
|
||||
private static final String STATS_COMPANION_LIFECYCLE_CLASS =
|
||||
"com.android.server.stats.StatsCompanion$Lifecycle";
|
||||
private static final String STATS_PULL_ATOM_SERVICE_CLASS =
|
||||
"com.android.server.stats.StatsPullAtomService";
|
||||
"com.android.server.stats.pull.StatsPullAtomService";
|
||||
private static final String USB_SERVICE_CLASS =
|
||||
"com.android.server.usb.UsbService$Lifecycle";
|
||||
private static final String MIDI_SERVICE_CLASS =
|
||||
|
||||
@@ -13,16 +13,16 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.server.stats;
|
||||
package com.android.server.stats.pull;
|
||||
|
||||
import static com.android.server.stats.IonMemoryUtil.parseIonHeapSizeFromDebugfs;
|
||||
import static com.android.server.stats.IonMemoryUtil.parseProcessIonHeapSizesFromDebugfs;
|
||||
import static com.android.server.stats.pull.IonMemoryUtil.parseIonHeapSizeFromDebugfs;
|
||||
import static com.android.server.stats.pull.IonMemoryUtil.parseProcessIonHeapSizesFromDebugfs;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.server.stats.IonMemoryUtil.IonAllocations;
|
||||
import com.android.server.stats.pull.IonMemoryUtil.IonAllocations;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
Reference in New Issue
Block a user