56 ms·
Amazon CodeGuru – Preview
- efdee 7y agoPoor naming choice, considering CodeGuru.com has been around for what, decades?
- mavsman 7y agoI worked on the relaunch of Cloud9 --> AWS Cloud9 and there was an extensive naming process shortly before the launch of the service, both for AWS Cloud9 and for the term "environments" (which was previously workspaces). I can tell you that there were lots of managers, PMs, directors, etc involved and they considered tons of naming options. They took into account third party services/products, first party services/products, and other things that might have overlap. This was likely the situation here and they accepted this as a drawback. That said, you're free to disagree and that doesn't mean it was the right choice, just wanted to point out that this was not an oversight.
- GordonS 7y ago> just wanted to point out that this was not an oversight With codeguru.com being a long established site, doesn't that make it worse?
- criddell 7y agoI'm thinking Amazon doesn't care a whole lot about the IP of others. I say that based on reports of rampant counterfeit goods and complaints about Amazon copying product design for their in-house brands.
- ReidZB 7y agoThe code review feature seems too expensive to run on every PR automatically (to me): $0.75 per 100 lines of code. From their example pricing: "if you have a typical pull request with 500 lines of code, it would only cost $3.75 to run CodeGuru Reviewer on it." I wonder if it's actually good enough to justify that price.
- Nican 7y agoI was thinking about the same thing. Even for a small project of 3 developers, it seems like this would rise easily to the $100+/month, for suggestions that may not even be that useful.
- rstupek 7y agoat which point you'd stop paying for it I would imagine?
- jtcruthers 7y agoThere doesn't seem to be a point to start paying for it, and the time to stop paying for it seems mighty early
- spyspy 7y agothat's insanely expensive if you're doing any type of code generation.
- pc86 7y agoThis seems like a good incentive not to be generating thousands of lines of codes with each PR, which most would probably consider a feature as opposed to a bug.
- derision 7y agoexactly. IMO if you're generating code, it should happen at build/compile time not at checkin
- scarejunba 7y agoWhat would the rationale be for that?
- 7y ago
- CodeSheikh 7y ago"Amazon CodeGuru is a machine learning service for automated code reviews and application performance recommendations. It helps you find the most expensive lines of code that hurt application performance..." I suspect if AWS is using customers code bases to train its AI models? Another source is to scavenge open source repositories.
- alexithym 7y ago"CodeGuru’s machine learning models are trained on Amazon’s code bases comprising hundreds of thousands of internal projects, as well as over 10,000 open source projects in GitHub" - from the article.
- mirekrusin 7y agoOh no, the code quality is going to be shit.
- eximius 7y agoThey might be superficial, but if they did any sort of supervised training (I'm assuming they did), then they probably won't be wrong.
- jsploit 7y agoCould Amazon really have that many internal projects? That doesn't seem right.
- Dunedan 7y agoMaybe you should have continued reading the second paragraph as well? > CodeGuru’s machine learning models are trained on Amazon’s code bases > comprising hundreds of thousands of internal projects, as well as over > 10,000 open source projects in GitHub. Tens of thousands of Amazon > developers have contributed to CodeGuru’s training based on decades of > experience in code review and application profiling.
- CodeSheikh 7y ago$0.75 per 100 lines of code scanned per month. Wonder if it automagically ignores new lines and javadocs?
- veselin 7y agoI found what it generates. https://github.com/pediredla/Algorithms/pull/3/files https://github.com/pediredla/Algorithms/pull/3/files It looks like a linter, but maybe there is more.
- faitswulff 7y agoI've never seen a linter tell me problems with code in this detail before: > You are using a `ConcurrentHashMap`, but your usage of `get()` and `put()` may not be thread-safe at lines: 110, 113, 135, and 137. Two threads can perform this same check at the same time and one thread can overwrite the value written by the other thread.
- stock_toaster 7y agostaticccheck for Go does _some_ of this kind of thing (documenting improper usage). https://staticcheck.io/docs/checks https://staticcheck.io/docs/checks
- Yeroc 7y agoSonarQube does as well. I've been shocked at some of the analysis it does.
- senko 7y agoMany linters are state-aware, for example to catch use-before-init bugs in various languages. This one could be a fairly simple rule ConcurrentHashMap.get() followed by some code that branches on the result, followed by put() is unsafe. These warnings can be very helpful, but no fairy ML magic needed.
- scarejunba 7y agoPretty sure you can turn on that inspection in IntelliJ. The other ones are much more impressive. The 'waiters' one for instance is gold.
- cangencer 7y agoI wanted to try it on a single repository, but it requested access to all repositories, public or private and also needs admin access for webhooks. No thanks.
- scblock 7y agoPlease do us a favor and consolidate all these Amazon announcements into a single announcement page link. This is ridiculous.
- outworlder 7y agoAWS Reinvent is going on. Announcements are done piece meal.
- dang 7y agoThis always comes up when the big tech cos do their annual conference day thing. We don't consolidate the posts, but we do downweight some of them, so you're actually getting less (Amazon|Google|Apple|Microsoft)iness then the system would otherwise be letting through. https://hn.algolia.com/?dateRange=all&page=0&prefix=true&query=by%3Adang%20annual%20conference%20day&sort=byDate&type=comment https://hn.algolia.com/?dateRange=all&page=0&prefix=true&que...
- cosmodisk 7y agoI love Salesforce for this.Every release, there's one place with all the changes and new features.No need to play a detective trying to figure out
- kyriakos 7y agohttps://aws.amazon.com/blogs/aws/?sc_icampaign=launch_aws-news-blog_reinvent19&sc_ichannel=ha&sc_icontent=awssm-3415&sc_iplace=2up https://aws.amazon.com/blogs/aws/?sc_icampaign=launch_aws-ne...
- farslan 7y agoNext step is to provide automated fixes. I've have a side project that does it for Go source code: https://fixmie.com https://fixmie.com (have plans for other languages and protocols). But due my Visa situation here in the US (H1B), I'll be never able to monetize it as it's illegal to have a side income. But I think this is just the start and there is an huge opportunity for new startups and projects.
- outworlder 7y ago> Next step is to provide automated fixes. That's a pretty deep rabbit hole. But considering that old "IDEs" with crappy "Intellisense", "Quickfix" or similar were widely sold, there's potential there.
- farslan 7y agoIt's not only about the code. For example it also could fixe your import paths if one of your libraries has a CVE and a new version was released. In the case of Fixmie, all the fixes are "suggestion" and GitHub nicely allows you to batch them all and submit with them in a single commit. (Disclaimer: I'm working for GitHub, but on a different project)
- meerita 7y agoWouldn't that create worse programmers?
- farslan 7y agoHow so? There is so many things that we sometimes forgot. Even experienced developers will make mistakes.
- meerita 7y agoIf you relieve the programmer of thinking where his error is and give him the fix, the programmer will not bother to reason out what the solution is, he will simply expect it from you.
- SlowRobotAhead 7y agoWas there a list of supported languages somewhere? I couldn't find it.
- hsaliak 7y agoOnly java, it's in the FAQ.
- totally 7y agoIf you squint this looks like a baby step towards computers writing code.
- JustSomeNobody 7y agoNot even close. We'll have to nail down how to write unambiguous design specifications in a format that the AI can consume, first.
- aripickar 7y agoMaybe we could come up with a consistent language to tell machines what to do first.
- origami777 7y agoIt definitely is. Automation is the end game. Devs are expensive and error prone.
- randomidiot666 7y agoNot even close. This is simple mechanical pattern recognition. It's an overpriced, overhyped code linter. See this example https://d1.awsstatic.com/re19/Screenshot_Catch-Code-Issue_2%20-%20Annotations%20LP.df0deb64bbfb02219d429db4d5bd3efd089e2a89.png https://d1.awsstatic.com/re19/Screenshot_Catch-Code-Issue_2%...
- djhworld 7y agoI got to preview this service (the code review service) a few weeks ago. The best thing about it was the recommendations on how to use the AWS SDK better as that's probably got the most potential to drift or make mistakes on
- buboard 7y agoconsidering how it can be a driver for AWS sales, they should give the service for free though
- z3t4 7y agoCode review if done right is a place to learn. Criticizing (and automatically fixing) code style issues and nit-picky can be done by a machine.
- yellowait44 7y agoOh my! Son of Anton is watching my code!
- dipthegeezer 7y agoIn case people are wondering about the reference. https://www.youtube.com/watch?v=xzx5Hwg24xw https://www.youtube.com/watch?v=xzx5Hwg24xw
- shubidubi 7y agoCode review is not linter. Code review is a chance to discuss design, scaling, trade-offs and mentor others. I don't think this solution will offer it.
- MisterPea 7y agoI think this does what you mention and not the former. I would imagine this works best when you have a codebase that heavily utilizes the AWS SDK so it can internally 'paint a picture' of what's going on and provide better architectural decisions and other best practices. How well it works is beyond me though
- randomidiot666 7y agoBullshit. You are vastly overestimating the "intelligence" of this overpriced linter. It mechanically detects patterns. See this example: https://d1.awsstatic.com/re19/Screenshot_Catch-Code-Issue_2%20-%20Annotations%20LP.df0deb64bbfb02219d429db4d5bd3efd089e2a89.png https://d1.awsstatic.com/re19/Screenshot_Catch-Code-Issue_2%... The kind of human-level artificial intelligence that you're suggesting this would have, is science fiction.
- MisterPea 7y agoWell I stand corrected, would've expected more from a company that knows all the best practices for their own services
- BinaryIdiot 7y ago> Code review is a chance to discuss design, scaling, trade-offs and mentor others. Trade offs sure but design and scaling need to be considered _before_ the code review. Maybe an architecture review of sorts? Once you hit code review it's a little too late to reconsider design and scale unless it's a serious issue. > mentor others Mentoring is mostly outside of a code review. Sure it can help with that but I don't think that really counts. IMO anyway.
- 7y ago
- formalsystem 7y agoIs this vaporware?
- whb07 7y agoNeat idea and a good place to start. But most of the time, people are willingly and sometimes violently opposed to automated free tooling like linters, formatters etc. I’m not holding my breath for that cohort (majority of devs).
- mping 7y agoI'm wondering did anyone actually tried it? It's not impossible for an automated tool to give valuable feedback over a PR guys. Should be easier than a self driving car I guess
- TheOperator 7y agoChess masters have long been combining human and computer analysis... even before computers were able to actually beat humans at chess.
- ecuaflo 7y agoWhy do this in the code review stage as opposed to in the code editor linting stage? I'd wanna have these suggestions before pushing.
- udkl 7y agoReminds me of the security analysis tool from FB https://engineering.fb.com/security/zoncolan/ https://engineering.fb.com/security/zoncolan/ https://www-wired-com.cdn.ampproject.org/c/s/www.wired.com/story/facebook-zoncolan-static-analysis-tool/amp https://www-wired-com.cdn.ampproject.org/c/s/www.wired.com/s... Also reminds me of sonatype or findbugs which does something similar but works on a set of rules instead of on ML.
- eigenvalue 7y agoThey should compute the SHA512 hash of lines of code or code blocks from well-known open source projects and then just give you pre-computed "reviews" for those lines/blocks, and then only charge for "novel" code. Otherwise you would need to waste time segregating your original code from the various packages you use. And it seems unfair to charge customers for canned results that can be cached and served at very low cost.
- drchewbacca 7y agoI think you can set it to only scan when new pull requests are made. So you could commit your libraries etc without asking for review and then turn it on only for code you have written. I might be wrong though.
- randomidiot666 7y agoYes obviously you would just choose not to submit those irrelevant PRs to this extremely overpriced linter (it's not a code reviewer)
- gcbw3 7y agoIf it was minimally not garbage, they would have run it on any high profile open source project and promoted the results. Hence, it is pure garbage.
- millstone 7y agoMany (most?) of the checks appear to be specific to Amazon libraries.
- conwy 7y agoIt seems good for performance, and probably only that. I don't see anything in the pitch about readability, maintainability, extendability, security, usability/accessibility or portability.
- gregdunn 7y agoDisclaimer: I work at AWS on an unrelated team. I was not involved in development of this product. Opinions stated are my own, and not necessarily a reflection of my employer. Nothing here is being posted in any sort of official capacity. There's lots of focus here in the comments on the code reviewer portion, but one of the things I'm most excited about is the profiler - https://aws.amazon.com/codeguru/features/ https://aws.amazon.com/codeguru/features/ I do a lot of performance engineering work, and one of my go to tools for visualizing where programs are spending their time is flamegraphs. While you can certainly create them with profilers besides CodeGuru (and I do not work with Java, so I haven't yet had the chance to check out CodeGuru for any of my use cases), I'm super excited about anything that gets more people using them. They make it very easy to see where your optimization opportunities are, and I have personally found them very useful when working with our customers - they're way easier, in my opinion, to go through and explain than just looking at raw perf output or similar.
- skynetv2 7y agoHave you tried https://cloud.google.com/profiler/ https://cloud.google.com/profiler/ ?
- tclancy 7y agoSeconded. I used them a lot when I worked for myself on old-school single server apps but have struggled to convince my team now that I work on something spread across AWS instances. I'd just brought the concept up again this week for a hackathon project but this looks like we could buy our way to what I want for cheap (compared to overall hosting). I suspect it may pay for itself.
- richdougherty 7y agoA profiling tool I want to try out—it seems almost magical—is Coz. It can estimate the effect of speeding up any line of code. It does this by pausing (!) other threads, so it gives a 'virtual' speed up for that line. What's interesting is that this technique correctly handles inter-thread effects like blocking, locking, contention, so it can point out inter-thread issues that traditional profilers and flame graphs struggle with. Summary: https://blog.acolyer.org/2015/10/14/coz-finding-code-that-counts-with-causal-profling/ https://blog.acolyer.org/2015/10/14/coz-finding-code-that-co... Video presentation: https://www.youtube.com/watch?v=jE0V-p1odPg&t=0m28s https://www.youtube.com/watch?v=jE0V-p1odPg&t=0m28s Coz: https://github.com/plasma-umass/coz https://github.com/plasma-umass/coz JCoz (Java version): http://decave.github.io/JCoz/ http://decave.github.io/JCoz/ and https://github.com/Decave/JCoz https://github.com/Decave/JCoz
- miheermunjal 7y agoAssuming trust in the AWS code reviews (I mean, that dataset is huge), I suspect this has use in the review portion even without considering profiling. Hoping there is more detail on the ML used, as it appears more adaptable than current rule based code reviewing solutions... here come more and more Dev-focused integrations coming to the code level
- eddywebs 7y agoAn open source alternative is PMD tool - https://pmd.github.io https://pmd.github.io
- redler 7y agoOne of their screenshot examples flags inefficient code in crypto libraries, and the suggested "fix" is "Evaluate switching to the Amazon Corretto Crypto Provider ACCP". I don't know enough about the subject matter area to know whether that's the right move, but it's interesting that CodeGuru is apparently, among other things, an opportunity to pay Amazon to upsell you on replacing some of your code with one of the panoply of services in the AWS universe.
- ensignavenger 7y agoAmazon Corretto is their OpenJDK Java distro that is free and Open Source. I don't know if the project was already using Corretto or not, but it makes sense for them to recommend their own, supported, open source solution.
- redler 7y agoYour point is a fair one, and I admit unfamiliarity with Corretto, specifically. But they're telegraphing, right on the tin, that this new service will indeed recommend solutions of the form "we see a problem pattern in your code; try Amazon _____". The fact that Corretto is actually open source further muddies the waters.
- weego 7y agoWe'll need to see what comes out in the wash. Maybe the more OSS they encounter the more suggestions it will be able to make. Or maybe not and it will indeed be a sales pitch masquerading as a feature.
- quin3 7y agoIn the future, You should do a quick search before naysaying. This crypto lib is free and offers non-negligible performance gains.
- NegativeLatency 7y agoIt's still increasing your dependence on AWS systems and software. (The upsell price may be free for now, but who knows maybe they add a premium version or enterprise features in the future) I imagine that the tool will be used for recommending more amazon services in the future, and this is possibly a poor POC of more to come.
- GordonS 7y ago> CodeGuru is inexpensive enough to use for every code review and application you run > For example, if you have a typical pull request with 500 lines of code, it would only cost $3.75 to run CodeGuru Reviewer on it Wat?! Come on, $4 per review is not inexpensive, especially for what is essentially a glorified SAST!
- dchichkov 7y agoNow, is it a code review with ML, or is it a data collection service with a human backend. That wants to be code review with ML ;)
- dakna 7y agoSo let me get this straight: Amazon packages open source software (Linux, Postgres etc) in a way that is an abstracted service (RDS, EBS, Elastic Load Balancer). They add so many abstracted building blocks that you need a special skill set to manage them (Aws Certified Solutions Architect) instead of knowing how to do this with bare metal or a container image running in your own data center. And now that things are complicated and developers might make mistakes using those services, they add a profiler that inspects your code running in production and a reviewer that ties into the stage before deployment. All just to optimize the use of their own services. From a business perspective this is an awesome way to get vendor lock-in to a much higher degree. They are basically the certifying authority that tells you if your intellectual property (your code) conforms to their own standard. Yes, they show examples of standard Java optimizations, but it clearly says it detects deviation from best practices for using AWS APIs and SDKs. And people were mad at Microsoft for shipping a non standards compliant browser as default and enriching it with HTML tags and plugins that would only work in that browser. Little did we know. I personally wait for the "Amazon Compliant Code" label in the not too distant future as a selling point for business people.
- Thorentis 7y ago> "Amazon Compliant Code" label Wow, this is a scary but very real thought. Though, the "Certified Windows XP / 7" stickers on hardware and video games / other software was quite common back in the day and isn't too dissimilar. I would argue that the level of vendor lock-in Amazon is going for is far greater than Microsoft's.
- sheeshkebab 7y agoMaybe at some point there will be an antitrust lawsuit to unbundle them - and say have compute or storage be provided by a different vendor, all from within their aws management console.
- ken 7y agoI don't care if AWS is big and bundled as long as they use standard interfaces. Linux is big and it doesn't really matter that there's not much competition. I don't care what system (or even virtual machines or containers) runs my program. If there were an open standard for "way to upload and store and serve files on the web", and S3 happened to implement that standard, and other companies and open-source projects did as well, then it wouldn't matter to me if AWS was the bundling king or not. There was nothing magical about the design of Unix, either. It's not the only way to make an operating system, or even the best way. It survived because we got many competing implementations which were basically source-compatible. It really took off when we got free clones that anyone could run on their PC.
- 013a 7y agoSomething doesn't sit right with me concerning their use of "over 10,000" open source projects on Github to train the AI, then immediately turning around and telling those same projects "thanks, that'll be $0.75/100 lines of code scanned." I feel like this should have a generous free tier for open source projects. I feel that very, very strongly.
- rodgerd 7y agoYour programming job is Jeff's opportunity.
- seanwilson 7y agoIs there a reason AWS products have names where you can rarely guess what they do? Why not something more obvious like one of AWS Code Auditor/Reviewer/Checker?
- richnich 7y agoThere is ZERO lock-in with this service. If people want to continue to do hand code reviews themselves, they can. There is also ZERO in Amazon's announcement that implies this is just about improving code specific to Amazon's platform. Stop being open source purists and start understanding reality. Many (most?) of the posters about this topic critiquing Amazon live in open source unicorn land, and seem to have almost no understanding of business realities. (Sorry for not saying what I really think but I thought I should be polite.)
- mirchibajji 7y agoIf anyone from AWS is reading this, is there a plan to support GitLab? We have a self-hosted GitLab enterprise on AWS, and wondering if we can try this out
- amai 7y agoWhat can it do better compared to solutions like https://www.sonarqube.org/ https://www.sonarqube.org/?
- zzangse 7y agoimport android.util.Log; import android.accounts.Account; import android.app.Activity; import android.content.Intent; import android.content.IntentSender; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.Signature; import android.content.res.Resources; import android.os.Bundle; import android.support.annotation.NonNull; import android.util.Base64; import com.google.android.gms.common.api.Result; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GoogleApiAvailability; import com.google.android.gms.auth.api.signin.GoogleSignIn; import com.google.android.gms.auth.api.signin.GoogleSignInAccount; import com.google.android.gms.auth.api.signin.GoogleSignInClient; import com.google.android.gms.auth.api.signin.GoogleSignInOptions; import com.google.android.gms.auth.api.signin.GoogleSignInStatusCodes; import com.google.android.gms.common.api.ApiException; import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.Task; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class GoogleLogin { / Responses supported by this class / public static final int GOOGLE_RESPONSE_OK = 0; public static final int GOOGLE_RESPONSE_CANCELED = 1; public static final int GOOGLE_RESPONSE_ERROR = 2; public static final int GOOGLE_RESPONSE_DEVELOPER_ERROR = 3; /* Debug output tag / private static final String TAG = "UE4-GOOGLE"; // Output device for log messages. private Logger GoogleLog; private Logger ActivityLog; /* Is this a shipping build / boolean bShippingBuild = false; /* Has init been called succesfully / public boolean bInitialized = false; /* Has onStart() been called / public boolean bStarted = false; /* * Activity needed here to send the signal back when user successfully logged in. / private GameActivity activity; /* Name of game package / private String packageName; /* Android key from Google API dashboard / private String clientId; /* Backend server key from Google API dashboard / private String serverClientId; /* Unique request id when using sign in activity / private static final int REQUEST_SIGN_IN = 9001; /* Google API client needed for actual sign in */ private GoogleSignInClient mGoogleSignInClient; public GoogleLogin(GameActivity activity, final Logger InLog, String inPackageName, String BuildConfiguration) { this.activity = activity; GoogleLog = new Logger(TAG); ActivityLog = InLog; packageName = inPackageName; bShippingBuild = BuildConfiguration.equals("Shipping"); } public boolean init(String inClientId, String inServerClientId) { if (bShippingBuild) { GoogleLog.SuppressLogs(); } boolean bClientIdValid = (inClientId != null && !inClientId.isEmpty()); boolean bServerIdValid = (inServerClientId != null && !inServerClientId.isEmpty()); if (bClientIdValid && bServerIdValid) { GoogleLog.debug("init"); boolean bIsAvailable = isGooglePlayServicesAvailable(); GoogleLog.debug("Is Google Play Services Available:" + bIsAvailable); if (bIsAvailable) { GoogleLog.debug("packageName: " + packageName); clientId = inClientId; GoogleLog.debug("GoogleSignIn clientId:" + clientId); serverClientId = inServerClientId; GoogleLog.debug("GoogleSignIn serverClientId:" + serverClientId); // Configure sign-in to request the user's ID, email address, and basic // profile. ID and basic profile are included in DEFAULT_SIGN_IN. GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(serverClientId) .requestProfile() //.requestServerAuthCode(serverClientId) .requestEmail() .build(); // Build a GoogleSignInClient with the options specified by gso. mGoogleSignInClient = GoogleSignIn.getClient(activity, gso); bInitialized = true; PrintKeyHash(packageName); } } else { GoogleLog.debug("clientId: " + inClientId + " or serverClientId: " + inServerClientId + " is invalid"); } GoogleLog.debug("init complete: " + bInitialized); return bInitialized; } public void onStart() { GoogleLog.debug("onStart"); bStarted = true; } public void onStop() { GoogleLog.debug("onStop"); } public void onDestroy() { GoogleLog.debug("onDestroy"); } public int login(String[] ScopeFields) { GoogleLog.debug("login:" + ScopeFields.toString()); int resultCode = GOOGLE_RESPONSE_ERROR; Intent signInIntent = mGoogleSignInClient.getSignInIntent(); if (signInIntent != null) { GoogleLog.debug("login start activity:"); activity.startActivityForResult(signInIntent, REQUEST_SIGN_IN); resultCode = GOOGLE_RESPONSE_OK; } else { GoogleLog.debug("getSignInIntent failure:"); nativeLoginComplete(GOOGLE_RESPONSE_ERROR, ""); } return resultCode; } public int logout() { GoogleLog.debug("logout"); mGoogleSignInClient.signOut() .addOnCompleteListener(activity, new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { boolean bWasSuccessful = task.isSuccessful(); GoogleLog.debug("onSignOut Complete success:" + bWasSuccessful); nativeLogoutComplete(bWasSuccessful ? GOOGLE_RESPONSE_OK : GOOGLE_RESPONSE_ERROR); } }); return GOOGLE_RESPONSE_OK; } public void onActivityResult(int requestCode, int resultCode, Intent data) { GoogleLog.debug("onActivityResult: " + requestCode + " result: " + resultCode); // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...); if (requestCode == REQUEST_SIGN_IN) { GoogleLog.debug("onActivityResult REQUEST_SIGN_IN"); GoogleLog.debug("data: " + ((data != null) ? data.toString() : "null")); if (resultCode == Activity.RESULT_OK) { GoogleLog.debug("signing in"); } Task<GoogleSignInAccount> completedTask = GoogleSignIn.getSignedInAccountFromIntent(data); try { // Try to access the account result GoogleSignInAccount account = completedTask.getResult(ApiException.class); // Signed in successfully GoogleLog.debug("Sign in success"); PrintUserAccountInfo(account); nativeLoginComplete(GOOGLE_RESPONSE_OK, getLoginJsonStr(account)); } catch (ApiException e) { // The ApiException status code indicates the detailed failure reason. // Please refer to the GoogleSignInStatusCodes class reference for more information. GoogleLog.debug("Sign in failure:" + GoogleSignInStatusCodes.getStatusCodeString(e.getStatusCode())); if (e.getStatusCode() == GoogleSignInStatusCodes.DEVELOPER_ERROR) { nativeLoginComplete(GOOGLE_RESPONSE_DEVELOPER_ERROR, ""); } else { nativeLoginComplete(GOOGLE_RESPONSE_ERROR, ""); } } GoogleLog.debug("onActivityResult end"); } } private String getLoginJsonStr(GoogleSignInAccount acct) { if (acct != null) { return "{\"user_data\":" + getUserJsonStr(acct) + "," + "\"auth_data\":" + getAuthTokenJsonStr(acct) + "}"; } return ""; } private String getUserJsonStr(GoogleSignInAccount acct) { if (acct != null) { return "{\"sub\":\""+ acct.getId() + "\"," + "\"given_name\":\"" + acct.getGivenName() + "\"," + "\"family_name\":\"" + acct.getFamilyName() + "\"," + "\"name\":\"" + acct.getDisplayName() + "\"," + "\"picture\":\"" + acct.getPhotoUrl() + "\"" + "}"; } return ""; } private String getAuthTokenJsonStr(GoogleSignInAccount acct) { if (acct != null) { return "{\"access_token\":\"androidInternal\"," + "\"refresh_token\":\"androidInternal\"," + "\"id_token\":\""+ acct.getIdToken() + "\"}"; } return ""; } public void PrintUserAccountInfo(GoogleSignInAccount acct) { GoogleLog.debug("PrintUserAccountInfo"); if (acct != null) { GoogleLog.debug("User Details:"); GoogleLog.debug(" DisplayName:" + acct.getDisplayName()); GoogleLog.debug(" Id:" + acct.getId()); GoogleLog.debug(" Email:" + acct.getEmail()); GoogleLog.debug(" Account:" + acct.getAccount().toString()); GoogleLog.debug(" Scopes:" + acct.getGrantedScopes()); GoogleLog.debug(" IdToken:" + acct.getIdToken()); GoogleLog.debug(" ServerAuthCode:" + acct.getServerAuthCode()); } else { GoogleLog.debug("Account is null"); } } private boolean isGooglePlayServicesAvailable() { GoogleApiAvailability apiAvail = GoogleApiAvailability.getInstance(); int status = apiAvail.isGooglePlayServicesAvailable(activity); GoogleLog.debug("isGooglePlayServicesAvailable statusCode: " + status); if (status == ConnectionResult.SUCCESS) { return true; } else { return false; } } public void PrintKeyHash(String packageName) { try { PackageInfo info = activity.getPackageManager().getPackageInfo( packageName, PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); GoogleLog.debug(Base64.encodeToString(md.digest(), Base64.DEFAULT)); } } catch (PackageManager.NameNotFoundException e) { GoogleLog.debug("NameNotFoundException:" + e); } catch (NoSuchAlgorithmException e) { GoogleLog.debug("NoSuchAlgorithmException:" + e); } } // Callback that notify the C++ implementation that a task has completed public native void nativeLoginComplete(int responseCode, String javaData); public native void nativeLogoutComplete(int responseCode); }