android源码学习:ActivityManager类全理解

android.app下有个ActivityManager类,该类的作用官方的解释是:
这个类提供有关、交互、 activities, services和包含process的信息。
这个类中的许多方法都是为了调试或信息的目的,它们不应该被用来影响应用程序的运行时行为,这些方法在方法级文档中被调用。
大多数应用程序开发人员不应该使用这个类,大多数的方法都是专门用例的。然而,一些方法更广泛地适用。例如,isLowRamDevice()允许您的应用程序检测它是否在低内存设备上运行,并相应的执行。clearApplicationUserData()用于具有重新设置数据功能的应用程序。

在一些特殊的用例中,应用程序可以与Task stack交互,应用程序可以使用该内部类的ActivityManager.AppTask和ActivityManager.RecentTaskInfo但是,一般来说,这个类中的方法只用于测试和调试。

内部类解释
ActivityManager.AppTask用于控制应用程序的任务
ActivityManager.MemoryInfogetMemoryInfo(ActivityManager.MemoryInfo)方法获取可用内存
ActivityManager.ProcessErrorStateInfo您可以检索任何在错误条件下的进程的信息。
ActivityManager.RecentTaskInfo您可以检索用户最近启动或访问的任务的信息。
ActivityManager.RunningAppProcessInfo您可以检索关于正在运行的进程的信息。
ActivityManager.RunningServiceInfo您可以检索当前系统中正在运行的特定服务的信息。
ActivityManager.RunningTaskInfo您可以检索当前正在系统中“运行”的特定任务的信息。
ActivityManager.TaskDescription您可以在最近的任务列表中设置和检索关于当前活动的信息。
方法返回值解释
addAppTask(Activity activity, Intent intent, ActivityManager.TaskDescription description, Bitmap thumbnail)int添加一个ActivityManager.AppTask
clearApplicationUserData()boolean允许应用程序从磁盘上删除自己的数据。
clearWatchHeapLimit()清除之前由setWatchHeapLimit(long)设置的Watch Heap限制。
dumpPackageState(FileDescriptor fd, String packageName)执行与给定的应用程序包名相关联的各种状态的系统转储。
getAppTaskThumbnailSize()Size返回用于当前 ActivityManager.AppTask缩略图的当前设计尺寸,用于addAppTask(Activity, Intent, ActivityManager.TaskDescription, Bitmap)
getAppTasks()List AppTask获取与调用应用程序关联的任务列表
getDeviceConfigurationInfo()ConfigurationInfo获取设备配置属性。
getLargeMemoryClass()int当应用程序在一个大堆中运行时,返回当前设备的每个应用程序的内存类。
getLauncherLargeIconDensity()int获取Launcher的图标的首选密度。
getLauncherLargeIconSize()int获取启动器的图标的首选密度。
getLockTaskModeState()int返回当前任务锁定状态。
getMaxNumPictureInPictureActions()int当用户与当前图片模式下的Activity进行交互时,将显示在图中UI中显示的最大动作数量。
getMemoryClass()int返回当前设备的每个应用程序的内存类。
getMemoryInfo(ActivityManager.MemoryInfo outInfo)返回关于系统内存状态的一般信息。
getMyMemoryState(ActivityManager.RunningAppProcessInfo outState)为调用进程返回全局内存状态信息。
getProcessMemoryInfo(int[] pids)MemoryInfo[]返回关于一个或多个进程的内存使用情况的信息。
getProcessesInErrorState()List ActivityManager.ProcessErrorStateInfo返回当前处于错误状态的任何进程的列表。
getRunningAppProcesses()List ActivityManager.RunningAppProcessInfo返回在设备上运行的应用程序进程列表。
getRunningServiceControlPanel(ComponentName service)PendingIntent返回一个PendingIntent,您可以开始显示给定的运行服务的一个控制面板。
getRunningServices(int maxNum)List ActivityManager.RunningServiceInfo返回当前运行的Services列表
isLowRamDevice()boolean如果这是一个低ram设备,返回true。
isRunningInTestHarness()boolean如果设备在一个测试工具中运行,则返回“true”。
isUserAMonkey()boolean如果用户界面被Monkey messed,返回“true”。
killBackgroundProcesses(String packageName)让系统立即终止与给定包关联的所有后台进程。
moveTaskToFront(int taskId, int flags, Bundle options)请求与给定任务ID关联的任务被移动到堆栈的前面,因此用户现在可以看到它。
moveTaskToFront(int taskId, int flags)同上
setVrThread(int tid)为 latency-sensitive low-runtime VR线程启用更积极的调度。
setWatchHeapLimit(long pssSize)请求系统开始监视调用进程,以超过pssSize

具体使用方式,还是用代码实现比较好理解:github位置:https://github.com/66668/ActivityManagerDemo
,代码将ActivityManager及其内部类的方法都打印出来,查看结果,其中比较重要的内部类是RunningServiceInfo,使用真机xplay6 android7.0测试,打印结果
发现,系统自行运行的Service有92个,大部分是厂商自己封装的service,见下表:

运行的Service解释
com.android.bluetooth.hid.HidService
com.android.providers.media.MediaScannerNullService
com.vivo.daemonService.batterywarning.BatteryWarningService
org.codeaurora.ims.ImsService
com.qualcomm.location.LocationService
com.vivo.permissionmanager.service.FloatWindowManagerService
OneShotService
GalleryService
com.android.systemui.keyguard.KeyguardService
com.tencent.mm.plugin.sport.service.SportService
com.qualcomm.location.izat.IzatService
com.vivo.magazine.MagazineService
com.android.systemui.ImageWallpaper
com.android.providers.media.FileObserverService
com.vivo.permissionmanager.service.FileObserverService
com.bbk.launcher2.appstore.DownloadPackageService
com.qualcomm.qti.tetherservice.TetherService
WifiNetworkDetectService
com.android.bbklog.ServerControlLogService
com.tencent.mm.booter.NotifyReceiver$NotifyService
com.android.printspooler.model.PrintSpoolerService
com.vivo.appfilter.service.PreventAutoStartService
com.dsi.ant.server.AntService
com.qualcomm.location.izatserviceprovider.service.UnifiedLocationService
com.vivo.daemonService.vivolog.VivologAlarmService
com.vivo.daemonService.Nail.NailDaemonService
com.bbk.iqoo.logsystem.services.LogCollectService
com.vivo.daemonService.motion.DeviceListener
org.simalliance.openmobileapi.service.SmartcardService
com.vivo.messagecenter.display.DisplayService
com.vivo.pem.core.hide.io.PemService
com.vivo.daemonService.unifiedconfig.UnifiedConfigService
com.vivo.doubleinstance.WhitelistQureyService
com.vivo.push.core.android.service.MqttService
com.vivo.appbehavior.AppBehaviorEngineService
com.android.bluetooth.pbap.BluetoothPbapService
DuerTextToSpeechService
com.vivo.devicereg.ctrl.CtrlServer
com.vivo.nail.service.NailService
ClassifyService
com.vivo.daemonService.usb.UsbDeviceManagerService
com.vivo.daemonService.IqooSecure.SoftwareLockService
com.vivo.smartmultiwindow.services.ManagerStateService
ManagerStateService
com.android.bluetooth.a2dp.A2dpService
com.vivo.upslide.UpSlideService
com.qualcomm.qcrilmsgtunnel.QcrilMsgTunnelService
com.qti.service.colorservice.ColorServiceApp
com.vivo.download.DownloadService
com.baidu.location.f
com.vivo.smartmultiwindow.services.ScreenObserverService
com.vivo.daemonService.VoiceOneshot.OneShotService
com.android.systemui.SystemUIService
com.bbk.updater.usage.CalculateService
android.hardware.location.GeofenceHardwareService
com.vivo.core.AbeCoreService
com.iqoo.secure.wifidetect.WifiCheckService
com.vivo.push.sdk.service.PushService
com.iqoo.secure.service.SecureService
com.baidu.map.location.BaiduNetworkLocationService
com.qualcomm.location.LBSSystemMonitorService
com.vivo.smartmultiwindow.services.ThreeFinger
com.android.server.telecom.BluetoothPhoneService
com.vivo.findphone.CommandService
com.qualcomm.location.izatserviceprovider.service.NetworkLocationService
com.qti.dpmserviceapp.DpmServiceApp
com.qualcomm.qti.appnetaccess.AppNetAccessService
com.android.stk.StkAppService
com.vivo.daemonService.gms.GmsMonitor
com.vivo.doubletimezoneclock.clock.ClockWidgetService
com.vivo.safecenter.paysafe.PaySafeService
com.iqoo.secure.service.DataUsageService
com.baidu.duersdk.opensdk.service.DuerCoreSpeechRecognitionService
com.android.bluetooth.hfp.HeadsetService
com.vivo.performaengine.BigDataService
com.qti.qualcomm.datastatusnotification.DataStatusNotificationServicecn.richinfo.dm.service.DMService
com.android.server.content.SyncJobService
com.vivo.daemonService.ProxCoverNotice.ProxCoverNoticeService
com.bbk.iqoo.logsystem.services.StartupIntentService
com.android.bbklog.BootLogParserService
com.vivo.daemonService.netStateStat.NetStateStatService
com.vivo.appfilter.service.VivoBringupManagerService
com.android.bluetooth.map.BluetoothMapService
com.android.mms.service.MmsService
com.android.defcontainer.DefaultContainerService
com.baidu.input_bbk.service.PinyinIME
android.ext.services.notification.Ranker
com.tencent.mobileqq.msf.service.MsfService
com.android.bluetooth.pan.PanService
com.android.server.telecom.smartdialer.BBKDialerInitService
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值