• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 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 
17 package com.android.camera.app;
18 
19 import java.util.HashMap;
20 
21 /**
22  * Keeps track of memory used by the app and informs modules and services if
23  * memory gets low.
24  */
25 public interface MemoryManager {
26     /**
27      * Classes implementing this interface will be able to get updates about
28      * memory status changes.
29      */
30     public static interface MemoryListener {
31         /**
32          * Called when the app is experiencing a change in memory state. Modules
33          * should listen to these to not exceed the available memory.
34          *
35          * @param state the new state, one of {@link MemoryManager#STATE_OK},
36          *            {@link MemoryManager#STATE_LOW_MEMORY},
37          */
onMemoryStateChanged(int state)38         public void onMemoryStateChanged(int state);
39 
40         /**
41          * Called when the system is about to kill our app due to high memory
42          * load.
43          */
onLowMemory()44         public void onLowMemory();
45     }
46 
47     /** The memory status is OK. The app can function as normal. */
48     public static final int STATE_OK = 0;
49 
50     /** The memory is running low. E.g. no new media should be captured. */
51     public static final int STATE_LOW_MEMORY = 1;
52 
53     /**
54      * Add a new listener that is informed about upcoming memory events.
55      */
addListener(MemoryListener listener)56     public void addListener(MemoryListener listener);
57 
58     /**
59      * Removes an already registered listener.
60      */
removeListener(MemoryListener listener)61     public void removeListener(MemoryListener listener);
62 
63     /**
64      * Returns the maximum amount of memory allowed to be allocated in native
65      * code by our app (in megabytes).
66      */
getMaxAllowedNativeMemoryAllocation()67     public int getMaxAllowedNativeMemoryAllocation();
68 
69     /**
70      * Queries the memory consumed, total memory, and memory thresholds for this app.
71      *
72      * @return HashMap containing memory metrics keyed by string labels
73      *     defined in {@link MemoryQuery}.
74      */
queryMemory()75     public HashMap queryMemory();
76 }
77