ronnie
2022-10-23 eadd9db01b24ccde96a129dafa989d4ec436cdfd
add ido services,delete boot on window
1 files modified
4 files added
1183 ■■■■■ changed files
android/packages/apps/Settings/src/com/android/settings/FallbackHome.java 8 ●●●● patch | view | raw | blame | history
android/packages/apps/Settings/src/com/android/settings/IdoDevCustomService.java 965 ●●●●● patch | view | raw | blame | history
android/packages/apps/Settings/src/com/android/settings/InstallResultReceiver.java 48 ●●●●● patch | view | raw | blame | history
android/packages/apps/Settings/src/com/android/settings/InstallUtils.java 142 ●●●●● patch | view | raw | blame | history
android/packages/apps/Settings/src/com/android/settings/MyBootReceiver.java 20 ●●●●● patch | view | raw | blame | history
android/packages/apps/Settings/src/com/android/settings/FallbackHome.java
....@@ -49,9 +49,9 @@
4949 private WallpaperManager mWallManager;
5050
5151 private final Runnable mProgressTimeoutRunnable = () -> {
52
- View v = getLayoutInflater().inflate(
53
- R.layout.fallback_home_finishing_boot, null /* root */);
54
- setContentView(v);
52
+ //View v = getLayoutInflater().inflate(
53
+ // R.layout.fallback_home_finishing_boot, null /* root */);
54
+ /*setContentView(v);
5555 v.setAlpha(0f);
5656 v.animate()
5757 .alpha(1f)
....@@ -59,7 +59,7 @@
5959 .setInterpolator(AnimationUtils.loadInterpolator(
6060 this, android.R.interpolator.fast_out_slow_in))
6161 .start();
62
- getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
62
+ getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);*/
6363 };
6464
6565 private final OnColorsChangedListener mColorsChangedListener = new OnColorsChangedListener() {
android/packages/apps/Settings/src/com/android/settings/IdoDevCustomService.java
....@@ -0,0 +1,965 @@
1
+package com.android.settings;
2
+
3
+import android.app.PendingIntent;
4
+import android.app.Service;
5
+import android.content.BroadcastReceiver;
6
+import android.content.Context;
7
+import android.content.Intent;
8
+import android.content.IntentFilter;
9
+import android.content.ComponentName;
10
+import android.os.IBinder;
11
+import android.os.PowerManager;
12
+import android.os.SystemClock;
13
+import android.util.Log;
14
+import android.os.Handler;
15
+import android.os.Environment;
16
+import android.os.Binder;
17
+import android.os.Build;
18
+import android.os.ServiceManager;
19
+
20
+import java.io.BufferedReader;
21
+import java.io.InputStreamReader;
22
+import java.io.File;
23
+import java.io.FileInputStream;
24
+import java.io.FileOutputStream;
25
+import java.io.FileReader;
26
+import java.io.FileWriter;
27
+import java.io.IOException;
28
+import java.text.SimpleDateFormat;
29
+import java.util.Calendar;
30
+import java.util.Date;
31
+import java.io.FileWriter;
32
+import java.util.List;
33
+
34
+import android.os.SystemProperties;
35
+import android.content.pm.PackageManager;
36
+import android.content.pm.IPackageManager;
37
+import android.content.pm.PackageInfo;
38
+import android.content.pm.ApplicationInfo;
39
+import android.text.TextUtils;
40
+import android.provider.Settings;
41
+import android.app.ActivityManager;
42
+import android.net.Uri;
43
+import android.app.PackageInstallObserver;
44
+import android.content.pm.ResolveInfo;
45
+import android.app.AlarmManager;
46
+
47
+import android.net.wifi.WifiConfiguration;
48
+import android.net.wifi.WifiManager;
49
+import android.net.wifi.WifiConfiguration.AuthAlgorithm;
50
+import android.net.wifi.WifiConfiguration.KeyMgmt;
51
+
52
+import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
53
+
54
+import org.ido.iface.DeviceCtrl;
55
+
56
+import android.os.ServiceManager;
57
+import android.os.Parcel;
58
+import android.os.RemoteException;
59
+
60
+//import com.android.settings.development;
61
+
62
+
63
+public class IdoDevCustomService extends Service {
64
+
65
+ private static final String TAG = "IdoDevCustomService";
66
+
67
+ private static final String ACTION_APK_INSTALL = "android.intent.action.SILENT_INSTALL_PACKAGE";
68
+ private static final String ACTION_TOUCH_TEST = "android.ido.intent.action.touchtest";
69
+ private static final String ACTION_IDO_SET_REBOOT = "android.ido.intent.action.set.reboot";
70
+ private static final String ACTION_IDO_SET_SHUTDOWN = "android.ido.intent.action.set.shutdown";
71
+ private static final String ACTION_IDO_SET_FACTORY = "android.ido.intent.action.set.factory";
72
+ private static final String ACTION_IDO_SET_AIRPLANE_MODE = "android.ido.intent.action.set.airPlaneMode";
73
+ private static final String ACTION_IDO_SET_APP_CHECK = "android.ido.intent.action.set.appcheck";
74
+
75
+ private static final String ACTION_IDO_SCREEN_SHOT = "android.ido.intent.action.screenshot";
76
+ private static final String ACTION_IDO_SET_TIME = "android.ido.intent.action.settime";
77
+ private static final String ACTION_IDO_SET_WIFIAP = "android.ido.intent.action.wifiap";
78
+
79
+ private static final String ACTION_IDO_SET_SCREEN_BRIGHTNESS = "android.ido.action.screen.brightness";
80
+ private static final String ACTION_IDO_SET_SCREEN = "android.ido.action.screen.set";
81
+ private static final String ACTION_IDO_SET_SCREEN_ONOFF_GET = "android.ido.action.screenoff.get";
82
+ private static final String ACTION_IDO_SET_TIMEOUT_SLEEP = "android.ido.action.sleep.set";
83
+ private static final String ACTION_IDO_GET_TIMEOUT_SLEEP = "android.ido.action.sleep.get";
84
+ private static final String ACTION_IDO_SET_LAUNCHER = "android.ido.intent.action.launcher";
85
+ private static final String ACTION_IDO_GET_APK_INSTALLED = "android.ido.intent.action.apk.installed";
86
+ private static final String ACTION_IDO_SET_ADB = "android.ido.intent.action.adb";
87
+ private static final String ACTION_IDO_SET_INPUT = "android.ido.intent.action.reset.sleep";
88
+
89
+ private Context mContext;
90
+
91
+ private static final boolean DEBUG = true;
92
+
93
+ private static final int PACKAGE_NAME_START_INDEX = 8;
94
+
95
+ private static final int CHECK_APP_LOOP_TIME = 2100;//ms
96
+
97
+ private static final int TS_CHECK_LOOP_TIME1 = 1000;//ms
98
+ private static final int TS_CHECK_LOOP_TIME2 = 230;//ms
99
+ private static int NO_TOUCH_CNT_TIMEOUT = 600;//600;//10分钟
100
+
101
+ private static String installPackageName="";
102
+ private static String installClassName="";
103
+
104
+ private boolean installedStartActivityFlag=false;
105
+
106
+ private static boolean enableAppCheck=false;
107
+ private static String checkPackageName="";
108
+ private static String runClassName="";
109
+ private static int checkAppCnt=5;//检测APP是否在界面显示的次数,大于此次数还没有发现APP在前端运行则重启app
110
+ private static int checkAppErrCnt=0;
111
+
112
+ private AlarmManager mAlarmManager = null;
113
+
114
+ private WifiManager mWifiManager;
115
+ private WifiConfiguration mWifiConfig = null;
116
+ private int wifiApState = WifiManager.WIFI_AP_STATE_DISABLED;
117
+ private boolean restartWifiApFlag=false;
118
+
119
+ private static int lastTsCnt,noTouchDataCnt,onTouchFlag=0;
120
+
121
+ private IBinder mSurfaceFlinger;
122
+
123
+ //private static int blBrightness;
124
+
125
+ private DeviceCtrl mDevCtrl;
126
+ private static int ts_check_loop_time=TS_CHECK_LOOP_TIME1;
127
+
128
+
129
+ @Override
130
+ public IBinder onBind(Intent arg0) {
131
+ // TODO Auto-generated method stub
132
+ return null;
133
+ }
134
+
135
+ @Override
136
+ public void onCreate() {
137
+ super.onCreate();
138
+
139
+ if(DEBUG) Log.d(TAG, "-----------------onCreate()");
140
+
141
+ mContext = this;
142
+
143
+ IntentFilter mFilter = new IntentFilter();
144
+ IntentFilter mFilter2 = new IntentFilter();
145
+
146
+ mFilter.addAction(ACTION_APK_INSTALL);
147
+ mFilter.addAction(ACTION_TOUCH_TEST);
148
+ mFilter.addAction(ACTION_IDO_SET_REBOOT);
149
+ mFilter.addAction(ACTION_IDO_SET_SHUTDOWN);
150
+ mFilter.addAction(ACTION_IDO_SET_FACTORY);
151
+ mFilter.addAction(ACTION_IDO_SET_AIRPLANE_MODE);
152
+ mFilter.addAction(ACTION_IDO_SET_APP_CHECK);
153
+ mFilter.addAction(ACTION_IDO_SCREEN_SHOT);
154
+ mFilter.addAction(ACTION_IDO_SET_TIME);
155
+ mFilter.addAction(ACTION_IDO_SET_WIFIAP);
156
+ mFilter.addAction(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
157
+ mFilter.addAction(ACTION_IDO_SET_SCREEN_BRIGHTNESS);
158
+ mFilter.addAction(ACTION_IDO_SET_SCREEN);
159
+ mFilter.addAction(ACTION_IDO_SET_SCREEN_ONOFF_GET);
160
+ mFilter.addAction(ACTION_IDO_SET_LAUNCHER);
161
+ mFilter.addAction(ACTION_IDO_SET_TIMEOUT_SLEEP);
162
+ mFilter.addAction(ACTION_IDO_GET_TIMEOUT_SLEEP);
163
+ mFilter.addAction(ACTION_IDO_SET_ADB);
164
+ mFilter.addAction(ACTION_IDO_SET_INPUT);
165
+
166
+ registerReceiver(mReceiver, mFilter);
167
+
168
+ mFilter2.addAction(Intent.ACTION_PACKAGE_ADDED);
169
+ //mFilter2.addAction(Intent.ACTION_PACKAGE_REPLACED);//替换安装也会有ADDED广播
170
+ mFilter2.addDataScheme("package");
171
+ registerReceiver(mReceiver2, mFilter2);
172
+
173
+ try {
174
+ mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
175
+ } catch (Exception e) {
176
+ Log.e(TAG, "Get AlarmManager error!\n");
177
+ e.printStackTrace();
178
+ }
179
+
180
+ try {
181
+ mDevCtrl = new DeviceCtrl();
182
+ //blBrightness = getSystemBrightness();
183
+ } catch (Exception e) {
184
+ Log.e(TAG, "DeviceCtrl error!\n");
185
+ e.printStackTrace();
186
+ }
187
+
188
+ try {
189
+ if ("true".equals(SystemProperties.get("persist.ido.appcheck.enable","false"))) {
190
+
191
+ checkPackageName = SystemProperties.get("persist.ido.appcheck.packageName","");
192
+ runClassName = SystemProperties.get("persist.ido.appcheck.className","");
193
+ checkAppCnt = Integer.parseInt(SystemProperties.get("persist.ido.appcheck.checkCnt","3"));//unit:2s,//检测APP是否在界面显示的次数,大于此次数还没有发现APP在前端运行则重启app,默认3次
194
+
195
+ if (runClassName.equals("") == false && runClassName.equals("") == false) {
196
+ mHandler.postDelayed(appCheckRunnable, 2 * CHECK_APP_LOOP_TIME);
197
+ enableAppCheck = true;
198
+ }
199
+ }
200
+
201
+ NO_TOUCH_CNT_TIMEOUT = Integer.parseInt(SystemProperties.get("persist.ido.screen.timeout","600"));
202
+ Log.d(TAG, "set no touch screen timeout:" + NO_TOUCH_CNT_TIMEOUT);
203
+
204
+ //mHandler.postDelayed(noTouchCheckRunnable, TS_CHECK_LOOP_TIME1);
205
+
206
+ } catch (Exception e) {
207
+ Log.e(TAG, "error:\n" + e);
208
+ e.printStackTrace();
209
+ }
210
+
211
+ //mSurfaceFlinger = ServiceManager.getService("android.ui.ISurfaceComposer");
212
+ //try {
213
+ // final Parcel data = Parcel.obtain();
214
+ // data.writeInterfaceToken("android.ui.ISurfaceComposer");
215
+ // data.writeInt(1);
216
+ // mSurfaceFlinger.transact(1008, data, null, 0);
217
+ // Log.d(TAG, "----------------- run mSurfaceFlinger.transact(1008)");
218
+ //}catch (RemoteException ex) {
219
+ // Log.d(TAG, "----------------- mSurfaceFlinger.transact error");
220
+ //}
221
+ }
222
+
223
+ @Override
224
+ public void onDestroy() {
225
+ unregisterReceiver(mReceiver);
226
+ unregisterReceiver(mReceiver2);
227
+ super.onDestroy();
228
+ }
229
+
230
+ private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
231
+ @Override
232
+ public void onReceive(Context context, Intent intent) {
233
+ try {
234
+ String action = intent.getAction();
235
+ if(action.equals(ACTION_APK_INSTALL)) {
236
+ String path = intent.getStringExtra("apkFilePath");
237
+ if (path != null) {
238
+ installPackageName = getPackage(mContext,path);
239
+ if (installPackageName != null) {
240
+ if (intent.getBooleanExtra("allPrms",false)) {
241
+ SystemProperties.set("persist.app.grant.prms",installPackageName);
242
+ }
243
+ silentInstallApk(path);
244
+ if (intent.getBooleanExtra("autostart",false)) {
245
+ installedStartActivityFlag = true;
246
+ }
247
+ }
248
+ }
249
+ Log.d(TAG,"start install apk name:" + installPackageName);
250
+ } else if(action.equals(ACTION_TOUCH_TEST)) {
251
+ int enable = intent.getIntExtra("enable",0);
252
+
253
+ if(DEBUG) Log.d(TAG,"touch test enable:" + enable);
254
+
255
+ if (enable == 1) {
256
+ //Settings.Global.getInt(mContext.getContentResolver(),
257
+ //Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1); //开启开发者模式
258
+
259
+ Settings.System.putInt(mContext.getContentResolver(),//开启指针位置
260
+ Settings.System.POINTER_LOCATION, 1);
261
+ } else {
262
+ //Settings.Global.putInt(mContext.getContentResolver(),//关闭开发者模式
263
+ //Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
264
+
265
+ Settings.System.putInt(mContext.getContentResolver(),//开启指针位置
266
+ Settings.System.POINTER_LOCATION, 0);
267
+ }
268
+ } else if(action.equals(ACTION_IDO_SET_SHUTDOWN)) {
269
+ systemShutdown(intent.getBooleanExtra("confirm",true));
270
+ //systemShutdown(false);
271
+ } else if(action.equals(ACTION_IDO_SET_REBOOT)) {
272
+ systemReboot(intent.getBooleanExtra("confirm",true));
273
+ } else if(action.equals(ACTION_IDO_SET_FACTORY)) {
274
+ doMasterClear();
275
+ } else if(action.equals(ACTION_IDO_SET_AIRPLANE_MODE)) {
276
+ setAirPlaneMode(intent.getBooleanExtra("enable",false));
277
+ } else if(action.equals(ACTION_IDO_SET_APP_CHECK)) {
278
+ if (intent.getBooleanExtra("enable",false)) {
279
+ checkAppErrCnt = 0;
280
+ enableAppCheck = true;
281
+ mHandler.removeCallbacks(appCheckRunnable);
282
+ mHandler.postDelayed(appCheckRunnable, CHECK_APP_LOOP_TIME);
283
+
284
+ checkPackageName = intent.getStringExtra("packageName");
285
+ runClassName = intent.getStringExtra("className");
286
+ checkAppCnt = intent.getIntExtra("checkCnt",3);//unit:2s,//检测APP是否在界面显示的次数,大于此次数还没有发现APP在前端运行则重启app,默认3次
287
+
288
+ SystemProperties.set("persist.ido.appcheck.packageName",checkPackageName);
289
+ SystemProperties.set("persist.ido.appcheck.className",runClassName);
290
+ SystemProperties.set("persist.ido.appcheck.checkCnt",""+checkAppCnt);
291
+ SystemProperties.set("persist.ido.appcheck.enable",""+enableAppCheck);
292
+ } else {
293
+ enableAppCheck = false;
294
+ checkAppErrCnt = 0;
295
+ mHandler.removeCallbacks(appCheckRunnable);
296
+ SystemProperties.set("persist.ido.appcheck.enable",""+enableAppCheck);
297
+ }
298
+ } else if(action.equals(ACTION_IDO_SCREEN_SHOT)) {
299
+ String savePath = intent.getStringExtra("path");
300
+ String id = intent.getStringExtra("id");
301
+ if (savePath != null && id != null)
302
+ screenshot(savePath,id);
303
+ else if (savePath != null && id == null)
304
+ screenshot(savePath,"0");
305
+ } else if(action.equals(ACTION_IDO_SET_TIME)) {
306
+ int[] time = intent.getIntArrayExtra("time");
307
+
308
+ int year = time[0];
309
+ int month = time[1] - 1;
310
+ int day = time[2];
311
+ int hour = time[3];
312
+ int minute = time[4];
313
+ int second = time[5];
314
+
315
+ setDateAndTime(year,month,day,hour,minute,second);
316
+ } else if(action.equals(ACTION_IDO_SET_WIFIAP)) {
317
+ mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
318
+ if (mWifiManager != null)
319
+ mWifiConfig = mWifiManager.getWifiApConfiguration();
320
+
321
+ if (mWifiManager != null && intent.getBooleanExtra("enable",false)) {
322
+ if (mWifiConfig == null) {
323
+ mWifiConfig = new WifiConfiguration();
324
+
325
+ String ssid = intent.getStringExtra("name");
326
+ if (ssid != null && ssid.length() != 0) {
327
+ mWifiConfig.SSID = ssid;
328
+ } else {
329
+ mWifiConfig.SSID = "wifiAp";//默认名称
330
+ }
331
+
332
+ mWifiConfig.apBand = 0;
333
+
334
+ mWifiConfig.allowedKeyManagement.set(KeyMgmt.WPA2_PSK);
335
+ mWifiConfig.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
336
+
337
+ String mPassword = intent.getStringExtra("password");
338
+ if (mPassword != null && mPassword.length() >= 8) {
339
+ mWifiConfig.preSharedKey = mPassword;
340
+
341
+ mWifiManager.setWifiApConfiguration(mWifiConfig);
342
+
343
+ if (wifiApState == WifiManager.WIFI_AP_STATE_ENABLED) {
344
+ Log.d(TAG, "wifi ap is enabled,first stop ap!\n");
345
+ mWifiManager.stopSoftAp();
346
+ restartWifiApFlag = true;
347
+ } else if (mWifiManager.startSoftAp(mWifiConfig)) {
348
+ Log.d(TAG, "Start wifi ap ok!\n");
349
+ } else {
350
+ Log.d(TAG, "Start ap failed!\n");
351
+ }
352
+ } else {
353
+ Log.e(TAG, "Set Wifi ap password length error!\n");
354
+ }
355
+ } else {
356
+ String ssid = intent.getStringExtra("name");
357
+ if (ssid != null && ssid.length() != 0) {
358
+ mWifiConfig.SSID = ssid;
359
+ } else {
360
+ mWifiConfig.SSID = "wifiAp";//默认名称
361
+ }
362
+
363
+ mWifiConfig.apBand = 0;
364
+
365
+ mWifiConfig.allowedKeyManagement.set(KeyMgmt.WPA2_PSK);
366
+ mWifiConfig.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
367
+
368
+ String mPassword = intent.getStringExtra("password");
369
+ if (mPassword != null && mPassword.length() >= 8) {
370
+ mWifiConfig.preSharedKey = mPassword;
371
+
372
+ mWifiManager.setWifiApConfiguration(mWifiConfig);
373
+
374
+ if (wifiApState == WifiManager.WIFI_AP_STATE_ENABLED) {
375
+ Log.d(TAG, "wifi ap is enabled,first stop ap!\n");
376
+ mWifiManager.stopSoftAp();
377
+ restartWifiApFlag = true;
378
+ } else if (mWifiManager.startSoftAp(mWifiConfig)) {
379
+ Log.d(TAG, "Start wifi ap ok!\n");
380
+ } else {
381
+ Log.d(TAG, "Start ap failed!\n");
382
+ }
383
+ } else {
384
+ Log.e(TAG, "Set Wifi ap password length error!\n");
385
+ }
386
+ }
387
+ } else if (mWifiManager != null) {
388
+ if (wifiApState == WifiManager.WIFI_AP_STATE_ENABLED && mWifiManager.stopSoftAp()) {
389
+ if(DEBUG) Log.d(TAG, "Stop wifi ap ok!\n");
390
+ } else if (wifiApState == WifiManager.WIFI_AP_STATE_DISABLED) {
391
+ Log.d(TAG, "wifi ap default is disabled!\n");
392
+ } else {
393
+ Log.d(TAG, "Stop wifi ap failed!\n");
394
+ }
395
+ } else {
396
+ Log.e(TAG, "Wifi manager is null!\n");
397
+ }
398
+ } else if (WifiManager.WIFI_AP_STATE_CHANGED_ACTION.equals(action)) {
399
+ int state = intent.getIntExtra(
400
+ WifiManager.EXTRA_WIFI_AP_STATE, WifiManager.WIFI_AP_STATE_FAILED);
401
+ if (state == WifiManager.WIFI_AP_STATE_FAILED) {
402
+ int reason = intent.getIntExtra(WifiManager.EXTRA_WIFI_AP_FAILURE_REASON,
403
+ WifiManager.SAP_START_FAILURE_GENERAL);
404
+ handleWifiApStateChanged(state, reason);
405
+ } else {
406
+ handleWifiApStateChanged(state, WifiManager.SAP_START_FAILURE_GENERAL);
407
+ }
408
+ } else if(action.equals(ACTION_IDO_SET_SCREEN)) {
409
+ String scState = intent.getStringExtra("screen");
410
+ if (mDevCtrl != null && scState != null && scState.equals("off")) {
411
+ //blBrightness = getSystemBrightness();
412
+ mDevCtrl.set_backlight_brightness(0);//关闭LCD背光
413
+ setUserLed(1,0);//关闭编码器灯
414
+ noTouchDataCnt = NO_TOUCH_CNT_TIMEOUT - 1;
415
+ } else if (mDevCtrl != null && scState != null && scState.equals("on")) {
416
+ mDevCtrl.set_backlight_brightness(getSystemBrightness());
417
+ setUserLed(1,1);//开启编码器灯
418
+ noTouchDataCnt = 0;
419
+ }
420
+
421
+ String tpState = intent.getStringExtra("tp");
422
+ if (tpState != null && tpState.equals("off")) {
423
+ setDisableTs(true);
424
+ } else if (tpState != null && tpState.equals("on")) {
425
+ setDisableTs(false);
426
+ }
427
+
428
+ int time = intent.getIntExtra("timeout",2147483600);
429
+
430
+ if (time != 2147483600) {
431
+ noTouchDataCnt = 0;
432
+ NO_TOUCH_CNT_TIMEOUT = time;
433
+ SystemProperties.set("persist.ido.screen.timeout",""+NO_TOUCH_CNT_TIMEOUT);
434
+ Log.d(TAG, "set no touch screen timeout:" + NO_TOUCH_CNT_TIMEOUT);
435
+ }
436
+ } else if (action.equals(ACTION_IDO_SET_SCREEN_BRIGHTNESS)) {
437
+ setSystemBrightness(intent.getIntExtra("value",200));
438
+ } else if (action.equals(ACTION_IDO_SET_TIMEOUT_SLEEP)) {
439
+ int time = intent.getIntExtra("time",-1);
440
+ if (time == -1) {
441
+ Settings.System.putInt(mContext.getContentResolver(), SCREEN_OFF_TIMEOUT, (int)2147483647);
442
+ } else if (time != 0) {
443
+ Settings.System.putInt(mContext.getContentResolver(), SCREEN_OFF_TIMEOUT, (int)time*1000);
444
+ }
445
+ } else if (action.equals(ACTION_IDO_GET_TIMEOUT_SLEEP)) {
446
+ final long displayTimeout = Math.max(0,Settings.System.getInt(mContext.getContentResolver(), SCREEN_OFF_TIMEOUT, 0));
447
+ Intent intent1 = new Intent("android.ido.action.sleep.time");
448
+ intent1.putExtra("time",(int)(displayTimeout/1000));
449
+ mContext.sendBroadcast(intent1);
450
+ } else if (ACTION_IDO_SET_LAUNCHER.equals(action)) {
451
+ String launcherPackageName = intent.getStringExtra("packageName");
452
+ String launcherClassName = intent.getStringExtra("className");
453
+
454
+ if (launcherPackageName != null && launcherClassName != null) {
455
+ SystemProperties.set("persist.ido.launcher.packagename",launcherPackageName);
456
+ SystemProperties.set("persist.ido.launcher.classname",launcherClassName);
457
+ }
458
+ } else if(action.equals(ACTION_IDO_SET_SCREEN_ONOFF_GET)) {
459
+ Intent intent1 = new Intent("android.ido.action.screenoff.time");
460
+ intent1.putExtra("timeout",NO_TOUCH_CNT_TIMEOUT);
461
+ mContext.sendBroadcast(intent1);
462
+ } else if(action.equals(ACTION_IDO_SET_ADB)) {
463
+ if (intent.getBooleanExtra("enable",false)) {
464
+ Settings.Secure.putInt(mContext.getContentResolver(),Settings.Global.ADB_ENABLED,1);
465
+ } else {
466
+ Settings.Secure.putInt(mContext.getContentResolver(),Settings.Global.ADB_ENABLED,0);
467
+ }
468
+ } else if(action.equals(ACTION_IDO_SET_INPUT)) {
469
+ setInputReport();
470
+ }
471
+ } catch (Exception e) {
472
+ if(DEBUG) Log.d(TAG, "BroadcastReceiver error:\n" + e);
473
+ }
474
+ }
475
+ };
476
+
477
+ private void setSystemBrightness(int val) {
478
+ try {
479
+ Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS,val);
480
+ } catch (Exception e) {
481
+ Log.e(TAG, "setSystemBrightness error:\n" + e);
482
+ }
483
+ }
484
+
485
+ private final BroadcastReceiver mReceiver2 = new BroadcastReceiver() {
486
+ @Override
487
+ public void onReceive(Context context, Intent intent) {
488
+ try {
489
+ if(intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED)) {
490
+
491
+ String data = intent.getDataString();
492
+
493
+ if(data == null || data.length() <= PACKAGE_NAME_START_INDEX)
494
+ {
495
+ return;
496
+ }
497
+
498
+ String packageName = data.substring(PACKAGE_NAME_START_INDEX);
499
+
500
+ Log.d(TAG,"apk installed package name:" + packageName + ",auto start:" + installedStartActivityFlag);
501
+
502
+ Intent intent1 = new Intent(ACTION_IDO_GET_APK_INSTALLED);
503
+ intent1.putExtra("packageName",packageName);
504
+ mContext.sendBroadcast(intent1);
505
+
506
+ if(installedStartActivityFlag && packageName.equals(installPackageName))
507
+ {
508
+ SystemProperties.set("persist.ido.launcher.kill","true");
509
+ startApkActivity(context,installPackageName);
510
+ installPackageName = null;
511
+ installedStartActivityFlag = false;
512
+ SystemProperties.set("persist.ido.launcher.kill","false");
513
+ }
514
+ } /*else if(intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED)) {
515
+
516
+ String data = intent.getDataString();
517
+
518
+ if(data == null || data.length() <= PACKAGE_NAME_START_INDEX)
519
+ {
520
+ return;
521
+ }
522
+
523
+ String packageName = data.substring(PACKAGE_NAME_START_INDEX);
524
+
525
+ if(packageName.equals(installPackageName) )
526
+ {
527
+ startApkActivity(context,installPackageName);
528
+ }
529
+
530
+ if(DEBUG) Log.d(TAG,"replace installed apk name:" + packageName);
531
+ }*/
532
+ } catch (Exception e) {
533
+ Log.e(TAG, "" + e);
534
+ }
535
+ }
536
+ };
537
+
538
+ private void handleWifiApStateChanged(int state, int reason) {
539
+ switch (state) {
540
+ case WifiManager.WIFI_AP_STATE_ENABLED:
541
+ wifiApState = WifiManager.WIFI_AP_STATE_ENABLED;
542
+ break;
543
+ case WifiManager.WIFI_AP_STATE_DISABLED:
544
+ wifiApState = WifiManager.WIFI_AP_STATE_DISABLED;
545
+
546
+ if (restartWifiApFlag) {
547
+ restartWifiApFlag = false;
548
+ if (mWifiManager != null && mWifiManager.startSoftAp(mWifiConfig))
549
+ Log.d(TAG, "Start wifi ap ok!\n");
550
+ else
551
+ Log.d(TAG, "Start ap failed!\n");
552
+ }
553
+ break;
554
+ }
555
+ }
556
+
557
+ private Handler mHandler = new Handler();
558
+ private Runnable apkRunnable = new Runnable() {
559
+ @Override
560
+ public void run() {
561
+ try {
562
+ Intent intent = new Intent();
563
+ if (installPackageName != null && installClassName != null) {
564
+ intent.setClassName(installPackageName,installClassName);
565
+ startActivity(intent);
566
+ }
567
+ } catch (Exception e) {
568
+ Log.e(TAG, e.toString());
569
+ }
570
+ }
571
+ };
572
+
573
+ private Runnable appCheckRunnable = new Runnable() {
574
+ @Override
575
+ public void run() {
576
+ try {
577
+ String processActivity = "";
578
+ ActivityManager manager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
579
+ //获取正在运行的task列表,其中1表示最近运行的task,通过该数字限制列表中task数目,最近运行的靠前
580
+ List<ActivityManager.RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1);
581
+
582
+ if (runningTaskInfos != null && runningTaskInfos.size() != 0) {
583
+ processActivity = (runningTaskInfos.get(0).baseActivity).getPackageName();
584
+ if(DEBUG) Log.d(TAG, "Current Activity Package Name:" + processActivity);
585
+ }
586
+
587
+ if(DEBUG) Log.d(TAG, "Check app Package Name:" + checkPackageName);
588
+ if(DEBUG) Log.d(TAG, "Check app Class Name:" + runClassName);
589
+
590
+ if (checkPackageName != null && processActivity.compareTo(checkPackageName) != 0) {
591
+ checkAppErrCnt++;
592
+ if (checkAppCnt > 0 && checkAppErrCnt >= checkAppCnt) {
593
+ checkAppErrCnt = 0;
594
+
595
+ Intent intent = new Intent();
596
+ if (checkPackageName != null && runClassName != null && checkPackageName.equals("") == false && runClassName.equals("") == false) {
597
+ intent.setClassName(checkPackageName,runClassName);
598
+ startActivity(intent);
599
+ } else {
600
+ Log.e(TAG, "checkAppErr,packageName:" + checkPackageName + ",ClassName" + runClassName);
601
+ enableAppCheck = false;
602
+ }
603
+ }
604
+ } else {
605
+ checkAppErrCnt = 0;
606
+ }
607
+
608
+ if(DEBUG) Log.d(TAG, "checkAppErrCnt:" + checkAppErrCnt);
609
+
610
+ } catch (Exception e) {
611
+ Log.e(TAG, e.toString());
612
+ }
613
+
614
+ if (enableAppCheck && appCheckRunnable != null)
615
+ mHandler.postDelayed(appCheckRunnable, CHECK_APP_LOOP_TIME);
616
+ }
617
+ };
618
+
619
+ private Runnable noTouchCheckRunnable = new Runnable() {
620
+ @Override
621
+ public void run() {
622
+ try {
623
+ int temp = getTsCnt();
624
+ if (lastTsCnt != temp) {
625
+ lastTsCnt = temp;
626
+ noTouchDataCnt = 0;
627
+ if (onTouchFlag == 1) {
628
+ onTouchFlag = 0;
629
+ setUserLed(1,1);//开启编码器灯
630
+ setDisableTs(false);
631
+ Log.d(TAG,"====>has touch on backlight!!!"); //开启LCD背光
632
+ if (mDevCtrl != null) {
633
+ mDevCtrl.set_backlight_brightness(getSystemBrightness());
634
+ Intent intent1 = new Intent("android.ido.action.screenon.now");
635
+ //intent1.putExtra("timeout",NO_TOUCH_CNT_TIMEOUT);
636
+ mContext.sendBroadcast(intent1);
637
+ ts_check_loop_time = TS_CHECK_LOOP_TIME1;
638
+ }
639
+ }
640
+ } else {
641
+ noTouchDataCnt++;
642
+
643
+ if ((NO_TOUCH_CNT_TIMEOUT != -1) && (noTouchDataCnt == NO_TOUCH_CNT_TIMEOUT)) {
644
+ if (onTouchFlag == 0) {
645
+ onTouchFlag = 1;
646
+ //关闭LCD背光
647
+ setUserLed(1,0);//关闭编码器灯
648
+ if (mDevCtrl != null) {
649
+ //blBrightness = getSystemBrightness();
650
+ mDevCtrl.set_backlight_brightness(0);//关闭LCD背光
651
+ Intent intent1 = new Intent("android.ido.action.screenoff.now");
652
+ intent1.putExtra("timeout",NO_TOUCH_CNT_TIMEOUT);
653
+ mContext.sendBroadcast(intent1);
654
+ ts_check_loop_time = TS_CHECK_LOOP_TIME2;
655
+ }
656
+ }
657
+ Log.d(TAG,"====>no touch timeout!!!");
658
+ }
659
+ }
660
+ mHandler.postDelayed(noTouchCheckRunnable, ts_check_loop_time);
661
+ } catch (Exception e) {
662
+ Log.e(TAG, e.toString());
663
+ }
664
+ }
665
+ };
666
+
667
+ private int getSystemBrightness() {
668
+ int systemBrightness = 0;
669
+ try {
670
+ systemBrightness = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
671
+ } catch (Exception e) {
672
+ e.printStackTrace();
673
+ }
674
+ return systemBrightness;
675
+ }
676
+
677
+ //confirm:ture-会弹出是否关机的确认窗口,false-无弹框,直接关机
678
+ private void systemShutdown(boolean confirm) {
679
+ Intent intent = new Intent("com.android.internal.intent.action.REQUEST_SHUTDOWN");
680
+ intent.putExtra(Intent.EXTRA_KEY_CONFIRM, confirm);
681
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
682
+ startActivity(intent);
683
+
684
+ /*PowerManager mPowerManager = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
685
+ if (mPowerManager != null)
686
+ mPowerManager.shutdown(false, "user shutdwon",false);*/
687
+ }
688
+
689
+ //confirm:ture-会弹出是否关机的确认窗口,false-无弹框,直接重启
690
+ private void systemReboot(boolean confirm) {
691
+ Intent intent = new Intent("android.intent.action.REBOOT");
692
+ intent.putExtra(Intent.EXTRA_KEY_CONFIRM, confirm);
693
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
694
+ startActivity(intent);
695
+ }
696
+
697
+ private void doMasterClear() {//恢复出厂设置
698
+ Intent intent = new Intent(Intent.ACTION_FACTORY_RESET);
699
+ intent.setPackage("android");
700
+ intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
701
+ intent.putExtra(Intent.EXTRA_REASON, "FactoryMode");
702
+ intent.putExtra(Intent.EXTRA_WIPE_EXTERNAL_STORAGE, true);
703
+ intent.putExtra(Intent.EXTRA_WIPE_ESIMS, true);
704
+ mContext.sendBroadcast(intent);
705
+ }
706
+
707
+ private void setAirPlaneMode(boolean enable) {//设置开启/关闭飞行模式
708
+ if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN) {
709
+ Settings.System.putInt(mContext.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, enable ? 1 : 0);
710
+ } else {
711
+ Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, enable ? 1 : 0);
712
+ }
713
+ Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
714
+ intent.putExtra("state", enable);
715
+ mContext.sendBroadcast(intent);
716
+ }
717
+
718
+ private void silentInstallApk(String path) {//安装的包可以卸载
719
+ if(DEBUG) Log.d(TAG, "silentInstallApk start");
720
+
721
+ if (path == null) {
722
+ Log.e(TAG,"Apk paht is null!");
723
+ return;
724
+ }
725
+
726
+ if (isApkFile(mContext,path)) {
727
+ if(DEBUG) Log.d(TAG,"Installing:" + path);
728
+ try{
729
+ InstallUtils.install28(mContext,path,InstallResultReceiver.class);
730
+ } catch (Exception e) {
731
+ Log.e(TAG,"silentInstallApk Error:" + e);
732
+ }
733
+ } else {
734
+ Log.e(TAG,path + " is invaild apk!");
735
+ }
736
+ }
737
+
738
+ private void screenshot(String savePath,String id) {
739
+ Process process = null;
740
+ BufferedReader successResult = null;
741
+ BufferedReader errorResult = null;
742
+ StringBuilder successMsg = new StringBuilder();
743
+ StringBuilder errorMsg = new StringBuilder();
744
+ try {
745
+ process = new ProcessBuilder("/system/bin/screencap","-d",id,"-p", savePath).start();
746
+ successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
747
+ errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
748
+ String s;
749
+ while ((s = successResult.readLine()) != null) {
750
+ successMsg.append(s);
751
+ if(DEBUG) Log.d(TAG,"screencap:" + savePath);
752
+ }
753
+ while ((s = errorResult.readLine()) != null) {
754
+ errorMsg.append(s);
755
+ Log.e(TAG,"screencap:" + savePath+",Error:"+errorMsg.toString());
756
+ }
757
+ } catch (Exception e) {
758
+ Log.e(TAG,e.toString());
759
+ }
760
+ }
761
+
762
+ public static String getPackage(Context context, String filePath) {
763
+ PackageManager pm = context.getPackageManager();
764
+
765
+ PackageInfo info = pm.getPackageArchiveInfo(filePath, PackageManager.GET_ACTIVITIES);
766
+
767
+ if (info != null)
768
+ return info.packageName;
769
+ else
770
+ return null;
771
+ }
772
+
773
+ public static void startApkActivity(final Context ctx, String packageName) {
774
+ PackageManager pm = ctx.getPackageManager();
775
+ PackageInfo pi;
776
+ try {
777
+ pi = pm.getPackageInfo(packageName, 0);
778
+ Intent intent = new Intent(Intent.ACTION_MAIN, null);
779
+ intent.addCategory(Intent.CATEGORY_LAUNCHER);
780
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
781
+ intent.setPackage(pi.packageName);
782
+
783
+ List<ResolveInfo> apps = pm.queryIntentActivities(intent, 0);
784
+
785
+ ResolveInfo ri = apps.iterator().next();
786
+ if (ri != null) {
787
+ String className = ri.activityInfo.name;
788
+ intent.setComponent(new ComponentName(packageName, className));
789
+ ctx.startActivity(intent);
790
+ }
791
+ } catch (Exception ex) {
792
+ Log.e(TAG, ex.toString());
793
+ }
794
+ }
795
+
796
+ private void setDateAndTime(int year, int month, int day,int hourOfDay, int minute,int second) {
797
+ Calendar c = Calendar.getInstance();
798
+
799
+ c.set(Calendar.YEAR, year);
800
+ c.set(Calendar.MONTH, month);
801
+ c.set(Calendar.DAY_OF_MONTH, day);
802
+ c.set(Calendar.HOUR_OF_DAY, hourOfDay);
803
+ c.set(Calendar.MINUTE, minute);
804
+ c.set(Calendar.SECOND, second);
805
+ c.set(Calendar.MILLISECOND, 0);
806
+
807
+ long when = c.getTimeInMillis();
808
+
809
+ if (when / 1000 < Integer.MAX_VALUE && mAlarmManager != null) {
810
+ mAlarmManager.setTime(c.getTimeInMillis());
811
+ }
812
+ }
813
+
814
+ private static void setDisableTs(boolean on) { //设置禁止触摸上报数据
815
+ final String path = "/dev/dis_ts";
816
+ if (new File(path).exists()) {
817
+ FileWriter writer = null;
818
+ try {
819
+ writer = new FileWriter(path);
820
+ if (on) {
821
+ writer.write("on ");
822
+ } else {
823
+ writer.write("off ");
824
+ }
825
+ writer.flush();
826
+ } catch (Exception ex) {
827
+ Log.d(TAG, "" + ex);
828
+ } finally {
829
+ if (writer != null) {
830
+ try {
831
+ writer.close();
832
+ } catch (IOException ex) {
833
+ }
834
+ }
835
+ }
836
+ }
837
+ }
838
+
839
+ private static int getTsCnt() {//获取触摸上报的记数,触摸一次变化一个数据
840
+ byte[] buff = new byte[3];
841
+ int tsCount;
842
+ final String IDO_TS = "/dev/dis_ts";;
843
+ if (new File(IDO_TS).exists()) {
844
+ try {
845
+ FileInputStream tsDev = new FileInputStream(new File(IDO_TS));
846
+ tsDev.read(buff, 0, 3);
847
+ tsCount = (buff[0] & 0xFF) * 256 + (buff[1] & 0xFF);
848
+ tsDev.close();
849
+ //Log.d(TAG,"Ts Count:" + tsCount);
850
+ return tsCount;
851
+ } catch (Exception ex) {
852
+ Log.d(TAG, "" + ex);
853
+ return 0;
854
+ }
855
+ }
856
+ return 0;
857
+ }
858
+
859
+ private static void setInputReport() { //上报1,1坐标为重置休眠计数
860
+ final String path = "/dev/dis_ts";
861
+ if (new File(path).exists()) {
862
+ FileWriter writer = null;
863
+ try {
864
+ writer = new FileWriter(path);
865
+ writer.write("inp ");
866
+ writer.flush();
867
+ } catch (Exception ex) {
868
+ Log.d(TAG, "" + ex);
869
+ } finally {
870
+ if (writer != null) {
871
+ try {
872
+ writer.close();
873
+ } catch (IOException ex) {
874
+ }
875
+ }
876
+ }
877
+ }
878
+ }
879
+
880
+ //on=1,LED灯亮
881
+ //on=0, LED灯灭
882
+ synchronized private static void setUserLed(int id, int on) {
883
+ String path = "/sys/class/leds/led" + id + "/brightness";
884
+ if (new File(path).exists()) {
885
+ final String filename = path;
886
+ FileWriter writer = null;
887
+ try {
888
+ writer = new FileWriter(filename);
889
+ if (on == 0) {
890
+ writer.write("0");
891
+ } else {
892
+ writer.write("1");
893
+ }
894
+ writer.flush();
895
+ } catch (Exception ex) {
896
+ Log.d(TAG, "" + ex);
897
+ } finally {
898
+ if (writer != null) {
899
+ try {
900
+ writer.close();
901
+ } catch (IOException ex) {
902
+ }
903
+ }
904
+ }
905
+ }
906
+ }
907
+
908
+ private static void setPowerSleep() {
909
+ String path = "/sys/power/state";
910
+ if (new File(path).exists()) {
911
+ final String filename = path;
912
+ FileWriter writer = null;
913
+ try {
914
+ writer = new FileWriter(filename);
915
+ writer.write("mem");
916
+ writer.flush();
917
+ } catch (Exception ex) {
918
+ Log.d(TAG, "" + ex);
919
+ } finally {
920
+ if (writer != null) {
921
+ try {
922
+ writer.close();
923
+ } catch (IOException ex) {
924
+ }
925
+ }
926
+ }
927
+ }
928
+ }
929
+
930
+ private static Boolean isApkFile(Context context, String filePath) {
931
+ String pkg;
932
+
933
+ try {
934
+ PackageManager mPackageManager = context.getPackageManager();
935
+ PackageInfo info = mPackageManager.getPackageArchiveInfo(filePath, PackageManager.GET_ACTIVITIES);
936
+ if (info !=null) {
937
+ ApplicationInfo appInfo = info.applicationInfo;
938
+ pkg=appInfo.packageName;
939
+ } else {
940
+ pkg="";
941
+ }
942
+ }catch (Exception e) {
943
+ pkg="";
944
+ }
945
+ return !TextUtils.isEmpty(pkg);
946
+ }
947
+
948
+
949
+ private boolean fileIsExists(String strFile) {
950
+ try
951
+ {
952
+ File f=new File(strFile);
953
+ if(!f.exists())
954
+ {
955
+ return false;
956
+ }
957
+ }
958
+ catch (Exception e)
959
+ {
960
+ return false;
961
+ }
962
+
963
+ return true;
964
+ }
965
+}
android/packages/apps/Settings/src/com/android/settings/InstallResultReceiver.java
....@@ -0,0 +1,48 @@
1
+package com.android.settings;
2
+import android.app.PendingIntent;
3
+import android.content.BroadcastReceiver;
4
+import android.content.Context;
5
+import android.content.Intent;
6
+import android.content.pm.PackageInstaller;
7
+import android.util.Log;
8
+
9
+import java.io.File;
10
+import java.io.FileInputStream;
11
+import java.io.IOException;
12
+import java.io.InputStream;
13
+import java.io.OutputStream;
14
+
15
+public class InstallResultReceiver extends BroadcastReceiver {
16
+ private String TAG = "myLog";
17
+
18
+ @Override
19
+ public void onReceive(Context context, Intent intent) {
20
+
21
+ if (intent != null) {
22
+
23
+ final int status = intent.getIntExtra(PackageInstaller.EXTRA_STATUS,
24
+ PackageInstaller.STATUS_FAILURE);
25
+ String packageName = null;
26
+
27
+ try {
28
+ packageName = intent.getData().getSchemeSpecificPart();
29
+ }catch (Exception e){
30
+ e.printStackTrace();
31
+ }
32
+
33
+ Log.e(TAG, "action="+intent.getAction()+" ,status="+status);
34
+
35
+ if (status == PackageInstaller.STATUS_SUCCESS) {
36
+ // success
37
+ Log.e(TAG, packageName + " install success, msg: "+intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE));
38
+ } else {
39
+ Log.e(TAG, packageName + " install filed, msg: "+intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE));
40
+ }
41
+ }
42
+ }
43
+}
44
+
45
+
46
+
47
+
48
+
android/packages/apps/Settings/src/com/android/settings/InstallUtils.java
....@@ -0,0 +1,142 @@
1
+//调用方法为:
2
+//InstallUtils.install28(MainActivity.this,"/data/local/tmp/test.apk",InstallResultReceiver.class)
3
+
4
+//需系统签名和添加以下权限
5
+//<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
6
+//<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
7
+
8
+package com.android.settings;
9
+import android.app.PendingIntent;
10
+import android.content.BroadcastReceiver;
11
+import android.content.Context;
12
+import android.content.Intent;
13
+import android.content.pm.PackageInstaller;
14
+import android.util.Log;
15
+
16
+import java.io.File;
17
+import java.io.FileInputStream;
18
+import java.io.IOException;
19
+import java.io.InputStream;
20
+import java.io.OutputStream;
21
+
22
+
23
+public class InstallUtils {
24
+ private static final String TAG = "myLog";
25
+
26
+ // 适配android9的安装方法。
27
+ public static void install28(Context context, String apkFilePath,Class<InstallResultReceiver> receiver) {
28
+
29
+ Log.d(TAG,"install28 path="+apkFilePath);
30
+
31
+ File apkFile = new File(apkFilePath);
32
+
33
+ PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller();
34
+
35
+ PackageInstaller.SessionParams sessionParams
36
+ = new PackageInstaller.SessionParams(PackageInstaller
37
+ .SessionParams.MODE_FULL_INSTALL);
38
+
39
+ sessionParams.setSize(apkFile.length());
40
+ int sessionId = createSession(packageInstaller, sessionParams);
41
+
42
+ Log.d(TAG,"install28 sessionId="+sessionId);
43
+
44
+ if (sessionId != -1) {
45
+ boolean copySuccess = copyInstallFile(packageInstaller, sessionId, apkFilePath);
46
+ Log.d(TAG,"install28 copySuccess="+copySuccess);
47
+ if (copySuccess) {
48
+ execInstallCommand(context,packageInstaller, sessionId,receiver);
49
+ }
50
+ }
51
+ }
52
+
53
+ private static int createSession(PackageInstaller packageInstaller,
54
+ PackageInstaller.SessionParams sessionParams) {
55
+
56
+ int sessionId = -1;
57
+
58
+ try {
59
+ sessionId = packageInstaller.createSession(sessionParams);
60
+ } catch (IOException e) {
61
+ e.printStackTrace();
62
+ }
63
+ return sessionId;
64
+ }
65
+
66
+ private static boolean copyInstallFile(PackageInstaller packageInstaller,int sessionId, String apkFilePath) {
67
+
68
+ InputStream in = null;
69
+ OutputStream out = null;
70
+ PackageInstaller.Session session = null;
71
+ boolean success = false;
72
+
73
+ try {
74
+
75
+ File apkFile = new File(apkFilePath);
76
+ session = packageInstaller.openSession(sessionId);
77
+ out = session.openWrite("base.apk", 0, apkFile.length());
78
+ in = new FileInputStream(apkFile);
79
+
80
+ int total = 0, c;
81
+ byte[] buffer = new byte[65536];
82
+ while ((c = in.read(buffer)) != -1) {
83
+ total += c;
84
+ out.write(buffer, 0, c);
85
+ }
86
+
87
+ session.fsync(out);
88
+ Log.i(TAG, "streamed " + total + " bytes");
89
+ success = true;
90
+ } catch (IOException e) {
91
+ e.printStackTrace();
92
+ } finally {
93
+
94
+ try {
95
+ if (out!=null){
96
+ out.close();
97
+ }
98
+
99
+ if (in!=null){
100
+ in.close();
101
+ }
102
+
103
+ if (session!=null){
104
+ session.close();
105
+ }
106
+
107
+ } catch (IOException e) {
108
+ e.printStackTrace();
109
+ }
110
+ }
111
+
112
+ return success;
113
+ }
114
+
115
+
116
+ private static void execInstallCommand(Context context, PackageInstaller packageInstaller, int sessionId, Class<InstallResultReceiver> receiver) {
117
+
118
+ PackageInstaller.Session session = null;
119
+ try {
120
+ session = packageInstaller.openSession(sessionId);
121
+ Intent intent = new Intent(context, receiver);
122
+ PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
123
+ 1, intent,
124
+ PendingIntent.FLAG_UPDATE_CURRENT);
125
+
126
+ session.commit(pendingIntent.getIntentSender());
127
+
128
+ Log.i(TAG, "begin session");
129
+
130
+ } catch (IOException e) {
131
+ e.printStackTrace();
132
+ } catch (Exception e) {
133
+ e.printStackTrace();
134
+ } finally {
135
+ session.close();
136
+ }
137
+ }
138
+}
139
+
140
+
141
+
142
+
android/packages/apps/Settings/src/com/android/settings/MyBootReceiver.java
....@@ -0,0 +1,20 @@
1
+package com.android.settings;
2
+//import android.settings.development;
3
+import android.content.BroadcastReceiver;
4
+import android.content.Context;
5
+import android.content.Intent;
6
+
7
+public class MyBootReceiver extends BroadcastReceiver {
8
+
9
+ @Override
10
+ public void onReceive(Context context, Intent intent) {
11
+ // TODO Auto-generated method stub
12
+ String action = intent.getAction();
13
+ if (action.equals(Intent.ACTION_BOOT_COMPLETED))
14
+ {
15
+ Intent service = new Intent(context, IdoDevCustomService.class);
16
+ context.startService(service);
17
+ }
18
+ }
19
+
20
+}