{"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/react-native-code-push/pulls/comments/45817591","id":45817591,"diff_hunk":"@@ -0,0 +1,412 @@\n+package com.microsoft.reactnativecodepush;\n+\n+import com.facebook.react.ReactPackage;\n+import com.facebook.react.bridge.Callback;\n+import com.facebook.react.bridge.JavaScriptModule;\n+import com.facebook.react.bridge.LifecycleEventListener;\n+import com.facebook.react.bridge.NativeModule;\n+import com.facebook.react.bridge.ReactApplicationContext;\n+import com.facebook.react.bridge.ReactContextBaseJavaModule;\n+import com.facebook.react.bridge.ReactMethod;\n+import com.facebook.react.bridge.ReadableMap;\n+import com.facebook.react.bridge.WritableMap;\n+import com.facebook.react.bridge.WritableNativeMap;\n+import com.facebook.react.modules.core.DeviceEventManagerModule;\n+import com.facebook.react.uimanager.ViewManager;\n+import com.facebook.soloader.SoLoader;\n+\n+import android.app.Activity;\n+import android.content.Context;\n+import android.content.Intent;\n+import android.content.SharedPreferences;\n+\n+import org.json.JSONException;\n+import org.json.JSONObject;\n+\n+import java.io.IOException;\n+import java.util.ArrayList;\n+import java.util.Calendar;\n+import java.util.Date;\n+import java.util.HashMap;\n+import java.util.List;\n+import java.util.Map;\n+import java.util.Timer;\n+import java.util.TimerTask;\n+\n+public class CodePush {\n+\n+    private String deploymentKey;\n+\n+    private boolean resumablePendingUpdateAvailable = false;\n+    private boolean didUpdate = false;\n+    private Timer timer;\n+    private boolean usingTestFolder = false;\n+\n+    private String assetsBundleFileName;\n+\n+    private final String FAILED_UPDATES_KEY = \"CODE_PUSH_FAILED_UPDATES\";\n+    private final String PENDING_UPDATE_KEY = \"CODE_PUSH_PENDING_UPDATE\";\n+    private final String PENDING_UPDATE_HASH_KEY = \"hash\";\n+    private final String PENDING_UPDATE_ROLLBACK_TIMEOUT_KEY = \"rollbackTimeout\";\n+    private final String ASSETS_BUNDLE_PREFIX = \"assets://\";\n+    private final String CODE_PUSH_PREFERENCES = \"CodePush\";\n+    private final String DOWNLOAD_PROGRESS_EVENT_NAME = \"CodePushDownloadProgress\";\n+\n+    private CodePushPackage codePushPackage;\n+    private CodePushReactPackage codePushReactPackage;\n+    private CodePushNativeModule codePushNativeModule;\n+    private CodePushConfig codePushConfig;\n+\n+    private Activity mainActivity;\n+    private Context applicationContext;\n+\n+    public CodePush(String deploymentKey, Activity mainActivity) {\n+        SoLoader.init(mainActivity, false);\n+        this.deploymentKey = deploymentKey;\n+        this.codePushPackage = new CodePushPackage(mainActivity.getFilesDir().getAbsolutePath());\n+        this.mainActivity = mainActivity;\n+        this.applicationContext = mainActivity.getApplicationContext();\n+        this.codePushConfig = new CodePushConfig(deploymentKey, this.applicationContext);\n+        checkForPendingUpdate(/*needsRestart*/ false);\n+    }\n+\n+    public ReactPackage getReactPackage() {\n+        if (codePushReactPackage == null) {\n+            codePushReactPackage = new CodePushReactPackage();\n+        }\n+        return codePushReactPackage;\n+    }\n+\n+    public String getDocumentsDirectory() {\n+        return codePushPackage.getDocumentsDirectory();\n+    }\n+\n+    public String getBundleUrl(String assetsBundleFileName) {\n+        this.assetsBundleFileName = assetsBundleFileName;\n+        String binaryJsBundleUrl = ASSETS_BUNDLE_PREFIX + assetsBundleFileName;\n+        try {\n+            String packageFile = codePushPackage.getCurrentPackageBundlePath();\n+            if (packageFile == null) {\n+                // There has not been any downloaded updates.\n+                return binaryJsBundleUrl;\n+            }\n+\n+            return packageFile;\n+        } catch (IOException e) {\n+            throw new CodePushUnknownException(\"Error in getting current package bundle path\", e);\n+        }\n+    }\n+\n+    private void cancelRollbackTimer() {\n+        if(timer != null) {\n+            timer.cancel();\n+            timer = null;\n+        }\n+    }\n+\n+    private void checkForPendingUpdate(boolean needsRestart) {\n+        SharedPreferences settings = applicationContext.getSharedPreferences(CODE_PUSH_PREFERENCES, 0);\n+        String pendingUpdateString = settings.getString(PENDING_UPDATE_KEY, null);\n+\n+        if (pendingUpdateString != null) {\n+            try {\n+                JSONObject pendingUpdateJSON = new JSONObject(pendingUpdateString);\n+                String pendingHash = pendingUpdateJSON.getString(PENDING_UPDATE_HASH_KEY);\n+                String currentHash = codePushPackage.getCurrentPackageHash();\n+                if (pendingHash.equals(currentHash)) {\n+                    int rollbackTimeout = pendingUpdateJSON.getInt(PENDING_UPDATE_ROLLBACK_TIMEOUT_KEY);\n+                    initializeUpdateWithRollbackTimeout(rollbackTimeout, needsRestart);\n+\n+                    settings.edit().remove(PENDING_UPDATE_KEY).commit();\n+                }\n+            } catch (JSONException e) {\n+                // Should not happen.\n+                throw new CodePushUnknownException(\"Unable to parse pending update metadata \" +\n+                        pendingUpdateString + \" stored in SharedPreferences\", e);\n+            } catch (IOException e) {\n+                // There is no current package hash.\n+                throw new CodePushUnknownException(\"Should not register a pending update without a saving a current package\", e);\n+            }\n+        }\n+    }\n+\n+    private void checkForPendingUpdateDuringResume() {\n+        if (resumablePendingUpdateAvailable) {","path":"android/app/src/main/java/com/microsoft/reactnativecodepush/CodePush.java","position":134,"original_position":134,"commit_id":"a636482846dbfea331f2b239d884965dbed0b5c8","original_commit_id":"a636482846dbfea331f2b239d884965dbed0b5c8","user":{"login":"geof90","id":8598682,"avatar_url":"https://avatars.githubusercontent.com/u/8598682?v=3","gravatar_id":"","url":"https://api.github.com/users/geof90","html_url":"https://github.com/geof90","followers_url":"https://api.github.com/users/geof90/followers","following_url":"https://api.github.com/users/geof90/following{/other_user}","gists_url":"https://api.github.com/users/geof90/gists{/gist_id}","starred_url":"https://api.github.com/users/geof90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geof90/subscriptions","organizations_url":"https://api.github.com/users/geof90/orgs","repos_url":"https://api.github.com/users/geof90/repos","events_url":"https://api.github.com/users/geof90/events{/privacy}","received_events_url":"https://api.github.com/users/geof90/received_events","type":"User","site_admin":false},"body":"Its not a hard rule. Consistency is the main concern. I will be happy to add underscores if you think it is important.","created_at":"2015-11-25T00:55:52Z","updated_at":"2015-11-25T00:55:52Z","html_url":"https://github.com/Microsoft/react-native-code-push/pull/62#discussion_r45817591","pull_request_url":"https://api.github.com/repos/Microsoft/react-native-code-push/pulls/62","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/react-native-code-push/pulls/comments/45817591"},"html":{"href":"https://github.com/Microsoft/react-native-code-push/pull/62#discussion_r45817591"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/react-native-code-push/pulls/62"}}},"pull_request":{"url":"https://api.github.com/repos/Microsoft/react-native-code-push/pulls/62","id":51605358,"html_url":"https://github.com/Microsoft/react-native-code-push/pull/62","diff_url":"https://github.com/Microsoft/react-native-code-push/pull/62.diff","patch_url":"https://github.com/Microsoft/react-native-code-push/pull/62.patch","issue_url":"https://api.github.com/repos/Microsoft/react-native-code-push/issues/62","number":62,"state":"open","locked":false,"title":"Android support","user":{"login":"geof90","id":8598682,"avatar_url":"https://avatars.githubusercontent.com/u/8598682?v=3","gravatar_id":"","url":"https://api.github.com/users/geof90","html_url":"https://github.com/geof90","followers_url":"https://api.github.com/users/geof90/followers","following_url":"https://api.github.com/users/geof90/following{/other_user}","gists_url":"https://api.github.com/users/geof90/gists{/gist_id}","starred_url":"https://api.github.com/users/geof90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geof90/subscriptions","organizations_url":"https://api.github.com/users/geof90/orgs","repos_url":"https://api.github.com/users/geof90/repos","events_url":"https://api.github.com/users/geof90/events{/privacy}","received_events_url":"https://api.github.com/users/geof90/received_events","type":"User","site_admin":false},"body":"This PR adds support for Android.","created_at":"2015-11-24T01:23:33Z","updated_at":"2015-11-25T00:55:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3a8484accddac6f670edeb3cecb60f4166b96e85","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/react-native-code-push/pulls/62/commits","review_comments_url":"https://api.github.com/repos/Microsoft/react-native-code-push/pulls/62/comments","review_comment_url":"https://api.github.com/repos/Microsoft/react-native-code-push/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Microsoft/react-native-code-push/issues/62/comments","statuses_url":"https://api.github.com/repos/Microsoft/react-native-code-push/statuses/a636482846dbfea331f2b239d884965dbed0b5c8","head":{"label":"Microsoft:android-support","ref":"android-support","sha":"a636482846dbfea331f2b239d884965dbed0b5c8","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":36749153,"name":"react-native-code-push","full_name":"Microsoft/react-native-code-push","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/react-native-code-push","description":"React Native plugin for the CodePush service","fork":false,"url":"https://api.github.com/repos/Microsoft/react-native-code-push","forks_url":"https://api.github.com/repos/Microsoft/react-native-code-push/forks","keys_url":"https://api.github.com/repos/Microsoft/react-native-code-push/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/react-native-code-push/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/react-native-code-push/teams","hooks_url":"https://api.github.com/repos/Microsoft/react-native-code-push/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/react-native-code-push/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/react-native-code-push/events","assignees_url":"https://api.github.com/repos/Microsoft/react-native-code-push/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/react-native-code-push/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/react-native-code-push/tags","blobs_url":"https://api.github.com/repos/Microsoft/react-native-code-push/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/react-native-code-push/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/react-native-code-push/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/react-native-code-push/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/react-native-code-push/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/react-native-code-push/languages","stargazers_url":"https://api.github.com/repos/Microsoft/react-native-code-push/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/react-native-code-push/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/react-native-code-push/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/react-native-code-push/subscription","commits_url":"https://api.github.com/repos/Microsoft/react-native-code-push/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/react-native-code-push/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/react-native-code-push/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/react-native-code-push/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/react-native-code-push/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/react-native-code-push/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/react-native-code-push/merges","archive_url":"https://api.github.com/repos/Microsoft/react-native-code-push/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/react-native-code-push/downloads","issues_url":"https://api.github.com/repos/Microsoft/react-native-code-push/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/react-native-code-push/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/react-native-code-push/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/react-native-code-push/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/react-native-code-push/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/react-native-code-push/releases{/id}","created_at":"2015-06-02T17:19:20Z","updated_at":"2015-11-24T23:27:30Z","pushed_at":"2015-11-25T00:10:37Z","git_url":"git://github.com/Microsoft/react-native-code-push.git","ssh_url":"git@github.com:Microsoft/react-native-code-push.git","clone_url":"https://github.com/Microsoft/react-native-code-push.git","svn_url":"https://github.com/Microsoft/react-native-code-push","homepage":"http://microsoft.github.io/code-push","size":2968,"stargazers_count":206,"watchers_count":206,"language":"Objective-C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":18,"mirror_url":null,"open_issues_count":7,"forks":18,"open_issues":7,"watchers":206,"default_branch":"master"}},"base":{"label":"Microsoft:master","ref":"master","sha":"f99a6cea920ccb40ced4ec9aad5d9a613e5a4f29","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":36749153,"name":"react-native-code-push","full_name":"Microsoft/react-native-code-push","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/react-native-code-push","description":"React Native plugin for the CodePush service","fork":false,"url":"https://api.github.com/repos/Microsoft/react-native-code-push","forks_url":"https://api.github.com/repos/Microsoft/react-native-code-push/forks","keys_url":"https://api.github.com/repos/Microsoft/react-native-code-push/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/react-native-code-push/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/react-native-code-push/teams","hooks_url":"https://api.github.com/repos/Microsoft/react-native-code-push/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/react-native-code-push/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/react-native-code-push/events","assignees_url":"https://api.github.com/repos/Microsoft/react-native-code-push/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/react-native-code-push/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/react-native-code-push/tags","blobs_url":"https://api.github.com/repos/Microsoft/react-native-code-push/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/react-native-code-push/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/react-native-code-push/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/react-native-code-push/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/react-native-code-push/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/react-native-code-push/languages","stargazers_url":"https://api.github.com/repos/Microsoft/react-native-code-push/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/react-native-code-push/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/react-native-code-push/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/react-native-code-push/subscription","commits_url":"https://api.github.com/repos/Microsoft/react-native-code-push/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/react-native-code-push/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/react-native-code-push/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/react-native-code-push/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/react-native-code-push/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/react-native-code-push/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/react-native-code-push/merges","archive_url":"https://api.github.com/repos/Microsoft/react-native-code-push/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/react-native-code-push/downloads","issues_url":"https://api.github.com/repos/Microsoft/react-native-code-push/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/react-native-code-push/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/react-native-code-push/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/react-native-code-push/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/react-native-code-push/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/react-native-code-push/releases{/id}","created_at":"2015-06-02T17:19:20Z","updated_at":"2015-11-24T23:27:30Z","pushed_at":"2015-11-25T00:10:37Z","git_url":"git://github.com/Microsoft/react-native-code-push.git","ssh_url":"git@github.com:Microsoft/react-native-code-push.git","clone_url":"https://github.com/Microsoft/react-native-code-push.git","svn_url":"https://github.com/Microsoft/react-native-code-push","homepage":"http://microsoft.github.io/code-push","size":2968,"stargazers_count":206,"watchers_count":206,"language":"Objective-C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":18,"mirror_url":null,"open_issues_count":7,"forks":18,"open_issues":7,"watchers":206,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/react-native-code-push/pulls/62"},"html":{"href":"https://github.com/Microsoft/react-native-code-push/pull/62"},"issue":{"href":"https://api.github.com/repos/Microsoft/react-native-code-push/issues/62"},"comments":{"href":"https://api.github.com/repos/Microsoft/react-native-code-push/issues/62/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/react-native-code-push/pulls/62/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/react-native-code-push/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/react-native-code-push/pulls/62/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/react-native-code-push/statuses/a636482846dbfea331f2b239d884965dbed0b5c8"}}}}