본문 바로가기
Long 을 Int 로 casting 할 때 다음을 고려하자. Long 을 Int 로 casting 할 때 다음을 고려하자. -casting 하려는 long 값이 양수, 음수를 모두 사용한다면, 그리고 충분히 큰 값을 사용한다면함부로 int 로 casting 해서는 안된다. - 안전한 down casting 다음과 같이 하면 좋다. public static int safeLongToInt(long l) {if (l Integer.MAX_VALUE) {throw new IllegalArgumentException(l + " cannot be cast to int without changing its value.");}return (int) l;} -값 손실을 고려한다면 IllegalArgumentException 대신 .. 2015. 12. 28.
[android] 디컴파일링시 Plain Text 로 노출되면 안 되는 정보들 숨기기 [android] 디컴파일링시 Plain Text 로 노출되면 안 되는 정보들 숨기기 -아주 간단하게는 각 character 들에 특정값을 더하고 빼기정도를 하는 것으로 인코딩할 수 있다. 하지만 보안 레벨 측면에서는 상당히 조악한 방법으로, 명석한 디컴파일러(사람기준)들은 이정도는 아주 간단하게 디코딩 할 수 있다. - 그럼 어떻게 안정적으로 만들 수 있을까? 너무 어렵지 않으면서 나름 안정성을 줄 수 있는 방법은 sign key 에서 특정 값을 추출해서, 보안적으로 안정성이 높은 알고리즘으로 encoding/decoding 을 하면 된다. Encrypt ( Encoding )SecretKey key = null;byte[] encryptedByte = null;try{PackageInfo packag.. 2015. 12. 24.
[android] Thread Scheduling 에 대한 이야기 [android] Thread Scheduling 에 대한 이야기 -Thread 에는 priority 값을 주어 CPU 사용량을 조절할 수 있다. ( Process#setThreadPriority( int ), Thread#setPriority( int ) ) 이 Priority 에 들어가는 값은 Nice value 라 부르는데, 다른 Thread 에 대해 얼마나 Nice 한가를 나타내는 값이다. Nice 값이 높다는 것은 다른 Thread 에게 많이 양보하는 착한(?)놈이라는 의미. 즉 Nice 값이 높을수록 우선순위가 낮아 CPU 활용이 적어진다. - Android 에서는 Main ( UI ) Thread 가 우선순위가 보통 가장 높아야 한다. BG 에서 도는 Thread 들의 Nice Value 가.. 2015. 12. 22.
[android] toLowerCase() 에 대한 고찰 ( 터키어, 이스라엘어, 리투아니아어 ) [android] toLowerCase() 에 대한 고찰 ( 터키어, 이스라엘어, 리투아니아어 ) -터키어, 이스라엘어, 리투아니아어 환경에서 개발할 일은 거의 없겠지만...영어에 대해 toLowerCase() 를 호출하면, 이상한 현상이 생기는 것을 목격할 수 있을 것이다. - toLowerCase() 는 Locale 을 지정할 수 있는데, Locale 을 지정해주지 않으면 기본적으로 Locale.getDefault() 를 호출하게 된다. 이 getDefault() 는 현재 단말에 설정된 언어에 기반한다. - 이스라엘어 ( Azeri ) 와 터키어 ( Turkish ) 의 경우는 영문자 I ( 아이 ) 가 점이 없는 ı 로 변경된다. 리투아니아어 ( Lituanian ) 의 경우는 I 뿐만 아니라 J .. 2015. 12. 21.
SQLite Bulk Insert 가장 빠른 방법은? SQLite Bulk Insert 가장 빠른 방법은? 결론 : 일반적인 Bulk Insert 보다 UNION 을 사용한 방법이 훨씬 빠르다. 일반 bulk insert SQLiteDatabase db = null;SQLiteStatement statement = null; try{db = getWritableDatabase();db.beginTransaction();statement = db.compileStatement("INSERT INTO table_name ( id, name, ... ) values( ?, ?, ... )" ); for( Item item : items ){statement.bindLong(1, item.id );statement.bindString( 2, item.name );.. 2015. 12. 18.
[android] Serialization 을 사용할 때 다음의 예외를 고려하자. [android] Serialization 을 사용할 때 다음의 예외를 고려하자. serialVersionUID 를 명시적으로 주자. serialVersionUID 를 명시적으로 주지 않으면, compiler 가 계산한 값을 부여한다. 환경이 변하지 않으면 좋겠지만, compiler 가 계산한 값은 상황에 따라 값이 달라질 수 있다. serialVersionUID 가 매치하지 않는 경우에 deserialize 하려고 시도하면 InvalidClassException 이 발생한다. 잠재적 위험을 피하기 위해 serialVersionUID 를 명시적으로 주는 것이 좋다. 만~약 이전 버전에 이미 compiler 가 자동으로 할당한 serialVersionUID 값을 사용하게 되었다면, 그 값을 찾아 명시적으로.. 2015. 12. 17.
[android] intent data filter - android:ssp xml attribute. [android] intent data filter - android:ssp xml attribute. https://chris.orr.me.uk/android-ssp-data-intent-filter - SDK 19 부터 android:sspPrefix, android:sspPattern 을 사용할 수 있다. - 예를 들어 내가 관심있는 것은 카카오톡의 설치 혹은 삭제여부인데, 기존과 같은 방식으로 broadcast receiver 를 등록하면 모든 앱에 대해서 받게 된다. -sspPrefix, sspPattern 을 사용하면 내가 관심있는 카카오톡에 대해서만 broadcast 를 받을 수 있다. ( cf, 카카오톡의 package 이름은 저것이 아닐 수 있다. ) -broadcast 뿐만 아니라 다른.. 2015. 12. 16.
[android] Activity Configuration Change Simulation. [android] Activity Configuration Change Simulation. https://developer.android.com/reference/android/app/Activity.html#recreate%28%29 Activity 의 recreate() 함수를 호출하면 된다. public void recreate ()Added in API level 11Cause this Activity to be recreated with a new instance. This results in essentially the same flow as when the Activity is created due to a configuration change -- the current instance w.. 2015. 12. 14.
[android] Useful ADB commands [android] Useful ADB commands # Start an activity adb shell am start / # Power Button adb shell input keyevent 26 # Menu Button adb shell input keyevent 82 # Print all installed packages adb shell pm list packages [-f] // -f 옵션이 있으면 apk 위치까지 함께 표시된다. # Logcat filter by tagname adb logcat -s TAG_NAME_1 TAG_NAME_2 # Logcat filter by priority adb logcat "*:E" # Logcat filter by tagname and priority.. 2015. 12. 12.
반응형