To expand on the situation in Mainland china mentioned by another answer, the State Compensation Law provides, since 2010, that the State is liable
Where a citizen is detained in violation of the provisions of the Criminal Procedure Law, or where a citizen is detained in accordance with the conditions and procedures set forth in the Criminal Procedure Law, but is detained for a period of time longer than the time limit set forth in the Criminal Procedure Law, and a decision is subsequently made to terminate the pursuit of criminal liability by dismissing the case, by refraining from prosecuting the case, or by a verdict of acquittal;
and
Where, after a citizen is arrested, a decision is taken to terminate the pursuit of criminal liability by dismissing the case, by refraining from prosecuting the case, or by a verdict of acquittal;
Detention and arrest are different steps in the Chinese criminal law system. The state compensation is not given in every case where a suspension of liberty occurs to a person subsequently absolved of criminal liability.
The investigative authority decides on detention of persons caught in commission of a crime or with significant suspicion, for formally "urgent" purposes e.g. to avoid destruction of evidence and continued criminal activity. Most of the time, the investigative authority is the police (public security), though some cases are directly investigated by the prosecuting authority. The investigative authority decides whether to dismiss a case.
The time of criminal detention is in law (not in practice) 3 days in principle with 4-day extension possible and another a 30-day extension possible for "serious" criminals; so, in practice, the maximum for normal cases is 37 days. This is considered a necessary emergency procedure and no compensation is due unless the detention violates the Code and the case against suspect is subsequently terminated without guilty finding.
The prosecuting authority alone decides on whether to arrest a person suspected of a crime based on the police's or its own investigative report and based on the severity of the crime (and other individual factors). It should be noted, formally, the Procuratorate is a separate branch of government and report directly to the legislature and to the higher-level Procuratorate instead of the local or national executive authority.
The maximum time for arrest is the same as the maximum time to make a decision whether to pursue the criminal charge in court. The formal maximum time is two months but there are many extensions possible (e.g. for remote areas, cases with multiple accuseds, offences punishable with 10 years of prison or more), and the counter is reset every time a significant evidence of another offence or criminal action is discovered or the jurisdiction is transferred to another Procuratorate, and in extreme cases can be essentially indefinite if the authorization is given by the Supreme Procuratorate.
The prosecutorial authority decides whether to prosecute. It can decide not to prosecute for legal reasons (e.g., insufficient evidence, exceeding the statute of limitation) or in exercise of its discretion (e.g. minor offence, possibly excessive self-defence, voluntary abandonment mid-offence). Only a non-prosecution decision based on legal reasons entitles the accused to state compensation.