liyujie
2025-08-28 d9927380ed7c8366f762049be9f3fee225860833
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#include <stdio.h>
#include <stdlib.h>
#include <utils/Log.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdio.h>
#include <cutils/properties.h>
#include <hardware/power.h>
#include "power-common.h"
 
static Power_Perfromance_State g_cur_power_state_test = POWER_STATE_NORMAL;
 
void sysfs_write(const char *path, char *s)
{
    char buf[64];
    int len;
    int fd = open(path, O_WRONLY);
    if (fd < 0)
    {
        strerror_r(errno, buf, sizeof(buf));
        //ALOGE("Error opening %s: %s\n", path, buf);
        return;
    }
    len = write(fd, s, strlen(s));
    if (len < 0)
    {
        strerror_r(errno, buf, sizeof(buf));
        //ALOGE("Error writing to %s: %s\n", path, buf);
    }
    close(fd);
}
 
void cpufreq_max_get(const char *path, char *s)
{
    char *max_freq, *p, buf[64], cpu_opp[128] = {0};
    int len, fd;
 
    fd = open(path, O_RDONLY);
    if (fd < 0) {
        strerror_r(errno, buf, sizeof(buf));
        ALOGE("Error opening %s: %s\n", path, buf);
        return;
    }
    len = read(fd, cpu_opp, sizeof(cpu_opp));
    if (len < 0) {
        strerror_r(errno, buf, sizeof(buf));
        ALOGE("Error reading from %s: %s\n", path, buf);
    }
    close(fd);
 
    for (p = cpu_opp, max_freq = p; ; p++) {
        if (strncmp(p, " ", 1))
            continue;
        if (!strncmp(p + 1, "\n", 1))
           break;
 
        max_freq = p + 1;
    }
 
    memcpy(s, max_freq, 8);
}
 
Power_Perfromance_State get_cur_power_state() {
   return g_cur_power_state_test;
}
 
void set_power_state(Power_Perfromance_State state) {
   g_cur_power_state_test = state;
}
 
 
void  command_power_hint(int hint, void *data)
{
 
   int parmdata = 0; //default value=0 if data is null pointer
   if(data != NULL) {
       parmdata = *((int* )data);
   }
 
   power_hint_platform(hint,parmdata);
 
 }
 
 
int main(int argc, char **argv)
{
    char propval[100]={0};
    if(argc<2 )
    {
        printf("missing arguments\n");
        return 0;
    }
    if(!strcmp(argv[1],"resume"))
    {
        if(argc!= 2)
        {
            printf("Usage:resume");
            return -1;
        }
        printf("quit debug mode!\n");
        property_set("persist.vendor.p_debug","false");
        property_set("persist.vendor.p_bootcomplete","true");
        property_set("persist.vendor.p_benchmark","true");
        property_set("persist.vendor.p_normal","true");
        property_set("persist.vendor.p_music","true");
        return 0;
    }
 
    if(!strcmp(argv[1],"enter"))
    {
        if(!strcmp("benchmark", argv[2]))
        {
            if(argc!=4)
            {
                printf("Usage:enter benchmark [pid0]\n");
                return -1;
            }
            property_get("persist.vendor.p_benchmark", propval,"false");
            if(!strcmp(propval,"false"))
            {
                printf("benchmark mode has been disabled!\n");
                return -1;
            }
            property_set("persist.vendor.p_debug","true");
            command_power_hint(POWER_HINT_BENCHMARK, argv[3]);
            printf("benchmark succeed!\n");
        }
 
        else if(!strcmp("normal",argv[2]))
        {
            if(argc!=3)
            {
                printf("Usage:enter normal\n");
                return -1;
            }
            property_get("persist.vendor.p_normal",propval,"false");
            if(!strcmp(propval,"false"))
            {
                printf("normal mode has been disabled!\n");
                return -1;
            }
            property_set("persist.vendor.p_debug","true");
            command_power_hint(POWER_HINT_NORMAL, "1");
            printf("normal succeed!\n");
        }
        else if(!strcmp("music",argv[2]))
        {
            if(argc!=3)
            {
                printf("Usage:enter music\n");
                return -1;
            }
            property_get("persist.vendor.p_music" , propval,"false");
            if(!strcmp(propval,"false"))
            {
                printf("music mode has been disabled!\n");
                return -1;
            }
            property_set("persist.vendor.p_debug","true");
            command_power_hint(POWER_HINT_BG_MUSIC, "2");
            printf("music succeed!\n");
        }
 
        else if(!strcmp("bootcomplete",argv[2]))
        {
            if(argc!=3)
            {
                printf("Usage:enter bootcomplete\n");
                return -1;
            }
            property_get("persist.vendor.p_bootcomplete",propval,"false");
            if(!strcmp(propval,"false"))
            {
                printf("benchmark mode has been disabled!\n");
                return -1;
            }
            property_set("persist.vendor.p_debug","true");
            command_power_hint(POWER_HINT_BOOTCOMPLETE,"false");
            printf("bootcomplete succeed!\n");
        }
        else
        {
            printf("un-defined command:%s!\n", argv[1]);
            return -1;
        }
    }
 
    else if(!strcmp(argv[1],"enable"))
    {
        if(!strcmp("benchmark", argv[2]))
        {
            if(argc!=3)
            {
                printf("Usage:enable benchmark");
                return -1;
            }
            property_set("persist.vendor.p_benchmark","true");
            printf("enable benchmark succeed!\n");
        }
        else if(!strcmp("normal", argv[2]))
        {
            if(argc!=3)
            {
                printf("Usage:enable normal\n");
                return -1;
            }
            property_set("persist.vendor.p_normal","true");
            printf("enable normal  succeed!\n");
        }
 
        else if(!strcmp("music", argv[2]))
        {
            if(argc!=3)
            {
                printf("Usage:enable music\n");
                return -1;
            }
            property_set("persist.vendor.p_music","true");
            printf("enable music succeed!\n");
        }
 
        else  if(!strcmp("bootcomplete", argv[2]))
        {
            if(argc!=3)
            {
                printf("Usage:enable bootcomplete\n");
                return -1;
            }
            property_set("persist.vendor.p_bootcomplete","true");
            printf("enable bootcomplete succeed!\n");
        }
        else
        {
            printf("un-defined command:%s!\n",argv[1] );
            return -1;
        }
    }
 
 
    else if(!strcmp(argv[1],"disable"))
    {
        if(!strcmp("benchmark", argv[2]))
        {
            if(argc!=3)
            {
                printf("Usage:disable benchmark");
                return -1;
            }
            property_set("persist.vendor.p_benchmark","false");
            printf("disable benchmark succeed!\n");
        }
        else if(!strcmp("normal", argv[2]))
        {
            if(argc!=3)
            {
                printf("Usage:disable normal\n");
                return -1;
            }
            property_set("persist.vendor.p_normal","false");
            printf("disable normal succeed!\n");
        }
        else if(!strcmp("music", argv[2]))
        {
            if(argc!=3)
            {
                printf("Usage:disable music\n");
                return -1;
            }
            property_set("persist.vendor.p_music","false");
            printf("disable music succeed!\n");
        }
 
        else  if(!strcmp("bootcomplete", argv[2]))
        {
            if(argc!=3)
            {
                printf("Usage:disable bootcomplete\n");
                return -1;
            }
            property_set("persist.vendor.p_bootcomplete","false");
            printf("disable bootcomplete succeed!\n");
        }
        else
        {
            printf("un-defined command:%s\n", argv[1]);
            return -1;
        }
    }
 
    else
    {
        printf("un-defined command:%s\n",argv[1]);
        return -1;
    }
    return 0;
}