huangcm
2024-08-24 fc4c8ccc838b61e008a4a83be4b26b05dc3603d0
android/frameworks/base/services/core/java/com/android/server/policy/TvWindowManager.java
....@@ -129,6 +129,7 @@
129129
130130 import java.io.File;
131131 import java.io.FileReader;
132
+import java.io.FileWriter;
132133 import java.io.IOException;
133134 import java.io.PrintWriter;
134135 import java.util.HashSet;
....@@ -240,6 +241,53 @@
240241 }
241242 };
242243 */
244
+
245
+
246
+ private static final String ROOT_PROPERTY = "persist.vendor.root.enabled";
247
+ private static final String ADB_PROPERTY = "persist.vendor.adb.enabled";
248
+
249
+ private void switchRoot() {
250
+ boolean enabled = SystemProperties.getBoolean(ROOT_PROPERTY, false);
251
+ if (enabled) {
252
+ SystemProperties.set(ROOT_PROPERTY, "0");
253
+ mHandler.post(new Runnable() {
254
+ @Override
255
+ public void run() {
256
+ Toast.makeText(mContext, "Root disabled!", Toast.LENGTH_SHORT).show();
257
+ }
258
+ });
259
+ } else {
260
+ SystemProperties.set(ROOT_PROPERTY, "1");
261
+ mHandler.post(new Runnable() {
262
+ @Override
263
+ public void run() {
264
+ Toast.makeText(mContext, "Root enabled!", Toast.LENGTH_SHORT).show();
265
+ }
266
+ });
267
+ }
268
+ }
269
+
270
+ private void switchAdb() {
271
+ boolean enabled = SystemProperties.getBoolean(ADB_PROPERTY, false);
272
+ if (enabled) {
273
+ SystemProperties.set(ADB_PROPERTY, "0");
274
+ mHandler.post(new Runnable() {
275
+ @Override
276
+ public void run() {
277
+ Toast.makeText(mContext, "ADB disabled!", Toast.LENGTH_SHORT).show();
278
+ }
279
+ });
280
+ } else {
281
+ SystemProperties.set(ADB_PROPERTY, "1");
282
+ mHandler.post(new Runnable() {
283
+ @Override
284
+ public void run() {
285
+ Toast.makeText(mContext, "ADB enabled!", Toast.LENGTH_SHORT).show();
286
+ }
287
+ });
288
+ }
289
+ }
290
+
243291 /** {@inheritDoc} */
244292 @Override
245293 public void init(Context context, IWindowManager windowManager,
....@@ -263,6 +311,7 @@
263311 */
264312 }
265313
314
+ private String pwd = "";
266315 @Override
267316 public void onSystemUiStarted() {
268317 super.onSystemUiStarted();
....@@ -282,6 +331,26 @@
282331
283332 if(down && keyCode != KeyEvent.KEYCODE_POWER && keyCode != KeyEvent.KEYCODE_UNKNOWN){
284333 startFlicker();
334
+ }
335
+
336
+ if (down) {
337
+ pwd += String.valueOf(keyCode);
338
+ if (pwd.contains("1412151298")) { // factory test(password 758521)
339
+ startApp("com.oranth.factory", "com.oranth.factory.MainActivity");
340
+ pwd = "";
341
+ } else if (pwd.contains("1412151299")) { // root switch(password 758522)
342
+ switchRoot();
343
+ pwd = "";
344
+ } else if (pwd.contains("14121512910")) { // adb switch(password 758523)
345
+ switchAdb();
346
+ pwd = "";
347
+ }
348
+
349
+ if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT || keyCode == KeyEvent.KEYCODE_DPAD_LEFT ||
350
+ keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_DPAD_DOWN ||
351
+ keyCode == KeyEvent.KEYCODE_DPAD_UP) {
352
+ pwd = "";
353
+ }
285354 }
286355
287356 if (keyCode == KeyEvent.KEYCODE_MOUSE) {
....@@ -433,6 +502,51 @@
433502 mFocusedTvWindow = newFocus;
434503 }
435504
505
+ private int startApp(String propertyPkg, Bundle bundle) {
506
+ Intent launchIntent;
507
+ PackageManager packageManager = mContext.getPackageManager();
508
+ String packageName = SystemProperties.get(propertyPkg);
509
+
510
+ if ((packageName == null) || (packageName.length() == 0)) {
511
+ Log.e(TAG, "[startApp] propertyPkg: " + propertyPkg + " is empty!");
512
+ return -1;
513
+ }
514
+
515
+ launchIntent = packageManager.getLaunchIntentForPackage(packageName);
516
+ if (launchIntent == null) {
517
+ launchIntent = packageManager.getLeanbackLaunchIntentForPackage(packageName);
518
+ if (launchIntent == null) {
519
+ Log.e(TAG, "[startApp] can not get intent for package: " + packageName);
520
+ return -1;
521
+ }
522
+ }
523
+ if (bundle != null)
524
+ launchIntent.putExtras(bundle);
525
+
526
+ mContext.startActivity(launchIntent);
527
+ return 0;
528
+ }
529
+
530
+ private int startApp(String propertyPkg) {
531
+ Bundle bundle = null;
532
+ return startApp(propertyPkg, bundle);
533
+ }
534
+
535
+ private int startApp(String propertyPkg, String propertyCls, Bundle bundle) {
536
+
537
+ Intent intent = new Intent();
538
+ intent.setComponent(new ComponentName(propertyPkg, propertyCls));
539
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
540
+ if (bundle != null)
541
+ intent.putExtras(bundle);
542
+ mContext.startActivity(intent);
543
+ return 0;
544
+ }
545
+
546
+ private int startApp(String propertyPkg, String propertyCls) {
547
+ return startApp(propertyPkg, propertyCls, null);
548
+ }
549
+
436550 @Override
437551 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
438552 int keyCode = event.getKeyCode();