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