Monday, January 18, 2016

Disable same origin and local url loading in browser for testing

Change local files security policy

Safari

Enable the develop menu using the preferences panel, under Advanced -> "Show develop menu in menu bar"
Then from the safari "Develop" menu, select "Disable local file restrictions", "Disable Cross-Origin Restrication", it is also worth noting safari has some odd behavior with caches, so it is advisable to use the "Disable caches" option in the same menu; if you are editing & debugging using safari.

Chrome

Close all running Chrome instances first. The important word here is 'all'.
On Windows, you may check for Chrome instances using the Windows Task Manager. Alternatively, if you see a Chrome icon in the system tray, then you may open its context menu and click 'Exit'. This should close all Chrome instances.
Then start the Chrome executable with a command line flag:
chrome --allow-file-access-from-files --disable-web-security
On Windows, probably the easiest is probably to create a special shortcut icon which has added the flag given above (right-click on shortcut -> properties -> target).

Firefox

  1. Go to about:config
  2. Find security.fileuri.strict_origin_policy parameter
  3. Set it to false

Wednesday, November 18, 2015

NSURLSession delegate and data task delegate for CustomHttpProtocol sample

Apple provides a sample project CustomHttpProtocol to demonstrate how NSURLProtocol works with NSURLSession.

Note the project includes a file QNSURLSessionDemux, which involves how NSURLSession' delegate works.

When creating a NSURLSession object from NSURLSessionConfiguration,
+ sessionWithConfiguration:delegate:delegateQueue:
a delegate of NSURLSessionDelegate can be specified in the delegate parameter. Apparently this delegate will be used to handle NSURLSessionDelegate event.

When creating the data task from the NSURLSession object, Apple defiends NSURLSessionDataDelegate and NSURLSessionTaskDelegate to handle the per task event. However, unlike NSURLSession, when creating the data task, there is no parameter in
- dataTaskWithRequest:completionHandler:
method to specify a delegate to handle the per task event. Instead the delegate object passed for creating NSURLSession will also be used to handle the per task delegate event.

Then the problem comes, as the delegate for NSURLSession is a shared delegate object for all data tasks, but each task has its own logic to handle the response data as well as mode and thread, so once the NSURLSession's common delegate get the per task delegate event, it has to find a way to route back to the per task delegate to handle it.

QNSURLSessionDemux in CustomHttpProtocol is created for this purpose, it keeps a dictionary of per task data delegate specified by application when the data task is created. Then the NSURLSessionDelegate will route the per task event their corresponding per task delegate.

Actually, NSURLSessionTaskDelegate and NSURLSessionDataDelegate are all derived from NSURLSessionDelegate, which implies the NSURLSession delegate will also be used to handle per task event.

One last note, when creating the data task, if custom delegate will be used to handle NSURLSession's data task event, then use the method that does not take the completionHandler. Otherwise, if completionHandler exists, then the default system delegate will be used, and custom delegate will not be invoked.  

SAP UI5: Logic to start a tile from launchpad

Shell-dbg.controller.js openApp() method is called, which then calls NavContainer-dbg.js to method.
Render manger will call ApplicationContainer-dbg.js createUI5Component method

The UI5 application's component.js createContent method is called, this is the first chance the application's code is executed. The method will create the view.
When creating the view, the application's Main.Controller.js' onInit method is called.

Application-dbg.js main() method is called, which calls ApplicationImplementation-dbg.js startApplication method.

ConnectionManger-dbg.js getNewInstance method is called, which will call initModels() for creating oDataModel based on url and application config (line 171)

oDataModel-dbg.js oDataModel constructor is called to create the model, which will get metadata from server.

The UI5 application view's onInit method is called, which will all getServiceSchemeVersion()

Monday, November 2, 2015

Config proxy for Android emulator for internet access

When running android emulator on a Windows box, if the Windows box is behind a proxy, then the android emulator will also need to config the proxy settings in order to get internet access. This can be easily verified by using mobile chrome browser to access www.google.com, if it fail, then likely it is due to proxy settings. 

The below steps can be used for this:
1. From Android emulator, open settings app
2. Under Wireless & Networks section, click More...
3. click Mobile network item
4. click Access Point Names item
5. click T-Mobile US item
6. Set proxy to your proxy server's name, for example: proxy.phl.sap.corp
7. Set port to your proxy server's port, for example: 8080
8. Go back and open mobile browser, and visit http://www.google.com and it should work

Friday, October 30, 2015

Fix Mac boot hanging due to missing var/folders

Although /var/folders" (or "/private/var/folders") is "per-user temporary files and caches", and its content can be cleaned by system at any time, but the var/folders itself cannot be deleted. After I accidentally deleted var/folders fold from my mac, and the box could not reboot successfully.  

By restarting the mac in single user mode (pressing Command+S) in unix shell, I tried to add the var/folders back, however, the mkdir failed as the folder is mounted as readonly. Unfortunately, chflags does not work in this case.

The rescue is
mount -uw

which will mount the folder as read-write. After that, mkdir can successfully create the var/folders again, and the mac can reboot properly. The strange thing is you can delete var/folders using Finder, but you cannot put it back or create a new var/folders folder using Finder.

Sunday, October 18, 2015

Android studio build issues- gradle proxy, file path size, etc

1. When running android studio on Windows, the gradle build may get an error of "No Resource found that matches ..." or "unable to open file ...". 

One possible reason of the error is due to the limitation of the maximal length of the file path. To fix the issue, move the project close to a root folder of the current drive, instead of staying in a deep nested subfolder on the current drive.


2. The android studio only build armv7 apk when running the app on emulator
In Build.gradle, locate productFlavors item and remove the "armv7" element


3. set proxy for gradle
create a text file with name of gradle.properties and put the file under the project's root folder with the content of:

systemProp.http.proxyHost=proxy.phl.sap.corp
systemProp.http.proxyPort=8080
systemProp.https.proxyHost=proxy.phl.sap.corp
systemProp.https.proxyPort=8080


4. for the error of "Unable to execute dex: method ID not in [0, 0xffff]"

You need to enable multiDex with the below steps:
First, update android defaultConfig
android {
   defaultConfig {
      ...
      multiDexEnabled = true
   }
}

Then, add multiple dependency
dependencies {
  ...
  compile 'com.android.support:multidex:1.0.0'


5. for the out of memory GC error
Add the below options in Android block
dexOptions {
    incremental true
    javaMaxHeapSize "4g"
}

Friday, October 16, 2015

Show and copy android screen from device to mac

1.download droidAtScreen-1.2.jar from http://droid-at-screen.org/
2.connect the android device with mac and Configure your device to allow USB Debugging from (Settings-> Developer options -> USB debugging)
3.from command line, run
java -jar droidAtScreen-a.b.c.jar