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