blob: 04e24d29a6fd5987ba09217ee6c375e178cec1f8 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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 Agopian07952722009-05-19 19:08:10 -070021#include <binder/Parcel.h>
22#include <binder/ProcessState.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023#include <utils/Vector.h>
24
25#ifdef HAVE_WIN32_PROC
26typedef int uid_t;
27#endif
28
29// ---------------------------------------------------------------------------
30namespace android {
31
32class IPCThreadState
33{
34public:
35 static IPCThreadState* self();
36
37 sp<ProcessState> process();
38
39 status_t clearLastError();
40
41 int getCallingPid();
42 int getCallingUid();
Brad Fitzpatrick27b3a7a2010-06-18 13:07:53 -070043
44 void setStrictModePolicy(int32_t policy);
45 int32_t getStrictModePolicy() const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046
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 Hackborn887f3552009-12-07 17:59:37 -080074 // 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 Project9066cfe2009-03-03 19:31:44 -080081private:
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 Hackborn887f3552009-12-07 17:59:37 -0800106 const pid_t mMyThreadId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 Vector<BBinder*> mPendingStrongDerefs;
108 Vector<RefBase::weakref_type*> mPendingWeakDerefs;
Dianne Hackborn887f3552009-12-07 17:59:37 -0800109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 Parcel mIn;
111 Parcel mOut;
112 status_t mLastError;
113 pid_t mCallingPid;
114 uid_t mCallingUid;
Brad Fitzpatrick27b3a7a2010-06-18 13:07:53 -0700115 int32_t mStrictModePolicy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116};
Brad Fitzpatrick27b3a7a2010-06-18 13:07:53 -0700117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118}; // namespace android
119
120// ---------------------------------------------------------------------------
121
122#endif // ANDROID_IPC_THREAD_STATE_H