enable usb debugging by code

http://www.linuxidc.com/Linux/2011-10/46146.htm

packages/apps/Settings/src/com/android/settings/DevelopmentSettings.java

Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED,  0 );

frameworks/base/services/java/com/android/server/NotificationManagerService.java

  1. void  observe() {    
  2.     ContentResolver resolver = mContext.getContentResolver();    
  3.     resolver.registerContentObserver(Settings.Secure.getUriFor(    
  4.             Settings.Secure.ADB_ENABLED), false ,  this );    
  5.     update();    
  6. }    
  7.     
  8. @Override   public   void  onChange( boolean  selfChange) {    
  9.     update();    
  10. }    
  11.     
  12. public   void  update() {    
  13.     ContentResolver resolver = mContext.getContentResolver();    
  14.     mAdbEnabled = Settings.Secure.getInt(resolver,    
  15.                 Settings.Secure.ADB_ENABLED, 0 ) !=  0 ;    
  16.     updateAdbNotification();    
  17. }   


  1. boolean enableAdb = (Settings.Secure.getInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 0) > 0);  
  2.     if (!enableAdb) {  
  3.     Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 1);  
  4.     } 


/system/app


AndroidManifest.xml

  1. <uses-permission android:name="android.permission.WRITE_SETTINGS"></uses-permission>   
  2. <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" /> 

你可能感兴趣的:(enable usb debugging by code)