| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2005 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 | #ifndef ANDROID_IPC_THREAD_STATE_H | 
|  | 18 | #define ANDROID_IPC_THREAD_STATE_H | 
|  | 19 |  | 
|  | 20 | #include <utils/Errors.h> | 
| Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 21 | #include <binder/Parcel.h> | 
|  | 22 | #include <binder/ProcessState.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | #include <utils/Vector.h> | 
|  | 24 |  | 
|  | 25 | #ifdef HAVE_WIN32_PROC | 
|  | 26 | typedef  int  uid_t; | 
|  | 27 | #endif | 
|  | 28 |  | 
|  | 29 | // --------------------------------------------------------------------------- | 
|  | 30 | namespace android { | 
|  | 31 |  | 
|  | 32 | class IPCThreadState | 
|  | 33 | { | 
|  | 34 | public: | 
|  | 35 | static  IPCThreadState*     self(); | 
| Brad Fitzpatrick | 1b60843 | 2010-12-13 16:52:35 -0800 | [diff] [blame] | 36 | static  IPCThreadState*     selfOrNull();  // self(), but won't instantiate | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 |  | 
|  | 38 | sp<ProcessState>    process(); | 
|  | 39 |  | 
|  | 40 | status_t            clearLastError(); | 
|  | 41 |  | 
|  | 42 | int                 getCallingPid(); | 
|  | 43 | int                 getCallingUid(); | 
| Amith Yamasani | 4e975bb | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 44 | int                 getOrigCallingUid(); | 
| Brad Fitzpatrick | 702ea9d | 2010-06-18 13:07:53 -0700 | [diff] [blame] | 45 |  | 
|  | 46 | void                setStrictModePolicy(int32_t policy); | 
|  | 47 | int32_t             getStrictModePolicy() const; | 
| Brad Fitzpatrick | 5273603 | 2010-08-30 16:01:16 -0700 | [diff] [blame] | 48 |  | 
|  | 49 | void                setLastTransactionBinderFlags(int32_t flags); | 
|  | 50 | int32_t             getLastTransactionBinderFlags() const; | 
|  | 51 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | int64_t             clearCallingIdentity(); | 
|  | 53 | void                restoreCallingIdentity(int64_t token); | 
|  | 54 |  | 
|  | 55 | void                flushCommands(); | 
|  | 56 |  | 
|  | 57 | void                joinThreadPool(bool isMain = true); | 
|  | 58 |  | 
|  | 59 | // Stop the local process. | 
|  | 60 | void                stopProcess(bool immediate = true); | 
|  | 61 |  | 
|  | 62 | status_t            transact(int32_t handle, | 
|  | 63 | uint32_t code, const Parcel& data, | 
|  | 64 | Parcel* reply, uint32_t flags); | 
|  | 65 |  | 
|  | 66 | void                incStrongHandle(int32_t handle); | 
|  | 67 | void                decStrongHandle(int32_t handle); | 
|  | 68 | void                incWeakHandle(int32_t handle); | 
|  | 69 | void                decWeakHandle(int32_t handle); | 
|  | 70 | status_t            attemptIncStrongHandle(int32_t handle); | 
|  | 71 | static  void                expungeHandle(int32_t handle, IBinder* binder); | 
|  | 72 | status_t            requestDeathNotification(   int32_t handle, | 
|  | 73 | BpBinder* proxy); | 
|  | 74 | status_t            clearDeathNotification( int32_t handle, | 
|  | 75 | BpBinder* proxy); | 
|  | 76 |  | 
|  | 77 | static  void                shutdown(); | 
|  | 78 |  | 
| Dianne Hackborn | 8c6cedc | 2009-12-07 17:59:37 -0800 | [diff] [blame] | 79 | // Call this to disable switching threads to background scheduling when | 
|  | 80 | // receiving incoming IPC calls.  This is specifically here for the | 
|  | 81 | // Android system process, since it expects to have background apps calling | 
|  | 82 | // in to it but doesn't want to acquire locks in its services while in | 
|  | 83 | // the background. | 
|  | 84 | static  void                disableBackgroundScheduling(bool disable); | 
|  | 85 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | private: | 
|  | 87 | IPCThreadState(); | 
|  | 88 | ~IPCThreadState(); | 
|  | 89 |  | 
|  | 90 | status_t            sendReply(const Parcel& reply, uint32_t flags); | 
|  | 91 | status_t            waitForResponse(Parcel *reply, | 
|  | 92 | status_t *acquireResult=NULL); | 
|  | 93 | status_t            talkWithDriver(bool doReceive=true); | 
|  | 94 | status_t            writeTransactionData(int32_t cmd, | 
|  | 95 | uint32_t binderFlags, | 
|  | 96 | int32_t handle, | 
|  | 97 | uint32_t code, | 
|  | 98 | const Parcel& data, | 
|  | 99 | status_t* statusBuffer); | 
|  | 100 | status_t            executeCommand(int32_t command); | 
|  | 101 |  | 
|  | 102 | void                clearCaller(); | 
|  | 103 |  | 
|  | 104 | static  void                threadDestructor(void *st); | 
|  | 105 | static  void                freeBuffer(Parcel* parcel, | 
|  | 106 | const uint8_t* data, size_t dataSize, | 
|  | 107 | const size_t* objects, size_t objectsSize, | 
|  | 108 | void* cookie); | 
|  | 109 |  | 
|  | 110 | const   sp<ProcessState>    mProcess; | 
| Dianne Hackborn | 8c6cedc | 2009-12-07 17:59:37 -0800 | [diff] [blame] | 111 | const   pid_t               mMyThreadId; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | Vector<BBinder*>    mPendingStrongDerefs; | 
|  | 113 | Vector<RefBase::weakref_type*> mPendingWeakDerefs; | 
| Dianne Hackborn | 8c6cedc | 2009-12-07 17:59:37 -0800 | [diff] [blame] | 114 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | Parcel              mIn; | 
|  | 116 | Parcel              mOut; | 
|  | 117 | status_t            mLastError; | 
|  | 118 | pid_t               mCallingPid; | 
|  | 119 | uid_t               mCallingUid; | 
| Amith Yamasani | 4e975bb | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 120 | uid_t               mOrigCallingUid; | 
| Brad Fitzpatrick | 702ea9d | 2010-06-18 13:07:53 -0700 | [diff] [blame] | 121 | int32_t             mStrictModePolicy; | 
| Brad Fitzpatrick | 5273603 | 2010-08-30 16:01:16 -0700 | [diff] [blame] | 122 | int32_t             mLastTransactionBinderFlags; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | }; | 
| Brad Fitzpatrick | 702ea9d | 2010-06-18 13:07:53 -0700 | [diff] [blame] | 124 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | }; // namespace android | 
|  | 126 |  | 
|  | 127 | // --------------------------------------------------------------------------- | 
|  | 128 |  | 
|  | 129 | #endif // ANDROID_IPC_THREAD_STATE_H |