@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); }
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 { 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 { 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); }
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(); }
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();  }