using command lines
http://www.what-could-possibly-go-wrong.com/creating-a-native-android-plugin-for-unity3d/
Wednesday, December 14, 2016
Wednesday, December 7, 2016
android file path convert content:// into file://
public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
Uri uri;
uri = resultData.getData();
String path = UriHelpers.getFileForUri(getContext(), uri).getAbsolutePath();
public static File getFileForUri(final Context context, final Uri uri) {
String path = null;
// DocumentProvider
if (DocumentsContract.isDocumentUri(context, uri)) {
// ExternalStorageProvider
if (isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
if ("primary".equalsIgnoreCase(type)) {
path = Environment.getExternalStorageDirectory() + "/" + split[1];
}
} else if (isDownloadsDocument(uri)) {
// DownloadsProvider
final String id = DocumentsContract.getDocumentId(uri);
final Uri contentUri = ContentUris
.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
path = getDataColumn(context, contentUri, null, null);
} else if (isMediaDocument(uri)) {
// MediaProvider
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
Uri contentUri = null;
if ("image".equals(type)) {
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
} else if ("video".equals(type)) {
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
} else if ("audio".equals(type)) {
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
}
final String selection = "_id=?";
final String[] selectionArgs = new String[] {
split[1]
};
path = getDataColumn(context, contentUri, selection, selectionArgs);
}
} else if ("content".equalsIgnoreCase(uri.getScheme())) {
// MediaStore (and general)
path = getDataColumn(context, uri, null, null);
} else if ("file".equalsIgnoreCase(uri.getScheme())) {
// File
path = uri.getPath();
}
if (path != null) {
return new File(path);
}
return null;
}
private static String getDataColumn(Context context, Uri uri, String selection,
String[] selectionArgs) {
Cursor cursor = null;
final String column = "_data";
final String[] projection = {
column
};
try {
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
null);
if (cursor != null && cursor.moveToFirst()) {
final int column_index = cursor.getColumnIndexOrThrow(column);
return cursor.getString(column_index);
}
} finally {
if (cursor != null) {
cursor.close();
}
}
return null;
}
private static boolean isExternalStorageDocument(Uri uri) {
return "com.android.externalstorage.documents".equals(uri.getAuthority());
}
private static boolean isDownloadsDocument(Uri uri) {
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
}
private static boolean isMediaDocument(Uri uri) {
return "com.android.providers.media.documents".equals(uri.getAuthority());
}
}
Uri uri;
uri = resultData.getData();
String path = UriHelpers.getFileForUri(getContext(), uri).getAbsolutePath();
public static File getFileForUri(final Context context, final Uri uri) {
String path = null;
// DocumentProvider
if (DocumentsContract.isDocumentUri(context, uri)) {
// ExternalStorageProvider
if (isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
if ("primary".equalsIgnoreCase(type)) {
path = Environment.getExternalStorageDirectory() + "/" + split[1];
}
} else if (isDownloadsDocument(uri)) {
// DownloadsProvider
final String id = DocumentsContract.getDocumentId(uri);
final Uri contentUri = ContentUris
.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
path = getDataColumn(context, contentUri, null, null);
} else if (isMediaDocument(uri)) {
// MediaProvider
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
Uri contentUri = null;
if ("image".equals(type)) {
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
} else if ("video".equals(type)) {
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
} else if ("audio".equals(type)) {
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
}
final String selection = "_id=?";
final String[] selectionArgs = new String[] {
split[1]
};
path = getDataColumn(context, contentUri, selection, selectionArgs);
}
} else if ("content".equalsIgnoreCase(uri.getScheme())) {
// MediaStore (and general)
path = getDataColumn(context, uri, null, null);
} else if ("file".equalsIgnoreCase(uri.getScheme())) {
// File
path = uri.getPath();
}
if (path != null) {
return new File(path);
}
return null;
}
private static String getDataColumn(Context context, Uri uri, String selection,
String[] selectionArgs) {
Cursor cursor = null;
final String column = "_data";
final String[] projection = {
column
};
try {
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
null);
if (cursor != null && cursor.moveToFirst()) {
final int column_index = cursor.getColumnIndexOrThrow(column);
return cursor.getString(column_index);
}
} finally {
if (cursor != null) {
cursor.close();
}
}
return null;
}
private static boolean isExternalStorageDocument(Uri uri) {
return "com.android.externalstorage.documents".equals(uri.getAuthority());
}
private static boolean isDownloadsDocument(Uri uri) {
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
}
private static boolean isMediaDocument(Uri uri) {
return "com.android.providers.media.documents".equals(uri.getAuthority());
}
}
Thursday, December 1, 2016
ubuntu git clone gnutls_handshake() failed: Illegal parameter
http://askubuntu.com/questions/186847/error-gnutls-handshake-failed-when-connecting-to-https-servers
Trouble shootings
* Unmet build dependencies: libcurl4-openssl-dev
add "-d" option to override
Trouble shootings
* Unmet build dependencies: libcurl4-openssl-dev
add "-d" option to override
sudo dpkg-buildpackage -rfakeroot -b -d
remove "NO_OPENSSL=1" from debian/rules
Thursday, November 10, 2016
android app read build.prop
String key = "ro.product.name";
String prop = getProp(key);
Log.e(TAG, key + ": [" + prop + "]");
public String getProp(String key) {
Process p = null;
String prop = "";
try {
p = new ProcessBuilder("/system/bin/getprop", key).redirectErrorStream(true).start();
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line=br.readLine()) != null) {
prop = line;
}
p.destroy();
} catch (IOException e) {
e.printStackTrace();
}
return prop;
}
Tuesday, November 1, 2016
build android application on command line
http://incise.org/android-development-on-the-command-line.html
http://incise.org/android-development-on-the-command-line.html
Monday, October 31, 2016
build android library on command line
android create lib-project --name UnityLibProject --target 1 --path . --package com.ebmajor.unitylib
- create project : Creates a new Android project.
- create lib-project : Creates a new Android library project.
UnityLibProject.java:
package com.ebmajor.unitylib;
public class UnityLibProject
{
public static float GetValue()
{
return 1.0f;
}
}
build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="AndroidPlugin" default="help">
... default stuff ...
<target name="jar" depends="debug">
<jar
destfile="bin/UnityLib.jar"
basedir="bin/classes" />
</target>
</project>
ant jar
android update lib-project
android update project
android update -h
android update project
android update -h
Monday, October 17, 2016
unity calls method in android plugin
for non-static method in android plugin return void
Calls a Java method on an object (non-static).
jo.Call("setToDefaults");
for non-static method in android plugin return int
AndroidJavaObject jo = new AndroidJavaObject("java.lang.String", "some string");
int hash = jo.Call<int>("hashCode");
for static method in android plugin
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer")
jc.CallStatic("UnitySendMessage", "Main Camera", "JavaMessage", "whoowhoo");
Calls a Java method on an object (non-static).
jo.Call("setToDefaults");
for non-static method in android plugin return int
AndroidJavaObject jo = new AndroidJavaObject("java.lang.String", "some string");
int hash = jo.Call<int>("hashCode");
for static method in android plugin
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer")
jc.CallStatic("UnitySendMessage", "Main Camera", "JavaMessage", "whoowhoo");
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject context = activity.Call<AndroidJavaObject>("getApplicationContext");
pluginClass.CallStatic("initialize", context);
static public void initialize (Context unityContext){
try {
MyApp.initialize(unityContext);
} catch (NullPointerException e){
Log.d("UnityPlugin", "Null PTR Exception");
e.printStackTrace();
}
}
void OnDestroy() {
int ret;
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject context = activity.Call<AndroidJavaObject>("getApplicationContext");
AndroidJavaClass plugIn = new AndroidJavaClass("com.ebmajor.plugin.MyReceiver");
ret = plugIn.CallStatic<int>("sendExitEvent", context, 10);
Debug.LogError("android lib: sendExitEvent returned: " + ret);
}
public static int sendExitEvent(Context context, int val) {
Intent intent = new Intent();
intent.setAction("com.ebmajor.ACTION");
context.sendBroadcast(intent);
return 1;
}
=========================================================================================
==========================================================================================
android plug-in under Unity
==========================================================================================
package com.le.androidlib;
public class MyActivity extends UnityPlayerActivity {
static public String getArgs() {
return uri_arg;
}
}
==========================================================================================
Unity.cs
==========================================================================================
void Awake()
{
AndroidJavaObject jo = new AndroidJavaObject("com.le.androidlib.MyActivity");
string arg = jo.CallStatic<string>("getArgs"); //string return
Debug.Log("MediaPlayer: arg: " + arg);
jo.CallStatic<int>("getArgsInt"); //int return
jo.CallStatic("flushPendingCommands"); //void return
}
==========================================================================================
Unity object script call prodecure
Object 1 - script 1
Android media player - script 2
MainCamera - script 3
----->>>
media player: start()
camera script: start()
object 1 script: start()
----->>> to quit Unity Application,
call "Application.Quit();"
------>>>>
object 1 script: OnApplicationQuit()
--- no camera scipt is called
media player: OnApplicationQuit()
--->>> OnDestroy() is called later than OnApplicationQuit()
object 1 script: OnDestroy()
camera script: OnDestroy()
media player: OnDestroy()
==== start and destroy is reverse order ======
Android media player - script 2
MainCamera - script 3
----->>>
media player: start()
camera script: start()
object 1 script: start()
----->>> to quit Unity Application,
call "Application.Quit();"
------>>>>
object 1 script: OnApplicationQuit()
--- no camera scipt is called
media player: OnApplicationQuit()
--->>> OnDestroy() is called later than OnApplicationQuit()
object 1 script: OnDestroy()
camera script: OnDestroy()
media player: OnDestroy()
==== start and destroy is reverse order ======
Friday, October 14, 2016
androiod background splash screen
https://www.bignerdranch.com/blog/splash-screens-the-right-way/
https://github.com/cstew/Splash/blob/master/app/src
Thursday, October 13, 2016
Linux key event
According to the Linux input documentation, section 5, the /dev/input/eventX devices return data as following:
You can use blocking and nonblocking reads, also select() on the /dev/input/eventX devices, and you'll always get a whole number of input events on a read. Their layout is:struct input_event { struct timeval time; unsigned short type; unsigned short code; unsigned int value; };
'time' is the timestamp, it returns the time at which the event happened. Type is for example EV_REL for relative moment, EV_KEY for a keypress or release. More types are defined in include/linux/input.h.'code' is event code, for example REL_X or KEY_BACKSPACE, again a complete list is in include/linux/input.h.'value' is the value the event carries. Either a relative change for EV_REL, absolute new value for EV_ABS (joysticks ...), or 0 for EV_KEY for release, 1 for keypress and 2 for autorepeat.
Event: type 4 (Misc), code 4 (ScanCode), value 458783 [Conveying the event is scancode]
Event: type 1 (Key), code 3 (2), value 1 [key 2 pressed]
Event: type 0 (Sync), code 0 (Sync), value 0 [sync event]
Event: type 4 (Misc), code 4 (ScanCode), value 458783 [conveying the event is scancode]
Event: type 1 (Key), code 3 (2), value 0 [key 2 release]
Event: type 0 (Sync), code 0 (Sync), value 0 [sync event]
In andriod,
Event: type 1 (Key), code 3 (2), value 1 [key 2 pressed]
Event: type 0 (Sync), code 0 (Sync), value 0 [sync event]
Event: type 1 (Key), code 3 (2), value 0 [key 2 release]
Event: type 0 (Sync), code 0 (Sync), value 0 [sync event]
Linux key event
According to the Linux input documentation, section 5, the /dev/input/eventX devices return data as following:
You can use blocking and nonblocking reads, also select() on the /dev/input/eventX devices, and you'll always get a whole number of input events on a read. Their layout is:struct input_event { struct timeval time; unsigned short type; unsigned short code; unsigned int value; };
'time' is the timestamp, it returns the time at which the event happened. Type is for example EV_REL for relative moment, EV_KEY for a keypress or release. More types are defined in include/linux/input.h.'code' is event code, for example REL_X or KEY_BACKSPACE, again a complete list is in include/linux/input.h.'value' is the value the event carries. Either a relative change for EV_REL, absolute new value for EV_ABS (joysticks ...), or 0 for EV_KEY for release, 1 for keypress and 2 for autorepeat.
Event: type 4 (Misc), code 4 (ScanCode), value 458783 [Conveying the event is scancode]
Event: type 1 (Key), code 3 (2), value 1 [key 2 pressed]
Event: type 0 (Sync), code 0 (Sync), value 0 [sync event]
Event: type 4 (Misc), code 4 (ScanCode), value 458783 [conveying the event is scancode]
Event: type 1 (Key), code 3 (2), value 0 [key 2 release]
Event: type 0 (Sync), code 0 (Sync), value 0 [sync event]
In andriod,
Event: type 1 (Key), code 3 (2), value 1 [key 2 pressed]
Event: type 0 (Sync), code 0 (Sync), value 0 [sync event]
Event: type 1 (Key), code 3 (2), value 0 [key 2 release]
Event: type 0 (Sync), code 0 (Sync), value 0 [sync event]
Wednesday, October 12, 2016
unity android player classes
unity android player classes version 5.4.1f1
https://1drv.ms/u/s!AvHuXY9pNXdik2V6-dJ1_YeW-O-v
* To add unity class jar to android build script
add jar.libs.dir=your_path_here/lib in ant.properties for SDK >=8
or your_path_here/libs which is the default for SDK 13. See the jar.libs.dir property in $SDK_DIR/tools/ant/build.xml.
C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Variations\mono\Development\Classes
https://1drv.ms/u/s!AvHuXY9pNXdik2V6-dJ1_YeW-O-v
* To add unity class jar to android build script
add jar.libs.dir=your_path_here/lib in ant.properties for SDK >=8
or your_path_here/libs which is the default for SDK 13. See the jar.libs.dir property in $SDK_DIR/tools/ant/build.xml.
C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Variations\mono\Development\Classes
Thursday, September 8, 2016
gnutls_handshake() failed illegal parameter
"gnutls package is working weird behind a proxy"
http://askubuntu.com/questions/186847/error-gnutls-handshake-failed-when-connecting-to-https-servers
http://askubuntu.com/questions/186847/error-gnutls-handshake-failed-when-connecting-to-https-servers
Thursday, August 25, 2016
vnc tightvnc ubuntu no security types supported
sharing desktop
gsettings set org.gnome.Vino require-encryption false
Tuesday, August 23, 2016
jni register native methods
env->RegisterNatives(clazz, gMethods, sizeof(gMethods) / sizeof(gMethods[0])
static JNINativeMethod gMethods[] = {
{ "_nativeGetBoardHWVersion", "()Ljava/lang/String;", (void *) nativeGetBoardHWVersion },
{ "_nativeGetBoardSWVersion", "()Ljava/lang/String;", (void *) nativeGetBoardSWVersion },
{ "_native_enterUpdateMode", "()I", (void *)native_enterUpdateMode },
{ "_native_init", "()V", (void *)native_init },
{ "_native_setup", "(Ljava/lang/Object;)V", (void *)native_setup },
{ "_native_start_unix_socket_thread", "()V", (void *)native_start_unix_socket_thread },
{ "_native_release", "()V", (void *)native_release },
{ "_native_finalize", "()V", (void *)native_finalize },
};
static JNINativeMethod gMethods[] = {
{ "_nativeGetBoardHWVersion", "()Ljava/lang/String;", (void *) nativeGetBoardHWVersion },
{ "_nativeGetBoardSWVersion", "()Ljava/lang/String;", (void *) nativeGetBoardSWVersion },
{ "_native_enterUpdateMode", "()I", (void *)native_enterUpdateMode },
{ "_native_init", "()V", (void *)native_init },
{ "_native_setup", "(Ljava/lang/Object;)V", (void *)native_setup },
{ "_native_start_unix_socket_thread", "()V", (void *)native_start_unix_socket_thread },
{ "_native_release", "()V", (void *)native_release },
{ "_native_finalize", "()V", (void *)native_finalize },
};
Thursday, August 18, 2016
android permission - automatically granted
Automatically granted permissions
Some Android permission granted automatically. We call it Normal Permission (PROTECTION_NORMAL).
android.permission.ACCESS_LOCATION_EXTRA_COMMANDS
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_NOTIFICATION_POLICY
android.permission.ACCESS_WIFI_STATE
android.permission.ACCESS_WIMAX_STATE
android.permission.BLUETOOTH
android.permission.BLUETOOTH_ADMIN
android.permission.BROADCAST_STICKY
android.permission.CHANGE_NETWORK_STATE
android.permission.CHANGE_WIFI_MULTICAST_STATE
android.permission.CHANGE_WIFI_STATE
android.permission.CHANGE_WIMAX_STATE
android.permission.DISABLE_KEYGUARD
android.permission.EXPAND_STATUS_BAR
android.permission.FLASHLIGHT
android.permission.GET_ACCOUNTS
android.permission.GET_PACKAGE_SIZE
android.permission.INTERNET
android.permission.KILL_BACKGROUND_PROCESSES
android.permission.MODIFY_AUDIO_SETTINGS
android.permission.NFC
android.permission.READ_SYNC_SETTINGS
android.permission.READ_SYNC_STATS
android.permission.RECEIVE_BOOT_COMPLETED
android.permission.REORDER_TASKS
android.permission.REQUEST_INSTALL_PACKAGES
android.permission.SET_TIME_ZONE
android.permission.SET_WALLPAPER
android.permission.SET_WALLPAPER_HINTS
android.permission.SUBSCRIBED_FEEDS_READ
android.permission.TRANSMIT_IR
android.permission.USE_FINGERPRINT
android.permission.VIBRATE
android.permission.WAKE_LOCK
android.permission.WRITE_SYNC_SETTINGS
com.android.alarm.permission.SET_ALARM
com.android.launcher.permission.INSTALL_SHORTCUT
com.android.launcher.permission.UNINSTALL_SHORTCUT
Some Android permission granted automatically. We call it Normal Permission (PROTECTION_NORMAL).
android.permission.ACCESS_LOCATION_EXTRA_COMMANDS
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_NOTIFICATION_POLICY
android.permission.ACCESS_WIFI_STATE
android.permission.ACCESS_WIMAX_STATE
android.permission.BLUETOOTH
android.permission.BLUETOOTH_ADMIN
android.permission.BROADCAST_STICKY
android.permission.CHANGE_NETWORK_STATE
android.permission.CHANGE_WIFI_MULTICAST_STATE
android.permission.CHANGE_WIFI_STATE
android.permission.CHANGE_WIMAX_STATE
android.permission.DISABLE_KEYGUARD
android.permission.EXPAND_STATUS_BAR
android.permission.FLASHLIGHT
android.permission.GET_ACCOUNTS
android.permission.GET_PACKAGE_SIZE
android.permission.INTERNET
android.permission.KILL_BACKGROUND_PROCESSES
android.permission.MODIFY_AUDIO_SETTINGS
android.permission.NFC
android.permission.READ_SYNC_SETTINGS
android.permission.READ_SYNC_STATS
android.permission.RECEIVE_BOOT_COMPLETED
android.permission.REORDER_TASKS
android.permission.REQUEST_INSTALL_PACKAGES
android.permission.SET_TIME_ZONE
android.permission.SET_WALLPAPER
android.permission.SET_WALLPAPER_HINTS
android.permission.SUBSCRIBED_FEEDS_READ
android.permission.TRANSMIT_IR
android.permission.USE_FINGERPRINT
android.permission.VIBRATE
android.permission.WAKE_LOCK
android.permission.WRITE_SYNC_SETTINGS
com.android.alarm.permission.SET_ALARM
com.android.launcher.permission.INSTALL_SHORTCUT
com.android.launcher.permission.UNINSTALL_SHORTCUT
Permission Group Required runtime permission request
Tuesday, August 16, 2016
GearVRf Could not find :framework-debug
Use 1.0.3 ovr mobile sdk
https://developer.oculus.com/downloads/mobile/1.0.3/Oculus_Mobile_SDK/
copy
C:\Android\ovr_sdk_mobile_1.0.3\VrApi\Libs\Android\armeabi-v7a\libvrapi.so
to
C:\cygwin64\home\Administrator\works\GearVRf-Demos\gvr-360video\app\src\main\jniLibs\armeabi-v7a\libvrapi.so
https://developer.oculus.com/downloads/mobile/1.0.3/Oculus_Mobile_SDK/
copy
C:\Android\ovr_sdk_mobile_1.0.3\VrApi\Libs\Android\armeabi-v7a\libvrapi.so
to
C:\cygwin64\home\Administrator\works\GearVRf-Demos\gvr-360video\app\src\main\jniLibs\armeabi-v7a\libvrapi.so
Two options:
- you can build the framework yourself; clone the GearVRf and the GearVRf-Demos repos in the same directory and then the GearVRf build automatically will copy the aar to GearVRf-Demos/gearvrf-libs/
cd C:\cygwin64\home\Administrator\works\GearVRf\GVRf\Framework
./gradlew assembleDebug
./gradlew assemble
- download the gvrf-3.0.1.aar from https://github.com/Samsung/GearVRf/releases/tag/v3.0.1; copy it to GearVRf-Demos/gearvrf-libs and rename it to framework-debug.aar; please note the release instructions about the Oculus binaries which have to be manually copied, for now.
GearVRf v3.0.1
- From the Oculus Mobile SDK:
- Under your application's directory create jniLibs and copy libvrapi.so there
- C:\cygwin64\home\Administrator\works\GearVRf-Demos\gvr-360video\app\src\main\jniLibs\armeabi-v7a\libvrapi.so
/data/app/org.gearvrf.sample-1/lib/arm/libvrapi.so (vrapi_Initialize+1644)
Monday, August 15, 2016
git (repo) init
Initialize the local directory as a Git repository.
git init
Add the files in your new local repository. This stages them for the first commit.
git add .
Commit the files that you've staged in your local repository.
git commit -s
In Terminal, add the URL for the remote repository where your local repository will be pushed.
git remote add origin ebmajor@github.com:peter.oh/hmd_service.git
git remote -v
Push the changes in your local repository to GitHub.
git push origin master
run repo sync with git --recursive option
1. in manifest, specify the attribute sync-s="true"
for example <default sync-s="true"/> to apply to all projects
or for a specific project, <project sync-s="true"/>
2. repo sync --fetch-submodules
git init
Add the files in your new local repository. This stages them for the first commit.
git add .
Commit the files that you've staged in your local repository.
git commit -s
In Terminal, add the URL for the remote repository where your local repository will be pushed.
git remote add origin ebmajor@github.com:peter.oh/hmd_service.git
git remote -v
Push the changes in your local repository to GitHub.
git push origin master
run repo sync with git --recursive option
1. in manifest, specify the attribute sync-s="true"
for example <default sync-s="true"/> to apply to all projects
or for a specific project, <project sync-s="true"/>
2. repo sync --fetch-submodules
Friday, August 12, 2016
PackageManager: Not granting permission because it was previously installed without
/data/system/packages.xml
What finally fixed it for me was to re-install the applications using the package manager, by running:
cd /data/app
for app in *.apk; do pm install -r $app; done
** another solution: run the application manually at least once.
What finally fixed it for me was to re-install the applications using the package manager, by running:
cd /data/app
for app in *.apk; do pm install -r $app; done
** another solution: run the application manually at least once.
Thursday, August 11, 2016
Why 'system' user cannot access /sdcard, follow-up question
Found the code and the answer to my question in case anyone else is
interested:
system/core/vold/volmgr.c
Processes are sent SIGTERM and then eventually SIGKILL if they don't
obey.
obey.
frameworks\base\core\java\android\os\Environment.java
private static void throwIfSystem() {
if (Process.myUid() == Process.SYSTEM_UID) {
Log.wtf(TAG, "Static storage paths aren't available from AID_SYSTEM", new Throwable());
}
}
Why 'system' user cannot access /sdcard, follow-up question
Found the code and the answer to my question in case anyone else is
interested:
system/core/vold/volmgr.c
Processes are sent SIGTERM and then eventually SIGKILL if they don't
obey.
obey.
frameworks\base\core\java\android\os\Environment.java
private static void throwIfSystem() {
if (Process.myUid() == Process.SYSTEM_UID) {
Log.wtf(TAG, "Static storage paths aren't available from AID_SYSTEM", new Throwable());
}
}
Android "App Not Found" error
Check AndroidManifest.xml -> <permission android:name="xxxx"> if xxxx is existing.
signing apk with platform key
The Android tree includes test-keys under
build/target/product/security
Use <root-of-android-source-tree>/out/host/linux-x86/framework/signapk.jar to sign your app using
platform.x509.pem and platform.pk8 in <root-of-android-source-tree>/build/target/product/security
java -jar signapk.jar platform.x509.pem platform.pk8 YourApp-unsigned.apk YourApp-signed.apk
java -jar out/host/linux-x86/framework/signapk.jar ./build/target/product/security/platform.x509.pem ./build/target/product/security/platform.pk8 hmd_service.apk hmd_service-signed.apk
signing apk with platform key
The Android tree includes test-keys under
build/target/product/security
Use <root-of-android-source-tree>/out/host/linux-x86/framework/signapk.jar to sign your app using
platform.x509.pem and platform.pk8 in <root-of-android-source-tree>/build/target/product/security
java -jar signapk.jar platform.x509.pem platform.pk8 YourApp-unsigned.apk YourApp-signed.apk
java -jar out/host/linux-x86/framework/signapk.jar ./build/target/product/security/platform.x509.pem ./build/target/product/security/platform.pk8 hmd_service.apk hmd_service-signed.apk
to check android permissions app granted
Dumpsys System Diagnostics
https://source.android.com/devices/tech/debug/dumpsys.htmlto see only permissions that were granted (but omitting ones that were requested but not granted) useadb shell dumpsys package packagename
and checkgrantedPermissions
section at the bottom of the output.To list all permissions (requested but not granted + requested and granted):
Notice the APK of a package. You can run the same commandadb shell dumpsys package packagename
and get the APK path fromcodePath
element of its output.
Monday, August 8, 2016
pre-built apk and shared library to sign platform key
1. (working folder example 'PreApp')
create a working folder under ./packages/apps/PreApp
2.
copy PreApp.apk and libpreapp.so to ./packages/apps/PreApp
3.
Create Android.mk under PreApp folder and compose like below
----------------------- Android.mk ------------------------------------
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := PreApp
LOCAL_CERTIFICATE := platform
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_REQUIRED_MODULES := libpreapp
include $(BUILD_PREBUILT)
include $(CLEAR_VARS)
LOCAL_MODULE := libpreapp
LOCAL_IS_HOST_MODULE :=
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_TAGS := optional
OVERRIDE_BUILT_MODULE_PATH := $(PRODUCT_OUT)/obj/lib
LOCAL_UNINSTALLABLE_MODULE :=
LOCAL_SRC_FILES := libpreapp.so
LOCAL_BUILT_MODULE_STEM := libpreapp.so
LOCAL_STRIP_MODULE :=
LOCAL_MODULE_STEM := libpreapp.so
LOCAL_CERTIFICATE :=
LOCAL_MODULE_PATH := $(PRODUCT_OUT)/system/lib
LOCAL_REQUIRED_MODULES :=
LOCAL_SHARED_LIBRARIES :=
include $(BUILD_PREBUILT)
------------------------------------------------------------------------------
4.
run "mmm ./packages/apps/PreApp" on android root or "mm" under "./packages/apps/PreApp".
5. /* To Do */
Check shared library's module path.
Installing PreApp.apk built from above script extracts libpreapp.so under /data/app/com.package.name/lib/arm.
create a working folder under ./packages/apps/PreApp
2.
copy PreApp.apk and libpreapp.so to ./packages/apps/PreApp
3.
Create Android.mk under PreApp folder and compose like below
----------------------- Android.mk ------------------------------------
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := PreApp
LOCAL_CERTIFICATE := platform
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_REQUIRED_MODULES := libpreapp
include $(BUILD_PREBUILT)
include $(CLEAR_VARS)
LOCAL_MODULE := libpreapp
LOCAL_IS_HOST_MODULE :=
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_TAGS := optional
OVERRIDE_BUILT_MODULE_PATH := $(PRODUCT_OUT)/obj/lib
LOCAL_UNINSTALLABLE_MODULE :=
LOCAL_SRC_FILES := libpreapp.so
LOCAL_BUILT_MODULE_STEM := libpreapp.so
LOCAL_STRIP_MODULE :=
LOCAL_MODULE_STEM := libpreapp.so
LOCAL_CERTIFICATE :=
LOCAL_MODULE_PATH := $(PRODUCT_OUT)/system/lib
LOCAL_REQUIRED_MODULES :=
LOCAL_SHARED_LIBRARIES :=
include $(BUILD_PREBUILT)
------------------------------------------------------------------------------
4.
run "mmm ./packages/apps/PreApp" on android root or "mm" under "./packages/apps/PreApp".
5. /* To Do */
Check shared library's module path.
Installing PreApp.apk built from above script extracts libpreapp.so under /data/app/com.package.name/lib/arm.
Thursday, August 4, 2016
android jni thread
https://developer.android.com/training/articles/perf-jni.html
Threads
All threads are Linux threads, scheduled by the kernel. They're usually started from managed code (using
Thread.start
), but they can also be created elsewhere and then attached to the JavaVM. For example, a thread started with pthread_create
can be attached with the JNI AttachCurrentThread
or AttachCurrentThreadAsDaemon
functions. Until a thread is attached, it has no JNIEnv, and cannot make JNI calls.
Attaching a natively-created thread causes a
java.lang.Thread
object to be constructed and added to the "main" ThreadGroup
, making it visible to the debugger. Calling AttachCurrentThread
on an already-attached thread is a no-op.
Android does not suspend threads executing native code. If garbage collection is in progress, or the debugger has issued a suspend request, Android will pause the thread the next time it makes a JNI call.
Threads attached through JNI must call
DetachCurrentThread
before they exit. If coding this directly is awkward, in Android 2.0 (Eclair) and higher you can use pthread_key_create
to define a destructor function that will be called before the thread exits, and call DetachCurrentThread
from there. (Use that key with pthread_setspecific
to store the JNIEnv in thread-local-storage; that way it'll be passed into your destructor as the argument.)#define JNI_VERSION_1_6 0x00010006
android-ndk/platforms/android-17/arch-arm/usr/include/jni.h
#define JNI_VERSION_1_1 0x00010001
#define JNI_VERSION_1_2 0x00010002
#define JNI_VERSION_1_4 0x00010004
#define JNI_VERSION_1_6 0x00010006
Wednesday, August 3, 2016
Generating JNI header under Android Studio
For Android Studio projects the command reads like this:
cd C:\<path to your app>\src\main\java
javah -o ../jni/NameOfHeaderFile.h package.name.of.java.class.YourJavaClass
peteroh@PC0D83UU:~/workspace/hmd_service/app/src/main$ cd java/
peteroh@PC0D83UU:~/workspace/hmd_service/app/src/main/java$ javah -o ../jni/hmd_service_jni.h com.levr.hmd_service.HmdNative
==============================================
hmd_service_jni.h
==============================================
cd C:\<path to your app>\src\main\java
javah -o ../jni/NameOfHeaderFile.h package.name.of.java.class.YourJavaClass
peteroh@PC0D83UU:~/workspace/hmd_service/app/src/main$ cd java/
peteroh@PC0D83UU:~/workspace/hmd_service/app/src/main/java$ javah -o ../jni/hmd_service_jni.h com.levr.hmd_service.HmdNative
==============================================
hmd_service_jni.h
==============================================
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_levr_hmd_service_HmdNative */
#ifndef _Included_com_levr_hmd_service_HmdNative
#define _Included_com_levr_hmd_service_HmdNative
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_levr_hmd_service_HmdNative
* Method: Init
* Signature: (Ljava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_com_levr_hmd_1service_HmdNative_Init
(JNIEnv *, jclass, jstring);
#ifdef __cplusplus
}
#endif
#endif
Subscribe to:
Posts (Atom)