/** ACTIVITY OVERRIDEN METHODS * */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LOG.Log(Module.GUI, "onCreate");

    if (getIntent() != null && getIntent().getExtras() != null) {

      extras = getIntent().getExtras();
      LOG.LogDebug(Module.GUI, "[K] notification Extra:" + extras.getString("item_id"));
    }
    // GUI initialization code
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

    /*disableThumbnails = checkUnityProperty("Unity_DisableThumbnails");
    blockRooted = checkUnityProperty("Appverse_BlockRooted");
    blockROMModified = checkUnityProperty("Appverse_BlockROMModified");*/

    // security reasons; don't allow screen shots while this window is displayed
    /* not valid for builds under level 14 */
    // TODO DISABLETHUMBNAILS_1
    // @@DISABLETHUMBNAILS_1@@

    // Initialize Webview component and provide specific settings
    this.initialiazeWebViewSettings();

    // create the application logger
    LogManager.setDelegate(new AndroidLoggerDelegate());

    // initialize the service locator
    activityManager = initialiazeActivityManager();

    // save the context for further access
    AndroidServiceLocator.setContext(this, activityManager);

    // killing previous background processes from the same package
    activityManager.killBackgroundProcesses();

    AndroidServiceLocator serviceLocator =
        (AndroidServiceLocator) AndroidServiceLocator.GetInstance();
    serviceLocator.RegisterService(
        this.getAssets(), AndroidServiceLocator.SERVICE_ANDROID_ASSET_MANAGER);
    serviceLocator.RegisterService(
        activityManager, AndroidServiceLocator.SERVICE_ANDROID_ACTIVITY_MANAGER);

    // registering Appverse modules (if any)
    this.registerModulesServices();

    // initialize config data files for app delegates
    serviceLocator.initConfigDataForServices();

    if (Build.VERSION.SDK_INT >= 17) { // Only used for JELLY_BEAN_MR1 or higher
      /** * INJECT SCRIPT MESSAGE HANDLER (new in Appverse 5) ** */

      /**
       * From Android documentation:
       *
       * <p>This method can be used to allow JavaScript to control the host application. This is a
       * powerful feature, but also presents a security risk for apps targeting JELLY_BEAN or
       * earlier. Apps that target a version later than JELLY_BEAN are still vulnerable if the app
       * runs on a device running Android earlier than 4.2. The most secure way to use this method
       * is to target JELLY_BEAN_MR1 and to ensure the method is called only when running on Android
       * 4.2 or later. With these older versions, JavaScript could use reflection to access an
       * injected object's public fields. Use of this method in a WebView containing untrusted
       * content could allow an attacker to manipulate the host application in unintended ways,
       * executing Java code with the permissions of the host application. Use extreme care when
       * using this method in a WebView which could contain untrusted content.
       *
       * <p>JavaScript interacts with Java object on a private, background thread of this WebView.
       * Care is therefore required to maintain thread safety. The Java object's fields are not
       * accessible. For applications targeted to API level LOLLIPOP and above, methods of injected
       * Java objects are enumerable from JavaScript.
       */
      this.addJavascriptIntefaceToWebView(serviceLocator, "appverseJSBridge");
    }

    if (performSecurityChecks(serviceLocator)) {

      LOG.Log(Module.GUI, "Security checks passed... initializing Appverse...");

      startServer();

      /* THIS COULD NOT BE CHECKED ON API LEVEL < 11; NO suchmethodexception
       * boolean hwAccelerated = appView.isHardwareAccelerated();
       * if(hwAccelerated)
       * LOG.Log(Module.GUI,"Application View is HARDWARE ACCELERATED"); else
       * LOG.Log(Module.GUI,"Application View is NOT hardware accelerated");
       */

      final IntentFilter actionFilter = new IntentFilter();
      actionFilter.addAction(android.net.ConnectivityManager.CONNECTIVITY_ACTION);
      // actionFilter.addAction("android.intent.action.SERVICE_STATE");
      registerReceiver(this.initialiazeNetworkReceiver(), actionFilter);

      ConnectivityManager conMan =
          (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo networkInfo = conMan.getActiveNetworkInfo();
      com.gft.unity.core.net.NetworkType type = NetworkType.Unknown;
      if (networkInfo != null) {
        boolean isWiFi = networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
        boolean isMobile = networkInfo.getType() == ConnectivityManager.TYPE_MOBILE;
        boolean isConnected = networkInfo.isConnected();
        if (isWiFi) {
          if (isConnected) {
            LOG.Log(Module.GUI, "Wi-Fi - CONNECTED (" + networkInfo.getType() + ")");
            type = NetworkType.Wifi;
          } else {
            LOG.Log(Module.GUI, "Wi-Fi - DISCONNECTED (" + networkInfo.getType() + ")");
          }
        } else if (isMobile) {
          if (isConnected) {
            LOG.Log(Module.GUI, "Mobile - CONNECTED (" + networkInfo.getType() + ")");
            type = NetworkType.Carrier_3G;
          } else {
            LOG.Log(Module.GUI, "Mobile - DISCONNECTED (" + networkInfo.getType() + ")");
          }
        } else {
          if (isConnected) {
            LOG.Log(
                Module.GUI,
                networkInfo.getTypeName() + " - CONNECTED (" + networkInfo.getType() + ")");
          } else {
            LOG.Log(
                Module.GUI,
                networkInfo.getTypeName() + " - DISCONNECTED (" + networkInfo.getType() + ")");
          }
        }
      } else {
        LOG.Log(Module.GUI, "DISCONNECTED");
      }

      final int typeOrdinal = type.ordinal();
      final Activity currentContext = this;
      new Thread(
              new Runnable() {
                public void run() {
                  currentContext.runOnUiThread(
                      new Runnable() {
                        public void run() {

                          InitializeAppverseContext(typeOrdinal);
                          String networkStatusListener =
                              "javascript:try{if(Appverse&&Appverse.Net){Appverse.Net.NetworkStatus = "
                                  + typeOrdinal
                                  + ";Appverse.Net.onConnectivityChange(Appverse.Net.NetworkStatus);}else{console.log('Appverse is not defined');}}catch(e){console.log('Error setting network status (please check onConnectivityChange method): '+e);}";
                          queueJSStatementsForWebviewClient(networkStatusListener);
                          loadMainURLIntoWebview();
                        }
                      });
                }
              })
          .start();
    }

    holdSplashScreenOnStartup = checkUnityProperty("Unity_HoldSplashScreenOnStartup");
    this.showSplashScreen();

    LocalNotificationReceiver.initialize(this.activityManager, this);

    // notify app delegates about the onCreate event
    ((AndroidServiceLocator) AndroidServiceLocator.GetInstance())
        .sendApplicationEvent(AndroidApplicationEvent.onCreate);
  }
Exemplo n.º 2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LOG.Log(Module.GUI, "onCreate");

    // GUI initialization code
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

    disableThumbnails = checkUnityProperty("Unity_DisableThumbnails");

    // security reasons; don't allow screen shots while this window is displayed
    /* not valid for builds under level 14 */
    if (disableThumbnails && Build.VERSION.SDK_INT >= 14) {
      getWindow()
          .setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
    }

    appView = new WebView(this);
    appView.enablePlatformNotifications();
    setGlobalProxy();

    appView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    appView.setId(APPVIEW_ID);
    appView.setWebViewClient(new UnityWebViewClient());
    appView.getSettings().setJavaScriptEnabled(true);
    appView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    appView.getSettings().setAllowFileAccess(true);
    appView.getSettings().setSupportZoom(false);
    appView.getSettings().setAppCacheEnabled(false);
    appView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    appView.getSettings().setAppCacheMaxSize(0);
    appView.getSettings().setSavePassword(false);
    appView.getSettings().setSaveFormData(false);
    appView.getSettings().setDefaultTextEncodingName("UTF-8");
    appView.getSettings().setGeolocationEnabled(true);
    appView.getSettings().setLightTouchEnabled(true);
    appView.getSettings().setRenderPriority(RenderPriority.HIGH);
    appView.getSettings().setDomStorageEnabled(true); // [MOBPLAT-129] enable HTML5 local storage

    appView.setVerticalScrollBarEnabled(false);

    // Required settings to enable HTML5 database storage
    appView.getSettings().setDatabaseEnabled(true);
    String databasePath =
        this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    appView.getSettings().setDatabasePath(databasePath);

    webChromeClient =
        new WebChromeClient() {

          // Required settings to enable HTML5 database storage
          @Override
          public void onExceededDatabaseQuota(
              String url,
              String databaseIdentifier,
              long currentQuota,
              long estimatedSize,
              long totalUsedQuota,
              WebStorage.QuotaUpdater quotaUpdater) {
            quotaUpdater.updateQuota(estimatedSize * 2);
          };

          @Override
          public void onReachedMaxAppCacheSize(
              long spaceNeeded,
              long totalUsedQuota,
              android.webkit.WebStorage.QuotaUpdater quotaUpdater) {
            quotaUpdater.updateQuota(0);
          };

          @Override
          public boolean onConsoleMessage(ConsoleMessage cm) {
            LOG.Log(
                Module.GUI,
                cm.message() + " -- From line " + cm.lineNumber() + " of " + cm.sourceId());
            return true;
          }
        };

    appView.setWebChromeClient(webChromeClient);

    // create the application logger
    LogManager.setDelegate(new AndroidLoggerDelegate());

    // save the context for further access
    AndroidServiceLocator.setContext(this);

    // initialize the service locator
    activityManager = new AndroidActivityManager(this, appView);

    // killing previous background processes from the same package
    activityManager.killBackgroundProcesses();

    AndroidServiceLocator serviceLocator =
        (AndroidServiceLocator) AndroidServiceLocator.GetInstance();
    serviceLocator.RegisterService(
        this.getAssets(), AndroidServiceLocator.SERVICE_ANDROID_ASSET_MANAGER);
    serviceLocator.RegisterService(
        activityManager, AndroidServiceLocator.SERVICE_ANDROID_ACTIVITY_MANAGER);
    startServer();

    /* THIS COULD NOT BE CHECKED ON API LEVEL < 11; NO suchmethodexception
    boolean hwAccelerated = appView.isHardwareAccelerated();
    if(hwAccelerated)
    	LOG.Log(Module.GUI,"Application View is HARDWARE ACCELERATED");
    else
    	LOG.Log(Module.GUI,"Application View is NOT hardware accelerated");
    */

    final IntentFilter actionFilter = new IntentFilter();
    actionFilter.addAction(android.net.ConnectivityManager.CONNECTIVITY_ACTION);
    // actionFilter.addAction("android.intent.action.SERVICE_STATE");
    registerReceiver(new AndroidNetworkReceiver(appView), actionFilter);

    final Activity currentContext = this;
    new Thread(
            new Runnable() {
              public void run() {
                currentContext.runOnUiThread(
                    new Runnable() {
                      public void run() {
                        appView.loadUrl(WEBVIEW_MAIN_URL);
                      }
                    });
              }
            })
        .start();

    holdSplashScreenOnStartup = checkUnityProperty("Unity_HoldSplashScreenOnStartup");
    hasSplash = activityManager.showSplashScreen(appView);
    RemoteNotificationIntentService.loadNotificationOptions(getResources(), appView, this);
    LocalNotificationReceiver.initialize(appView, this);
  }