1/*
2 * Copyright (C) 2006 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
17package android.content;
18
19/**
20 * Extended {@link ComponentCallbacks} interface with a new callback for
21 * finer-grained memory management.
22 */
23public interface ComponentCallbacks2 extends ComponentCallbacks {
24
25    /**
26     * Level for {@link #onTrimMemory(int)}: the process is nearing the end
27     * of the background LRU list, and if more memory isn't found soon it will
28     * be killed.
29     */
30    static final int TRIM_MEMORY_COMPLETE = 80;
31
32    /**
33     * Level for {@link #onTrimMemory(int)}: the process is around the middle
34     * of the background LRU list; freeing memory can help the system keep
35     * other processes running later in the list for better overall performance.
36     */
37    static final int TRIM_MEMORY_MODERATE = 60;
38
39    /**
40     * Level for {@link #onTrimMemory(int)}: the process has gone on to the
41     * LRU list.  This is a good opportunity to clean up resources that can
42     * efficiently and quickly be re-built if the user returns to the app.
43     */
44    static final int TRIM_MEMORY_BACKGROUND = 40;
45
46    /**
47     * Level for {@link #onTrimMemory(int)}: the process had been showing
48     * a user interface, and is no longer doing so.  Large allocations with
49     * the UI should be released at this point to allow memory to be better
50     * managed.
51     */
52    static final int TRIM_MEMORY_UI_HIDDEN = 20;
53
54    /**
55     * Level for {@link #onTrimMemory(int)}: the process is not an expendable
56     * background process, but the device is running extremely low on memory
57     * and is about to not be able to keep any background processes running.
58     * Your running process should free up as many non-critical resources as it
59     * can to allow that memory to be used elsewhere.  The next thing that
60     * will happen after this is {@link #onLowMemory()} called to report that
61     * nothing at all can be kept in the background, a situation that can start
62     * to notably impact the user.
63     */
64    static final int TRIM_MEMORY_RUNNING_CRITICAL = 15;
65
66    /**
67     * Level for {@link #onTrimMemory(int)}: the process is not an expendable
68     * background process, but the device is running low on memory.
69     * Your running process should free up unneeded resources to allow that
70     * memory to be used elsewhere.
71     */
72    static final int TRIM_MEMORY_RUNNING_LOW = 10;
73
74
75    /**
76     * Level for {@link #onTrimMemory(int)}: the process is not an expendable
77     * background process, but the device is running moderately low on memory.
78     * Your running process may want to release some unneeded resources for
79     * use elsewhere.
80     */
81    static final int TRIM_MEMORY_RUNNING_MODERATE = 5;
82
83    /**
84     * Called when the operating system has determined that it is a good
85     * time for a process to trim unneeded memory from its process.  This will
86     * happen for example when it goes in the background and there is not enough
87     * memory to keep as many background processes running as desired.  You
88     * should never compare to exact values of the level, since new intermediate
89     * values may be added -- you will typically want to compare if the value
90     * is greater or equal to a level you are interested in.
91     *
92     * <p>To retrieve the processes current trim level at any point, you can
93     * use {@link android.app.ActivityManager#getMyMemoryState
94     * ActivityManager.getMyMemoryState(RunningAppProcessInfo)}.
95     *
96     * @param level The context of the trim, giving a hint of the amount of
97     * trimming the application may like to perform.  May be
98     * {@link #TRIM_MEMORY_COMPLETE}, {@link #TRIM_MEMORY_MODERATE},
99     * {@link #TRIM_MEMORY_BACKGROUND}, {@link #TRIM_MEMORY_UI_HIDDEN},
100     * {@link #TRIM_MEMORY_RUNNING_CRITICAL}, {@link #TRIM_MEMORY_RUNNING_LOW},
101     * or {@link #TRIM_MEMORY_RUNNING_MODERATE}.
102     */
103    void onTrimMemory(int level);
104}
105