1

grepcode サイトから AOSP コードをトレースしようとしています。

を呼び出すとgetSystemService(Context.WIFI_P2P_SERVICE)、次のコードになります。

 @Override public Object getSystemService(String name) {
    if (getBaseContext() == null) {
        throw new IllegalStateException(
                "System services not available to Activities before onCreate()");
    }
    if (WINDOW_SERVICE.equals(name)) {
        return mWindowManager;
    } else if (SEARCH_SERVICE.equals(name)) {
        ensureSearchManager();
        return mSearchManager;
    }
    return super.getSystemService(name);
}

そして、WIFI_P2P_SERVICEとして宣言されているpublic static final String WIFI_P2P_SERVICE = "wifip2p";ため、条件のいずれにも該当せず、super.getSystemService(name);

Activity extends ContextThemeWrapper, the code there is:
 @Override public Object getSystemService(String name) {
        if (LAYOUT_INFLATER_SERVICE.equals(name)) {
            if (mInflater == null) {
                mInflater = LayoutInflater.from(mBase).cloneInContext(this);
            }
            return mInflater;
        }
        return mBase.getSystemService(name);
    }

ここでも、必要なサービス名が一致しません。これmBaseはのインスタンスであるContextため、Context のコードは次のようになります。

public abstract Object getSystemService(String name);

つまり、そこから拡張されたクラスはその機能を処理する必要があります。 さて、私のリクエストはどこで処理されますか?

4

1 に答える 1

2

私の知る限り、 Context の実装コードは、クラス名が ContextImpl のパッケージ android.app の下にあります

これがそのクラスの getSystemService です -

@Override
public Object getSystemService(String name) {
    ServiceFetcher fetcher = SYSTEM_SERVICE_MAP.get(name);
    return fetcher == null ? null : fetcher.getService(this);
}

編集 - WIFI_P2P_SERVICE のエントリ ポイント -

registerService(WIFI_P2P_SERVICE, new ServiceFetcher() {
    public Object createService(ContextImpl ctx) {
          IBinder b = ServiceManager.getService(WIFI_P2P_SERVICE);
          IWifiP2pManager service = IWifiP2pManager.Stub.asInterface(b);
          return new WifiP2pManager(service);
        }});
于 2013-02-16T20:20:01.527 に答える