{"id":14080,"date":"2024-07-27T17:14:55","date_gmt":"2024-07-27T09:14:55","guid":{"rendered":"http:\/\/xinyiworld.top\/wordpress_it\/?p=14080"},"modified":"2024-07-27T17:16:19","modified_gmt":"2024-07-27T09:16:19","slug":"localservices-java","status":"publish","type":"post","link":"http:\/\/xinyiworld.top\/wordpress_it\/?p=14080","title":{"rendered":"LocalServices.java"},"content":{"rendered":"<p>\u6e90\u7801\u4f4d\u7f6e\uff1a<code>frameworks\/base\/core\/java\/com\/android\/server\/LocalServices.java<\/code><\/p>\n<pre><code class=\"language-java\"> 23 \/**\n 24  * This class is used in a similar way as ServiceManager, except the services registered here\n 25  * are not Binder objects and are only available in the same process.\n 26  *\n 27  * Once all services are converted to the SystemService interface, this class can be absorbed\n 28  * into SystemServiceManager.\n 29  *\n 30  * {@hide}\n 31  *\/\n 32 public final class LocalServices {\n 33     private LocalServices() {}\n 34 \n 35     private static final ArrayMap&lt;Class&lt;?&gt;, Object&gt; sLocalServiceObjects =\n 36             new ArrayMap&lt;Class&lt;?&gt;, Object&gt;();\n 37 \n 38     \/**\n 39      * Returns a local service instance that implements the specified interface.\n 40      *\n 41      * @param type The type of service.\n 42      * @return The service object.\n 43      *\/\n 44     @SuppressWarnings(&quot;unchecked&quot;)\n 45     public static &lt;T&gt; T getService(Class&lt;T&gt; type) {\n 46         synchronized (sLocalServiceObjects) {\n 47             return (T) sLocalServiceObjects.get(type);\n 48         }\n 49     }\n 50 \n 51     \/**\n 52      * Adds a service instance of the specified interface to the global registry of local services.\n 53      *\/\n 54     public static &lt;T&gt; void addService(Class&lt;T&gt; type, T service) {\n 55         synchronized (sLocalServiceObjects) {\n 56             if (sLocalServiceObjects.containsKey(type)) {\n 57                 throw new IllegalStateException(&quot;Overriding service registration&quot;);\n 58             }\n 59             sLocalServiceObjects.put(type, service);\n 60         }\n       }\n        ...\n}<\/code><\/pre>\n<button class=\"simplefavorite-button\" data-postid=\"14080\" data-siteid=\"1\" data-groupid=\"1\" data-favoritecount=\"0\" style=\"\">\u6536\u85cf <i class=\"sf-icon-star-empty\"><\/i><\/button>","protected":false},"excerpt":{"rendered":"<p>\u6e90\u7801\u4f4d\u7f6e\uff1aframeworks\/base\/core\/java\/com\/android\/server\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1059],"tags":[],"_links":{"self":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/14080"}],"collection":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14080"}],"version-history":[{"count":1,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/14080\/revisions"}],"predecessor-version":[{"id":14081,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/14080\/revisions\/14081"}],"wp:attachment":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14080"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14080"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14080"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}