| 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 |  | 
| Yabin Cui | 0dd549a | 2014-11-11 09:26:00 -0800 | [diff] [blame] | 25 | #if defined(_WIN32) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 |  | 
| Dan Stoza | 9c634fd | 2014-11-26 12:23:23 -0800 | [diff] [blame] | 42 |             pid_t               getCallingPid() const; | 
 | 43 |             uid_t               getCallingUid() const; | 
| Brad Fitzpatrick | 702ea9d | 2010-06-18 13:07:53 -0700 | [diff] [blame] | 44 |  | 
 | 45 |             void                setStrictModePolicy(int32_t policy); | 
 | 46 |             int32_t             getStrictModePolicy() const; | 
| Brad Fitzpatrick | 5273603 | 2010-08-30 16:01:16 -0700 | [diff] [blame] | 47 |  | 
 | 48 |             void                setLastTransactionBinderFlags(int32_t flags); | 
 | 49 |             int32_t             getLastTransactionBinderFlags() const; | 
 | 50 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 |             int64_t             clearCallingIdentity(); | 
 | 52 |             void                restoreCallingIdentity(int64_t token); | 
 | 53 |              | 
| Todd Poynor | 8d96cab | 2013-06-25 19:12:18 -0700 | [diff] [blame] | 54 |             int                 setupPolling(int* fd); | 
 | 55 |             status_t            handlePolledCommands(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 |             void                flushCommands(); | 
 | 57 |  | 
 | 58 |             void                joinThreadPool(bool isMain = true); | 
 | 59 |              | 
 | 60 |             // Stop the local process. | 
 | 61 |             void                stopProcess(bool immediate = true); | 
 | 62 |              | 
 | 63 |             status_t            transact(int32_t handle, | 
 | 64 |                                          uint32_t code, const Parcel& data, | 
 | 65 |                                          Parcel* reply, uint32_t flags); | 
 | 66 |  | 
 | 67 |             void                incStrongHandle(int32_t handle); | 
 | 68 |             void                decStrongHandle(int32_t handle); | 
 | 69 |             void                incWeakHandle(int32_t handle); | 
 | 70 |             void                decWeakHandle(int32_t handle); | 
 | 71 |             status_t            attemptIncStrongHandle(int32_t handle); | 
 | 72 |     static  void                expungeHandle(int32_t handle, IBinder* binder); | 
 | 73 |             status_t            requestDeathNotification(   int32_t handle, | 
 | 74 |                                                             BpBinder* proxy);  | 
 | 75 |             status_t            clearDeathNotification( int32_t handle, | 
 | 76 |                                                         BpBinder* proxy);  | 
 | 77 |  | 
 | 78 |     static  void                shutdown(); | 
| Wale Ogunwale | 376b822 | 2015-04-13 16:16:10 -0700 | [diff] [blame] | 79 |  | 
| Dianne Hackborn | 8c6cedc | 2009-12-07 17:59:37 -0800 | [diff] [blame] | 80 |     // Call this to disable switching threads to background scheduling when | 
 | 81 |     // receiving incoming IPC calls.  This is specifically here for the | 
 | 82 |     // Android system process, since it expects to have background apps calling | 
 | 83 |     // in to it but doesn't want to acquire locks in its services while in | 
 | 84 |     // the background. | 
 | 85 |     static  void                disableBackgroundScheduling(bool disable); | 
| Wale Ogunwale | 376b822 | 2015-04-13 16:16:10 -0700 | [diff] [blame] | 86 |  | 
 | 87 |             // Call blocks until the number of executing binder threads is less than | 
 | 88 |             // the maximum number of binder threads threads allowed for this process. | 
 | 89 |             void                blockUntilThreadAvailable(); | 
 | 90 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | private: | 
 | 92 |                                 IPCThreadState(); | 
 | 93 |                                 ~IPCThreadState(); | 
 | 94 |  | 
 | 95 |             status_t            sendReply(const Parcel& reply, uint32_t flags); | 
 | 96 |             status_t            waitForResponse(Parcel *reply, | 
 | 97 |                                                 status_t *acquireResult=NULL); | 
 | 98 |             status_t            talkWithDriver(bool doReceive=true); | 
 | 99 |             status_t            writeTransactionData(int32_t cmd, | 
 | 100 |                                                      uint32_t binderFlags, | 
 | 101 |                                                      int32_t handle, | 
 | 102 |                                                      uint32_t code, | 
 | 103 |                                                      const Parcel& data, | 
 | 104 |                                                      status_t* statusBuffer); | 
| Todd Poynor | 8d96cab | 2013-06-25 19:12:18 -0700 | [diff] [blame] | 105 |             status_t            getAndExecuteCommand(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 |             status_t            executeCommand(int32_t command); | 
| Todd Poynor | 8d96cab | 2013-06-25 19:12:18 -0700 | [diff] [blame] | 107 |             void                processPendingDerefs(); | 
| Wale Ogunwale | 376b822 | 2015-04-13 16:16:10 -0700 | [diff] [blame] | 108 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 |             void                clearCaller(); | 
| Wale Ogunwale | 376b822 | 2015-04-13 16:16:10 -0700 | [diff] [blame] | 110 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 |     static  void                threadDestructor(void *st); | 
 | 112 |     static  void                freeBuffer(Parcel* parcel, | 
 | 113 |                                            const uint8_t* data, size_t dataSize, | 
| Arve Hjønnevåg | 84e625a | 2014-01-28 20:12:59 -0800 | [diff] [blame] | 114 |                                            const binder_size_t* objects, size_t objectsSize, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 |                                            void* cookie); | 
 | 116 |      | 
 | 117 |     const   sp<ProcessState>    mProcess; | 
| Dianne Hackborn | 8c6cedc | 2009-12-07 17:59:37 -0800 | [diff] [blame] | 118 |     const   pid_t               mMyThreadId; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 |             Vector<BBinder*>    mPendingStrongDerefs; | 
 | 120 |             Vector<RefBase::weakref_type*> mPendingWeakDerefs; | 
| Wale Ogunwale | 376b822 | 2015-04-13 16:16:10 -0700 | [diff] [blame] | 121 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 |             Parcel              mIn; | 
 | 123 |             Parcel              mOut; | 
 | 124 |             status_t            mLastError; | 
 | 125 |             pid_t               mCallingPid; | 
 | 126 |             uid_t               mCallingUid; | 
| Brad Fitzpatrick | 702ea9d | 2010-06-18 13:07:53 -0700 | [diff] [blame] | 127 |             int32_t             mStrictModePolicy; | 
| Brad Fitzpatrick | 5273603 | 2010-08-30 16:01:16 -0700 | [diff] [blame] | 128 |             int32_t             mLastTransactionBinderFlags; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | }; | 
| Brad Fitzpatrick | 702ea9d | 2010-06-18 13:07:53 -0700 | [diff] [blame] | 130 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | }; // namespace android | 
 | 132 |  | 
 | 133 | // --------------------------------------------------------------------------- | 
 | 134 |  | 
 | 135 | #endif // ANDROID_IPC_THREAD_STATE_H |