Pre AIA MPEP (Manual of Patent Examining Procedure) states:
Likewise, there may be a nonpublic, e.g., “secret,” sale or offer to sell an invention which nevertheless constitutes a statutory bar. Hobbs v.United States, 451 F.2d 849, 859-60, 171 USPQ 713, 720 (5th Cir. 1971).
In similar fashion, not all “public use” and “on sale” activities will necessarily occasion the identical result. Although both activities affect how an inventor may use an invention prior to the filing of a patent application, “non-commercial” pre-AIA 35 U.S.C. 102(b) activity may not be viewed the same as similar “commercial” activity. See MPEP § 2133.03(a) and § 2133.03(e)(1). Likewise, “public use” activity by an applicant may not be considered in the same light as similar “public use” activity by one other than an applicant. See MPEP § 2133.03(a) and § 2133.03(e)(7). Additionally, the concept of “experimental use” may have different significance in “commercial” and “non-commercial” environments. See MPEP § 2133.03(c) and § 2133.03(e) - § 2133.03(e)(6).
2.Even If the Invention Is Hidden, Inventor Who Puts Machine or Article Embodying the Invention in Public View Is Barred from Obtaining a Patent as the Invention Is in Public Use
When the inventor or someone connected to the inventor puts the invention on display or sells it, there is a “public use” within the meaning of pre-AIA 35 U.S.C. 102(b) even though by its very nature an invention is completely hidden from view as part of a larger machine or article, if the invention is otherwise used in its natural and intended way and the larger machine or article is accessible to the public. In re Blaisdell, 242 F.2d 779, 783, 113 USPQ 289, 292 (CCPA 1957); Hallv. Macneale, 107 U.S. 90, 96-97 (1882); Ex parteKuklo, 25 USPQ2d 1387, 1390 (Bd. Pat. App. & Inter. 1992) (Display of equipment including the structural features of the claimed invention to visitors of laboratory is public use even though public did not see inner workings of device. The person to whom the invention is publicly disclosed need not understand the significance and technical complexities of the invention.).
There are some more information regarding commerciality etc. of the use, but I'm leaving that out because it wasn't part of your question.
Under AIA (MPEP again):
As discussed previously, public use under AIA 35 U.S.C. 102(a)(1) is limited to those uses that are available to the public. The public use provision of AIA 35 U.S.C. 102(a)(1) thus has the same substantive scope, with respect to uses by either the inventor or a third party, as public uses under pre-AIA 35 U.S.C. 102(b) by unrelated third parties or others under pre-AIA 35 U.S.C. 102(a).
As also discussed previously, once an examiner becomes aware that a claimed invention has been the subject of a potentially public use, the examiner should require the applicant to provide information showing that the use did not make the claimed process accessible to the public.
So it's essentially the same if the invention was part of a publicly sold product like you asked. (Question1)
As to question 2, as long as the invention hasn't been on sale or in public use, you should be fine. Determining exactly if the use was public use could prove difficult, for example, if a user can enter a query and get the result while the algorithm only runs on the server, that might be enough for public use. If however it is only used internally, that shouldn't be public use.