BinderInternal.java revision 6f357d3284a833cc50a990e14b39f389b8972254
1/* 2 * Copyright (C) 2008 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 com.android.internal.os; 18 19import android.os.IBinder; 20import android.os.SystemClock; 21import android.util.EventLog; 22 23import java.lang.ref.WeakReference; 24 25/** 26 * Private and debugging Binder APIs. 27 * 28 * @see IBinder 29 */ 30public class BinderInternal { 31 static WeakReference<GcWatcher> mGcWatcher 32 = new WeakReference<GcWatcher>(new GcWatcher()); 33 static long mLastGcTime; 34 35 static final class GcWatcher { 36 @Override 37 protected void finalize() throws Throwable { 38 handleGc(); 39 mLastGcTime = SystemClock.uptimeMillis(); 40 mGcWatcher = new WeakReference<GcWatcher>(new GcWatcher()); 41 } 42 } 43 44 /** 45 * Add the calling thread to the IPC thread pool. This function does 46 * not return until the current process is exiting. 47 */ 48 public static final native void joinThreadPool(); 49 50 /** 51 * Return the system time (as reported by {@link SystemClock#uptimeMillis 52 * SystemClock.uptimeMillis()}) that the last garbage collection occurred 53 * in this process. This is not for general application use, and the 54 * meaning of "when a garbage collection occurred" will change as the 55 * garbage collector evolves. 56 * 57 * @return Returns the time as per {@link SystemClock#uptimeMillis 58 * SystemClock.uptimeMillis()} of the last garbage collection. 59 */ 60 public static long getLastGcTime() { 61 return mLastGcTime; 62 } 63 64 /** 65 * Return the global "context object" of the system. This is usually 66 * an implementation of IServiceManager, which you can use to find 67 * other services. 68 */ 69 public static final native IBinder getContextObject(); 70 71 /** 72 * Special for system process to not allow incoming calls to run at 73 * background scheduling priority. 74 * @hide 75 */ 76 public static final native void disableBackgroundScheduling(boolean disable); 77 78 static native final void handleGc(); 79 80 public static void forceGc(String reason) { 81 EventLog.writeEvent(2741, reason); 82 Runtime.getRuntime().gc(); 83 } 84 85 static void forceBinderGc() { 86 forceGc("Binder"); 87 } 88} 89