17
17
18
18
#include < unistd.h>
19
19
#include < android_runtime/ActivityManager.h>
20
+ #ifdef SU_LEGACY_BUILD
21
+ #include < utils/IBinder.h>
22
+ #include < utils/IServiceManager.h>
23
+ #include < utils/Parcel.h>
24
+ #else
20
25
#include < binder/IBinder.h>
21
26
#include < binder/IServiceManager.h>
22
27
#include < binder/Parcel.h>
28
+ #endif
23
29
#include < utils/String8.h>
24
30
#include < assert.h>
25
31
26
32
extern " C" {
27
33
#include " su.h"
28
- #include < private/android_filesystem_config.h>
29
- #include < cutils/properties.h>
30
34
}
31
35
32
36
using namespace android ;
@@ -40,13 +44,9 @@ static const int VAL_INTEGER = 1;
40
44
41
45
static const int START_SUCCESS = 0 ;
42
46
43
- int send_intent (struct su_initiator *from, struct su_request *to, const char *socket_path, int allow, int type)
47
+ int send_intent (const struct su_context *ctx,
48
+ const char *socket_path, int allow, const char *action)
44
49
{
45
- char sdk_version_prop[PROPERTY_VALUE_MAX] = " 0" ;
46
- property_get (" ro.build.version.sdk" , sdk_version_prop, " 0" );
47
-
48
- int sdk_version = atoi (sdk_version_prop);
49
-
50
50
sp<IServiceManager> sm = defaultServiceManager ();
51
51
sp<IBinder> am = sm->checkService (String16 (" activity" ));
52
52
assert (am != NULL );
@@ -57,54 +57,50 @@ int send_intent(struct su_initiator *from, struct su_request *to, const char *so
57
57
data.writeStrongBinder (NULL ); /* caller */
58
58
59
59
/* intent */
60
- if (type == 0 ) {
61
- data.writeString16 (String16 (" com.noshufou.android.su.REQUEST" )); /* action */
62
- } else {
63
- data.writeString16 (String16 (" com.noshufou.android.su.RESULT" )); /* action */
64
- }
60
+ data.writeString16 (String16 (action)); /* action */
65
61
data.writeInt32 (NULL_TYPE_ID); /* Uri - data */
66
62
data.writeString16 (NULL , 0 ); /* type */
67
63
data.writeInt32 (0 ); /* flags */
68
- if (sdk_version >= 4 ) {
64
+ if (ctx-> sdk_version >= 4 ) {
69
65
// added in donut
70
66
data.writeString16 (NULL , 0 ); /* package name - DONUT ONLY, NOT IN CUPCAKE. */
71
67
}
72
68
data.writeString16 (NULL , 0 ); /* ComponentName - package */
73
- data.writeInt32 (0 ); /* Categories - size */
74
- if (sdk_version >= 7 ) {
69
+ if (ctx->sdk_version >= 7 ) {
75
70
// added in eclair rev 7
76
- data.writeInt32 (0 );
71
+ data.writeInt32 (0 ); /* Rect - the bounds of the sender */
77
72
}
78
- if (sdk_version >= 15 ) {
73
+ data.writeInt32 (0 ); /* Categories - size */
74
+ if (ctx->sdk_version >= 15 ) {
79
75
// added in IceCreamSandwich 4.0.3
80
76
data.writeInt32 (0 ); /* Selector */
81
77
}
82
78
{ /* Extras */
83
79
data.writeInt32 (-1 ); /* dummy, will hold length */
84
- int oldPos = data.dataPosition ();
85
80
data.writeInt32 (0x4C444E42 ); // 'B' 'N' 'D' 'L'
81
+ int oldPos = data.dataPosition ();
86
82
{ /* writeMapInternal */
87
83
data.writeInt32 (7 ); /* writeMapInternal - size */
88
84
89
85
data.writeInt32 (VAL_STRING);
90
86
data.writeString16 (String16 (" caller_uid" ));
91
87
data.writeInt32 (VAL_INTEGER);
92
- data.writeInt32 (from-> uid );
88
+ data.writeInt32 (ctx-> from . uid );
93
89
94
90
data.writeInt32 (VAL_STRING);
95
91
data.writeString16 (String16 (" caller_bin" ));
96
92
data.writeInt32 (VAL_STRING);
97
- data.writeString16 (String16 (from-> bin ));
93
+ data.writeString16 (String16 (ctx-> from . bin ));
98
94
99
95
data.writeInt32 (VAL_STRING);
100
96
data.writeString16 (String16 (" desired_uid" ));
101
97
data.writeInt32 (VAL_INTEGER);
102
- data.writeInt32 (to-> uid );
98
+ data.writeInt32 (ctx-> to . uid );
103
99
104
100
data.writeInt32 (VAL_STRING);
105
101
data.writeString16 (String16 (" desired_cmd" ));
106
102
data.writeInt32 (VAL_STRING);
107
- data.writeString16 (String16 (to-> command ));
103
+ data.writeString16 (String16 (get_command (&ctx-> to ) ));
108
104
109
105
data.writeInt32 (VAL_STRING);
110
106
data.writeString16 (String16 (" socket" ));
@@ -122,15 +118,13 @@ int send_intent(struct su_initiator *from, struct su_request *to, const char *so
122
118
data.writeInt32 (VERSION_CODE);
123
119
}
124
120
int newPos = data.dataPosition ();
125
- data.setDataPosition (oldPos - 4 );
121
+ data.setDataPosition (oldPos - 8 );
126
122
data.writeInt32 (newPos - oldPos); /* length */
127
123
data.setDataPosition (newPos);
128
124
}
129
125
130
126
data.writeString16 (NULL , 0 ); /* resolvedType */
131
127
132
- data.writeInt32 (-1 ); /* Not sure what this is for, but it prevents a warning */
133
-
134
128
data.writeStrongBinder (NULL ); /* resultTo */
135
129
data.writeInt32 (-1 ); /* resultCode */
136
130
data.writeString16 (NULL , 0 ); /* resultData */
@@ -140,7 +134,6 @@ int send_intent(struct su_initiator *from, struct su_request *to, const char *so
140
134
data.writeString16 (String16 (" com.noshufou.android.su.RESPOND" )); /* perm */
141
135
data.writeInt32 (0 ); /* serialized */
142
136
data.writeInt32 (0 ); /* sticky */
143
- data.writeInt32 (-1 );
144
137
145
138
status_t ret = am->transact (BROADCAST_INTENT_TRANSACTION, data, &reply);
146
139
if (ret < START_SUCCESS) return -1 ;
0 commit comments