Ejemplo n.º 1
0
  private void checkAndLaunchUpdate() {
    Log.i(LOG_FILE_NAME, "Checking for an update");

    int statusCode = 8; // UNEXPECTED_ERROR
    File baseUpdateDir = null;
    if (Build.VERSION.SDK_INT >= 8)
      baseUpdateDir = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
    else baseUpdateDir = new File(Environment.getExternalStorageDirectory().getPath(), "download");

    File updateDir = new File(new File(baseUpdateDir, "updates"), "0");

    File updateFile = new File(updateDir, "update.apk");
    File statusFile = new File(updateDir, "update.status");

    if (!statusFile.exists() || !readUpdateStatus(statusFile).equals("pending")) return;

    if (!updateFile.exists()) return;

    Log.i(LOG_FILE_NAME, "Update is available!");

    // Launch APK
    File updateFileToRun = new File(updateDir, getPackageName() + "-update.apk");
    try {
      if (updateFile.renameTo(updateFileToRun)) {
        String amCmd =
            "/system/bin/am start -a android.intent.action.VIEW "
                + "-n com.android.packageinstaller/.PackageInstallerActivity -d file://"
                + updateFileToRun.getPath();
        Log.i(LOG_FILE_NAME, amCmd);
        Runtime.getRuntime().exec(amCmd);
        statusCode = 0; // OK
      } else {
        Log.i(LOG_FILE_NAME, "Cannot rename the update file!");
        statusCode = 7; // WRITE_ERROR
      }
    } catch (Exception e) {
      Log.i(LOG_FILE_NAME, "error launching installer to update", e);
    }

    // Update the status file
    String status = statusCode == 0 ? "succeeded\n" : "failed: " + statusCode + "\n";

    OutputStream outStream;
    try {
      byte[] buf = status.getBytes("UTF-8");
      outStream = new FileOutputStream(statusFile);
      outStream.write(buf, 0, buf.length);
      outStream.close();
    } catch (Exception e) {
      Log.i(LOG_FILE_NAME, "error writing status file", e);
    }

    if (statusCode == 0) System.exit(0);
  }
Ejemplo n.º 2
0
 public void addEnvToIntent(Intent intent) {
   Map<String, String> envMap = System.getenv();
   Set<Map.Entry<String, String>> envSet = envMap.entrySet();
   Iterator<Map.Entry<String, String>> envIter = envSet.iterator();
   int c = 0;
   while (envIter.hasNext()) {
     Map.Entry<String, String> entry = envIter.next();
     intent.putExtra("env" + c, entry.getKey() + "=" + entry.getValue());
     c++;
   }
 }
Ejemplo n.º 3
0
  @Override
  protected void onNewIntent(Intent intent) {
    if (checkLaunchState(LaunchState.GeckoExiting)) {
      // We're exiting and shouldn't try to do anything else just incase
      // we're hung for some reason we'll force the process to exit
      System.exit(0);
      return;
    }
    final String action = intent.getAction();
    if (ACTION_DEBUG.equals(action)
        && checkAndSetLaunchState(LaunchState.Launching, LaunchState.WaitForDebugger)) {

      mMainHandler.postDelayed(
          new Runnable() {
            public void run() {
              Log.i(LOG_FILE_NAME, "Launching from debug intent after 5s wait");
              setLaunchState(LaunchState.Launching);
              launch(null);
            }
          },
          1000 * 5 /* 5 seconds */);
      Log.i(LOG_FILE_NAME, "Intent : ACTION_DEBUG - waiting 5s before launching");
      return;
    }
    if (checkLaunchState(LaunchState.WaitForDebugger) || launch(intent)) return;

    if (Intent.ACTION_MAIN.equals(action)) {
      Log.i(LOG_FILE_NAME, "Intent : ACTION_MAIN");
      GeckoAppShell.sendEventToGecko(new GeckoEvent(""));
    } else if (Intent.ACTION_VIEW.equals(action)) {
      String uri = intent.getDataString();
      GeckoAppShell.sendEventToGecko(new GeckoEvent(uri));
      Log.i(LOG_FILE_NAME, "onNewIntent: " + uri);
    } else if (ACTION_WEBAPP.equals(action)) {
      String uri = intent.getStringExtra("args");
      GeckoAppShell.sendEventToGecko(new GeckoEvent(uri));
      Log.i(LOG_FILE_NAME, "Intent : WEBAPP - " + uri);
    } else if (ACTION_BOOKMARK.equals(action)) {
      String args = intent.getStringExtra("args");
      GeckoAppShell.sendEventToGecko(new GeckoEvent(args));
      Log.i(LOG_FILE_NAME, "Intent : BOOKMARK - " + args);
    }
  }
Ejemplo n.º 4
0
 static {
   MathUtils.RANDOM = new Random(System.nanoTime());
 }
Ejemplo n.º 5
0
 @Override
 public void onDestroy() {
   super.onDestroy();
   System.gc();
 }
  public void run() {
    Log.i(getClass().getSimpleName(), "Starting thread (run method started)");

    boolean gameOverTriggered = false;
    long currentFrameIndex = 0;
    long currentFrameTimesAccumulated = 0;
    long lastLoopStartTime = System.currentTimeMillis();
    // Debug.startMethodTracing( "escapePitTrace" );

    // gameResult.status = GameResultStatus.RUNNING;

    loadFirstLevel();

    if (orderedSubSystems == null)
      throw new IllegalStateException(
          "Cannot start a MainRunThread until you've loaded all SubSystems; try calling loadAllCoreSubSystems() first");

    /**
     * ********************************************************************* START OF MAIN BODY OF
     * RUN LOOP **********************************************************************
     */
    while (myThread != null) {
      long loopStartTime = System.currentTimeMillis();
      long lastFrameTime = loopStartTime - lastLoopStartTime;
      currentFrameTimesAccumulated += lastFrameTime;

      Canvas c = surfaceView.getHolder().lockCanvas(null);
      try {
        /**
         * Critical: lots of things in rendering depend on the size / shape of the Canvas; => we
         * must make sure the renderingSystem has the latest, current, correct Canvas before we do
         * anything else
         */
        renderingSystem.canvas = c;

        for (SubSystem system : orderedSubSystems) {
          system.processOneGameTick(lastFrameTime);
        }

        synchronized (surfaceView.getHolder()) {
          renderingSystem.drawBackground();
          renderingSystem.processOneGameTick(lastFrameTime);
        }

        Thread.sleep(5);
      } catch (GameOverError goe) {
        Log.i(getClass().getSimpleName(), "GameOver; killing thread");

        myThread = null;

        Log.i(getClass().getSimpleName(), "GameOver; locking Entity System");
        es.freeze();

        gameOverTriggered = true;
      } catch (Throwable t) {
        Log.e(
            getClass().getSimpleName(),
            "Inside main draw loop, a major exception, killing draw thread:" + t);
        t.printStackTrace();
        myThread = null;
      } finally {
        // ANDROID EXAMPLE CODE COMMENT:
        // do this in a finally so that if an exception is thrown
        // during the above, we don't leave the Surface in an
        // inconsistent state
        if (c != null) {
          surfaceView.getHolder().unlockCanvasAndPost(c);
        }

        currentFrameIndex++;
        lastLoopStartTime = loopStartTime;
        int frameTimesPerSample = 25;
        if (currentFrameIndex % frameTimesPerSample == 0) {
          // DEBUG: Log.i( getClass().getSimpleName(), "Averaged frame rate = " +
          // frameTimesPerSample * 1000 / currentFrameTimesAccumulated + " fps" );
          currentFrameTimesAccumulated = 0;
        }
      }
    }
    // Debug.stopMethodTracing();

    if (gameOverTriggered) {
      /**
       * Another bad design decision from the Android authors? This is not a great way to manage
       * inter-Activity communication (is there a better way?)
       */
      Intent i = parentActivity.getIntent();
      parentActivity.setResult(Activity.RESULT_OK, i);
      parentActivity.finish();
    }

    Log.i(
        getClass().getSimpleName(),
        "Thread-stop COMPLETE: (run method expired; mythread was set to null)");
  }