.. | .. |
---|
129 | 129 | |
---|
130 | 130 | import java.io.File; |
---|
131 | 131 | import java.io.FileReader; |
---|
| 132 | +import java.io.FileWriter; |
---|
132 | 133 | import java.io.IOException; |
---|
133 | 134 | import java.io.PrintWriter; |
---|
134 | 135 | import java.util.HashSet; |
---|
.. | .. |
---|
240 | 241 | } |
---|
241 | 242 | }; |
---|
242 | 243 | */ |
---|
| 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 | + |
---|
243 | 291 | /** {@inheritDoc} */ |
---|
244 | 292 | @Override |
---|
245 | 293 | public void init(Context context, IWindowManager windowManager, |
---|
.. | .. |
---|
263 | 311 | */ |
---|
264 | 312 | } |
---|
265 | 313 | |
---|
| 314 | + private String pwd = ""; |
---|
266 | 315 | @Override |
---|
267 | 316 | public void onSystemUiStarted() { |
---|
268 | 317 | super.onSystemUiStarted(); |
---|
.. | .. |
---|
282 | 331 | |
---|
283 | 332 | if(down && keyCode != KeyEvent.KEYCODE_POWER && keyCode != KeyEvent.KEYCODE_UNKNOWN){ |
---|
284 | 333 | 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 | + } |
---|
285 | 354 | } |
---|
286 | 355 | |
---|
287 | 356 | if (keyCode == KeyEvent.KEYCODE_MOUSE) { |
---|
.. | .. |
---|
433 | 502 | mFocusedTvWindow = newFocus; |
---|
434 | 503 | } |
---|
435 | 504 | |
---|
| 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 | + |
---|
436 | 550 | @Override |
---|
437 | 551 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { |
---|
438 | 552 | int keyCode = event.getKeyCode(); |
---|