Posts

Showing posts from 2014

Merge branches in Git

Merge branches in Git Few days ago, my superior gave a task to make a presentation about the daily usage of git for R&D department, so I resumed the git pro book to prepare this presentation. And the following article is to recognize my former wrong and unclear opinion about branch merging in git, and a little suggestion about branch management. So how to merge two branches? There are two methods to merge two branches, merge and rebase. Merge method is to merge two branch and generate a new commitment, whose parents are the two HEAD of the older branch. This is called a cross in the branch network. While the rebase method is to re-play every commitment of a branch to another branch, and there are no cross between them after two branch's rebase. And the best way to check the branches is working in right way is to check if there are crosses in branches. So the recommended method of combine two branches is to always use rebase instead of the merge. Because If you always u

How to configure Samba Server in Ubuntu?

How to configure Samba Server in Ubuntu? Table of Contents What is Samba? Target Prepare configure /etc/samba/smb.conf 1 What is Samba? Samba is a linux implementation of file share and transaction protocol for LAN, which mainly used in Windows OS. Samba is more convenient than FTP in my opinion, and it is useful in a small group who works in a same LAN, but its members are familiar with different OS, Bob works in Mac, David works in Ubuntu, while Mars likes Windows more. 2  Target This tutorial is a step to step document of how to build a Samba Server which met the following requirement: Share a Directory with both readable and writable authority for Guest. Share a Directory with both readable and writable authority for certain Users. Share a Directory with only readable authority for Guest. 3 Prepare addgroup smbgrp adduser abc smbgrp smbpasswd -a abc mkdir /xxx/path chown -R abc:smbgrp /xxx/path mkdir /xxx/public chown -R nobody:nogroup /xx

How to configure Android project's build types in Gradle?

Image
How to configure Android project's build types in Gradle? Table of Contents Generate Java Constants Generate Android resources A few days ago, our team needs to configure the Gradle's build scripts to auto build the project. Here is the requirement, to build three versions of app, release, development and test, from the command line. I found the ways from the following link, http://stackoverflow.com/questions/17197636/is-it-possible-to-declare-a-variable-in-gradle-usable-in-java Actually, we can generate the Java constants and Android resources from the Gradle's build script: 1 Generate Java Constants android { buildTypes { debug { buildConfigField "int" , "FOO" , "42" buildConfigField "String" , "FOO_STRING" , "\"foo\"" } release { buildConfigField "int" , "FOO" , "52"

My Android JNI Tutorial

Image
My Android JNI Tutorial Since I worked for my current employer, I found out my passion of writing was dropping down dramatically. My salary was raised and also got a promotion, but my ambition for the software looks have not evolved. So what is my favorite? coding and writing. I should keep that in my mind. I reviewed what I did in the last few months, there are one thing suit my desire of writing. I wrote a JNI module to process the jbig compressed image, both decoding and encoding, actually I initially allocated this job to one of my former colleague, but it looks so sucks, then I have to refactor his code after his resignation, basically rewrote the code. This is my first time to wrote JNI code with android-ndk, also my former jobs included a few JNI tasks, but it is in android system development not as an app developer. Here are my experience and summary of JNI coding. 1. How to design JNI code? Load the sharable library in static code in java part.     static

How to extract or backup apk from android system?

As an android developer, I always wanna hack awesome app to learn its design inside. The first step of that is to get the APK file itself, and the obvious way to do that is to extract it from our android phone. There are two ways to make that, both of them need no root privilege. 1. Use android adb backup command adb shell pm list packages adb backup -apk com.google.android.wearable.app dd if=backup.ab bs=1 skip=24 | python -c “import zlib,sys;sys.stdout.write(zlib.decompress(sys.stdin.read()))” | tar -xvf - 2. Use adb package management cmd  adb shell pm list packages  adb shell pm path com.google.android.wearable.app  adb pull /data/app/com.google.android.wearable.app-1.apk

Learning a new way to release and package python source code

Image
This article is one part of learning notebook after I read the youtube-dl 's source code, I learned a lot of knowledge from this software, I guess the most interesting part is found two porn website inside it, haha. The anther interesting thing, I learned from its source code, is a python packaging technology. It is a new way to release or publish python software. Before I learned this way, I always use the following two methods to publish python software. Just release the raw source code. Use the package management tools like setuptools or distutils But, youtube-dl release itself in a standalone executable single file. So I read its build script, it zipped all its source code into a package and it is its way to make an executable file. I guess python interpreter has the capacity of interpreting source code from the zip file. As usual, I wrote some sample code to illustrate how this way works, and you can browser sample code from the following site. https://githu

A LAN server discovery web app

Image
A LAN server discovery web app Table of Contents Requirement Next movement how to deploy the service? 1 Requirement the purpose of this project: Many services were running in my desktop environment at the company LAN, but the IP address was always alternate after I reboot, so my initial intent to develop this app is to let my fellow colleagues detect my desktop's IP address much quickly. this solution is to run a HTTP server on my desktop, and the client must post request at least with a key/value pair: req=get_ip. Then a client scan all the LAN IP address with that request, my computer will response with {'status' : 0, 'ret':ip_address}. 2 Next movement Since I am studied a lot of certification and encryption knowledge recently, I guess the next target of this project is to add a certificate process to reject the fake one. The simple ways were to employ an asymmetry encryption algorithm like RSA, then client generate a random number

Android's Package Management System

Image
Android's Package Management System Table of Contents How to resign an android app? How to install an android apk? android package management system. How to get an app's certification? 1 How to resign an android app? Android apk's digital signature strategy just employs the java's jar package method. So We can use java's keystore and jarsigner tools to sign an apk. And the first step is to generate a valid certification: make your own keystore keytool -genkey -v -keystore iboxpay.keystore -alias ibox -keyalg RSA -keysize 2048 -validity 100000 please remember the store password and key password, I always set them the same one. then before to resign an apk, I should remove its original signature first. remove apk's digital signature zip -d whatever.apk "META-INF/*" After that, I can sign that apk by our own certification. sign apk by jarsigner jarsigner -verbose -keystore iboxpay.keystore -storepass 123456 what

Reverse Engineering Android apk

Image
Reverse Engineering Android apk Table of Contents Background Apktool dex2jar + JD-GUI 1 Background Here is my puzzle at this moment, my superior gave me a task to make Bluetooth Low Energy product which includes Android APP part, but there are no virtual designer and product manager, just myself as a software engineer. So, my first step is to found out a similar product and refer its design. Then, I need to decompile that app, some reverse engineering skills of Android app and java are necessary. I guess following two methods are enough to decompile an Android app. 2 Apktool ApkTool is a tool for reverse engineering Android apps, what it is pretty good at is to decode resources to nearly original form and rebuild them after some modification. But the java code part is decompiled into the smali format, which is not a good format to read and understand. 3 dex2jar + JD-GUI Apktool can not generate readable java source code, actually, there are no re

Mobile APP development team composition

Image
Android APP development team composition Table of Contents Android APP team Exploration Stage Team Structure Acceleration Stage Team Structure Innovation Stage Team Structure 1 Android APP team Recently I have a job to develop an Android APP, this one is not a toy app anymore, it is a serious product. In the former time, When the superior dispatch an app task to me, most of the time, I did not worry about the user interface or UI design, I just need to finish the job by my way, just ignore the ugly interface, because most of the jobs are just test or research oriented. But this time is different, I need to develop a serious product. How can I make a product by myself? So I try to figure out the quality of the good team to make an awesome app. Then I found the following link to answer my question: http://www.slideshare.net/Mutual_Mobile/maturing-your-mobile-development-team This article provided three stages of Team structure, which can be a reference to ru

Light_BLE - a practical APP tool to develop Bluetooth LE device

Image
Light BLE APP Table of Contents What is Light BLE APP? The Advantage of this APP Why I make above improvement? Source Code 1 What is Light BLE APP? It is an enhanced android app to communicate with Bluetooth LE peripheral. This app may be useful in Bluetooth Low Energy peripheral equipment development. It is based on an example in Android's SDK source code sample which located in sdk/samples/android-19/connectivity/BluetoothLeGatt/ , but that example sucks(yeah, Light BLE  sucks too, but much better than that sample). 2 The Advantage of this APP Following is what I improved based on that sample. Change the LocalService and Activity communication mechanism from broadcast intent into callback hooks. Add RSSI signal detects. Add write characteristic dialog(still need to improve). 3 Why I make above improvement? Broadcast Intents was not dependable, I guess that's the reason that I missed a lot of messages. So I studied the communicat

How to write Android Service?

Image
How to write Android Service? Table of Contents Two kinds of Services in Android Local Service Remote Service Broadcast 1 Two kinds of Services in Android When we wanna make an Android app, we should put the time-consuming jobs into a service, actually, there are two kinds of services in Android, Local Service, and Remote Service. The difference between them is that whether they are running in the same process as the app, the local Services are running in the same process as the app, while the remote Services are running in the separate process, and I just need to add the following attribute to the AndroidManifest declaration to announce a remote service, it is a local Service without this attribute. android:process=":remote" After We build the Service, We need to communicate with this object, send a message to Service is obvious, I just need to bind to that Service. But how to receive announcement and messages from the Service, the mechanisms to do

How to setup a NAT server?

Image
How to setup an NAT server? Table of Contents What is NAT? How to setup NAT host? a shell script from vbird's book 1 What is NAT? NAT stands for Network Address Transition, which is the basic function of gateway host. I try to hack Bluetooth tethering module in android this week, it include the Bluetooth Pan profile and the NAT setup process, which means in order to implement the Bluetooth tethering, first, two devices must be connected by Bluetooth Pan profile, and then the server part device acted as gateway host to supply the network forward service. In other words, after Bluetooth Pan profile connected, the server must to setup its NAT rules to forward the IP packages. So how to setup NAT rules? 2 How to setup NAT host? My memory is still fresh that at the start of my Linux journey, I setup my Linux desktop as an NAT host to provide Internet services for my lab's classmates. During the days as a programmer, I once did a job to hacking android&

Async Networking in Android

Async Networking in Android (Deprecated, I never use those technology anymore.)  Table of Contents Background Source code examples 1 Background A few days ago, people ask me a question, How to write an application which has to download the resources from the network? or Let me narrow the scope, how to write an android app, which can download the images from the Internet with HTTP protocol and insert the image into a view container like a ListView. So, in this scenario, because the networking connections are always resources burden works, the solution is always put the heavy jobs into the background threads. Following is the equation to that problem. Threads + Cache + HttpClient I found three ways to met this equation after study that topic. Use AsyncTask(thread) directly, put the networking job into a background AsyncTask. Use ThreadPool, which is better than AsyncTask, especially in massive networking connection scenario. Use Volley library, which is advo

Practise Git

Image
Practise Git Table of Contents What's git? Daily Usage 1 What's git? Git, initially started by Linus, is a most advanced distributed version control system. The another kinds of version control system are centralized version control system, SVN is one of them. 2 Daily Usage you wanna stage a file git add file untrack(unstage) a file git reset HEAD file get a diff between staged area and unstaged area git diff get a diff between staged area and last commitment git diff --cached commit staged area into the repository git commit push to the last commitment into the remote repository git push [remote-name] [branch-name] git push [remote-name] [locale-branch]:[remote-branch] remove staged file git rm file # or git reset HEAD file rm file turn back to former status git checkout -- file get a list of all remote repository git remote -v add a remote repository git remote add [shortnam

A sort algorithm question from a job interview

Image
A sort algorithm question from a job interview Table of Contents Question My Answer After rethinking the question 1 Question Here we are, there is an abstract data type(ADT), which has two members - student number and student score, to represent a student, and there are a millions of the students and the score is ranged from 1 to 100 as integer, there is a container to store this ADT, maybe an array. So please tell me one student's position in this exam in the fastest way. 2 My Answer If you wanna design an algorithm, there are only two points, which you need to focus, space efficiency and time efficiency. They are a perpetual conflict, you can never achieve both space and time efficiency at the same time. Then after a silent break, yeah, I was thinking this question, I believe I gave the stupid answer, just iterate the whole container. Damn it. 3 After rethinking the question The interviewer gave me a hint to finding the most time efficient wa

Bluedroid stack in android

Image
Bluedroid stack in android Table of Contents Bluetooth stack in android Bluedroid .VS. Bluez Porting guide of Bluedroid stack 1 Bluetooth stack in android From Android 4.2, google use Bluedroid stack as its default Bluetooth host stack, before android 4.2, its default Bluetooth host stack was Bluez, which is also the Linux distribution's default stack. So why google changed its Bluetooth stack? The reason is maybe that Bluez stack was designed for the desktop environment, so in order to port Bluez into android, android must solve some dependency issues, like porting Dbus, Linux desktop's default IPC, into android. So there are at least five processes to power Bluetooth before android 4.2, they are systems, Bluetooth APP, Bluez, hciattach, and Dbus. The damn thing is that there are bugs between them, so Bluetooth stack is the weakest part in the android system before android 4.2, yeah, it is the usual reason that android system corrupted. So, what's t