MCPcopy Create free account
hub / github.com/cocos/cocos-engine / init

Method init

native/cocos/platform/android/AndroidPlatform.cpp:782–827  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

780AndroidPlatform::~AndroidPlatform() = default;
781
782int AndroidPlatform::init() {
783#if CC_USE_XR
784 registerInterface(std::make_shared<XRInterface>());
785#endif
786 IXRInterface *xr = CC_GET_XR_INTERFACE();
787 if (xr) {
788 JniHelper::getEnv();
789 xr->initialize(JniHelper::getJavaVM(), getActivity());
790 }
791 cc::FileUtilsAndroid::setAssetManager(_app->activity->assetManager);
792 _inputProxy = ccnew GameInputProxy(this);
793 _inputProxy->registerAppEventCallback([this](int32_t cmd) {
794 IXRInterface *xr = CC_GET_XR_INTERFACE();
795 if (xr) {
796 xr->handleAppCommand(cmd);
797 }
798
799 if (APP_CMD_START == cmd || APP_CMD_INIT_WINDOW == cmd) {
800 if (_inputProxy->isAnimating()) {
801 _isLowFrequencyLoopEnabled = false;
802 _loopTimeOut = 0;
803 }
804 } else if (APP_CMD_STOP == cmd) {
805 _lowFrequencyTimer.reset();
806 _loopTimeOut = LOW_FREQUENCY_TIME_INTERVAL;
807 _isLowFrequencyLoopEnabled = true;
808 if (xr && !xr->getXRConfig(xr::XRConfigKey::INSTANCE_CREATED).getBool()) {
809 // xr will sleep, -1 we will block forever waiting for events.
810 _loopTimeOut = -1;
811 _isLowFrequencyLoopEnabled = false;
812 }
813 }
814 });
815 _app->userData = _inputProxy;
816 _app->onAppCmd = handleCmdProxy;
817
818 registerInterface(std::make_shared<Accelerometer>());
819 registerInterface(std::make_shared<Battery>());
820 registerInterface(std::make_shared<Network>());
821 registerInterface(std::make_shared<Screen>());
822 registerInterface(std::make_shared<System>());
823 registerInterface(std::make_shared<SystemWindowManager>());
824 registerInterface(std::make_shared<Vibrator>());
825
826 return 0;
827}
828
829void AndroidPlatform::onDestroy() {
830 UniversalPlatform::onDestroy();

Callers

nothing calls this directly

Calls 9

registerInterfaceFunction · 0.85
isAnimatingMethod · 0.80
getBoolMethod · 0.80
getXRConfigMethod · 0.80
GameInputProxyClass · 0.70
initializeMethod · 0.65
resetMethod · 0.65
handleAppCommandMethod · 0.45

Tested by

no test coverage detected