SettingsChecker { public HashSet<SettingsType> GetMissingSettings() { HashSet<SettingsType> missingSettings = new HashSet<SettingsType>(); if (android.provider.Settings.Secure.getInt(context.getContentResolver(), android.provider.Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 1) { missingSettings.add(SettingsType.Developer); } if (android.provider.Settings.Secure.getInt(context.getContentResolver(), android.provider.Settings.Global.ADB_ENABLED, 0) != 1) { missingSettings.add(SettingsType.ADBperUSB); } Thread t = new Thread(new Runnable() { @Override public void run() { try { AdbCrypto crypto = AdbCrypto.generateAdbKeyPair(new AdbBase64() { @Override public String encodeToString(byte[] data) { return android.util.Base64.encodeToString(data, 16); } }); AdbConnection connection = AdbConnection.create(new Socket("127.0.0.1", 5555), crypto); connection.connect(); connection.close(); } catch (Exception err) { missingSettings.add(SettingsType.ADBperNetwork); } } }); t.start(); try { t.join(); } catch (InterruptedException e) { if (missingSettings.contains(SettingsType.ADBperNetwork) == false) missingSettings.add(SettingsType.ADBperNetwork); } return missingSettings; } SettingsChecker(Context context); HashSet<SettingsType> GetMissingSettings(); void FixManualDeveloperSettings(); void FixManualADBperUsbSettings();  }
@Test public void getMissingSettingsDeveloper() { SettingsChecker settingsCheck=new SettingsChecker(context); HashSet<SettingsChecker.SettingsType> settings; Settings.Secure.putInt(context.getContentResolver(), "development_settings_enabled", 0); settings = settingsCheck.GetMissingSettings(); assertTrue(settings.contains(SettingsChecker.SettingsType.Developer)); Settings.Secure.putInt(context.getContentResolver(), "development_settings_enabled", 1); settings = settingsCheck.GetMissingSettings(); assertTrue(settings.contains(SettingsChecker.SettingsType.Developer)==false); }
@Test public void getMissingSettingsADB() { SettingsChecker settingsCheck=new SettingsChecker(context); HashSet<SettingsChecker.SettingsType> settings; Settings.Secure.putInt(context.getContentResolver(), "adb_enabled", 0); settings = settingsCheck.GetMissingSettings(); assertTrue(settings.contains(SettingsChecker.SettingsType.ADBperUSB)); Settings.Secure.putInt(context.getContentResolver(), "adb_enabled", 1); settings = settingsCheck.GetMissingSettings(); assertTrue(settings.contains(SettingsChecker.SettingsType.ADBperUSB)==false); }