Police forcing me to install Jingwang spyware app, how to minimize impact?

Question: Chinese police are forcing whole cities to install an Android spyware app Jingwang Weishi. They are stopping people in the street and detaining those who refuse to install it.
Knowing that I may be forced to install it sooner or later, what are my options to prepare against it?
Ideally:

Make it appear like the app is installed and working as intended,
without having it actually spy on me.

The app is downloadable and documented. It basically sends the IMEI and other phone metadata, as well as file hashes, to a server. It also monitors messages sent via otherwise secure apps. I don't know whether it includes sophisticated anti-tempering features or not.
I can't afford two phones nor two contracts, so using a second phone is not a viable option for me.
Comment: Most of the people here's primary experience with security will be in a corporate setting. The attitudes, adversaries, and resulting threat models are pretty fundamentally different from those of a citizen in a totalitarian setting. Professional infosec thinking can usually rely on law enforcement as an ally or at least as non-hostile; the rules are very different when they are your adversary. None of the existing answers address how to deal with an adversary who can make you disappear if they discover attempts to resist them. That's simply not a threat faced by most security professionals.
Comment: How do police check whether or not the application is installed?
Comment: When contemplating circumvention measures always keep in mind the resources and possible responses of those imposing whatever you're trying to get around. No matter how clever and tech savvy you are you're unlikely to be better than the combined capabilities of a state funded security team looking for people circumventing monitoring measures. Don't make the mistake of assuming that your opposition is stupid or incompetent and that they will remain that way.
Comment: The status screen will almost certainly give away any attempts to firewall the app, drawing more attention to you when they see that your internet connection is working.
Comment: @trogdor of course the problem is the risk of doing things wrong (or not fully understanding the ecosystem and getting caught as a result).  I imagine the consequences for getting caught trying to fool the police/app are not going to be small...
Comment: Then it is very possible that you could use a dummy program which mimics the interface/behavior of this spyware. Perhaps you could even use the spyware itself, but "crippled" (i.e. use a firewall to prevent it from accessing the internet, assuming its status screen won't give away the fact that it is unable to contact the server).
Comment: None of the answers mention this. It's a pretty bad idea to present a solution as universal when it could be devastatingly insufficient to some people. This is meant to be a reference site, that presents canonical answers to questions. None of these answers limit their scope appropriately. Also, the camps are only one risk. The Chinese government takes very poorly to activism of any sort, and if someone's interested in preventing government spyware from being installed on their phone then chances are they don't view their government with very high regard.
Comment: Isn't the cliche in the security world that, if an attacker has physical access to your device, it isn't your device anymore?  It's not hard to imagine that some clever attempts to evade the spyware might work in the short-term (at the risk of provoking law enforcement), but if they're really going around forcing everyone to convert, they'll likely just get more adept and aggressive about it in the near future.
Comment: @dn3s no one is presenting a "universal answer". They are all ideas. And while the site strives to be canonical, no one can assume that all accepted answers are.
Comment: What if you don't have an Android phone? What if you had a feature phone instead? Or an iPhone / Windows Phone / FireFox / Blackberry? (this may be a stupid question, but I don't know anything about phone providers in China)
Comment: @forest: They just take the phone, find the app, open it, and check some status screen, I presume.
Comment: If you have a potential answer, please post as answers. If you wish to discuss details in other comments, please take to chat. If you want to discuss philosophy, [there's a Stack Exchange for that](https://philosophy.stackexchange.com/).
Comment: Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackexchange.com/rooms/83627/discussion-on-question-by-citizen-police-forcing-me-to-install-jingwang-spyware).
Comment: I can't leave an answer due to the protection element (been lurking, don't have enough non-bonus points). You need to work out how they validate or prove it's been installed. If you can create a 'dummy' copy of the spyware, install that, so when it's physically checked it appears to be working, then you can say 'it's already been installed officer', but that takes a great risk (if they verify it technologically, it'd need to be a working version). You also need to ask yourself what you need the phone for (I presume it isn't just for calls) - is there something else that could do it's job?
Comment: While not an answer, since this might vary from phone to phone, on my Samsung S8 I have a "My Safe" (or however it's called in English) - part of Samsung Knox security suite, an isolated part of the phone where non-authorized apps don't have access. It can be used to take pictures and data securely (data is encrypted) - this data SHOULD be safe from the prying "eyes" of other installed apps (unless explicitly given access to the safe). That said, if your phone is rooted and / or you don't have this feature, then this solution (obviously) won't work.
Comment: You, or someone with experience, can:

1. Download the app (.APK)
2. Decode the app and read the code
3. Remove API calls / bad functionality / etc.
4. Build app and run it on you phone (you can send the file on mail)

Now you have the exact same app without the bad things. It looks the same both icon and functionality, but it doesn't send your info to the "bad" guys. :)
Comment: It would be helpful to know why Citizen wants to avoid being spied on, and how much time and effort they are willing to put in to do so.  If the goal(s) and how important they are, absolutely and relatively, are clarified, the answers can be more tailored.  Citizen, are you still around to answer?
Comment: Is this happening only in Xinjiang (and possibly Tibet)? Or also even in the "Han heartland" cities (Beijing, Shanghai, etc.)?
Answer: This may not be the answer you will be happy with but how about abstaining from having any undesirable data inside your phone in the first place and instead using the right tool for the job?
According to Wikipedia:

The app records information about the device it is installed on, including its [...] IMEI, the phone's model and manufacturer, and the phone number. The app searches the phone for images, videos, audio recordings, and files [...]

So, instead of trying to tamper with this spyware in any way (which can get you in a much bigger trouble), simply don't do anything suspicious on this phone and let this app do its job. Prepare against it by not having any photos, videos, audios, file, etc., and instead use the right tool for the job. Use some other secure software/hardware to connect to internet, use encrypted email provider and do all of your communication through the computer where you can do communication safely, and store all of your files somehow in a safe place (encrypted, somewhere on computer or USB, etc). Pretend to be an obedient citizen and use the right tool for the job to do whatever it is you don't want your government to find out.
Some people may wonder why bother having a phone in the first place (and FYI, I asked the same question under OP's question, for clarification). My answer is:

to make phone calls (and have conversations which are not going to be considered by Chinese government suspicious, in case they are tracking that too)
to use it as a "red herring" - if police asks you to give them your phone you won't have to lie to them that you have no phone, or worry that they will find out that you tampered with app, or get in trouble if you don't have app, etc. You'll just confidently give them phone, with no "illegal" information on it, they will check it, and walk away. You may, actually, even have some "red herring" files: pictures of nature, shopping list (milk, eggs, etc.), etc., just so that they wouldn't suspect that you deliberately not using your phone for such purposes, and harass you farther.

I mean, not long ago mobile phones didn't even have the ability to store pictures, videos, files, etc.
Are you willing to put your life in danger simply because you want to have some files on your phone?
Tough times require tough decisions.
Comment: Reminds me of the alleged habit of New York City inhabitants of the 1970s and -80s, when crime was at a high, to [carry two wallets](https://www.nytimes.com/1982/01/31/nyregion/fear-of-crime-is-now-woven-into-the-fabric-of-city-lives.html) -- one with 20 dollars or so for a mugger and the other one with the real valuables. (Any parallels between police and muggers are, of course, entirely coincidental.)
Comment: Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackexchange.com/rooms/83672/discussion-on-answer-by-alex-l-police-forcing-me-to-install-jingwang-spyware-app).
Answer: Get a phone which doesn't support Android apps.
Why are so many of the answers complex? And not just complex, fragile and suspicious and downright dangerous to the questioner?
You want to use your phone to send messages and make calls, right? You don't want this app installed, right?
Say hello to your new phone:

Good luck getting an Android app running on this.
It's probably not illegal to have an old phone.
Comment: *It's probably not illegal to have a crappy old phone.*, op would need to make very sure that is indeed the case.
Comment: Only problem, they can still listen to all your calls, read your text and track your whereabouts through carrier surveillance. May be worth mentioning.
Comment: Be wary - my nokia 6310 supported Java, and stored up to 102 kbytes of JAR files.  And even worse, it was java.
Comment: I agree with you. Getting this type of phone is the best solution IFF this won't draw suspicion from police even farther. I asked OP in comments if he can get simple phone or live without of phone at all, but didn't get reply and now my comment is deleted. Whatever. Regardless, additional "benefit" of keeping android phone with running app is for it to be "red herring". You give up a little bit of privacy in order to not get yourself into an even **bigger trouble**. What's better: government knowing exactly where you are at any time or sitting in jail?
Comment: @Criggie While possible that they've got a java version of the app... I'm betting they didn't get into that nightmare and just wave people on if their phone doesn't support the app.
Comment: Sadly, from what I've heard - having a non-smart phone *does* cause you problems in that province.
Comment: Something like the upcoming Librem 5 that's a smartphone but can't run Android apps and isn't mainstream enough for them to develop a specific application for might also work, but only if their response to not being able to use their tracking app isn't going to be just stapling a transponder tag to your ear...
Comment: You will definitely rise suspicion with this phone. Human rights watch analyzed an app which was used to track the behavior of people living in the Xinjiang region. (This is also where the Jingwang is used) Here's an excerpt of their report: `[..] The app's source code also reveals that the police platform targets 36 types of people for data collection.Those include people who have stopped using smart phones [..]`. You can find the report here: https://www.hrw.org/video-photos/interactive/2019/05/02/china-how-mass-surveillance-works-xinjiang
Comment: @Murphy So you are actually recommending a phone without any available security updates while it's still possible to run arbitrary code on it? Despite that: Where's the difference to a smartphone where most of the 'smart' features are simply not used?
Comment: @Noir

A phone which has rarely seen serious security issues, low feature and incapable of installing the app which the questioner specifically wants to avoid having installed on their phone. Random chinese cops are not going to start looking through the java API for the phone to code up a custom java version of the app in question. Regardless of whether someone could theoretically write it.

I'm talking practice rather than theory.
Comment: Why not an iPhone?
Comment: @Murphy Police will likely start developing on this phone if they notice that most dissidents they track have a Nokia 3310. Or, well, maybe not even: Have a 3310? They assume you have something to hide and start tracking you.
Comment: @Daniel sure, but that's a given with any phone. If you really want to communicate securely and want something low-profile get the version with basic internet and get a java app that can encrypt chat then bury the java app between a dozen Snake clones and make sure it doesn't save any history.
Comment: You can get one of these with Bluetooth tethering (my Nokia candybar in 2009 did it) and carry an "unphone" Android device with no SIM card that you run actual apps on.
Comment: @Criggie I used Java apps a lot on on a more modern phone than this one, and they don't run unless you select them, and you can't do anything else while one is running.
Comment: Could also get a Blackberry or an iPhone I suppose as well.
Comment: JavaME applications do not support spying at all.
Comment: @dim I guess non-smart phones have not disappeared of china. You will look more suspicious with a "Librem 5".
Comment: The Gibbs method, i approve! :D
Comment: I do not understand why this answer has so many up votes. One should not stop using technological devices just because some entity can spy on you. Would you stop using your computer and starting using traditional letters to communicate with people, knowing that there is a risk that someone can spy your computer, or that someone is doing it? Or you would rather try to find a solution to that problem and keep using your computer?
Comment: @PedroGomes I disagree. If a technical device is too unsafe, then it is only prudent to stop using it and find an alternative. Of course, if you can still safely use them then you should do so, but that's not always possible. Switching to a different technique _is_ a valid solution to certain threats. Consider an obvious example: If you are a prisoner and wish to communicate outside the prison but the prison has GSM jamming equipment set up, do you try to use a cell phone anyway despite it being a nearly unsurmountable task or do you pass paper notes to someone who can deliver them covertly?
Answer: This is a tricky one.  It goes without saying, but it's also a dangerous one.  Attempting to circumvent these restrictions and getting caught doing so will potentially cause a lot of legal trouble.  If they throw people in jail for refusing to install the app, I wouldn't want to figure out what they do to people circumventing the app restrictions.  It is especially relevant because even experts in tech security have gotten caught by their governments despite extensive safeguards (the founder of Silk Road is a great example and is now serving a life sentence).  Granted, evading this app is most likely a much less serious "crime", but the Chinese government isn't exactly known for lenience here.  So while I would like to answer your question, please don't take this as me suggesting that you actually do any of this.  I consider myself a tech-expert, but I still wouldn't do it.
Still, to answer your question, you have a few options.  I won't bother mentioning the "Get a second phone" option because you've already ruled that out.
1. Virtual Machine/Dual Boot
There are some options for "dual booting" android phones.  I don't have any examples to immediately link to (software suggestions are off topic here anyway) but there are options.  If you can get your phone to dual boot then you can install the tracking software on one ROM and then do all your personal stuff on the other.  You may need to put some basic information on the ROM with the tracking app installed just so you don't raise too many flags.
Of course there are still risks here: risks that they might reboot your phone and notice, risks that they might realize you have a completely different system installed next to the tracked one, and the simple risk that you would go out and about and forget to reboot into the "tracked" system, allowing a police officer to find and install the tracking app on your actual system.
2. App modification/interceptors
If this app creates enough bad press it is possible that anti-tracking apps or hacked versions of this app may start floating around that try to automatically protect you from it.  I would not expect there to be any general tools already available that would protect you from this, so this is something that would simply take lots of googling or (perhaps) requests to the right people.  This has a major downside that unless you are an expert at reverse engineering, there isn't much to do to make this happen.  It's also hard to estimate what the risks of detection are.  That will obviously vary wildly depending on the skill level of the person who put it together.
3. Server Spoofing
Depending on your level of technological know-how you might be able to put something together yourself (note: this is not for novices).  Based on what I know and my experience in this area, I'm going to try to summarize some details about what a server-spoofing measure might look like.  Again, I'm not summarizing this because I think you should do it, but because understanding how things like this operate can be generally informative and also help understand the risks there-in.
Built-in security
First, we need to understand how this spying app might secure itself.  From all information available so-far, the answer is "it doesn't".  This is a pretty simple conclusion to come to because the app communicates exclusively through http.  It is very easy to intercept http requests, either from the device itself (if your phone is rooted) or with network sniffing tools on a computer attached to the same network as the device.  Most likely it is also very possible to easily figure out how the app authenticates itself with the end-server and how the end-server authenticates itself with the app.  In all likelihood there is no authentication in either direction, which means that spoofing requests in either direction is trivially easy.  This might be hard to believe (given that a country like China sets aside lots of resources to invasive technology like this), but the reality is that if the people who developed this app wanted to secure it from outside tampering, using HTTPS for transit would be the very first step to perform.  It is cheap, easy, and very effective.  The lack of HTTPS means that it is very likely that there is no actual security in this ecosystem, which is a plus for anyone trying to evade it.
Sniff all traffic coming out of this app to determine what requests/responses it makes
This is the first step.  By watching the traffic leaving this app (which can be easily intercepted in the network itself since there is no SSL encryption) you can figure out what requests it sends to the destination server and what responses it expects back.  Understanding the underlying API is critical, but easy due to the lack of encryption.  This will also let you know if there is any authentication happening in either direction.  If there is, you can at least see the full request and responses, so you can most likely figure out how to spoof it.  It is possible that there is some hard-to-reverse-engineer authentication going back and forth, but again, given the lack of basic encryption, I doubt there is any such thing built in.
Figure out if the app is talking to a domain name or IP address
The destination server the app is talking to is either found via a DNS lookup or has its IP address hard-coded in the app.  In the event of the former you can edit the DNS for your android phone to repoint it to a different server, including one running on your phone.  In the event of a hard-coded IP address you will similarly have to redirect all traffic to that IP address to your local android phone (presumably you can do this with Android - you can with other operating systems, but you would definitely have to root your phone).
Setup a replacement server
You then setup a local server that responds to all requests just like the server did in your initial spoofing.  You would have to get this server to run on your phone itself, that way it is always available.  This doesn't necessarily have to be complicated (although that depends on how detailed the actual server interaction is), as you don't actually care about keeping any data on hand.  You just need to make sure that you provide valid responses to all requests.
Risks:

The app may auto-update itself (although your mock-server may make this impossible) and point to new domains/ip addresses, suddenly removing your protections
If there is an auto-update functionality and your end up unintentionally killing it (which would be good per point #1 above), a police officer may notice that it is not properly updated, flag you for "extra" checking, and discover what you are doing.
They may do server-side tracking and discover what you are doing because they don't find any data on their end for your particular IMEI (because your mock-server acts like a black-hole and sucks up everything).  Even if you send spoofed requests there will be easy ways for them to determine that (imagine the police copy a blacklisted image to your phone and discover that the app doesn't block/report it)
They may have root-checking in the app itself, which will cause you problems

Actually, that's it
I was trying for a longer list but that is really what it all boils down to.  Short of not carrying around a phone or purchasing a separate one, these are about your only options.  For reference, I haven't gone into details about the server spoofing because I think you're necessarily going to go out and do it.  If anything, I've gone through it because it gives opportunity to talk through the risks in more detail, and those should make it clear that there are a lot of risks.  Even if you find a solution from someone, they have to deal with all of these same risks (or ones like it).  Right now this app sounds like it is poorly executed and easily fooled, but depending on how much the Chinese government decides it cares, that could change very quickly.  At that point in time not getting caught basically turns into a cat-and-mouse game with the Chinese government, and that isn't realistically something that someone can continue to win for an extended period of time.  There are a lot of risks, so tread lightly.
Comment: actually httpS is not very effective on neither Android devices nor iOS devices. the free version of Fiddler Proxy (+ [this plugin](http://fiddler2.com/r/?FiddlerCertMaker.)) has everything needed to generate a fake certificate, install it on the phone, and perform MITM https-decryption, modifcation, redirection, and blocking. i've used this myself several times to study and cheat in mobile games. (and study the Facebook Messenger / friends API)
Comment: There is one more risc too to concider - other channels used more less frequently - and it may not be for security, just for convenience. I can say, that I made application, which normally communicate in plain text each 1/2 hour, but 4x a day it also use other channel for other data and sometimes (like once a week to once a three months) use another channel for totally another kind of data. (And sometimes it update itself.) Lack of any of such communications is reported as big red error at central server. And it has nothing to do with spying or security, just with primary function of the app.
Comment: @user1067003 Sure, performing a MitM on yourself is very doable.  I wasn't trying to imply otherwise.  However, it is still harder than simply sniffing network traffic for an unencrypted connection.  My point was that SSL is the first and most basic security step for web systems, and also very easy to do.  Anyone who is not bothering with HTTPS these days simply isn't trying, and SSL certainly does provide *a* barrier from simple snooping.   Add in HSTS and public key pinning and you're starting to get about as secure as possible on someone else's device.
Comment: I'm not exactly an expert on mobile communication, but AFAIK any phone comes with both an IMEI (spoofable, but it's tricky) and an IMSI (not spoofable, as it's the ID of your phone in the network). Considering the capacities of Chinas surveillance I would be astonished if they couldn't detect a phone with an unique ID having the app active only sporadically. Let alone sniffing on higher levels of the system or examining the entire storage when the app is running.
Comment: There are a few more: sandbox the app + sandbox apps that you want to hide, off the top of my head.
Comment: **Any** of these can be **remotely** detected, this is just a matter of state will.
Comment: The reference to the founder of the Silk Road isn't really relevant as he was neither a tech security expert, nor was he caught despite an abundance of caution.  He was essentially caught because he posted questions in forums with traceable accounts that referred back to Silk Road before it was well known.  The FBI didn't cut through TOR's encryption.
Comment: Another risk of a local server is making it as slow as interactions over the air with the real server.
Comment: @user285259 yup.  That's pretty much the gist of what I was trying to say at the very end of my answer.
Answer: They can execute code on your device while they have physical access to it. And you can't refuse it. I'm sorry to say that but you are basically doomed. There's no way to trust this device anymore. That's part of the 10 immutable laws of security. In your case the rules #1, #2, #3, #6 and #10 are applicable.
But when you act like you don't trust the device you could raise their suspicion. Maybe. Because nobody knows what they are actually doing with the collected data. Maybe nothing at all. In the "best" case it's primary for spreading FUD.
But when they are actually using the data it's easy for them to spot burner phones and all kind of tampering. As far as I know you only get a SIM card by identifying with your ID. Since the spyware reads identifying information like IMEI and IMSI they can simple compare the collected data from the phones with the purchase records. They can combine this with behavior tracking based on metadata collected on the phone (Which apps are used and how often, how long the screen is on etc.) and the mobile network (usage of data, location based on cell tower etc). Since they can do that on a large scale, they can spot strange usage patterns by your usage history or how a "average" user is behaving. Of course there's a vast amount of ambiguity and such in this data but they have the ultimate interpretational sovereignty.
You must also keep in mind that you need to keep your measures working all of the time because it could always happen that you get stopped on the street again.
I'd like to emphasize on rule #10. You are basically trying to solve a social problem with technology - just as your government does.
Answer: Use a custom ROM (two, to be correct).
Android phones can have more than one ROM installed, and you choose one or the other. So install two copies.
On the clean ROM you install the spyware, anything not dangerous, games, whatever you feel clean. On the secure ROM you install things you don't want anyone to know about.
Keep the clean ROM running almost all the time, specially when you are out of home. Boot on the secure ROM only when you really need.
You will need to keep a secure mindset too, to have awareness of what ROM you are using and what content you can create or access. That is the main point of failure. Using a different keyboard on each ROM, or different OS languages can help: Chinese on the clean, English on the secure, for example.
But first you must weight the risk/reward of doing so. If the risk of getting caught plus the mental effort to keep activities and files containerized is worth the benefits of bypassing the spyware, do it. Don't do otherwise.
Comment: @ThoriumBR The assumption that they want the app to be invisible and unobtrusive is also dubious. The Chinese government conducts surveillance by coercion, not subterfuge - they're not installing this app remotely without users' permission, they are (allegedly) demanding that they install it under threat of arrest. They have no motivation to hide what it does; anyone who gets angry and decides to bypass it can simply be publicly punished as "subversive"; that's how totalitarianism works.
Comment: @ThoriumBR A mobile phone doesn't go to sleep when not in use like a closed laptop; if nothing else, it will be constantly checking with transmitters to ensure it can receive incoming calls. It seems perfectly plausible to me for a background application to be logging many times a minute whenever the phone is switched on; saving to a local, encrypted, database; and periodically uploading reports to a central server. Gaps in that log might be viewed as suspicious, particularly if they can be compared against logs demanded from the network operator.
Comment: Whether this is possible is extremely dependent on the particular phone, even if Android is a given.
Comment: What stops them using the logs of the mobile phone network to check that app is running at all times the phone is connected?
Comment: @ThoriumBR Surveillance apps presumably *do* run all the time.
Comment: Apparently this is a contentious topic - so far this is the only answer with a positve score that doesn't have any downvotes.  lol!
Comment: Apps don't run all the time, and OP should not run the secure ROM all the time.
Comment: But they don't run all the time. Or the battery will run dry in a couple hours, more people will know something is wrong, and lots of angry people will have incentives to bypass the surveillance. They are presumably to be invisible and unobtrusive. They will log things here and there, and send data from time to time.
Comment: @IMSoP: I used to frequently put my phone in airplane mode to save the battery.  But your point is valid, and one that most of the answers miss: that if any method succeeds in stopping the reporting, the government will (or can) notice the gap.
Answer: I'd recommend you just go with it. The Chinese police doesn't just stop any random person in the street and asks for their phone. They stop Uyghur.
This happens for reasons which are somewhere in between "mitigate a real threat" and "Woah, no go, dude", but whatever it is, it's what the government does, so it's legal and "right". No benefit of doubt, and no assumption of innocence, no Sir. By Western standards, it's kind of unthinkable, but you cannot draw to the same standards there.
So the situation is that you are easily identified as Uyghur, both from looking at your face, and from the fact that police knows. They know who you are and where you live. And sure they know whether you've been stopped before. Again, you're not being stopped at random. You're stopped because you are already a well-identified target, on their screen.
It isn't even unreasonable to expect that your Internet traffic is monitored (targetted) and even asking about how to circumvent the measures may move your name onto a different, more high priority list.
You can bet that police keeps a list of people where the spyware has been installed (with device IDs), too. If no data comes in from your device, well, guess what. You'll be stopped again by police, and they will look very carefully why this isn't working.
Insofar, it is kind of unwise to try and circumvent (and risking being caught) what police wants. From their point of view, you are a possible criminal, and a possible terrorist. By trying to circumvent the measures you prove that you are a criminal.
The surveillance happens on the base that if you have nothing to hide, then you need not bother if they're watching you. Again, by Western standards, this stance would in no way be acceptable. But whatever, in China it's perfectly acceptable.
I wouldn't want to risk disappearing in a detention camp if I was you. Rather, let them have their spyware, and simply don't do anything that isn't opportune to the system.
Comment: Given how insecure the spyware appears to be, simply installing it will likely open you up to attacks from actors other than the Chinese government.
Comment: The situation certainly sucks. I just wanted to point out that even if you accept that it's ok for the Chinese government to do this, there are still other risks.
Comment: @AndrolGenhald: Probably, but if you can't leave the country, what else do you want to do? Not complying is not an option, really.
Comment: @iBug: That's true, but sometimes "Don't do it" is the right answer. There's too much at stake, and chances that OP gets caught are high (I'd say 99%). The spyware transmits the IMEI, so they know _exactly_ who isn't sending. They _also_ know exactly who had the spyware installed. So... not good.
Comment: This doesn't really answer the question. It's about "I know I'm targeted. How do I defend?". Your answer is basically "How to avoid being targeted" and therefore not really answering the exact question.
Comment: This doesn't answer the question, and what is worst, it's accepting a total loss of privacy...
Comment: @Mr.E: It _does_ answer the question. The in my opinion only correct answer is "Don't do it". Given the circumstances, any other answer is just unresponsibly dangerous. Being targetted individually by a governmental institution (as is the case) means your chances of being smarter than the system and getting away are close to zero. This is a suicide move. Given "no privacy" and "die in detention" as alternatives, I know which one I'd choose. Your opinion may differ, and free feel to downvote.
Comment: "even asking about how to circumvent the measures may move your name onto a different, more high priority list." .... makes me think that if I wanted to find how to defeat those attempting to defeat my security system, I would pose as someone just like OP here and review all the answers for further closing of loop holes.  IOWs, this entire question and answers appears to help the security of the government  perhaps even more than individuals.   Hmmm
Answer: First of all, I think you should search for solutions that are already implemented by other people. For instance, what do other people in your case do to prevent the spying activities?
One possible solution would be to have a man-in-the-middle implementation analyzing the information that is being sent, altering it, and sending it to the same server and port the spyware is trying to connect to.
I read a bit about the functionality of the app, and the information it gathers is, and I quote from the Wikipedia source you provided:

sent in plaintext

Hence, after doing some tests with a packet sniffer tool and clearly understanding how the spyware and server exchanges made using the HTTP protocol work, you could, if you have root access to your Android phone, redirect the traffic of the spyware app to a process that is running on the background of your Android OS. This process would change the data that is going to be sent to the server the spyware is trying to connect to. That way, you can send data that matches another cellphone (maybe, literally faking the data is a bad idea, because that can trigger alarms).
You should also take into consideration any kind of validation processes that the spyware has implemented so you do not alter them. More specifically, the data that is in the HTTP packets' headers and that is sent from the spyware app to the server to gracefully initiate an upload.
Of course this is theoretical, but it is a realistic thing to do. Also, you probably will require knowledge of Android programming (mostly in C or Java) and IT.
This approach is stealthy and will not require an uninstall of the spyware app. There is always a risk, but in this case, depending on the data that is actually spoofed, the risk is minimal.
Comment: I believe the first paragraph is the most critical one. OP is not alone in this, it's a big community of people affected and they _will_ have found a workable solution. Just be aware that the more people fooling the system, the more likely the government will pick up on it and close the loophole. If you're using a method that gets closed there's a chance their net will catch you.
Comment: This will not help in case of keylogger spyware.
Comment: How can a keylogger affect this approach ? Please explain.
Comment: Bare in mind that, keylogger can keep data inside the phone. So if the phone confiscated by the Big brother, the user still susceptible to phone activities forensic.
Comment: @Ruadhan2300 I mis read indeed your comment. I totally agree with you on that point.
Comment: I still do not understand what you are trying to point out. A keylogger logs keystrokes, that's it, the background process has nothing to do with that.
Comment: Do I need to explicit say that keylogger may also take screenshot ?
Comment: A screenshot will not affect anything at all on this approach. How a screenshot will affect a process running on the background ? It is not an app
Comment: @Ruadhan2300 I did not suggest this approach to be shared, I suggested him to search for already existing solutions, not to share mine with everyone in the same case. Depending on how the data is faked it could be hard for the government to "close the loophole"
Comment: @PedroGomes I believe you misunderstand me, I don't mean sharing the approach with others, I mean that finding your own solution may not be necessary if there's other people who have already done it and shared it. It's a maxim in software development that any technical problem you encounter has probably already been found and fixed by someone else, you just have to find out what they did.
Answer: Due to the nature of the spyware, they will be able to detect any mitigation techniques which will make you a person of interest to them.
I know you said you can't afford two phones but it really is the best advice - why not clean and refurb an older phone if you have one around?
A burner phone doesn't need to be anything special and even better if it isn't a smartphone.
Comment: Police might not be information security gurus, but they are good at telling if I am hiding something in my other pocket. Then the consequences might be worse.
Comment: I really doubt this is true, and even if it is correct you are not providing any evidence of that fact.  Rather, you are expecting everyone to just take your word for it.  Given the importance of this question to the OP, I think a little more effort is required.
Comment: @forest But it might not be the same tomorrow as it is today, and that can make all the difference in defeating it or losing to it. When we're talking an oppressive government, can you, in good conscience, really tell someone you've never met to take that risk?
Comment: There are certainly ways to defeat this spyware without raising red flags. It's not like the spyware's functionality is particularly secret (or particularly sophisticated).
Comment: Note that with the cooperation of network carriers, they will be able to tell if you are using another cellphone with the same SIM card, or if a subscriber has two SIM cards nearby, or the number of devices that are connected to your home WiFi or network. It may be unwise to use a second phone in any case.
Answer: One idea is to think of your phone as a networking device and nothing more.  If you carry a secondary "tablet", that is NOT a phone, you can tether through your phone, and use a VPN on the tablet to protect your data.  Now you can hand out your phone to be inspected as all of your actual important data and work is on your tablet which is clearly not a cellphone.  If traditional hotspotting is too dangerous, you may want to consider alternative methods such as using a USB2Go cable or bluetooth pairing. If hotspotting is detected or blocked, you might also be able to use an app like PDANet to bypass those restrictions.
Comment: If I were trying to monitor everything, I would have code that flags packets going through the towers without corresponding reports from my spyware.
Comment: It would indeed be difficult to catch 100%.  It would not be difficult to catch 90%.  And if they weren't already catching a huge percentage of what they want, threads like this would not exist.
Comment: @tripleee do people not use tethering in China?
Comment: You're still assuming there's a presumption of innocence - it seems more likely that even if there's a valid/acceptable explanation OP can expect to be investigated first.
Comment: That would be very difficult to do.  Nothing is ever 100%.
Comment: "Hang on, there are packets flying back and forth, but they are not connected to any running app ... Flag this phone as suspicious."
Answer: Disclaimer: I live in North America.

Knowing that I may be forced to install it sooner or later, what are my options to prepare against it?

Remove illegal items and anything else that you think that the government wouldn't approve of from your property - your clothing, phone, desk at work, home, etc.
If the government can't find you doing anything wrong then you only have to worry about someone planting false evidence on you - you need to search your own stuff from time to time.
When I go through Customs I've made absolutely certain that I have checked everything for anything I shouldn't have, because you know that they will likely check when you go through the port of entry.
As a result of my efforts they've not found anything to object to and have even simply waved me through a few times. Nothing to see here, move along.

Ideally:

Make it appear like the app is installed and working as intended, without having it actually spy on me.

We have different ideas of what's ideal.
Ideally I'd prefer to be paid millions of dollars per hour.

I don't know whether it includes sophisticated anti-tampering features or not. I can't afford two phones nor two contracts, so using a second phone is not a viable option for me.

It wouldn't make any sense for it not to detect tampering.

The APP is probably an excuse.
If they obtain the information by another means (like monitoring the cell phone towers and WiFi, along with all Internet traffic, and then there's your neighbors whom earn a healthy living turning people in) they can say in Court that they obtained the information from the spyware - that way you don't know how the information was actually obtained.

This happens in more places than just where you are, it's different where you are in that roving gangs force you to install the APP. In other places (including North America) they get by without using an APO and rely on other techniques.
Proof: In the last few months people whom have a lot of contact with children (Coaches, High School Principals, etc.) have had their work, home and computers searched for possession of inappropriate images. This appears in the news monthly.

Moral of the story: If you are poor and unsophisticated don't fight the rich, powerful, intelligent army trying to do something that they can find someone to back their actions to prevent you from doing it.
If you can't afford a second phone and contract that's a hint that you couldn't afford trouble in the first place, and the fine.
In your country they are upfront about it and demanding because objections fall on deaf ears. It's not much different in North America, just that they are sneaky to avoid complaints and only focus on major infractions so people don't suspect that they can see the lessor consequential things just as easily.
Comment: If you CAN afford a second phone, either they find out when you buy it or they find out when you use it.
Comment: This is what I'm saying, the cellphone tower reports people in the area that aren't running the APP and then they can triangulate you and pull up a CCTV image of someone walking the path of the offending phone. Also, chances are this webpage is no longer available to the majority of the people there.
Answer: For a rooted phone (without you will have a hard time to stop the app from doing what it is doing), you can use AFWall+ to prevent the app from phoning home and XPrivacy.
XPrivacy on Android up to 6 is better than XPrivacyLua (Android 6 and newer), because the old version can block more different things.
This setup works best, if you can install the app voluntary at a time nobody is watching you configuring the security solutions. If you can only get the app when a policeman stops you, it is a bit harder to hide the security apps.
Comment: +1. Unfortunately rooting and using niche tools like XprivacyLua is not for everyone ( I use).  Just as FYI am alternative in my answer https://security.stackexchange.com/a/194842/99059
Answer: I wouldn't be shocked if there isn't a fake version somewhere--looks exactly real but doesn't actually spy.  Unless the police are actually checking functionality in some fashion this would stop them.
As others have said, though, getting caught fooling the cops would not be a good thing!
Answer: While other answers do provide useful insights, my alternative would be to use the phone as you normally would but isolate the app access to data
One method has been suggested by rooting the device, installing Xposed and corresponding modules of Xprivacy / XPrivacyLua. While I personally use this, rooting the device, managing additional risks due to unlocked bootloader and malicious apps gaining root access is yet another challenge - IMO beyond the scope of average user and hence easy alternative approach below
There is an open source app called Shelter that does two things

Use the "Work Profile" available in Android from version 5.0 (Lollipop) onwards
It allows you to install the app of your choice, in this case, your spy app in the work profile. Once it is installed on the work profile (by cloning) , it essentially is on an island and can't access any data that is outside your work profile (your photos, emails, SMS or any other app information). You can safely uninstall the original app and if police check, show them your app, which has a padlock icon indicating it is on your work profile. You can keep the app always in your recents or Overview and pull from there so that they don't even see the icon

In simple terms, the spy app has nothing to spy on!
Download Shelter - an open source app from F-droid or GitHub. Quoting the developer, relevant use case

Run "Big Brother" apps inside the isolated profile so they cannot access your data outside the profile

(Emphasis supplied)
I am currently using this, in addition to XprivacyLua. For more details see WhatsApp: How to isolate contacts and photos - Privacy concerns
Comment: your answer is good.   and is also just an example of how complicated it is to do monitoring and surveillence, which seemed like is an easy job to do.   your answer examplify the many variations of technologies that are available for monitoring and anti-monitoring - just like the end-less game of virus and anti-virus.   which is also why i hardly read all other solutions and techniques, which is not as technically deep as I wanted (from the monitoring/trojanizing point of view).
Comment: talking about PC:   you also have chrome bugs reporting, windows telemetry etc all capable of sending back debugging information.   if they want to monitor, and you are not doing anything "harmful", just let them do it - it is like having a security guard near your house.   and you may be afraid that one day this security guard may come back and attack you?   then get multiple security guards.   Apps that can monitor other apps - like those of parental control apps which I used to install on my kids' phone.
Comment: @PeterTeoh Thanks. *Variations* as you rightly pointed out is the key to both sides. For those who care this is an endless game but sadly majority dint care IMO
Comment: I would expect the Jingwang Weishi spyware to notice if it never sees any calls, photos, emails, SMS etc and raise a red flag.
Answer: There are a lot of great answers, but most of them give solutions that are beyond the ability of the average Android user.
I would like to offer a compromise between absolute privacy and getting spied upon.
I assume that your government has other means of acquiring the IMEI and phone metadata. You can stop the app from acquiring other information by denying it permission for:

Body sensors
Calendar
Camera
Contacts
Location
Microphone
Phone
SMS
Storage

Here are instructions on how to do it.
(I am not sure of your Android OS version, but the steps should be similar.)
This way the spyware would not be able to collect information about you, and therefore I assume that it will either not try to send information to servers, or it will send empty information.
However, this means that you install the app before police stops you and makes you install it. You can let the app download, kill the network connection while it's installing, and then remove permissions before it starts.
Risks
You should be aware that if the police does a deeper investigation, turned off permissions would be evidence that you have willfully tampered with the spyware. You should calculate if this risk is worthy.
This will also be a useful method of stopping other spyware (such as your flashlight app that requires contact information) from breaching your privacy.
Answer: You can simply resolve the servers it attempts to connect to back to localhost.
This can be accomplished by modifying the /etc/hosts file on your device if you have root.
Alternatively, you can use a local VPN which doesn't require root, such as this.
Comment: Presumably then the app will alert that it cannot call home and display a big friendly red badge with yellow stars.
Comment: I'm not sure how the app works exactly. It could definitely be passed off as server-side error that wouldn't be your fault. You can also change it whenever you are about to be inspected and otherwise have it set to block traffic.
Answer: Based on your question I cannot be sure whether you are a Chinese resident, or someon who is planning to visit (for instance a tourist).
It was already mentioned earlier that so far it seems that only certain minority citizens people are targeted (and if they were to start targeting foreigners that news is sure to spread very quickly).
Regardless of what I think about that, the following bit may actually help most tourists:
The google play store is currently blocked in China, so though it is easy to overcome, this likely means that you will not be able to get the app through the standard procedure.
Answer: (radically edited)
I had proposed that one idea to consider was that

Playing dumb can be a good strategy.
For example, ask the phone vendor, :"Hi.  My phone is working really slow and keeps crashing.  Can you show me how to do a factory reset?"

However, I've been informed (see comments below) that even if this led to it being documented that someone else had removed the spyware, the person would likely still get in deep trouble when it was noticed that the spyware was no longer installed.   It sounds like the answer to the question, "Is there any excuse for not having the spyware installed that would be considered valid?" is 'NO!'  So it wouldn't matter whether the factory reset is more effective at wiping the system than the spyware is at staying installed.  I would say don't risk it, especially if you think you'd make a high-value target.
Sadly, the software is effective at repressing dissidents and dissent even if technically it is 100% defective.
So my answer is that secretly helping to evangelize, build or crowdfund efforts to make it not work or prove it doesn't work well or to break it or make the phone to appear broken when spies try to install spyware would be better than a more direct approach, which would paint a target on your back.  Good luck, and may the force be with you.
Comment: Most of this answer is just saying "lol you're f---ed good luck", it doesn't really try to answer the question itself. Even if you factory reset your phone, if the police are on the streets, as the question says they are, they're just going to stop you and demand you install it again.
Comment: @MatthewElvey people are sometimes being sent to "reeducation camps" for not having the software installed in this province, and they keep track of who has it installed. If it is suddenly not sending data anymore, they WOULD catch that. Not only is this answer not helpful, it is genuinely dangerous, especially if OP is Uyghur.
Comment: Ok, thanks, user185163.  If the excuse/explanation:

_"I didn't remove it.  I was having trouble with my phone and the phone vendor removed it when they reset my phone.  Here's a receipt / record of the visit."_

won't work to avoid 'reeducation camp' then my "idea to consider" indeed was poor and I've just edited my answer to reflect that.  What do you think now, @user185163 ?
Comment: I've radically edited my answer; would appreciate more re-rates and/or more feedback.  I find it interesting that the playing dumb strategy is said to be sure not to work in China. I imagine it might be useful in other countries/other legal systems.  But then the only repressive regimes I have significant experience with are the relatively lighter touch ones in the US.
Answer: I agree with Doomgoose. Get a burner phone for this. Alternatively, get an app called Orbot (it's Tor for Android) which can get you a bit of the privacy you so desire by encrypting your online activities. Another alternative is adding a VPN on top of the equation.
Comment: Transport encryption doesn't do any good if the endpoint is compromised.
Comment: They'll generate a report on him stating that he uses Tor/VPN? What a recommendation...
Comment: The spyware is locally intercepting the data, making both TOR and a VPN more than useless.  Those change and somewhat protect the path your data takes through the internet, they don't change what your device is doing before that!  And if the spyware sends its report over one of these the government could easily notice that they're receiving data from a known TOR node or VPN service....
Comment: They also know what phones are using which towers and whether those phones are reporting.  And they shut down/block VPNs when they detect them.


OSX bash script to execute once on Terminal.app open

Question: I am using OSX on a Mac and use Terminal quite often.  I have built a few startup scripts that execute on shell open with the .bash_profile file.  However, I would like to be able to have one of them run only on the open of the first shell session when I launch the Terminal app.  I can't figure out how to have it launch just once on Terminal app open (the first bash shell opened) but not on subsequently opened new shells.
Answer: Here's how I just did it:
I added this to .bash_profile
# Only do this in the first terminal opened
termsOpen=$(who | grep 'ttys' | wc -l)

if (( $termsOpen < 2 )); then
    echo "This is echoed in the first tty opened only"
fi

So, upon launching the terminal the first time, I get this output:
Last login: Mon Sep 26 08:30:42 on ttys001
This is echoed in the first tty opened only

When I open another terminal (and thus have two terminal windows open at the same time) I get this output:
Last login: Mon Sep 26 08:33:43 on ttys000

**How it works:**
Every time a new terminal window is opened `.bash_profile` is sourced.
This command
who | grep 'ttys' | wc -l

simply counts the number of terminal windows that are open. If they are lower than 2 (in other words; there is only one terminal window active), then echo This is echoed in the first tty opened only

Version info:
OS X Version: 10.11.5
bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin15)

Comment: Good work man, works great.  The command I wanted to issue actually as a part of the code closes the window it's currently launched in (it's essentially like f.lux for the command line whereby if it's after a certain hour it launches a night themed command line for working late and regular if it's daytime) so that took a little bit of finagling with this solution but I just put a sleep in so that after it opened the second terminal, the first stayed open long enough that the conditional didn't trigger and then it exits the first terminal.
Comment: @MLP I am glad that you were able to implement it!


Please ID deep green fuzzy-leafed shrub

Question: I've seen this one several times and I like it, but have no idea what it is called. It grows in northern California. Please advise!
Answer: One candidate for this might be Woolly Viburnum. Clearly it is a woody shrub, opposite leaf arrangement with recurved leaf and perhaps reminds us of viburnums. Native of China, just a hop skip and jump across the Pacific from California. The rosy colour of the juvenile leaf shoots might be due to unusually dry conditions combined with good amounts of sun.

Please ID deep green fuzzy-leafed shrub


Can I use the GPIO for pulse width modulation (PWM)?

Question: Can I use the GPIO as a pulse-width modulation output?
If so, how would I go about doing it and how many concurrent, distinct PWM outputs can I have?
Comment: @user1147688 This question was asked back when there was only one model!
Comment: You probably need to specify which model you're using. They are all slightly different.
Answer: As suggested by Alex Chamberlain, the WiringPi library appears to support both hardware PWM output on one or two GPIO pins depending on model, and software PWM on any of the other GPIO pins. Meanwhile the RPIO.PWM library does PWM by DMA on any GPIO pin. Effectively this is a halfway house between hardware and software PWM, providing a 1 µs timing resolution compared to 100 µs with WiringPi's Software PWM[1].
Which of these is suitable for your applications depends on how many PWM outputs you need and what performance you want out of those outputs.
If your application is tolerant of low-timing resolution and high jitter then you could use a software or DMA assisted timing loop. If you want higher precision / lower jitter PWM then you may need hardware assistance.
When might software PWM be suitable?
If you want to flash a bunch of LEDs with different human visible cadences (10's of hertz) with soft real-time response requirements then the software loop could handle as many PWM's as you have GPIO pins.
When might hardware PWM be suitable?
If you want to control a servo motor with hard real-time response requirements then you will need to use hardware PWM. Even then you may have problems ensuring a real-time response for the servo loop which ties encoder input to PWM output.
A stable servo loop needs to read encoders at a regular rate (low jitter), write out revised PWM output values at a regular rate and the latency between these should be fixed (low jitter overall). If you can't do this, then you will have to undertune (soft tune) your motor to prevent it becoming unstable under load. This is hard to do with a multi-tasking operating system without low-level support.
What if I need more hardware PWM outputs?
If you need to run more servo loops than you have hardware PWM outputs, then you are probably going to need to offload them to another device to ensure hard real-time performance, relegating your Raspberry Pi to being a soft real-time supervisor.
One option, would be something like the Adafruit 16-Channel 12-bit PWM/Servo Driver - I²C interface - PCA9685 which would allow you to control 16 PWM outputs with just a few pins of GPIO for the I²C bus. For an example of its use, check out the I²C 16 Channel PWM/Servo Breakout - Working post on the Raspberry Pi forums.
1. Thanks to dm76 for the suggestion, however Auden Young says that RPIO.PWM may no longer work for newer pi models.
Comment: FYI, the RPI library (http://pythonhosted.org/RPIO/pwm_py.html) seem to have a much better resolution (1us) compared to WiringPi with 100us resolution
Comment: Can I use the software PWM approach to run DC motors?
Comment: @gideon - Yes, the motor power amplifiers that I have used have all taken PWM as their input.
Comment: @MarkBooth - No probs. The library is really well written and can be used as drop-in replacement for RPi.GPIO which is very handy if you started a project with the latter and later realised PWM signals were needed...
Comment: RPIO.PWM may no longer work for newer pi models, I think.
Comment: Adafruit has a very new servo control that uses and RP2040. https://www.adafruit.com/product/5437
Answer: Hardware PWM
Yes, there is one hardware PWM output on the Raspberry Pi, connected to P1-12 (GPIO18). Further, PWM outputs could be added using an I²C or SPI interface; some people have had success with this (forum post).
Example Code
You can use the WiringPi library to control the PWM pin; you could look at the code to avoid including the entire library.
Software PWM
The Raspberry Pi is not suitable for any serious software PWM as Linux is not a real-time operating system.
Comment: @AnthonyBlake A "Real-Time OS" (RTOS) is an operating system that gives you a guarantee on the upper time limit of execution. Like saying to the program "Yes, you will have some execution time in 33ms (give or take 2ms tolerance) to flip that GPIO pin bit to give your step motor a signal in the exact time window when he needs it. And you can rely on that!" There's a RT Linux out there. Don't know if it's been ported to the RPi (yet).
Comment: Newer models with 40 pins have a second hardware PWM connected to GPIO19 (pin 35).
Comment: Question, what is the definition or an example of serious software PWM? And what are "real time operating systems" and is there ever any chance of getting one on a Pi
Comment: @AnthonyBlake Well, you can probably control the brightness of a light using software PWM, but I suspect a motor will stall. There's no need to do software PWM though, hardware is simpler and more effective. Real time operating systems will be better explained by Google; they guarentee certain things about how long and often software is run.
Comment: Sorry Alex, I didn't intentionally steal another part of your answer, but I've just noticed that we came to the same forum post via different routes.
Comment: Hi! Thanks for the info, can you please update your post to reflect the Raspberry Pi 3? I can't find any reliable documentation confirming the existence of a HW PWM pin on that device. Is there 1 or 2 or any? Which pins?
Answer: Recent Pis have two hardware PWM channels.  In addition hardware timed PWM pulses may be independently generated on all the GPIO connected to the 40 pin expansion header.
In practice this means there are two highly accurate PWM channels and all the other GPIOs may have Arduino style PWM (800 Hz, 0 off - 255 fully on).
E.g. servoblaster and my pigpio,  etc.
Comment: Heavy CPU load shouldn't make a difference.  Heavy network load can make a difference to gpioServo especially if sampling at 1MHz rather than the default 200kHz.  The frequency is 50 (Hz), the range of duty cycles will be 0 - 1000000 (mapped to the true underlying value of 0 - 5000000).  1 ms is 1 ms in 20 ms so a dutycycle of 5% so 50000, 1.5ms->7.5%->75000, 2ms->10%->100000.
Comment: [C](http://abyz.co.uk/rpi/pigpio/cif.html#gpioHardwarePWM), [Python](http://abyz.co.uk/rpi/pigpio/python.html#hardware_PWM), [pigs command line](http://abyz.co.uk/rpi/pigpio/pigs.html#HP).
Comment: Page 102 of [BCM2835 ARM Peripherals](http://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf) shows the various modes that the GPIO can be assigned.  Look on-line for which GPIO are led out to the various Pi model expansion headers.
Comment: @user1147688 PLLD (500MHz) is used as the core PWM clock.  Because of the way "it" works the PWM core frequency is 250 MHz. To be able to switch on and off (pretty essential for PWM) the maximum is 125 MHz.  You could double the figures by using PLLC (1000 MHz) but that PLL varies with the core clock speed.
Comment: Nice answer! How can I use those two HW PWMs? I need to control 2 servos, I know you say servoblaster and pigpio are OK for that, but I just wonder about the HW PWM, because I can not find anything about them... are there some docs for it out there? I have an RPi 2 V1.1 for tests.
Comment: Ok, thanks. Is the servo control via the gpioServo() function reliable under heavy CPU load too or do I need to use the HW PWM then? I need to process computer vision stack so all my CPU cores will be under decent load... What are the gpioHardwarePWM freq and duty values for the common 50 Hz 1-2ms servo standard?
Comment: Can you post the references for this info please. I mean, where are the documents showing the 2 HW driven GPIOs on the Rpi3, for example?
Comment: Thanks @joan , I had a look at that, but I'm trying to find the max frequency for the PWM, which should be well above the 125 MHz as shown in that document. Someone mentioned 750 MHz somewhere in a transmitter thread... In addition the headers may not be up-to-date since no datasheet has been released, and nobody has confirmed equivalence to BCM2835.
Comment: @user1147688 I suggest you get someone to show you how to set a PWM frequency of 750 MHz then.  Let someone enlighten us all.
Comment: I agree its too good to be true. So it's probably a typo and should be 750 **kHz**. However, I don't see it completely impossible to be 2-4 times of 125 MHz either.
Comment: Hi @joan, I 've seen your [post](http://raspberrypi.stackexchange.com/a/23277/17798). The "*using PLLC (1000 MHz) but that PLL varies with the core clock speed*" is exactly what I want to know! How so? Where in the kernel sources is this?
Comment: @user1147688 Can't help with that.  I'm not that familiar with the kernel source structure.  I'm not even sure the kernel has any knowledge or control over the PLLs.
Answer: Not quite a real-time OS, but RISC OS for Raspberry Pi is cooperative multitasking, so you can easily run an application that has 100% CPU so you can manage your timings much better. Just don't expect to do anything else but your own code.
Comment: @PeterMortensen: Well I don't know how radio transmitters and such generate their signals, but some might do it with PWM. PiFM does that at 100 MHz. That seems to contradict my comment though, so I wonder if maybe the pin can still be commanded at that frequency, but it's just that the pin capacitance attenuates such signals, so that a 100 MHz square-wave might actually oscillate from e.g. (1.0 V, 2.3 V) instead of the full (0 V, 3.3 V) range.
Comment: I read somewhere that there is a hardware limit as to the switching frequency of an output pin, too. I think it was around 20 MHz. So don't expect to be able to pull of 300 MHz PWM or anything of that sort, even with 100% CPU usage.
Comment: @Wallacoloo: What applications require 300 MHz PWM?
Answer: I have found this library (pi-blaster) which claims to be "extremely efficient: does not use the CPU and gives very stable pulses."
I've not tested it yet, but will update as soon as I do (probably today)
Comment: Just want to bump this.  Pi-blaster has worked for me where these other answers did not.
Comment: I've been trying this but so far no luck.  So far as I can tell it doesn't actually switch the hardware?


Implementing native-like time picker on Blackberry with mobiscroll

Question: I have a web application which has a text box for entering time in hh:mm:tt format. A time picker has been integrated using mobiscroll
I am having issues while trying to enter time using the Blackberry browser. I have tried the following:

Tried to use the clickpick option in mobiscroll but the buttons do not get clicked using the mouse pointer in BB non touch devices.
Tried to implement the native HTML time control. It seemed to work fine on most devices but it does not work on BB Bold 9700
Tried datebox plugin but could not get it to work, plus it is very slow.

I am running out of options, could anyone please answer the following questions:
a. Is it possible to call the BB native time picker control in a webapp ?
b. Can a BB webworks component be used in a webapp ?
c. Is there any way to make the HTML time input control work on BB Bold 9700
Appreciate your help with this.
Thanks.
Answer: Try the latest release 2.0.3
Issues with BB were fixed.


What's the difference between "made of" and "is made of" the passive voice issue!

Question: I came across a sentence from LongMan dictionary while I was looking up the word "fence", and the phrase example was: a structure made of wood, metal etc that surrounds a piece of land.
my question is: why the sentence wouldn't be: a structure IS made of wood,...
"is made of wood" instead of "made of wood" since we talk about passive voice?!!
please explain to me that issue..
Comment: Dictionary definitions are shaped to match definendum syntactically, so as to be able to substitute for it in a sentence. Since the sense of *fence* here in question is as a simple noun, the addition of the verb *is,* so as to make this a complete passive-voice sentence, would be step in the wrong direction.
Comment: It's not even clear to me that this is a passive construction.
Comment: If we were discussing a specific fence then we would say something like "The fence around the paddock is made of wood". However a dictionary definition is discussing fences in the abstract. In this case we either say "A fence is a structure made of wood, metal, etc" or "A fence is a structure _which is_ made of wood, metal, etc"
Answer: A fence is a structure made of wood means the same thing as

A fence is a wooden structure.

In the dictionary, you will look up the word fence and you will see

a wooden structure

The dictionary definition omits the word "is".
There's no passive voice here.  "Made" is an adjective, formed from the past participle.

Let's look at the passive voice.

I made this birthday cake.
This birthday cake was made by me.

That last sentence uses the passive voice.
Comment: What I understood is that the header of the sentence was cashed, I mean this part "a fence is" and the rest of the sentence began from "a structure made of wood" thank you for your help even I didn't understand why this is not a passive voice anyway thank you all..


Vector error correction model

Question:
I investigate the relationship among 3 variables (XMIN, LPIB, LIPI). I found that all variables are stationnary in their first differences. Johansen's cointegration method has been adopted to examine the long run relationship among the variables. I found that there is one cointegrating vector in the model.
Now, it is convenient to make the test based on vector error correction models (VECM), so I made the test with Eviews and I don't know how to interpret the table.
Comment: You can read the table as follows: here is the first column: $\Delta PIB_t=0.0069ect_{t-1}+0.1567\Delta PIB_{t-1}+0.2781\Delta PIB_{t-2}-0.0027\Delta LXMIN_{t-1}-0.0137\Delta LXMIN_{t-2}-0.0810\Delta LIPI_{t-1}-0.0839 \Delta LIPI_{t-2}+0.0056+\varepsilon_t$ where $ect_t=1.0000\cdot LPIB_{t-1}-0.4173LXMIN_{t-1}+2.9926LIPI_{t-1}-0.0204trend-21.0302$. Is that what you need?
Comment: i appreciate your help, your answer will help me a liitle bit :)
Comment: I don't see a table with the test results. The one included looks like estimation output for an unrestricted VECM. Also, what is the actual question? First you ask about interpreting the error correction term, then you ask about interpreting the results of a Granger causality test.
Comment: Oh, and your title does not quite match the content. Consider adapting it to make it more informative and to the point.
Comment: the table is above represent the VECM. My question is how to interpret this table
Comment: After the edit you are referring to *the test* in the last paragraph; however, it is not clear *what* test that is. The last paragraph still does not quite make sense, since you refer to a test you did but do not present its results. The table contains estimated model coefficients with their significances and model diagnostics such as $R^2$, AIC and other. Please elaborate on which part of the table is unclear.
Comment: I mean the middle part of the table: How can i elaborate the short-run model that is to express each variable with others ( for exemple to express the PIB with XMIN and IPI). i learned in many articles that i must should the equation which have a negative coeff of Coin Eq 1
Comment: Did you get your question answered, or did you just get fed up? :)
Comment: @RichardHardy, if that is the information the OP needs, why not turn that into an official answer?
Comment: @gung, it is unclear to me what the OP needs, but perhaps it is worthwhile turning that into an answer nevertheless...
Answer: Still having some doubts over what your question really is, I will convert a comment that you found helpful to an answer.
You can read the middle part of the table as follows:
$$
\begin{equation}
\begin{aligned}
\Delta PIB_t &= 0.0069ect_{t−1} \\
             &+ 0.1567 \Delta PIB_{t−1}+0.2781 \Delta PIB_{t−2} \\
             &− 0.0027 \Delta LXMIN_{t−1}−0.0137 \Delta LXMIN_{t−2} \\
             &− 0.0810 \Delta LIPI_{t−1}−0.0839 \Delta LIPI_{t−2} \\
             &+ 0.0056+\varepsilon_t
\end{aligned}
\end{equation}
$$
where
$$
\begin{equation}
\begin{aligned}
ect_{t-1} &= 1.0000⋅LPIB_{t−1}−0.4173LXMIN_{t−1}+2.9926LIPI_{t−1}−0.0204(t-1) \\
          &- 21.0302.
\end{aligned}
\end{equation}
$$

Vector error correction model


"Nothing but seventh place is good enough"

Question: I would like help modifying the famous phrase nil satis nisi optimum to lower expectations somewhat to "nothing but seventh place is good enough". Google Translate creates a suspicious range of different suggestions, so I thought I'd ask the experts.
Answer: To parallel optimum ("best", singular neuter nominative), I would go with septimum ("seventh", same form).
Therefore I suggest nil satis nisi septimum.
Funnily enough, it sounds very similar to the original, which is always a good bonus for an analogy.
As brianpck comments below, optimum means "the best [thing]".
Similarly, my septimum means "the seventh [thing]", not so much "the seventh place".
But I think the message is clear enough in this form, and the word play would be diluted by additional words.
Comment: Hmm...my reservation is that *optimum* means "the best [thing]" whereas *septimum* doesn't lend itself to that kind of abstraction. Do you know of any examples where ordinal numbers stand for "X place"?


Adding Python package to Sql Server 2017 machine learning services breaks it

Question: I am trying to get started running python inside of Sql Server 2017 with Python Machine Learning Services.
Out of the box it works and I can run simple scripts like listing the installed packages:
EXEC sp_execute_external_script
@language = N'Python',
@script = N'import pkg_resources
print([p.project_name for p in pkg_resources.working_set])'

When I want to add a new package I follow the Microsoft documentation for 2017: https://learn.microsoft.com/en-us/sql/machine-learning/package-management/install-python-packages-standard-tools?view=sql-server-2017
which says to basically just pip install the new package. So I go to the sql server python install:
C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES

and run:
scripts\pip.exe install pyarrow

This installs an upgraded numpy version as a dependency and when I then try to call even simple python scripts like above I get the following error:
Msg 39012, Level 16, State 1, Line 0
Unable to communicate with the runtime for 'Python' script. Please check the requirements of 'Python' runtime.

Nothing will run while numpy is in this newer version. I can fix the issue by repairing the Sql Server install from the installation media, but that gets me back to my initial setup without the required pyarrow package.
After trying to troubleshoot (incl. installing specific versions of pandas and numpy) I now can't get back to a working state with repairs - will try uninstall and reinstalling the feature.
I can see that the procedure has changed for installing python packages in Sql Server 2019 (https://learn.microsoft.com/en-us/sql/machine-learning/package-management/install-additional-python-packages-on-sql-server?view=sql-server-ver15) so there might be some flaws in 2017 but I can't find it documented anywhere.
I run the latest Sql Server 2017 (cu21) developer edition.
Some suspects:

I'm not too familiar but it says in multiple places that Sql Server 2017 Machine Learning services comes with Conda and I'm not sure if Conda and pip are compatible?
The error suggests a dependency from microsofts revoscalepy on pandas and again from pandas on numpy.

Current full error:
Msg 39012, Level 16, State 1, Line 0
Unable to communicate with the runtime for 'Python' script. Please check the requirements of 'Python' runtime.
STDERR message(s) from external script:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\revoscalepy\__init__.py", line 99, in <module>
    from .RxSerializable import RxMissingValues
  File "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\revoscalepy\RxSerializable.py", line 10, in <module>
    from pandas import DataFrame
  File "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\pandas\__init__.py", line 39, in <module>
    from pandas.core.api import *
  File "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\pandas\core\api.py", line 10, in <module>
    from pandas.core.groupby import Grouper

STDERR message(s) from external script:
  File "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\pandas\core\groupby\__init__.py", line 1, in <module>
    from pandas.core.groupby.groupby import GroupBy  # noqa: F401
  File "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\pandas\core\groupby\groupby.py", line 25, in <module>
    from pandas.util._validators import validate_kwargs
  File "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\pandas\util\_validators.py", line 7, in <module>
    from pandas.core.dtypes.common import is_bool
  File "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\pandas\core\dtypes\common.py", line 10, in <module>
    from pandas.core.dtypes.dtypes import (

STDERR message(s) from external script:
  File "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\pandas\core\dtypes\dtypes.py", line 16, in <module>
    from .inference import is_list_like
  File "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\pandas\core\dtypes\inference.py", line 9, in <module>
    from pandas.compat import (
ImportError: cannot import name 'Set'

Completion time: 2020-08-25T09:43:23.9780283+02:00

Answer: I had the same type of issue with the pandas module on SQL Server 2017 with the same ImportError message that you received. The issue surfaced after installing CU22 for SQL Server 2017 recently and was not present when I set up the environment in question about two months earlier.
In my setup of the environment I performed an upgrade of the numpy and pandas modules to the latest available versions for Python 3.5.2 (which is the default Python version included with SQL Server 2017):

numpy:

Pre-installed version: 1.12.1
Updated version: 1.18.5

pandas:

Pre-installed version: 0.19.2
Updated version: 0.24.2

The reason for the upgrades were requirements from other modules (on numpy) and compatiblity issues between pandas and the new numpy version.
After receiving the ImportError error message when doing import pandas, I pinpointed it to line 9-10 in the file:
C:\Program Files\Microsoft SQL Server\MSSQL14.<instance_name>\PYTHON_SERVICES\Lib\site-packages\pandas\core\dtypes
from pandas.compat import (
    PY2, Set, re_type, string_and_binary_types, string_types, text_type)

As I could not find any reason nor any reference from Microsoft on why this should stop working, I did some research and found this post from the pandas Github project:
Missing required dependencies ['numpy'] on pandas 0.24.1 #25316
It seems that there can be issues with old, installed versions of the numpy and pandas modules, even though they are supposed to be removed by pip.exe during the module upgrade/installation process.
Fair enough, I ran repeated uninstalls of the pandas and numpy modules until pip.exe no longer reported any installed versions and the related directories were gone from Lib\site-packages
Set-Location 'C:\Program Files\Microsoft SQL Server\MSSQL14.instance_name\PYTHON_SERVICES\Scripts'
& '.\pip.exe' uninstall pandas # repeated 2 times
& '.\pip.exe' uninstall numpy # repeated 2 times

In both cases, both the updated and some remaining parts of the original versions of the modules were removed.
I then reinstalled both modules and had no issues after that:
& '.\pip.exe' install --upgrade numpy
& '.\pip.exe' install --upgrade pandas


Troubleshooting electric pump that triggers GFCI

Question: I have a submersible pool cover pump that keeps triggering the GFCI outlet.  I know the pump is the problem because I have another, identical pump that does not trigger the outlet.  I'd like to try to repair the pump. I assume there's a short in it somewhere but how do I find it? Can anyone make suggestions for troubleshooting steps?
Answer: It's not about a short.  It's about insulation leakage.  Tear it down and look for any place where electricity is able to contact where it should not, or places where debris is able to form a conductive path where it should not.   You can paint it with insulating paint, or epoxy.
Answer: Had that problem with a hot tub.  Little caterpillars(?) were attracted to the heat perhaps?, and bridged the insulation gap between the heater and grounded sleeve, resulting in a current path to ground.  This is exactly the situation that GFCIs are designed to detect and trip for, because of the likelihood that a human is part of the current path to ground.
Start disconnecting things until the issue goes away, then investigate.  An ohmmeter might be helpful, along with a bright light.


What to write in a detailed description about a gunshot?

Question: She heard a gunshot. Then the fell silent.
how would you improve this to make it sound better?
Comment: It depends on the context. Some stories don't need more than this. So step one is to determine what the story should get out of the description of this gunshot. Is it for style, effect, plot purposes, just to see if you can fill a page with the details of a gunshot without driving all your readers off, etc. Why does the gunshot need to be more detailed? Then work from there.
Comment: Yes, please add some context, and we could give you much more specific suggestions. I left an answer, but don't be shocked if people think this is "asking what to write" or "help with rewriting a sentence."
Comment: Does this answer your question? [...and then she held the gun](https://writing.stackexchange.com/questions/45963/and-then-she-held-the-gun)
Answer: If your desire is to expand the description of the sound, it may be helpful to remember that the sound of a real gunshot is quite different from the exaggerated movie soundtrack sound. Rather than a deep "boom", most real-world gunshots have more of a "pop" sound. Some smaller calibers have a sound better described as a "crack".
The resulting sound also depends on distance and whether the gun is fired indoors or outdoors. Indoors, the reverberation of a gunshot can make it sound deeper and much louder. Outdoors, nearby gunshots have a sharper sound. The further away the gunshot, the less high-frequency energy the sound has. This makes distant gunshots sound deeper.
Finally, it's easy to forget that gunshots are extremely LOUD. If a gun fires near you and catches you off-guard, your breath catches in your lungs, your heart all but stops, and your ears will complain of the mistreatment for a long time.
Answer: Add Detail and Emotional content:
While functional, this statement is rather thin. A gunshot should be a jarring thing in a story. It often represents someone or thing dying. So more description would add intensity and punctuate the event. The gunshot transforms the world.
I would involve more senses into the event and extend the duration. Maybe even leave the nature open until she identifies in her mind that it was a shot. Use words emphasizing the traumatic nature of the event. Context is critical here, but for example:

"Her eyes barely registered the flicker of light before the the sound struck her like a slap. The noise was shocking and overwhelmed her hearing. Afterwards, her ears rung with the echo. The burning smell of powder wafted through the air. In the sudden silence following, she froze until remembering to breathe."
Answer: That very much depends on the context of the scene, style of the writing, and so on. In some works, what works best may be a detailed description like DWKraus wrote. In others, what provides the best effect may be:

A gunshot.

Just this, as a whole paragraph, or even section.
There are lots of different possibilities for lots of different stories.
It depends.
Answer: What would the point-of-view character think?
Bear in mind that she's familiar enough with gunshots that she recognizes it immediately, there may not be much more detail about it for her.
If she's not, describe her sensory impressions and then how she realizes it's a gunshot.


Why do the phaser blasts of the U.S.S. Vengeance in Star Trek Into Darkness curve?

Question: In the Star Trek Alternate Reality Series, the Enterprise used red phasers very similar to pulse phasers. I understood that, although they do not really seem that useful, now that I've matured. In Star Trek: Into Darkness, the U.S.S. Vengeance fired sharp, red, fast phaser blasts that curved towards the Enterprise. When it attacked at warp, the majority of phaser blasts heavily damaged the Enterprise, of course, but some missed! Is there a point to the curving phasers?
Comment: I assumed it was because they were firing at warp and the bolts were losing momentum. Maybe they were trying to impress upon us some kind of star trek physics logic stating that trajectory of phasers are unreliable while firing faster than the ship which is in a warp bubble moving at whatever factor of light speed they are currently in.
Comment: Pics or it didn't happen. -- But IIRC, in TOS, we often had phasers shoot in directions diverging by some 30 degrees, but hitting the same small spot on a planet ... :)
Comment: That doesn't make sense, because it also happened while they weren't at warp. In _ST: VOY, "Message In a Bottle,"_ a Nebula class ship pursuing the Prometheus fired a phaser, and there didn't seem to be _any_ curvature in the beam.
Comment: "*This time, Admiral Marcus did not bother with professional niceties. Closing fast on the Enterprise, his state-of-the-art warship unleashed an array of powerful, state-of-the-art weaponry. Already barely traveling at warp on a wing, a prayer, and an assortment of increasingly frantic Russian entreaties, the Enterprise was rocked, jolted, and finally knocked sideways by a succession of explosions.*" - Novelisation
Comment: I think it has something to do with spacetime warping.
Answer: Watching the video, it would seem some of the apparently curving phaser shots may be because of a moving camera point of view (particularly at the point were the Enterprise spins and drops out of warp).
However, at 25 seconds into the video, there is a clearly curving light trail that hits one of the Enterprise's nacelles. I think that this is actually a photon torpedo rather than a phaser, which explains the curve.


Permits to field record in China and Hong Kong?

Question: I'd like to make a field recording trip to Hong Kong and mainland China in June.   Anyone know if I need to worry about permits?  Can I float a blimp around without worrying the authorities, or should I keep it stealth?  Any advice concerning such an endeavor would be greatly appreciated.
Answer: I am in hong kong now and it's a city which never sleeps! I reckon HK is less strict than china and is overall more English language-friendly. I have done recordings with a team in the industrial area and we never really got questioned aside from curious onlookers.  When in HK, Be sure to look out for small protests downtown almost every Sunday (usually against government policies etc) those make quite interesting recordings ;) they are safe to be around and are well-managed. All the domestic workers get an off-day on Sundays too, and depending on which zone you go to, you can get really interesting Indonesian walla, or Filipino walla mixed with Cantonese.
If you're down there in June, you're in luck. Don't miss the memorial gathering (in rememberance of the Tiananmen Massacre) on June 4th I think. Hundreds of thousands of people gather, holding a candle each. Quite an experience!
It's hard to get recordings without traffic or unwanted walla but if you go to the New Territories away from the city, there are buses which go into the mountains and rural areas. You can hike on Lantau Island too if you wanna record something more natural, or take small boats across to isolated islands from Sai Kung where people fish. I doubt people will stop you from recording there.
China would be different because they are generally wary of outsider reporters (mistaking you for one) and based on experience, they are also harder to reason with. I could also only make do with a handheld.
When in Beijing, be sure to visit Jingshan Park. My last visit there (4 years ago?), it was super lively with mostly old folks doing activities like reciting poetry, performing, singing, dancing, some with whole orchestras. Definitely an unique sonic experience.
Sorry I can't really share more about Beijing (it was also one of my first recording trips :P) !
Comment: Thanks for all the detail Gwen!  Knowing all this makes me want to go even more.
Answer: I think in any country the foreigner with a reserved (stealth) behavior always provoke more suspicions than a usual (impudent) tourist with a camera. Or in your case with a blimp.
If there will be some prohibited places a local police officer will always warn you about that. Or you just can ask him about it yourself.
Comment: you have a point there, I would imagine if I behave as though I'm doing something wrong I'll have started off on the wrong foot!  I bet I could use binaurals as @Andrew mentioned.
Comment: @aross001 I don't have an experience with binaural recordings and I'm curious, is there any possibility to use those records later in DAW as a usual (non-binaural) material?
Comment: I believe so.  It's just a standard stereo L/R but when listened to on head phones it sounds like surround because of spacing and the acoustics of the recordists own head.  The actual files can be manipulated like any other regular stereo or mono file.  I would imagine that the mics are close enough together so that phasing probably isn't an issue if you wanted to just record in mono.  Not sure about that though...

 http://en.wikipedia.org/wiki/Binaural_recording
Answer: I would say that there are some places that are considered more sensitive than others (i.e. government buildings, public transport systems) so this may be more problematic if you intend to record in these places. Though I don't think a recording permit exists, it may be worth inquiring at the Chinese embassy when you sort out your visa. If you are working for a production, this should be more easily sorted by the production company, but if this is a personal trip you should check with the embassy if any sort of official documentation is required.
On arrival, customs officials can be quite strict. Most of the time, they are familiar with recording equipment (every sound recordist travelling to China will 99% of the time have the essential/breakable items in his/her hand luggage). I would also suggest having a small test recording on your recorder - it can be useful to quickly playback to the official just to show what it is you do.
I have only been to Beijing and did all my recordings using a small handheld, so don't have first hand experience. I think it's probably very similar in other big cities, so here's some tips that may be useful. Everytime you enter the metro, you have to scan your bag. This is also the case in many shopping centers. Though I genuinely got the impression that the police were much less concerned with foreign tourists than Chinese locals, be prepared to be questioned on your kit. Having mic cables going into your recorder may freak them out slightly, so have your explanation ready. English is not widely spoken, so make sure you are prepared to explain that you are a recordist. Perhaps learn the word in mandarin and cantonese before you travel - speaking a few words of the local dialect can go a very long way!
My experience, although limited to the capital, was fantastic. It took a little getting used to, but the locals are genuinely friendly and I had some awesome conversations (usually myself speaking English and the the other in Chinese) and learnt a lot from this country.
Good luck with your trip!
Comment: Thanks!  I think you're right, learning some mandarin will be a good idea.
Answer: Years ago I was in China and had a little recorder, it was my first recording trip overseas actually. I had no issues whatsoever apart from people staring and coming to talk in the middle of the recording - the usual... Don't know about a blimp though. As Colin says, be careful of certain places. Maybe if there are lots of officials around, skip it, or go stealth  (in-ear binaural mics?).
If I can recommend a place, you should really try head to Pingyao, it's an amazing place..
Oh, and the Beijing train station was particularly interesting sonically, it's huge!


Slow switching up higher gears

Question: I have a fairly new MTB and I'm currently trying to tune the gears. Currently I can change down gears pretty smoothly I.e. 6 > 5 > 4 etc but going up the gears is slow for the chain to switch cogs. What should I check to fix this problem?
Answer: It would have been slightly helpful if you told us from what front and back gear ratio (e.g. 2:3 or 2:4) the problem starts occurring.
I had similar problems and it was even the case when I was changing to higher front gear but the cassettes (or clogs) did not change or they changed after a long time when it received external shocks from my ride. Did you check how the shifts are happening from 1(front):1(rear) onwards i.e. if you were to use the gear ratio from 1:1 to upwards? If you do this, then you will come to the point where you feel exactly from which gear ratio it is taking longer to switch cogs. Also, you might even find out once in a while changing to a higher gear actually does not change to the new cassette at all and gets stuck. One of the cable (front/rear derailleur) tension would not feel right to you.
For me it was some dirt and blockage in the front derailleur lever area (i.e. the allen key-based connnector with wire clenched around) which is universally near pedals. Usually, this is a minor problem and the way to fix it was to make sure first your gear ratio is 1:1. Then, loosen the allen key just enough so that the wire comes out. Now clean around the allen key are well enough and then use a little bit of wet lube around it to finalise. Then, put the wire back in and tighten the allen key as it was before. Reccheck the gear shifting from 1:1 upwards and see if the problem is solved. This could happen even to the rear derailleur too. The key problem originator is the derailleur lever (i.e. the allen key based moving area). What happens normally is that dirt and blockage occur there and the cable tension feels higher than it should normally feel. Also, please update your question by saying for how long and where (i.e. what type of tarmac) you have used your MTB until the problem started manifesting.
Also, I am assuming that you know NEVER to change both gears at the same time? If you don't know and have done this already, please don't do this again. For the investigation I mentioned above, make sure you change the gears down or up appropriately.
Let us know :)....Don't forget to add the additional information to your original question :)
UPDATE
If these are of any help see This one
And also this
Hope this helps
Comment: Got my MTB last Spring, largely used on roads and a little off road. The problem existed from the time I got the bike, I was never really fully satisfied how it changed up to higher gears, but didn't bother sending it back because it was bought online, plus its a problem I know I can fix if I knew what to check.I haven't been out on my bike enough to test the front gear 1 and 2. just had a quick road ride today in front gear at 3. Saying that, I would say it was worst at front 3 back 3. Yes I never change both gears at the same time!
Comment: @user985351    hmm....so did you check what I asked i.e. how the shifts go 1:1 upwards? It is constantly striking me as derailleur lever prob....also, 3:3 seems to be slightly unusual ratio do pedalling from start up...I would go for a 2:4 or 2:5, but the choice is yours...also, I insist you check how it goes from 1:1 because otherwise you will not know if the cable tension is not right throughout or just up to certain gear ratio. and also, given that you have 3 gears at the front and probably 7 at the back, the ideal ratio should be multiples of 1:2 to avoid crossover effect on your chain.
Comment: @user985351     **UPDATE** I have added update to my answer above. Check it

Slow switching up higher gears