@Test public void mockUnauthorized() throws Exception { IDevice device = Mockito.mock(IDevice.class); AndroidDeviceImpl spied = Mockito.spy(new AndroidDeviceImpl()); Mockito.when(device.getState()).thenReturn(IDevice.DeviceState.UNAUTHORIZED); boolean rooted = spied.isAndroidRooted(device); rooted = spied.isAndroidRooted(device); assertTrue(rooted == false); }
@Override public boolean isAndroidRooted(IDevice device) throws Exception { if (device == null) { throw new Exception("device is null"); } DeviceState state = device.getState(); if (state.equals(DeviceState.UNAUTHORIZED)) { return false; } for (String cmd : new String[] { "su -c id", "id" }) { String[] res = android.getShellReturn(device, cmd); for (String string : res) { if (string.contains("uid=0(root) gid=0(root)")) { return true; } } } return false; }
AndroidDeviceImpl implements IAndroidDevice { @Override public boolean isAndroidRooted(IDevice device) throws Exception { if (device == null) { throw new Exception("device is null"); } DeviceState state = device.getState(); if (state.equals(DeviceState.UNAUTHORIZED)) { return false; } for (String cmd : new String[] { "su -c id", "id" }) { String[] res = android.getShellReturn(device, cmd); for (String string : res) { if (string.contains("uid=0(root) gid=0(root)")) { return true; } } } return false; } }
AndroidDeviceImpl implements IAndroidDevice { @Override public boolean isAndroidRooted(IDevice device) throws Exception { if (device == null) { throw new Exception("device is null"); } DeviceState state = device.getState(); if (state.equals(DeviceState.UNAUTHORIZED)) { return false; } for (String cmd : new String[] { "su -c id", "id" }) { String[] res = android.getShellReturn(device, cmd); for (String string : res) { if (string.contains("uid=0(root) gid=0(root)")) { return true; } } } return false; }  }
AndroidDeviceImpl implements IAndroidDevice { @Override public boolean isAndroidRooted(IDevice device) throws Exception { if (device == null) { throw new Exception("device is null"); } DeviceState state = device.getState(); if (state.equals(DeviceState.UNAUTHORIZED)) { return false; } for (String cmd : new String[] { "su -c id", "id" }) { String[] res = android.getShellReturn(device, cmd); for (String string : res) { if (string.contains("uid=0(root) gid=0(root)")) { return true; } } } return false; }  @Autowired void setAndroid(IAndroid android); RootCheckOutputReceiver makeRootCheckOutputReceiver(); @Override boolean isSeLinuxEnforced(IDevice device); @Override boolean isAndroidRooted(IDevice device); }
AndroidDeviceImpl implements IAndroidDevice { @Override public boolean isAndroidRooted(IDevice device) throws Exception { if (device == null) { throw new Exception("device is null"); } DeviceState state = device.getState(); if (state.equals(DeviceState.UNAUTHORIZED)) { return false; } for (String cmd : new String[] { "su -c id", "id" }) { String[] res = android.getShellReturn(device, cmd); for (String string : res) { if (string.contains("uid=0(root) gid=0(root)")) { return true; } } } return false; }  @Autowired void setAndroid(IAndroid android); RootCheckOutputReceiver makeRootCheckOutputReceiver(); @Override boolean isSeLinuxEnforced(IDevice device); @Override boolean isAndroidRooted(IDevice device);  }