Date Archives July 17, 2016

adb on terminal

adb

  • In Android/sdk/platform-tools, there is adb call.

adb1

adb devices

  • able to see connected device
  • on mine, emulator is running as shown

adb2

adb shell

  • connects to your device
  • Can look up all the files on the device
  • exit: to come out

adb3

adb logcat

  • way to check logcat on terminal
  • ctrl+ c : to exit
  • V is the lowest priority. If we pick V, it will get all the data V and above.(V,D,I,W,E,F,S)
  • S is the highest priority

adb4

  • adb logcat TEST:D
    • gets all logcat which tag is TEST and above debug

adb5

vi .bash_profile

  • on here we can set PATH. So, I don’t need to get into the specific directory to do a job(ex. adb call)

bash1

  • If you add this line to bash_profile, Path automatically sets as shown below

bash2

  • Now, you can call adb on everypath where you are on

bash3

Android File Components

Manifest

  • Describes what the application is about
  • activities
  • Android studio auto save the contents to here
  • Best place to check what’s going on the appManifest

Gradle file (Module)

  • Defines build dependencies , configurations

Gradle

  • minSdkVersion:
    • minimum version of android which can use this app
    • 18 and below cannot use this app
  • targetSdkVersion:
    • highest version of android which can use this app
  • versionCode:
    • version of the app
    • 1,2,3,4
  • versionName:
    • you can name version name on your own
    • 1.0.2 or 2.34

Drawable

  • Can have images which will be linked with android code
  • ldpi – low resolution
  • mdpi – middle resolution
  • hdpi – high resolution

Drawable

Layout Directory

  • Contains layout files for the android project

Layout

Menu Directory

  • Holds the menu layout files for use in android project

Menu

Value Directory

  • Each file contains each list of simple values that we can use for the application

Value1 Value2

 

Architecture Breakdown

androidArchitectureReal

Linux Kernel

  • Interacts with Android hardware and contains all the essential hardware drivers. Also provides abstraction layer between software and hardware

Libraries

  • Core proven libraries that handle specific types of data. Some examples include, SQLite, Surface Manager, Media Framework, Webkit, and OpenGL.

Android Runtime

  • The type of Java Virtual Machine used in android to run android applications. Optimized for low processing power and low memory environments

Application Framework

  • Building blocks that our application directly interact with. These programs manage basic functions of the phone such as phone calls, and resource management.

Applications

  • Programs that utilize all of the above to create new functionality for our devices

onCreate(), Activity, Bundle

Life cycle of activity

activity

  • entire lifetime
    • happens between the first call to onCreate(Bundle)through to a single final call to onDestroy()
  • visible lifetime
    • happens between a call to onStart() until a corresponding call to onStop(). During this time the user can see the activity on-screen, though it may not be in the foreground and interacting with the user.
  • foreground lifetime
    • happens between a call to onResume() until a corresponding call to onPause(). During this time the activity is in front of all other activities and interacting with the user. An activity can frequently go between the resumed and paused states

 

  • onCreate() – Called when the activity is first created. This is where you should do all of your normal static set up: create views, bind data to lists, etc.
    • setContentView
  • onRestart() – Called after your activity has been stopped, prior to it being started again. Always followed by onStart()
  • onStart() – Called when the activity is becoming visible to the user. Followed by onResume() if the activity comes to the foreground, or onStop() if it becomes hidden.
  • onResume() – Called when the activity will start interacting with the user. At this point your activity is at the top of the activity stack.
  • onPause() – Called when the system is about to start resuming a previous activity. This is typically used to commit unsaved changes to persistent data, stop animations and other things that may be consuming CPU.
  • onStop() – Called when the activity is no longer visible to the user, because another activity has been resumed and is covering this one.
  • onDestroy() – The final call you receive before your activity is destroyed. This can happen either because the activity is finishing

 

  • bundle in onCreate parameter
    • gives information when creating activity
    • Initially set to null
    • In the case that calling onCreate method after onStop(), and also it was killed not intentionally, it gives current status information for onCreate()

 

  • setContentView()
    • sets actual view which users will see
  • onSaveInstanceState(Bundle)
    • called when activity abnormally becomes onStop() state
    • store instance status information
    • When activity is being initialized again, calls the bundle information which onSaveInstanceState() had saved.
  • onRestoreInstanceState(Bundle)
    • called when activity abnormally becomes onStop() state and becomes back onResume() state

 

extends (and super) vs. implements

extends

  • extending a class
    • A extends B
      • Both classes or both interfaces
  • extends parent class’ already defined methods
  • Also possible to override the methods

extend1extend2

  • Super
    • With using super, you can call parent’s variable and methods.
      • Ex) super.p1 (variable), super.getName() (method)
    • Also, you can call parent’s constructor itself

super1

it calls parent class Base’s a variable

output

100

200

super2

it calls parent Base’s show() method

output

100

200

implements

  • implementing an interface
    • A implements B
      • A is class, and B is an interface
  • multiple interfaces can be implemented(separated by comma)
  • you cannot implement declared methods
  • you need to specify the method before using

implement1

CodeIgniter

codeigniter

  • Famous Framework using php
  • MVC
    • Model: interacts with database
    • View: Presentation side
    • Controller: Intermediary between model and view

Interface vs. Abstract class vs. Concrete class

interface

  • uses “implements” to be implemented
  • multiple interfaces can be implemented
  • interface can extends only interface

interface

abstract class

  • uses “extends” to be extended
  • if it includes at least one abstract method, it should be declared as an abstract class.
    • abstract method: undefined method
    • concrete method: defined method
  • There are already defined methods also
  • Abtract class extends both regular class and abstract class.

abstractClass

Concrete class

  • uses “extends” to be extended
  • Concrete class has only concrete methods(already defined).
class Example{

   public void display1(){
      System.out.println("display1 method");
   }
   public void display2(){
      System.out.println("display2 method");
   }
}

final

Variable

  • Variable cannot be changed

final int num=3;

Method

  • Method cannot be modified
final String getNumber() {
   return "result";
}

Class

  • Nobody can extend this class
  • That means, no body can override methods of this class
  • Possible to use as it is(not modifying).
public final class String{

}

Jimple

Soot program converts Android application file into Jimple code.

Jimple contains two general concepts

  • Local – local variables
  • Units – statements

 

IdentityStatements

  • $r0 := @this: de.ecspride.RV2013;
  • $r1 := @parameter(): android.view.View;

 

AssignStatements

  • Assignments between locals, constants, and fields

 

CastExpr

  • Right-hand side of the assignment is a typecast
  • $r4 := (android.widget.EditText) $r1;

 

Four different expressions to call methods

  • VirtualInvokeExpr
    • Virtual dispatch invoke to an instance method
  • StaticInvokeExpr
    • Calling a static method
  • InterfaceInvokeExpr
    • Calling a method of an object of which only its interface type is known
  • InvokeStmt
    • Any invoke expression which can be part of standalone statement

super vs. this

  • super : used to access methods of the base class
  • this : used to access methods of the current class

superTHis1 superThis2

The third line is printing “animal : eat” because we are calling super.eat().

If we called this.eat(), it would have printed “dog : eat”.