package ru.exlmoto.aaaa;

import java.io.File;
import java.io.IOException;

import android.app.Activity;
import android.content.Intent;
import android.content.res.ObbInfo;
import android.content.res.ObbScanner;
import android.os.Bundle;
import android.os.storage.OnObbStateChangeListener;
import android.os.storage.StorageManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class AAAALauncherActivity extends Activity {

	private String obbFilePathName = "/storage/sdcard0/main.1.ru.exlmoto.aaaa.obb";
	// private final String obbKey = "aaaa";
	private ObbInfo mObbInfo = null;
	private StorageManager mStorageManager = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		mStorageManager = (StorageManager) getApplicationContext().getSystemService(STORAGE_SERVICE);

		checkObbMount();

		setContentView(R.layout.aaaa_launcher);

		Button buttonRun = (Button) findViewById(R.id.buttonRun);
		buttonRun.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(v.getContext(), AAAAActivity.class);
				startActivity(intent);
			}
		});
	}

	private void checkObbMount() {
		File obbFile = new File(obbFilePathName);
		if (obbFile.exists() && obbFile.isFile()) {
			try {
				try {
					mObbInfo = ObbScanner.getObbInfo(obbFilePathName);
				} catch (IllegalArgumentException e) {
					e.printStackTrace();
					AAAAActivity.toDebugLog("The OBB file could not be found!");
				} catch (IOException e) {
					e.printStackTrace();
					AAAAActivity.toDebugLog("The OBB file could not be read!");
				}

				if (mStorageManager.mountObb(obbFilePathName, null, mObbEventListener)) {
					AAAAActivity.toDebugLog("Mount OBB file...");
				} else {
					AAAAActivity.toDebugLog("Failed to start OBB mounting!");
				}
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
				AAAAActivity.toDebugLog("The OBB file already mounted!");
			}
		} else {
			AAAAActivity.toDebugLog("OBB file isn't exist or it's a directory!");
		}

		obbFile = null;
		System.gc();
	}

	OnObbStateChangeListener mObbEventListener = new OnObbStateChangeListener() {

		@Override
		public void onObbStateChange(String path, int state) {
			AAAAActivity.toDebugLog("ObbStateChanged, path: " + path + ", state: " + state);

			switch (state) {
			case OnObbStateChangeListener.ERROR_ALREADY_MOUNTED:
				AAAAActivity.toDebugLog("Obb File Already Mounted! Unmounting... #2");
				mStorageManager.unmountObb(obbFilePathName, true, mObbEventListener);
				break;
			case OnObbStateChangeListener.MOUNTED:
				AAAAActivity.toDebugLog("Obb Mounted! Path: " + mStorageManager.getMountedObbPath(obbFilePathName));
				break;
			case OnObbStateChangeListener.UNMOUNTED:
				AAAAActivity.toDebugLog("Obb File Unmounted!");
				break;
			default:
				break;
			}
		}
	};
}

@@ -639,53 +639,162 @@
 l;%0A%09
-private StorageManager mStorageManager = null
+// JNI-access%0A%09public static String obbMountedPath = %22%22;%0A%09private StorageManager mStorageManager = null;%0A%09AAAALauncherActivity aaaaLauncherActivity = this
 ;%0A%0A%09
@@ -997,28 +997,8 @@
 );%0A%0A
-%09%09checkObbMount();%0A%0A
 %09%09se
@@ -1206,96 +1206,22 @@
 %09%09%09%09
-Intent intent = new Intent(v.getContext(), AAAAActivity.class);%0A%09%09%09%09startActivity(intent
+checkObbMount(
 );%0A%09
@@ -1693,17 +1693,16 @@
 ;%0A%09%09%09%09%7D%0A
-%0A
 %09%09%09%09if (
@@ -2397,17 +2397,16 @@
 state);%0A
-%0A
 %09%09%09switc
@@ -2683,108 +2683,463 @@
 %09%09%09%09
-AAAAActivity.toDebugLog(%22Obb Mounted! Path: %22 + mStorageManager.get
+obbMountedPath = mStorageManager.getMountedObbPath(obbFilePathName);%0A%09%09%09%09AAAAActivity.toDebugLog(%22Obb Mounted! Path: %22 + obbMountedPath);%0A%0A%09%09%09%09File readMeFile = new File(obb
 Mounted
-Obb
 Path
-(obbFilePathName));
+ + %22/AAAA-Data/DONOTREAD.ME%22);%0A%09%09%09%09if (readMeFile.exists() && readMeFile.isFile()) %7B%0A%09%09%09%09%09Intent intent = new Intent(aaaaLauncherActivity, AAAAActivity.class);%0A%09%09%09%09%09startActivity(intent);%0A%09%09%09%09%7D else %7B%0A%09%09%09%09%09AAAAActivity.toDebugLog(%22Error access to mounted files!%22);%0A%09%09%09%09%7D%0A
 %0A%09%09%09

Optimize OBB Java Frontend