Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
On this page
Help Center/ Cloud Phone Host/ User Guide/ Using AOSP/ Background Process Management

Background Process Management

Updated on 2024-07-31 GMT+08:00

Function

The cloud phone performance automatically clears background application processes. It prevents automatic startup and mutual wakeup of the third-party applications in the background. This improves the startup speed and reduces the occurrence of OOM and high CPU usage.

  • performance: low-memory detection and process killing policy
    When the remaining memory of a cloud phone is lower than a threshold, processes with different priorities are killed in descending order of the remaining memory size.

    Level

    Remaining Memory

    Processes to Be Cleared

    High

    25% of the total memory

    Empty processes

    Cache processes

    Middle

    20% of the total memory

    Used and unperceivable processes

    (invisible, no floating window, no audio focus, and more)

    Low

    15% of the total memory

    Activity processes that have been used last time

    Provider processes that have been used last time

    Background service processes

    Critical

    200 MB

    Kill all application processes in descending order of the memory used until the remaining memory is greater than 200 MB.

How to Use

  • Listening to the broadcast of the killed application
    Your background management program obtains the package name and cause why the application was killed by listening to the broadcast of the killed application.
    public static final String ACTION_APP_KILLED = "android.intent.action.APP_KILLED";
    
    private MyBroadcastReceiver mBroadcastReceiver = new MyBroadcastReceiver();
    
    private void registerReceiver() {
    	IntentFilter filter = new IntentFilter(ACTION_APP_KILLED);
    	this.registerReceiver(mBroadcastReceiver, filter);
    }
    
    private void unregisterReceiver() {
    	this.unregisterReceiver(mBroadcastReceiver);
    }
    
    private class MyBroadcastReceiver extends BroadcastReceiver {
    
    	private static final String TAG = "AppKilled";
    
    	@Override
    	public void onReceive(Context context, Intent intent) {
    		Log.d(TAG, "package: " + intent.getStringExtra("package"));
    		Log.d(TAG, "reason: " + intent.getStringExtra("reason"));
    	}
    }
  • Example of memory leak in the foreground app

    The total memory of a cloud phone is 3.79 GB. Compile the demo app to request ultra-large memory. Use the Java layer to call the native layer through the Java Native Interface (JNI) so that the remaining memory of the system is less than 200 MB. As a result, processes corresponding to the high level to the critical level are killed.

    #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,TAG,__VA_ARGS__)
    #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,TAG,__VA_ARGS__)
    extern "C" JNIEXPORT jint JNICALL
    Java_com_android_memnative_MainActivity_mallocMem(JNIEnv *env, jobject thiz, jint mb) {
        jint total = 0;
        for (jint i = 0; i < mb; i++) {
            jint size = sizeof(char) * 1024 * 1024;
            char *p = (char *) malloc(size);
            if (p != NULL) {
                memset(p, 1, size);
                LOGI("malloc success: %d mb\n", mb);
                total += 1;
            } else {
                LOGE("malloc failed: %d mb\n", mb);
            }
        }
        LOGI("malloc total: %d mb\n", total);
        return total;
    }
    public class MainActivity extends AppCompatActivity {
     
        static {
            System.loadLibrary("memnative");
        }
    
        public native int mallocMem(int mb);
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            setContentView(R.layout.activity_main);
    
            mallocMem(3300); // malloc native memory 3300MB
        }
    }

    The system automatically clears the application processes based on the process importance and sends a broadcast of the application killed. After the background processes are cleared, if the remaining memory is still less than 200 MB and there is a foreground app that uses the largest amount of memory, the foreground app will be killed and a low memory notification is displayed in the notification bar.

  • Background automatic startup management policy
    Except for the processes of the applications specified in the following exemption policies, third-party application processes are not allowed to automatically start or wake up each other in the background.

    Application to Which Exemption Policies Apply

    Example

    System applications

    /system/app, /system/priv-app, and more

    Privileged applications

    uid=1000 (system processes), the default input method, and more

    Visualization applications

    Apps with desktop widgets and live wallpapers

    Whitelisted applications

    Refer to the command line tool.

  • Key Logcat logs
    • Key logs of low memory detection and process killing
      logcat | grep LMK
      BackgroundAppKiller: [LMK] start to kill top app, which takes up a lot of memory: ActivityRecord{248080f u0 com.android.memnative/.MainActivity t84}
      BackgroundAppKiller: [LMK] Killing AppInfo{packageName='com.android.memnative', uid=10059, isHighMemClean=false, reason='[memory:critical]', startTraffic=0, delayMillis=0, totalMillis=0}
      lowmemorykiller: [LMK] start to kill process.
      lowmemorykiller: [LMK] Killing 'com.android.deskclock' (4198), uid 10049, adj 906

      BackgroundAppKiller: performance

      lowmemorykiller: native AOSP low memory killer daemon (lmkd) service

    • Viewing logs of processes that are automatically started in the background and intercepted
      logcat -s AutoRunController | grep "has no auto-run permission"
      AutoRunController: com.android.memnative has no auto-run permission to startProcess

  • Command line tool
    • adb shell cmd performance [command] [args]
      You can use this command to enable or disable a performance feature of CPH, add a whitelist, or delete a whitelist.

      Command

      Parameter

      Description

      Example

      bg-killer

      -e <true|false>

      Enables or disables background process clearing. This feature is enabled by default.

      adb shell cmd performance bg-killer -e true

      -a <packageName|packageNames>

      Adds a whitelist of background processes to be cleared.

      Use commas (,) to separate multiple package names.

      adb shell cmd performance bg-killer -a com.android.test1,com.android.test2

      -d <packageName|packageNames>

      Deletes the whitelist of background processes to be cleared.

      Use commas (,) to separate multiple package names.

      adb shell cmd performance bg-killer -d com.android.test1,com.android.test2

      auto-run

      -e <true|false>

      Enables or disables automatic startup of background third-party applications. This feature is enabled by default.

      adb shell cmd performance auto-run -e true

      -a <packageName|packageNames>

      Adds a whitelist of third-party applications that will automatically start in the background.

      Use commas (,) to separate multiple package names.

      adb shell cmd performance auto-run -a com.android.test1,com.android.test2

      -d <packageName|packageNames>

      Deletes the whitelist of third-party applications that will automatically start in the background.

      Use commas (,) to separate multiple package names.

      adb shell cmd performance auto-run -d com.android.test1,com.android.test2

    • adb shell dumpsys performance [command] [args]

      You can use this command to view whether a performance feature of CPH is enabled or not and to view a whitelist.

Constraints

  • Background process management is enabled by default.
  • By default, daemon processes and processes of whitelisted applications are exempted.
  • All running application processes, including those of the whitelisted applications, at the critical level of low memory, will be killed.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback