The Android Open Source Project | 9066cfe | 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 | 0795272 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 21 | #include <binder/Parcel.h> |
| 22 | #include <binder/ProcessState.h> |
The Android Open Source Project | 9066cfe | 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(); |
| 36 | |
| 37 | sp<ProcessState> process(); |
| 38 | |
| 39 | status_t clearLastError(); |
| 40 | |
| 41 | int getCallingPid(); |
| 42 | int getCallingUid(); |
Brad Fitzpatrick | 27b3a7a | 2010-06-18 13:07:53 -0700 | [diff] [blame^] | 43 | |
| 44 | void setStrictModePolicy(int32_t policy); |
| 45 | int32_t getStrictModePolicy() const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | |
| 47 | int64_t clearCallingIdentity(); |
| 48 | void restoreCallingIdentity(int64_t token); |
| 49 | |
| 50 | void flushCommands(); |
| 51 | |
| 52 | void joinThreadPool(bool isMain = true); |
| 53 | |
| 54 | // Stop the local process. |
| 55 | void stopProcess(bool immediate = true); |
| 56 | |
| 57 | status_t transact(int32_t handle, |
| 58 | uint32_t code, const Parcel& data, |
| 59 | Parcel* reply, uint32_t flags); |
| 60 | |
| 61 | void incStrongHandle(int32_t handle); |
| 62 | void decStrongHandle(int32_t handle); |
| 63 | void incWeakHandle(int32_t handle); |
| 64 | void decWeakHandle(int32_t handle); |
| 65 | status_t attemptIncStrongHandle(int32_t handle); |
| 66 | static void expungeHandle(int32_t handle, IBinder* binder); |
| 67 | status_t requestDeathNotification( int32_t handle, |
| 68 | BpBinder* proxy); |
| 69 | status_t clearDeathNotification( int32_t handle, |
| 70 | BpBinder* proxy); |
| 71 | |
| 72 | static void shutdown(); |
| 73 | |
Dianne Hackborn | 887f355 | 2009-12-07 17:59:37 -0800 | [diff] [blame] | 74 | // Call this to disable switching threads to background scheduling when |
| 75 | // receiving incoming IPC calls. This is specifically here for the |
| 76 | // Android system process, since it expects to have background apps calling |
| 77 | // in to it but doesn't want to acquire locks in its services while in |
| 78 | // the background. |
| 79 | static void disableBackgroundScheduling(bool disable); |
| 80 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | private: |
| 82 | IPCThreadState(); |
| 83 | ~IPCThreadState(); |
| 84 | |
| 85 | status_t sendReply(const Parcel& reply, uint32_t flags); |
| 86 | status_t waitForResponse(Parcel *reply, |
| 87 | status_t *acquireResult=NULL); |
| 88 | status_t talkWithDriver(bool doReceive=true); |
| 89 | status_t writeTransactionData(int32_t cmd, |
| 90 | uint32_t binderFlags, |
| 91 | int32_t handle, |
| 92 | uint32_t code, |
| 93 | const Parcel& data, |
| 94 | status_t* statusBuffer); |
| 95 | status_t executeCommand(int32_t command); |
| 96 | |
| 97 | void clearCaller(); |
| 98 | |
| 99 | static void threadDestructor(void *st); |
| 100 | static void freeBuffer(Parcel* parcel, |
| 101 | const uint8_t* data, size_t dataSize, |
| 102 | const size_t* objects, size_t objectsSize, |
| 103 | void* cookie); |
| 104 | |
| 105 | const sp<ProcessState> mProcess; |
Dianne Hackborn | 887f355 | 2009-12-07 17:59:37 -0800 | [diff] [blame] | 106 | const pid_t mMyThreadId; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | Vector<BBinder*> mPendingStrongDerefs; |
| 108 | Vector<RefBase::weakref_type*> mPendingWeakDerefs; |
Dianne Hackborn | 887f355 | 2009-12-07 17:59:37 -0800 | [diff] [blame] | 109 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | Parcel mIn; |
| 111 | Parcel mOut; |
| 112 | status_t mLastError; |
| 113 | pid_t mCallingPid; |
| 114 | uid_t mCallingUid; |
Brad Fitzpatrick | 27b3a7a | 2010-06-18 13:07:53 -0700 | [diff] [blame^] | 115 | int32_t mStrictModePolicy; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | }; |
Brad Fitzpatrick | 27b3a7a | 2010-06-18 13:07:53 -0700 | [diff] [blame^] | 117 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | }; // namespace android |
| 119 | |
| 120 | // --------------------------------------------------------------------------- |
| 121 | |
| 122 | #endif // ANDROID_IPC_THREAD_STATE_H |