3768

I was looking at the new APIs introduced in Android 4.2. While looking at the UserManager class I came across the following method:

public boolean isUserAGoat()

Used to determine whether the user making this call is subject to teleportations.

Returns whether the user making this call is a goat.

How and when should this be used?

Luca Kiebel
  • 8,292
  • 5
  • 24
  • 37
Ovidiu Latcu
  • 68,451
  • 14
  • 71
  • 82
  • 4
    If can be used to avoid some Java warning, as an easter egg, and as a test to see who read the API. And it's a reference to an easter egg in Chrome. – Dorian Nov 14 '12 at 20:53
  • 13
    This might be related to when [Google use goats](http://googleblog.blogspot.com/2010/04/goats-are-baaaahk.html) [as a mower](http://googleblog.blogspot.com/2009/05/mowing-with-goats.html) in their [Mountain View Headquarters](https://maps.google.com/?q=Google+Inc.%4037.423156,-122.084917&hl=en). – John Isaiah Carmona Nov 15 '12 at 04:58
  • 3
    _googlers_ seem to like goats for some reason, no wonder they made an easter egg out of it. there is also a serious (__!__) investment in goats: - as blogged in googleblog - [mowing with goats](http://googleblog.blogspot.com/2009/05/mowing-with-goats.html) - [goats are baaaahk](http://googleblog.blogspot.com/2010/04/goats-are-baaaahk.html) - and recorded in [youtube](http://www.youtube.com/watch?v=Jw_XI0WVZBg) after all they are native lawn movers, efficient as well.. – none Nov 15 '12 at 10:21
  • 21
    There are also constants for the gravity on the first death star http://developer.android.com/reference/android/hardware/SensorManager.html#GRAVITY_DEATH_STAR_I and on the island of the tv show Lost http://developer.android.com/reference/android/hardware/SensorManager.html#GRAVITY_THE_ISLAND which is of course, the numbers. – Fernando Gallego Mar 29 '13 at 22:09
  • 8
    They even updated the documentation after Lollipop: ["As of LOLLIPOP, this method can now automatically identify goats using advanced goat recognition technology."](http://developer.android.com/reference/android/os/UserManager.html#isUserAGoat()) – Patrick Apr 25 '16 at 07:49

11 Answers11

1876

Android R Update:

From Android R, this method always returns false. Google says that this is done "to protect goat privacy":

/**
 * Used to determine whether the user making this call is subject to
 * teleportations.
 *
 * <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can
 * now automatically identify goats using advanced goat recognition technology.</p>
 *
 * <p>As of {@link android.os.Build.VERSION_CODES#R}, this method always returns
 * {@code false} in order to protect goat privacy.</p>
 *
 * @return Returns whether the user making this call is a goat.
 */
public boolean isUserAGoat() {
    if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.R) {
        return false;
    }
    return mContext.getPackageManager()
            .isPackageAvailable("com.coffeestainstudios.goatsimulator");
}

Previous answer:

From their source, the method used to return false until it was changed in API 21.

/**
 * Used to determine whether the user making this call is subject to
 * teleportations.
 * @return whether the user making this call is a goat 
 */
public boolean isUserAGoat() {
    return false;
}

It looks like the method has no real use for us as developers. Someone has previously stated that it might be an Easter egg.

In API 21 the implementation was changed to check if there is an installed app with the package com.coffeestainstudios.goatsimulator

/**
 * Used to determine whether the user making this call is subject to
 * teleportations.
 *
 * <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can
 * now automatically identify goats using advanced goat recognition technology.</p>
 *
 * @return Returns true if the user making this call is a goat.
 */
public boolean isUserAGoat() {
    return mContext.getPackageManager()
            .isPackageAvailable("com.coffeestainstudios.goatsimulator");
}

Here is the source and the change.

Wrichik Basu
  • 229
  • 4
  • 16
meh
  • 20,901
  • 7
  • 44
  • 57
  • 106
    Theory: Goats are found in all kinds of precarious places, like sheer cliffs, possibly bucking location trends they get from regular non-goat users. Might explain "teleportations", which could be goats appearing to wildly relocate as the software tries to determine their location with algos designed for non-goats. – tedders Nov 14 '12 at 12:58
  • 3
    How does this answer add anything to the info that the question already showed? – LarsH Nov 14 '12 at 17:17
  • 12
    @LarsH - the source for one. – djechlin Nov 14 '12 at 20:07
  • 58
    This is a history lesson, not an answer. Even if it is an Easter egg, is there a valid use case for it? Being an Easter egg doesn't preclude it from being useful, and you've not shown whether it is or is not useful. – casperOne Nov 14 '12 at 20:26
  • 3
    @djechlin, one aspect of the source is informative, and now that the answer has been edited, it's far more obvious: (this implementation of) this method always returns false. – LarsH Nov 14 '12 at 20:52
  • The method could be overridden in a test scenario. – Thorbjørn Ravn Andersen Aug 25 '13 at 06:13
  • 2
    It's also a reference to http://en.wikipedia.org/wiki/The_Men_Who_Stare_at_Goats , about a U.S. military project involving goats. – Matthew Flaschen Feb 19 '14 at 06:03
  • 7
    The monkey function is to detect the MonkeyRunner debug tool as specified in another answer. – logain Mar 30 '14 at 20:49
  • 9
    They need to add `canPigsFly()`. `while (!canPigsFly()) { /* code */ }` – Jared Rummler Feb 05 '15 at 09:25
  • 38
    That's a [real app](https://play.google.com/store/apps/details?id=com.coffeestainstudios.goatsimulator). – Kevin Krumwiede Feb 21 '15 at 08:07
  • 207
    I feel bad for anyone who cheekily used this function, expecting it to return `false` forever. – Martin Konecny Apr 27 '15 at 05:11
  • 5
    @casperOne given the content of the method I think the use case is pretty self explanatory. – Ced Aug 22 '15 at 05:40
  • 5
    What's funny is there's an app with that ID: https://play.google.com/store/apps/details?id=com.coffeestainstudios.goatsimulator&hl=en. And it's not free, nor made by Google! – raulk Jan 14 '16 at 18:58
  • 12
    @raulk Yes, they used the ID of that app, they didn't pick a random app ID and then happen to have someone create an app with that ID... – user253751 Sep 27 '16 at 01:01
  • 2
    Starting with Android 11 (R), the function always returns false again "in order to protect goat privacy", according to the updated documentation: https://developer.android.com/reference/android/os/UserManager.html#isUserAGoat() – aberaud Oct 14 '20 at 00:20
1001

I don't know if this was "the" official use case, but the following produces a warning in Java (that can further produce compile errors if mixed with return statements, leading to unreachable code):

while (1 == 2) { // Note that "if" is treated differently
    System.out.println("Unreachable code");
}

However this is legal:

while (isUserAGoat()) {
    System.out.println("Unreachable but determined at runtime, not at compile time");
}

So I often find myself writing a silly utility method for the quickest way to dummy out a code block, then in completing debugging find all calls to it, so provided the implementation doesn't change this can be used for that.

JLS points out if (false) does not trigger "unreachable code" for the specific reason that this would break support for debug flags, i.e., basically this use case (h/t @auselen). (static final boolean DEBUG = false; for instance).

I replaced while for if, producing a more obscure use case. I believe you can trip up your IDE, like Eclipse, with this behavior, but this edit is 4 years into the future, and I don't have an Eclipse environment to play with.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
djechlin
  • 54,898
  • 29
  • 144
  • 264
  • 1
    My bad - those are warnings, however they often lead to actual compile errors if you are returning from a block that control flow is now forced down. – djechlin Nov 14 '12 at 15:05
  • 2
    Wouldn't compiler directive be a better use for conditions you want to compile out? – Andy Nov 14 '12 at 18:13
  • 11
    @djechlin I do not know if this is android only, in standard java ` if(false){...}` compiles just fine (open jdk javac 1.6 and 1.7) – josefx Nov 14 '12 at 20:24
  • 2
    @josefx - compiler warnings and can lead to errors if the branch the code is forced down has a `return` statement as this produces unreachable code. This is a useful compiler error; e.g. if you forget `break;` statements in a switch and your `default` case throws an exception, you will get this error. – djechlin Nov 14 '12 at 20:26
  • @djechlin sorry, I somehow failed to read your first sentence after seeing your (1==2) example - that if(false) is handled by the compiler is a downside in this case (and I should get some sleep to avoid more of these mistakes :-)). – josefx Nov 14 '12 at 20:36
  • 10
    @PeterOlson - if you are specifically trying to test a code branch where an if goes false or true, this is the most precise and obvious way to simulate that - commenting out the block could be less accurate if you don't match to the proper end of the block (perhaps you didn't notice a discreet if/else block immediately following), it will lead to a compile error if you're forcing to the following `else` block, etc. – djechlin Nov 15 '12 at 02:01
  • 2
    @Vadzim nope, compiler will detect that always evaluates to true. – djechlin Oct 09 '13 at 15:43
  • 177
    **"provided the implementation doesn't change"** - and there's the problem. This is a disastrous way to implement a warning-free "if (false)" because the implementation can and does change. See my answer to this question: as of API21 `isUserAGoat()` returns true if a user has a specific app installed. Good luck diagnosing that when your code suddenly starts behaving oddly on "random" devices! – Mark Whitaker Nov 05 '14 at 12:29
  • 15
    @MarkWhitaker Or if goats start using devices. – thedayturns Feb 18 '16 at 01:51
  • 12
    @thedayturns If goats start using Android devices this will be the least of our problems. – Szymon Drosdzol Feb 29 '16 at 13:16
  • 2
    @djechlin No it isn't, did you actually try it? – user253751 Mar 19 '16 at 22:02
  • 2
    have you tried using /* and */ for commenting out code? – BlueWizard Nov 15 '16 at 08:17
780

This appears to be an inside joke at Google. It's also featured in the Google Chrome task manager. It has no purpose, other than some engineers finding it amusing. Which is a purpose by itself, if you will.

  1. In Chrome, open the Task Manager with Shift+Esc.
  2. Right click to add the Goats Teleported column.
  3. Wonder.

There is even a huge Chromium bug report about too many teleported goats.

chrome

The following Chromium source code snippet is stolen from the HN comments.

int TaskManagerModel::GetGoatsTeleported(int index) const {
  int seed = goat_salt_ * (index + 1);
  return (seed >> 16) & 255;
}
  • 25
    i don't have it, where do you right click? or what it is used for – auselen Nov 14 '12 at 09:17
  • I guess it depends on the version of Chrome. Mine is 23.0.1271.64 – CocoNess Nov 14 '12 at 09:33
  • @OvidiuLatcu In the bug report I just added, it shows a Windows screenshot. –  Nov 14 '12 at 09:37
  • 14
    @auselen You have to right click on a column title in order to see the drop down menu to add the Goats Teleported column (at least that's how it works in Chrome on OS X). http://cl.ly/Ksbd – greenie Nov 14 '12 at 09:38
  • 1
    @greenie: Thanks for adding this. In Linux you can right click anywhere. –  Nov 14 '12 at 09:39
  • 54
    Windows XP + latest Chrome = it isn't there, on Ubuntu I see it. – auselen Nov 14 '12 at 09:47
  • 1
    It's there on OSX, though I had to right click on the columns and check the Goats Teleported item. – James Gregory Nov 14 '12 at 10:09
  • 4
    @Xeoncross Yes because nobody has put an easter egg in Windows software, ever. – Mark Allen Nov 15 '12 at 23:56
  • 2
    @pdknsk When your answer was deleted, it already had the latest edit. I think it's a decent explanation of what it is, but what's missing is an answer to the original question: **"Does anyone know how and when this should be used?"** – NullUserException Nov 16 '12 at 00:03
  • 18
    It's likely that the inside joke has it's origins here: http://googleblog.blogspot.be/2010/04/goats-are-baaaahk.html – CupOfTea696 Nov 20 '12 at 21:59
  • 1
    @pdknsk goats are those creatures who follow each other, or used to follow leading goat without thinking, so gotchas too many goats in programming world. This might be someone's style @ google to say so. Do not follow without thinking. – om252345 Jan 30 '14 at 18:06
  • seed from goat salt. interesting. – Thanos Sep 30 '19 at 06:04
  • @om252345 I thought that was a sheep, not a goat. – David Callanan Jan 04 '20 at 15:52
  • This is no longer an available column in the recent chrome versions (Checking in Chrome 83 macOS build) – noob Jun 21 '20 at 17:32
301

Complementing the @djechlin answer (good answer by the way!), this function call could be also used as dummy code to hold a breakpoint in an IDE when you want to stop in some specific iteration or a particular recursive call, for example:

enter image description here

isUserAGoat() could be used instead of a dummy variable declaration that will be shown in the IDE as a warning and, in Eclipse particular case, will clog the breakpoint mark, making it difficult to enable/disable it. If the method is used as a convention, all the invocations could be later filtered by some script (during commit phase maybe?).

enter image description here

Google guys are heavy Eclipse users (they provide several of their projects as Eclipse plugins: Android SDK, GAE, etc), so the @djechlin answer and this complementary answer make a lot of sense (at least for me).

Community
  • 1
  • 1
higuaro
  • 14,758
  • 3
  • 32
  • 40
  • 15
    If you are writing "dummy" code just to quickly test something, what is the problem with an Eclipse warning?? I think this is actually great as you can find it in case you've forgotten – Tomasz Apr 30 '13 at 20:16
  • 22
    @Tomasz the problem is that, in Eclipse, the warning mark clutters the breakpoint, and you have to open the breakpoint view to either deactivate or remove it – higuaro May 08 '13 at 22:18
  • 4
    Yeah, I have a solution for that. You can right click on the warning symbol and select "Toggle Breakpoint". If the following line/option is enabled it means the breakpoint is created. My point was, dummy code is bad and it should be a warning so yo don't forget ;) – Tomasz May 09 '13 at 01:40
  • 9
    @Tomasz The problem with that solution is that you have know beforehand where the breakpoint is, so a simple visual inspection won't let you know that the warning hides a breakpoint, an even better solution though, is to use conditional breakpoints, with them you can forget about dummy code (and convention methods) altogether, but those differ between IDE's and can't be automatically shared among workstations – higuaro May 16 '13 at 14:51
  • 2
    Why not just use a null statement `;`? I mean, goats are clearly better, but there is an easy way around this already – Bassinator Mar 15 '17 at 17:57
  • The warning **may** be due to the declaration of *dummy* variable without using, making the statement a *dead store*. – luizfzs Jun 14 '17 at 16:22
  • 1
    Hey, it ain't called Eclipse for nothing! I recommend changing your Eclipse settings so that you get a little vertical line next to your breakpoints. That way, you can see whether they're on or off when you toggle them. – Dawood ibn Kareem Apr 15 '18 at 20:22
  • seriously are you using `isUserAGoat()` functions? – Davide Dec 20 '19 at 11:56
155

There's a funny named method/constant/whatever in each version of Android.

The only practical use I ever saw was in the Last Call for Google I/O Contest where they asked what it was for a particular version, to see if contestants read the API diff report for each release. The contest had programming problems too, but generally some trivia that could be graded automatically first to get the number of submissions down to reasonable amounts that would be easier to check.

Lance Nanek
  • 6,267
  • 2
  • 22
  • 19
  • 11
    "There's a funny named method/constant/whatever in each version of Android." Could you name some? – Angelo.Hannes Nov 15 '12 at 08:30
  • 48
    For example, there are a nivel of log called Log.wtf that they call What a Terrible Failure :P – Aracem Nov 15 '12 at 10:41
  • 8
    A bit like Delphi's EProgrammerNotFound? http://stackoverflow.com/questions/2084120/eprogrammernotfound-exception-in-delphi – Gerry Coll Nov 15 '12 at 10:52
  • 12
    HoneyComb is AdapterViewAnimator#fyiWillBeAdvancedByHostKThx() – Lance Nanek Nov 15 '12 at 14:11
  • 18
    @Angelo.Hannes, In the Sensor Constants for Gravity there's one for Death Star (Star Wars) – st0le Nov 15 '12 at 14:58
  • 5
    In 1.5 there was a "Tricorder" sensor type. – peejaybee Mar 05 '13 at 14:23
  • 2
    @Aracem That one is actually useful and not so much an easter egg. I've used that one quite a lot for errors that break functionality but shouldn't happen (i.e. for if Exceptions get thrown that I prevent with a previous check). It is a far better solution than just ignoring the error. – Emil S. Nov 15 '18 at 16:42
147

In the discipline of speech recognition, users are divided into goats and sheeps.

For instance, here on page 89:

Sheeps are people for whom speech recognition works exceptionally well, and goats are people for whom it works exceptionally poorly. Only the voice recognizer knows what separates them. People can't predict whose voice will be recognized easily and whose won't. The best policy is to design the interface so it can handle all kinds of voices in all kinds of environments

Maybe, it is planned to mark Android users as goats in the future to be able to configure the speech recognition engine for goats' needs. ;-)

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
rainer198
  • 3,003
  • 2
  • 23
  • 40
134

As of API 21 (the first Android 5.0/Lollipop SDK), this detects whether the Goat Simulator app is installed:

/**
 * Used to determine whether the user making this call is subject to
 * teleportations.
 *
 * <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can
 * now automatically identify goats using advanced goat recognition technology.</p>
 *
 * @return Returns true if the user making this call is a goat.
 */
public boolean isUserAGoat() {
    return mContext.getPackageManager()
            .isPackageAvailable("com.coffeestainstudios.goatsimulator");
}

This should make it clear that djechlin's suggestion of using it as a warning-free if (false) is a potentially disastrous strategy. What previously returned false for every device now returns a seemingly random value: if this was buried deep enough in your code it could take a long time to figure out where your new bugs are coming from.

Bottom line: if you don't control the implementation of a method and decide to use it for purposes other than stated in the API documentation, you're heading for trouble.

Mark Whitaker
  • 8,049
  • 8
  • 44
  • 66
  • 20
    Why would anyone ever put any kind of `if(false)` in production? Come on here. If that's what your code looks like then this implementation changing is the *least* of your problems. – djechlin Nov 05 '14 at 15:56
  • @djechlin "do we need this feature? *changes to if(false)*, *tests feature* nope. *checks in*" – user253751 Sep 25 '20 at 15:37
131

Google has a serious liking for goats and goat based Easter eggs. There has even been previous Stack Overflow posts about it.

As has been mentioned in previous posts, it also exists within the Chrome task manager (it first appeared in the wild in 2009):

<message name="IDS_TASK_MANAGER_GOATS_TELEPORTED_COLUMN" desc="The goats teleported column">
    Goats Teleported
</message>

And then in Windows, Linux and Mac versions of Chrome early 2010). The number of "Goats Teleported" is in fact random:

 int TaskManagerModel::GetGoatsTeleported(int index) const {
     int seed = goat_salt_ * (index + 1);
     return (seed >> 16) & 255;
 }

Other Google references to goats include:

The earliest correlation of goats and Google belongs in the original "Mowing with goats" blog post, as far as I can tell.

We can safely assume that it's merely an Easter egg and has no real-world use, except for returning false.

Community
  • 1
  • 1
rickyduck
  • 3,790
  • 13
  • 55
  • 90
  • 4
    ibm is also rumored to have goat references throughout various internal software. – goat Sep 17 '14 at 04:29
112

There is a similar call, isUserAMonkey(), that returns true if the MonkeyRunner tool is being used. The SDK explanation is just as curious as this one.

public static boolean isUserAMonkey(){}     

Returns true if the user interface is currently being messed with by a monkey.

Here is the source.

I expect that this was added in anticipation of a new SDK tool named something with a goat and will actually be functional to test for the presence of that tool.

Also see a similar question, Strange function in ActivityManager: isUserAMonkey. What does this mean, what is its use?.

Community
  • 1
  • 1
KDEx
  • 3,355
  • 2
  • 27
  • 39
  • 3
    My assumption with this one is it allows the `ActivityManager` to report if it has been invoked by the `monkey` ui stress testing tool, but i have never confirmed this. – CtrlF Jan 28 '14 at 08:16
43

Funny Easter Egg.
In Ubuntu version of Chrome, in Task Manager (shift+esc), with right-click you can add a sci-fi column that in italian version is "Capre Teletrasportate" (Teleported Goats).

A funny theory about it is here.

GAMITG
  • 3,670
  • 7
  • 30
  • 50
j.c
  • 2,636
  • 3
  • 24
  • 43
5

It's not an inside joke

Apparently it's just an application checker for Goat Simulator - by Coffee Stain Studios

If you have Goat Simulator installed, you're a goat. If you don't have it installed, you're not a goat.

I imagine it was more of a personal experiment by one of the developers, most likely to find people with a common interest.

Manaus
  • 387
  • 4
  • 9
Gadget Guru
  • 454
  • 4
  • 12
  • 12
    The method was created before the goat simulator. Although it checks if the app is installed now, it didn't do anything before. And it's a joke anyway. – Ricardo A. Jun 04 '19 at 12:07
  • 2
    Google Chrome's tab monitor had an easter egg column «goats teleported» (and `isUserAGoat` docs refers to goats teleportation too. So it's definitely an internal joke. – artem Aug 17 '20 at 19:41