1 /* 2 * Copyright (C) 2017 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 package com.android.car.procfsinspector; 17 18 import android.annotation.Nullable; 19 import android.os.RemoteException; 20 import android.os.ServiceManager; 21 import android.util.Log; 22 import java.util.Arrays; 23 import java.util.Collections; 24 import java.util.List; 25 import java.util.Objects; 26 27 public final class ProcfsInspector { 28 private static final String TAG = "car.procfsinspector"; 29 private static final String SERVICE_NAME = "com.android.car.procfsinspector"; 30 private final IProcfsInspector mService; 31 32 private ProcfsInspector(IProcfsInspector service) { 33 mService = service; 34 } 35 36 @Nullable 37 private static IProcfsInspector tryGet() { 38 return IProcfsInspector.Stub.asInterface( 39 ServiceManager.getService(SERVICE_NAME)); 40 } 41 42 public static List<ProcessInfo> readProcessTable() { 43 IProcfsInspector procfsInspector = tryGet(); 44 if (procfsInspector != null) { 45 try { 46 return procfsInspector.readProcessTable(); 47 } catch (RemoteException e) { 48 Log.w(TAG, "caught RemoteException", e); 49 } 50 } 51 52 return Collections.emptyList(); 53 } 54 } 55