Sunday, 21 December 2014

Charge rate of Nexus Devices

I decided to test the charge rate of my Nexus devices, I have a Nexus 10, Nexus 7 (2012) Nexus 5 and Galaxy Nexus. I have a Nexus 1 but I couldnt be bothered booting it.

Tests were done using a 5v source from an old ATX power supply, so it has 30 Amps at 5V to play with.
DeviceUSBACDock (AC)
N70.4150.4121.2
N100.7690.5570.62
N50.4290.485N.A
GN0.4350.688

All devices are running android 5.0.X except the Galaxy Nexus which is running a recent Cyanogen Mod Android 4.3

Some odd things, at times the N7 would decide to draw practically nothing, seemed rather random. It though through its pogo pin by far drew the most power at 1.2 amps. The N10 was a little surprising, it seemed to think that the USB mode was AC and would draw more power than actual AC mode did. Its Magnetic POGO didn't seem to provide that much power. I would have expected something with large pins would take more than 1 Amp, since its charger is 2 Amp rated. I guess this is why Google/Samsung never got the charging right. The Nexus 5 was a little disappointing in that it drew very little more power on AC Mode.

We cant expect much really through micro USB, the wires are so small on the connector and on the circuits behind them, they really are not capable of carrying much.

Sunday, 14 December 2014

ACRA Reporter

ACRA reporter is an appengine app for receiving acra error reports, decoding the stack traces, allowing easy fixes and tracking there of. It is not intended as a reporting tool on the number of errors the apps have..

Get Started

  1. Sign-up and logon, https://wintersacrareporter.appspot.com or http://acra.winters.org.nz (no ssl yet on the domain).
  2. Add your application details under "Applications->Add".
    1. Important, the details are such.
    2. Package Name - must match your app's package name, it is case sensitive.
    3. App Name - what your app is known by, used to display in the reporter.
    4. Error Report Script Authentication - this is the username/password your app will use to authenticate with the server when posting errors.
    5. E-Mail Template - a template for sending fix reports to the users (currently not implemented).
  3. Add code to your application to send the error reports.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
@ReportsCrashes(formKey = "",
  formUri="https://wintersacrareporter.appspot.com/acrareport",
  formUriBasicAuthLogin = "username", 
  formUriBasicAuthPassword = "password",
  mode = ReportingInteractionMode.DIALOG, 
  resNotifTickerText = R.string.crash_notif_ticker_text, 
  resNotifTitle = R.string.crash_notif_title, 
  resNotifText = R.string.crash_notif_text, 
  resNotifIcon = android.R.drawable.stat_notify_error,
  resDialogText = R.string.crash_dialog_text, 
  resDialogIcon = android.R.drawable.ic_dialog_info, 
  resDialogTitle = R.string.crash_dialog_title, 
  resDialogCommentPrompt = R.string.crash_dialog_comment_prompt, 
  resDialogOkToast = R.string.crash_dialog_ok_toast)
public class CrashAppWrapper extends Application
{
  @Override
  public void onCreate()
  {
    // The following line triggers the initialization of ACRA
    super.onCreate();
     try
    {
      ACRA.init(this);
    }catch(IllegalStateException e)
    {
      // ignore acra error
    }
  }

 
}


I use the dialog method, and prompt the user to enter their e-mail address in the comments, this allows me to e-mail them and tell them the problem has been fixed, or ask for more information.
Upload the proguard mapping files.
Currently uploading from within the reporter doesn't work, but this is best done from a curl script within your continuous build system (you do use one???).
eg, in an ant script.

1
2
3
<exec executable="curl"> 
  <arg line="-u username:password -T  bin/proguard/mapping.txt &quot;https://wintersacrareporter.appspot.com/mappingfile?package=${app_package}&amp;version=${bigbuildnumber}&quot;"/> 
</exec> 

The username & password to use here is the one you entered when you signed up.
You also need to ensure the app_package and bigbuildnumber ant properties are set, eg.

1
<property name="app_package" value="nz.org.winters.android.gnfastcharge"/> <property name="bigbuildnumber" value="${buildmajor}.${buildnumber}.${svnrevision}"/>

Now, its all go - run some tests..

Some other bits.

Your existing error reports in the google docs spreadsheets can be altered to automatically upload any new records, and also upload any existing records..

  1. Open up the spreadsheet.
  2. Select Tools->Script Editor.
  3. Paste in the following.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    /**
     * Retrieves all the rows in the active spreadsheet that contain data and logs the
     * values for each row.
     * For more information on using the Spreadsheet API, see
     * https://developers.google.com/apps-script/service_spreadsheet
     */
    function readRows() {
      var sheet = SpreadsheetApp.getActiveSheet();
      var rows = sheet.getDataRange();
      var numRows = rows.getNumRows();
      var values = rows.getValues();
    
      var headers = values[0];
      
      for (var i = 1; i <= numRows - 1; i++) {
        var payload = {}; 
        var row = values[i];
        for(var y = 1; y < headers.length; y++)
        {
          payload[headers[y]] = row[y];
        }
        
    
        var unamepass ="username:password";
         var digest = Utilities.base64Encode(unamepass);
         var digestfull = "Basic "+digest;
      var options =
        {
          "method" : "post",
          headers: {"Authorization": digestfull},
          "payload" : payload
        }    
    
      //Logger.log(options);
        
        var feed =  UrlFetchApp.fetch('https://wintersacrareporter.appspot.com/acrareport',options);
        Logger.log(feed.getContentText());
      }
      sheet.deleteRows(2, numRows-1)
    };
    
    /**
     * Adds a custom menu to the active spreadsheet, containing a single menu item
     * for invoking the readRows() function specified above.
     * The onOpen() function, when defined, is automatically invoked whenever the
     * spreadsheet is opened.
     * For more information on using the Spreadsheet API, see
     * https://developers.google.com/apps-script/service_spreadsheet
     */
    function onOpen() {
      var sheet = SpreadsheetApp.getActiveSpreadsheet();
      var entries = [{
        name : "Send Data",
        functionName : "readRows"
      }];
      sheet.addMenu("Script Center Menu", entries);
    };
    
Remember to change username/password.



  • Select Resources->Current Script Triggers
  • Make the trigger run readRows from spreadsheet on form submit
  • run the script "readrows" all your current rows will be uploaded and removed from the spreadsheet..
  • PROGUARD what can go wrong!

    Overview

    I updated my app, and things started to go wrong, everyone was crashing, I had no idea why, my own installs weren't, it took several iterations and some additional debug information to figure out what went wrong.

    I use proguard, it is an obfuscater of Java code, so it is harder to reverse engineer all android developers should be using this. One of the things proguard does is change the Java class and package names to something that is not too recognizable..

    What I did wrong!

    My app, the NZ Phone Account Widget, can get data from different sources, all of these need different processing to suit, so to match the "provider" as i call them to the account, I was saving the class name of the provider as a setting in the database, this is where proguard tripped me up. For quite a long while proguard must have kept the same obtuse names for the provider classes, then it changed.. So when the setting was read out of the database and used to find the class, it couldn't find the class and returned a null..

    Why did I not see it.

    My tablet runs a debug version, which the class names are not obtuse, so the non obtuse names are saved in the database. My Phones database is rather old and stores an index id from an earlier database conversion (which is valid), and when I add new account for testing (I add/remove skinny for this), the new obtuse name was saved..

    What specifically were the changes..

    On the left, is the raw name, on the right is the obtuse name, see it change in the version..
    mapping.2.262.789.txt:nz.org.winters.android.nzmobileaccountwidget.providers.base.ProviderTwoDegrees -> nz.org.winters.android.nzmobileaccountwidget.providers.a.g:
    mapping.2.263.803.txt:nz.org.winters.android.nzmobileaccountwidget.providers.base.ProviderTwoDegrees -> nz.org.winters.android.nzmobileaccountwidget.b.a.g:

    mapping.2.262.789.txt:nz.org.winters.android.nzmobileaccountwidget.providers.base.ProviderTelecomXT -> nz.org.winters.android.nzmobileaccountwidget.providers.a.f:
    mapping.2.263.803.txt:nz.org.winters.android.nzmobileaccountwidget.providers.base.ProviderTelecomXT -> nz.org.winters.android.nzmobileaccountwidget.b.a.f:

    mapping.2.262.789.txt:nz.org.winters.android.nzmobileaccountwidget.providers.base.ProviderSkinny -> nz.org.winters.android.nzmobileaccountwidget.providers.a.e:
    mapping.2.263.803.txt:nz.org.winters.android.nzmobileaccountwidget.providers.base.ProviderSkinny -> nz.org.winters.android.nzmobileaccountwidget.b.a.e:

    mapping.2.262.789.txt:nz.org.winters.android.nzmobileaccountwidget.providers.base.ProviderVodafone -> nz.org.winters.android.nzmobileaccountwidget.providers.a.h:
    mapping.2.263.803.txt:nz.org.winters.android.nzmobileaccountwidget.providers.base.ProviderVodafone -> nz.org.winters.android.nzmobileaccountwidget.b.a.h:

    How fixed/ worked around..

    Basically, had to create 2 new methods on the provider interface, one to return a known text name eg "2DEGREES" this is now used as the setting for new accounts created. The other method takes the string from the setting and compares it against, the new text name, and the above obtuse names (both of them), this will get around all changes.

    Morel of the story!

    Don't use class names to save as a setting when using proguard!

    Thursday, 11 December 2014

    Polymer - skip loading webcomponents.js on Chrome

    With polymer, it can help just a little to skip loading the webcomponents.js script, which is the polyfills on a complient browser, like chrome..

    To do this, change the following in your index.html from:

    <script src="/bower_components/webcomponentsjs/webcomponents.js"></script>
    
    To:

    <script>  
      if('registerElement' in document    
          && 'createShadowRoot' in HTMLElement.prototype    
          && 'import' in document.createElement('link')    
          && 'content' in document.createElement('template')) {      
        // we are using browser with WC support YAY!!    
        console.log("YOU ARE USING A FULLY HTML5 COMPLIANT BROWSER");  
      } else {    
        document.write('<script src="/bower_components/webcomponentsjs/webcomponents.js"><\/script>');    
        console.log("YOU ARE NOT USING A FULLY HTML5 COMPLIANT BROWSER");  
      }
    </script>
    

    Wednesday, 10 December 2014

    Starting again.

    Time to start again on developing a new website - same content and more, just hope blogger can fill my needs..


     

    © 2013 Winters.nz . All rights resevered. Designed by Templateism