97
Plugins in PhoneGap User-group meeting 26/04/2016 Michiel Willocx

Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

  • Upload
    others

  • View
    12

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Plugins in PhoneGap

User-group meeting

26/04/2016

Michiel Willocx

Page 2: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Table of content

• Introduction

• The internals of a PhoneGap plugin

• The PhoneGap Plugin Store

• Performance of PhoneGap plugins (case study: data storage)

• Security of PhoneGap plugins (case study: hot code updates)

Page 3: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Web Apps

Web-To-Native

WrappersSource Code

Translator

Application

Code

Runtime

Environment

Operating

System

Runtimes

1) Based on web technology 2) Not based on Web technology

Introduction

Page 4: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom
Page 5: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom
Page 6: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Add PhoneGap plugins to your application

$ cd <location main folder of PhoneGap project>

$ cordova plugin add https://github.com/<plugin name>

Page 7: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

The internals of a PhoneGap plugin

• Example: media capture plugin

• Captures:

o Audio

o Images

o Video

Page 8: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

// capture callbackvar captureSuccess = function(mediaFiles) {

var i, path, len;for (i = 0, len = mediaFiles.length; i < len; i += 1) {

path = mediaFiles[i].fullPath;// do something interesting with the file

}};

// capture error callbackvar captureError = function(error) {

navigator.notification.alert('Error code: ' + error.code, null, 'Capture Error');};

// start audio capturenavigator.device.capture.captureAudio(captureSuccess, captureError, {limit:2});

Code Example

Page 9: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

The internals of a PhoneGap plugin

Page 10: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

plugin.xml

Contains all plugin settings

Page 11: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

plugin.xml

All JavaScript files included in

the plugin.

Page 12: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

plugin.xml

Platform specific settings

In Android:

• Permissions required by the plugin

• Included Java files

is copied to Android Manifest

Analogous, iOS

configurations are

copied to Info.plist,

and Windows Phone

configurations to

WMAppManifest.xml

Page 13: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

www folder

Page 14: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

JavaScript file

Functions, available for the

developer to use in the

PhoneGap application

Page 15: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

src folder

Page 16: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Android Source

Page 17: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

PhoneGap Plugin Store

Page 18: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

PhoneGap Plugin Store

http://cordova.apache.org/plugins/

Page 19: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Featured/Core Plugins

• Basic device plugins provided by PhoneGap/Cordova

• Geolocation

• Globalization

• InAppBrowser

• Keyboard

• Media

• Dialogs (Notification)

• SplashScreen

• StatusBar

• Vibration

• Whitelist

• (Whitelist legacy version)

• Device Motion (Accelerometer)

• Battery Status

• Camera

• Media Capture (Capture)

• Device Orientation (Compass)

• Network Information (Connection)

• Console

• Contacts

• Device

• File (FileSystem)

• File Transfer

Totaal: 21(+1)

Page 20: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

The PhoneGap Plugin Store: An overview

Page 21: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Analysis Method:

• Collecting information about each plugin in the store

• Selenium with Firefox in Java

• Download and analyze each plugin

• Download: Shell script

• Analyze: Java program

Page 22: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Overview of the PhoneGap Plugin Store

• Plugin store is growing fast

February Now

# Plugins ± 950 ± 1150

# Developers ± 450 ± 500

Page 23: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Platform Coverage of the Plugins

Average for all plugins:

• Coverage of 1,7-1,8 platforms per plugin

< 2 platforms

Android iOS WP Blackberry Ubuntu Firefoxos Fireos

# Plugins 810 732 168 123 63 44 79

% Plugins 71% 64% 15% 11% 6% 4% 7%

Page 24: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Platform Coverage of the Plugins

Some more stats

961 84% Support at least one of the 3 main platforms

157 14% Support all 3 main platforms

587 51% Support Android and iOS

• Coverage remains at 1,7-1,8 platforms per plugin

0

50

100

150

200

250

300

350

400

450

500

1 2 3

AmountofSupportedplatforms

Page 25: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Downloads of Plugins

Most downloaded : Whitelist plugin (see later this presentation)

0

100

200

300

400

500

600

700

800

0-10 10-100 100-1000 1000-10.000 10.000-100.000 More

AmountofdownloadsforPhoneGapPlugins(LastMonth)

Mostly featured plugins

Page 26: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Most popular non-featured PluginsPlugin name #Downloads What?

cordova-ios 92.897allows Cordova-based projects to be built for the iOS Platform

ionic-plugin-keyboard 72.587Easy interaction with the keyboard (hide, show,…)

com.instafeez.cordova 38.350 integration for Razorpay checkout

cordova-plugin-baidupush 34.811 baidu push = chinese cloud service

com.shahidachmat.intermec.scanner 23.777 barcode scanner

phonegap-plugin-push 17.008 Receive and handle native push notifications

cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android)

cordova-camera-custom 10.258 allows camera interaction from html code

cordova-plugin-x-socialsharing 8.300 Share text, images,… via the native sharing widget

cordova-plugin-x-toast 6.119 show a Toast

Page 27: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

CrossWalk Webview for Android

Page 28: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Recently: Crosswalk also available on iOS

Page 29: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Plugin Updates

0

50

100

150

200

250

300

<1month <3months <6months <9months <1year >1year

LastUpdateforPhoneGapPlugins • Most plugins are

frequently updated

• Many non-updated

plugins are submitted by

the same programmer

• “All” plugins were

updated last year

• Most featured plugins

are frequently updated

Page 30: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Plugin Updates

Plugin Name AuthorLast

UpdatedDownloads Last

MonthAmount of Commits

Amountof Issues

Amountof stars

cordova-plugin-okhttp agrieve 384 117 4 1 4

cordova-plugin-service-worker maxw 368 45 137 6 45

cobweb-camera-va-plugin panterz 355 17 12 0 0

cobweb-los-plugin panterz 355 10 12 0 0

cordova-plugin-websql-async dickvdbrink 349 43 43 9 4

cordova-plugin-android-support-v4 floatinghotpot 348 1.270 2 0 2

cordova-plugin-paypalmpl floatinghotpot 348 35 19 5 3

cordova-plugin-mobfox floatinghotpot 348 26 28 6 10

cordova-plugin-smartadserver floatinghotpot 348 9 15 0 4

cordova-plugin-iflyspeech floatinghotpot 348 8 4 1 18

cordova-plugin-wifi floatinghotpot 347 91 6 4 8

cordova-plugin-android-support-v7-appcompat floatinghotpot 347 23 1 0 0

cordova-plugin-appleiap floatinghotpot 347 11 16 1 13

cordova-plugin-barcodescanner hypery2k 346 943 170 6 10

Page 31: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

How to update a Cordova plugin in a PhoneGap app

• PhoneGap Plugins are not automatically updated!

• Manually remove and add the plugin again:

$ cordova plugin rm https://github.com/apache/cordova-plugin-camera

$ cordova plugin add https://github.com/apache/cordova-plugin-camera

Plugin updated in the Plugin Store ≠ Plugin updated in your application

Page 32: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Android permissionsandroid.permission.INTERNET 177

android.permission.ACCESS_NETWORK_STATE 161

android.permission.WRITE_EXTERNAL_STORAGE 116

android.permission.WAKE_LOCK 66

android.permission.ACCESS_COARSE_LOCATION 62

android.permission.ACCESS_FINE_LOCATION 60

android.permission.VIBRATE 51

com.google.android.c2dm.permission.RECEIVE 50

android.permission.READ_PHONE_STATE 47

$PACKAGE_NAME.permission.C2D_MESSAGE 42

android.permission.ACCESS_WIFI_STATE 41

android.permission.RECORD_AUDIO 35

android.permission.GET_ACCOUNTS 29

android.permission.RECEIVE_BOOT_COMPLETED 29

android.permission.BLUETOOTH 26

android.permission.READ_EXTERNAL_STORAGE 26

android.permission.BLUETOOTH_ADMIN 22

android.permission.CAMERA 22

android.permission.MODIFY_AUDIO_SETTINGS 18

android.permission.CHANGE_WIFI_STATE 9

Page 33: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Android permissions

github.com/Lancezh/cordova-plugin-qtpaysdk 18

github.com/Pushwoosh/pushwoosh-phonegap-3.0-plugin 17

github.com/Code1Tech/phonegap-plugin-push 14

github.com/Kandy-IO/kandy-phonegap 14

github.com/cranberrygame/cordova-plugin-ad-admob-inmobi 13

github.com/rongcloud/cordova-plugin-rongcloud-im 12

github.com/mrwutong/cordova-qdc-baidu-push 12

github.com/EtherZhou/baidupush 10

github.com/Donky-Network/cordova-plugin-donky-core 10

github.com/Donky-Network/cordova-plugin-donky-push 10

github.com/mobiletools/context-sensing-cordova 10

Page 34: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

github.com/Lancezh/cordova-plugin-qtpaysdk

android.permission.ACCESS_NETWORK_STATE

android.permission.WRITE_EXTERNAL_STORAGE

android.permission.WAKE_LOCK

android.permission.ACCESS_COARSE_LOCATION

android.permission.ACCESS_FINE_LOCATION

android.permission.VIBRATE

android.permission.READ_PHONE_STATE

android.permission.ACCESS_WIFI_STATE

android.permission.RECORD_AUDIO

android.permission.BLUETOOTH

android.permission.READ_EXTERNAL_STORAGE

android.permission.BLUETOOTH_ADMIN

android.permission.CHANGE_WIFI_STATE

android.permission.ACCESS_LOCATION_EXTRA_COMMANDS

android.permission.DISABLE_KEYGUARD

android.permission.SYSTEM_ALERT_WINDOW

android.permission.BROADCAST_STICKY

Page 35: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Pushwoosh/pushwoosh-

phonegap-3.0-plugin

Page 36: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

What do PhoneGap Plugins offer?

“There is a plugin

for everything”

Page 37: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

What do PhoneGap Plugins offer?

• Featured/Core PhoneGap plugins provide basic device features

• Geolocation

• Globalization

• InAppBrowser

• Keyboard

• Media

• Dialogs (Notification)

• SplashScreen

• StatusBar

• Vibration

• Whitelist

• (Whitelist legacy version)

• Device Motion (Accelerometer)

• Battery Status

• Camera

• Media Capture (Capture)

• Device Orientation (Compass)

• Network Information (Connection)

• Console

• Contacts

• Device

• File (FileSystem)

• File Transfer

Page 38: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

User interface

Page 39: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

User interface

Page 40: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

User interface

Page 41: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Security

Storage

Page 42: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Social networks

Page 43: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Payment

• In app purchases

Page 44: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Payment related

• PayPal

Page 45: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Other

• Push notifications

Page 46: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Other

• Update JavaScript code of the PhoneGap application

o Update without the app store

Page 47: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Alternatives for the PhoneGap Plugin Store

Most JavaScript Frameworks have a custom plugin store

• Some plugins are also in the main PhoneGap plugin store

• Also paid plugins

Page 48: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Alternatives for the PhoneGap Plugin Store: Examples

Ionic

• >100 plugins

• Free and paid

• Only 19 Ionic plugins in the

PhoneGap Plugin store

Page 49: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Alternatives for the PhoneGap Plugin Store: Examples

Page 50: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Alternatives for the PhoneGap Plugin Store: Examples

jQuery Mobile

• >500 free JavaScript plugins

(Plugins which don’t require a

JavaScript bridge)

Page 51: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Performance of PhoneGap Plugins

Case study: Data Storage

Page 52: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Case Study: Data Storage

Database Storage

Store 100 books, request

all books, delete 50

books and finaly request

all books again

File Storage

Storing and retrieving file

contents native and

through Cordova

Key-Value Pairs

Save and retrieve a

string (1000 iterations)

Page 53: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Storage strategies in Cordova

Storageimplementations Androiddevice

iOSdevice

Database

WebSQL ■ ■

IndexedDB þ ý

SQLite(plugin) þ þ

File FileAPI(plugin) þ þ

Variables

LocalStorage þ þ

NativeStorage þ þ

Not supported

Supported

■ Deprecated (but supported)

Page 54: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

NativeStorage vs classic LocalStorage

NativeStorage LocalStorage

Plugin HTML5

Executed on the native side Executed in the webview

Guaranteed persistent storage NO guaranteed persistent storage

All primitive types (string, int,

double, boolean) and objects(!)

Only strings

https://www.npmjs.com/package/cordova-plugin-nativestorage

Page 55: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Database performance

Store 100 books, request

all books, delete 50

books and finaly request

all books again

SQLiteWebSQLSQLite PluginIndexedDB SQLite

Page 56: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

SQLite

WebSQL

SQLite Plugin

IndexedDB

Duration of

total operation

time

97 1398 1855 2140(ms)

Database performance [Android]

Page 57: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

SQLite

WebSQLSQLite Plugin

Duration of

total operation

time

1925 2235 2467(ms)

Database performance [iOS]

Page 58: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

File storage performance

Storing and retrieving file

contents native and

through Cordova

SQLite SQLite

File API (plugin)

https://github.com/apache/cordova-plugin-file

Page 59: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

File storage performance [Android]

0

500

1000

1500

2000

2500

3000

3500

4000

4500

0 5 10 15 20

Rea

d/W

rite

du

rati

on

(ms)

File volume (Mb)

Cordova Write

Cordova Read

Android Read

Android Write

Page 60: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Read overhead in Cordova Android

Native read

Cordova Read Overhead

Get JS message

(our text)

Resolve to local URL

Page 61: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Cordova Write Overhead

Write overhead in Cordova Android

JS Processing command

Execute call delay

Blob creation

Native write

A blob

represents a

byte sequence

Page 62: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

File storage performance [iOS]

https://github.com/apache/cordova-plugin-file

0

1000

2000

3000

4000

5000

6000

7000

8000

0 2 4 6 8 10 12

Rea

d/W

rite

Du

rati

on

(m

s)

Read/Write volume (MB)

Cordova vs iOS (iphone 6 [9.2])

iOS Read

iOS Write

Cordova iOS Read

Cordova iOS Write

Page 63: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Read overhead in Cordova iOS

Native read

Cordova Read Overhead

Send over bridge

Convert to JSONArray

Page 64: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Cordova Write Overhead

Write overhead in Cordova iOS

JS Processing command

Blob creation

Native write

Page 65: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Key-value storage performance

SharedPreferencesNativeStorage (plugin)localStorage NSuserDefaults

Save and retrieve a

string (1000 iterations)

Plists

https://www.npmjs.com/package/cordova-plugin-nativestorage

Page 66: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Key-value storage performance

GET: <1 ms for all implementations

SET: <1 ms for all implementations, except NativeStorage (1,8 ms)

GET: <1 ms for all implementations

SET: <1 ms for all implementations

Cordova overhead +

asynchronous

Page 67: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Plugins and Security

Page 68: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Plugins and Security

The resource could not be loaded because the App Transport Security

policy requires the use of a secure connection.

Intro

Page 69: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom
Page 70: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom
Page 71: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom
Page 72: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom
Page 73: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Whitelist Plugin

• Featured PhoneGap Plugin

• Automatically added to each PhoneGap project

Page 74: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom
Page 75: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom
Page 76: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Adaptation of the whitelist plugin

Mohamed Shehab and Abeer AlJarrah. 2014. Reducing Attack Surface on Cordova-based Hybrid Mobile Apps. In Proceedings

of the 2nd International Workshop on Mobile Development Lifecycle (MobileDeLi '14). ACM, New York, NY, USA, 1-8.

60 % of PhoneGap apps grants open access to all domains

Personal experience: it’s probably even worse…

Page 77: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

History of the whitelist plugin

• Cordova Whitelist doesn’t work

o On Android API 10 and below (=2.3.3 Gingerbread)

o On Windows Phone 8 for iframes and XMLHttpRequest

o On Cordova versions below 2.9

example.com whitelisted example.com.evil.com also accepted

Page 78: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Hot code update plugins

• Allow PhoneGap applications to be updated without the app store

Page 79: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Hot code update plugins

APK

Webview

…Assets

WWW …

……

Updated www

<Location outside of the APK>

Page 80: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Meteor-cordova-update-plugin

Page 81: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Meteor Todo App

Page 82: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Man-In-The-Middle Attack

iptables -t nat -A PREROUTING -i wlan0 -p tcp --dport 80 -j

DNAT --to 192.168.1.100:8080

Page 83: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Man-In-The-Middle Attack

Page 84: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Man-In-The-Middle Attack

Page 85: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom
Page 86: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom
Page 87: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Actual content,

loaded into the

application

Page 88: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Replaced the HTML content

of the response

Page 89: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Result

Page 90: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Okay, but what is the point?

Page 91: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Actual content,

loaded into the

application

Page 92: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Insert some extra

JavaScript code

Page 93: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Result

App launches as always, nothing special?

Page 94: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Pictures from the device

Page 95: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

How to protect against this?

Page 96: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom

Conclusion Security of PhoneGap Plugins

What does the plugin do?

What is the quality of the code?

Is the plugin up-to-date (store & app)?

How do I use the plugin?

Do I still use every plugin in my

application?

Page 97: Plugins in PhoneGap plugins.pdf · phonegap-plugin-push 17.008 Receive and handle native push notifications cordova-plugin-crosswalk-webview 15.357 Crosswalk webview (Android) cordova-camera-custom