예제 #1
0
    def testFlashFail(self):
        partition = 'matey'
        self.ExpectFlash(partition, succeed=False)

        commands = fastboot.FastbootCommands(self.usb)
        with self.assertRaises(fastboot.FastbootRemoteFailure):
            commands.Flash(partition)
예제 #2
0
    def testSimplerCommands(self):
        commands = fastboot.FastbootCommands(self.usb)

        self.usb.ExpectWrite(b'erase:vector')
        self.usb.ExpectRead(b'OKAY')
        commands.Erase('vector')

        self.usb.ExpectWrite(b'getvar:variable')
        self.usb.ExpectRead(b'OKAYstuff')
        self.assertEqual(b'stuff', commands.Getvar('variable'))

        self.usb.ExpectWrite(b'continue')
        self.usb.ExpectRead(b'OKAY')
        commands.Continue()

        self.usb.ExpectWrite(b'reboot')
        self.usb.ExpectRead(b'OKAY')
        commands.Reboot()

        self.usb.ExpectWrite(b'reboot-bootloader')
        self.usb.ExpectRead(b'OKAY')
        commands.RebootBootloader()

        self.usb.ExpectWrite(b'oem a little somethin')
        self.usb.ExpectRead(b'OKAYsomethin')
        self.assertEqual(b'somethin', commands.Oem('a little somethin'))
예제 #3
0
    def testDownload(self):
        raw = b'aoeuidhtnsqjkxbmwpyfgcrl'
        data = BytesIO(raw)
        self.ExpectDownload([raw])
        commands = fastboot.FastbootCommands(self.usb)

        response = commands.Download(data)
        self.assertEqual(b'Result', response)
예제 #4
0
    def testFlashFail(self):
        partition = b'matey'

        self.ExpectFlash(partition, succeed=False)
        dev = fastboot.FastbootCommands()
        dev.ConnectDevice(handle=self.usb)

        with self.assertRaises(fastboot.FastbootRemoteFailure):
            dev.Flash(partition)
예제 #5
0
 def fastboot(self):
     cmds = fastboot.FastbootCommands()
     while True:
         try:
             dev = cmds.ConnectDevice()
             return dev
         except:
             print("Device offline, go back to bootloader!")
             time.sleep(3)
예제 #6
0
    def testDownload(self):
        raw = u'aoeuidhtnsqjkxbmwpyfgcrl'
        data = io.StringIO(raw)

        self.ExpectDownload([raw])
        dev = fastboot.FastbootCommands()
        dev.ConnectDevice(handle=self.usb)

        response = dev.Download(data)
        self.assertEqual(b'Result', response)
예제 #7
0
    def testVariousFailures(self):
        commands = fastboot.FastbootCommands(self.usb)

        self.usb.ExpectWrite(b'continue')
        self.usb.ExpectRead(b'BLEH')
        with self.assertRaises(fastboot.FastbootInvalidResponse):
            commands.Continue()

        self.usb.ExpectWrite(b'continue')
        self.usb.ExpectRead(b'DATA000000')
        with self.assertRaises(fastboot.FastbootStateMismatch):
            commands.Continue()
예제 #8
0
    def testDownloadFail(self):
        raw = u'aoeuidhtnsqjkxbmwpyfgcrl'
        data = io.StringIO(raw)

        self.ExpectDownload([raw], succeed=False)
        commands = fastboot.FastbootCommands(self.usb)
        with self.assertRaises(fastboot.FastbootRemoteFailure):
            commands.Download(data)

        data = io.StringIO(raw)
        self.ExpectDownload([raw], accept_data=False)
        with self.assertRaises(fastboot.FastbootTransferError):
            commands.Download(data)
예제 #9
0
  def testFlash(self):
    partition = 'yarr'

    self.ExpectFlash(partition)
    commands = fastboot.FastbootCommands(self.usb)

    output = StringIO()
    def InfoCb(message):
      if message.header == 'INFO':
        output.write(message.message)
    response = commands.Flash(partition, info_cb=InfoCb)
    self.assertEqual('Done', response)
    self.assertEqual('Random info from the bootloader', output.getvalue())
예제 #10
0
    def testDownloadFail(self):
        raw = 'aoeuidhtnsqjkxbmwpyfgcrl'
        data = cStringIO.StringIO(raw)
        self.ExpectDownload([raw], succeed=False)

        commands = fastboot.FastbootCommands(self.usb)
        with self.assertRaises(fastboot.FastbootRemoteFailure):
            commands.Download(data)

        self.usb.ExpectWrite('download:%08x' % _SumLengths([raw]))
        self.usb.ExpectRead('DATA%08x' % (_SumLengths([raw]) - 2))

        with self.assertRaises(fastboot.FastbootTransferError):
            commands.Download(cStringIO.StringIO(raw))
예제 #11
0
    def testFlash(self):
        partition = b'yarr'

        self.ExpectFlash(partition)
        dev = fastboot.FastbootCommands()
        dev.ConnectDevice(handle=self.usb)

        output = io.BytesIO()

        def InfoCb(message):
            if message.header == b'INFO':
                output.write(message.message)

        response = dev.Flash(partition, info_cb=InfoCb)
        self.assertEqual(b'Done', response)
        self.assertEqual(b'Random info from the bootloader', output.getvalue())
예제 #12
0
    def testFlashFromFile(self):
        partition = b'somewhere'
        # More than one packet, ends somewhere into the 3rd packet.
        raw = b'SOMETHING' * 1086
        tmp = tempfile.NamedTemporaryFile(delete=False)
        tmp.write(raw)
        tmp.close()
        progresses = []

        pieces = []
        chunk_size = fastboot.FastbootProtocol(None).chunk_kb * 1024
        while raw:
            pieces.append(raw[:chunk_size])
            raw = raw[chunk_size:]
        self.ExpectDownload(pieces)
        self.ExpectFlash(partition)

        cb = lambda progress, total: progresses.append((progress, total))

        commands = fastboot.FastbootCommands(self.usb)
        commands.FlashFromFile(partition, tmp.name, progress_callback=cb)
        self.assertEqual(len(pieces), len(progresses))
        os.remove(tmp.name)
예제 #13
0
 def fastboot(self):
     return fastboot.FastbootCommands().ConnectDevice(handle=self.usbdev)
예제 #14
0
 def fastboot(self):
     return fastboot.FastbootCommands(self.usbdev)
예제 #15
0
# just a quick demo of the adb fastboot thing, untested

from adb import fastboot

dev = fastboot.FastbootCommands()
dev.ConnectDevice()

# dev.Oem("unlock")
dev.RebootBootloader()

dev.Close()