前三个lec讲的java基础
本篇只涉及lec里的安卓知识点,不涉及开发代码

Lec4:

讲了如何安装AS

Lec5 Application Components

5.1. Services

运行在手机后台的应用服务,没有UI。如后台播放音乐

5.2. BroadcastReceiver

能够接受安卓系统或其他app的broadcast广播并给出响应。如“你正在使用移动流量”看视频

5.3. ContentProvider

应用可能会存储多种文件和数据库且只能被自己访问,ContentProvider支持在应用程序之间共享信息。如在邮件应用中可以给手机日历增加一个日程

5.4. Activities

Activity通常是一个单独的屏幕,上面可以显示控件并根据用户的动作做出响应。如知乎打开后的各种页面

一个安卓应用可能会包含多个activities,但是只有一个是main activity。所有activities都会在系统里先注册,使得它能够被跳转(比如在美团外卖唤起invokes微信付款页面。

Back Stack:
页面的堆栈,当跳转页面时,前一个Activity被pause,然后被放置到back stack的最顶端。
栈——先进后出,当点击back按钮,当前activity会被destroyed,然后back stack顶部的activity会activated and shown

Activity Life Cycle
一个Activity通常有四个状态:

  1. Running,该页面处于前台,获取用户操作焦点
  2. Paused,该页面被其他页覆盖了一部分
  3. Stopped,该页面被完全覆盖
  4. Destroyed,摧毁,资源全部释放

处于stopped状态的页面在手机内存不足时会被自动销毁

页面状态切换

动作 回调函数执行顺序
某个activity被启动 OnCreate -> onStart -> onResume
失去焦点,被隐藏 onPause -> onStop
重新获取焦点 OnRestart -> onStart -> onResume
关闭 onPause -> onStop -> onDestroy
从Activity1跳转到Activity2:
1. Activity1启动
2.点击按钮跳转到Activity2:Activity1: onPause()Activity2: onCreate()Activity2: onStart()Activity2: onResume()Activity1: onStop() #与下面情况二不同
3.从Activity2中返回:Activity2: onPause()Activity1: onRestart()  #与下面情况二不同Activity1: onStart()  #与下面情况二不同Activity1: onResume()Activity2: onStop()Activity2: onDestroy()
4.Activity1退出
从Activity1跳转到透明的Activity2:
1.Activity1启动
2.点击按钮跳转到Activity2:Activity1: onPause()Activity2: onCreate()Activity2: onStart()Activity2: onResume()3.从Activity2中返回:Activity2: onPause()Activity1: onResume()Activity2: onStop()Activity2: onDestroy()4.Activity1退出

【https://blog.csdn.net/GracefulGuigui/article/details/115817190】

一个Activity的完整生命周期:

回调函数CallBack functions 通常使用情况
onCreate() Initial setup, load persistent state.
onRestart() read cached state
onStart() reset application
onResume() start foreground-only behaviors
onPause() shutdown foreground-only behaviors. For example: temporarily stop UI animations.
onStop() cache state
onDestroy() save persistent state

Lec6

res文件夹里的资源都会注册为全局的R.java(R.<resource_type>.<resource_name>)包,来供快速调用

同样,每个View可以有自己的id:@+id/records
使用findViewById(R.id.records)来获取这个元素实例

6.1. View Class

widgets的base class是View,View代表屏幕中的一块矩形区域,渲染可视的元素。
layout的base class是ViewGroup,ViewGroup是View的子类,代表了包含了许多widgets的一块区域。ViewGroup可以嵌套。
使用如findViewByID(R.id.textView1)来获取一个在XML里定义的widget的实例。

6.2. View Dimension

padding:内边距,属于View,android:padding=“12dp”
margin:外边距,外边距占据的部分,不属于这个View,android:layout_margin=“20dp”

6.3. 度量单位

  • Pixel (px): actual pixels on the screen.
  • Inch (in): physical size of the screen.
    1 Inch = 2.54 centimetres
  • Millimetre (mm)
  • Points (pt): 1/72 of an inch.
  • Density-independent Pixel (dp or dip):
    • An abstract unit that is based on the physical density of the screen. These units are relative to a 160-dpi screen.
    • Using dp can ensure proper display of your UI on screens with different dpi settings.
  • px = dp * (dpi / 160)
    If you use a dpi of 240, then 2 dp uses 3 pixels.
  • Scale-independent Pixels (sp):
    Similar to dp, but also scaled by the user’s font size preference.

6.4. Event listeners

View.OnClickListener
View.OnDragListener
View.OnLayoutChangeListener
每个Listener可以绑定一个回调方法

onItemSelected()为下文Spinner选定下拉框中某个元素的回调

6.5. Widgets(Multiple Options)

Spinner和ListView和GridView
以Spinner为例,会创建一个可选的下拉框

Lec 7 Layouts and the UI Thread

android:id=“@id/records 和 android:id=”@+id/records"区别:
+号表示如果不存在这个symbol(ID)则创建

android:layout_width="match_parent"解释:
layout_开头属性用于告知父Layout如何渲染这个View,每个Layout需要的属性不同,LinearLayout需要weight而GridLayout需要column和row属性
- wrap_content: tells your view to size itself to the dimensions required by its content.
- match_parent: tells your view to become as big as its parent view group will allow.

7.1. RelativeLayout

相对布局允许子元素相对定位
每个元素锚点在左上角,如果两个元素处于同一位置,则后面那个会覆盖

不同的定位方式

7.2. Android UI Thread

使用单独的线程渲染UI,监听事件以及控制activity生命周期。如果这个线程阻塞太长时间,安卓就会认为app停止响应。

可以使用新线程控制activity,但是UI只能由UI线程来渲染。因此,使用如下方法来协程:

  1. Activity.runOnUiThread(Runnable)

  2. View.post(Runnable)

  3. AsyncTask,四个关键函数:onPreExecute(),onPostExecute(),onProgressUpdate()运行在UI线程,doInBackground()运行在其他线程。工作流程:创建AsyncTask对象并override以上方法,调用execute方法,执行顺序:onPreExecute()→doInBackground(Params… params)、onProgressUpdate(Progress… values)→onPostExecute(Result result)

Lec8 Context, Notification and Service

Context:为了与不同设备的硬件交互,控制app的权限,允许安卓组件获取共享信息

8.1. Notification

Toast弹窗提示
Notification系统菜单栏消息

  • NotificationChannel定义消息管道,根据消息类型不同都有不同的管道,交由安卓系统进行注册。
  • Notification.Builder创建消息,可以携带后续用户点击消息时的操作’PendingIntent‘
  • NotificationManager来发送消息

8.2. Service

软件的后台服务,也运行在UI线程上

  • 创建Service类,重写方法,然后在AndroidManifest里注册

startService():
This service can run in the background indefinitely, even if the component that started it is destroyed.
It lacks methods to interact with other components.

bindService():
This service only lives while it serves another component.
If its last component unbinds, the service will be destroyed by the Android System.
It provides mechanisms to interact with callers.

foreground不会被杀掉,non-foreground service在低电量时会被杀掉

使用Service的好处:
Service有生命周期,可以由任何活动控制。(甚至从不同的应用程序!)
Service可以接收广播信息。这允许你根据一些系统事件(电池寿命等)来调整应用程序的行为。
假如没有Service,我们可能需要在多个Activity里面设定许多个后台事务处理代码,防止某个单一Activity被杀掉后后台停止。Service能够保持后台一只运行

bindService四个关键部分:

  • Service本身,client(如activity)绑定了service,Binder对象定义了接口使client能够交互service,ServiceConnection监听service状态
  1. 创建Binder,定义onBind等事件
  2. 在Service里创建业务处理事件
  3. 创建Client,也就是调用bindService连结Activity和Service和ServiceConnection对象
  4. 定义ServiceConnection
  5. 记得onStop()的时候unbindService(ServiceConnection)


整个逻辑:

  1. The client creates the intent to inform the system of its target service.
  2. The client prepares a ServiceConnection object.
  3. The client calls bindService().
    A ServiceConnection object is passed to the system so that later, the system will call onServiceConnected() when the service is connected.
  4. The system receives its first bind request. It calls onCreate() method of the service class.
  5. The system then calls your service’s onBind() method to retrieve the IBinder.
    This only happens when the first client binds.
    The system then delivers the same IBinder to any additional clients that bind, without calling onBind() again.
  6. Then, it calls onServiceConnected() with the Ibinder object it just received from onBind().

Binder is needed because:
Android system need to prepare things first, it cannot return the service object immediately.
The service need a way to inform the system the time clients can interact with itself, through onBind().

Lec9 Intent and Broadcast

9.1. Intent

Intent被用于方便应用程序组件之间的通信

Explicit intents:显示的定义谁发起了intent,如组件类名
Implicit intents:大概定义一个action,安卓系统通过用intent filters匹配这个隐式intent找到最适合的组件

Intent构成:

  1. Implicit intents构成

    1. Action,一个字符串如ACTION_MAIN,可以结合action和data:ACTION_VIEW content://contacts/people/1:要求android显示标识符为 "1 "的人的信息。
    2. Data,uniform resource identifier (URI),URI是一个格式化的文本<scheme>://<host>:<port>/<path>,是对资源或数据的不可改变的一对一映射。如ftp://ftp.is.co.za/rfc/rfc1808.txt。
    3. Category:字符串,定义了应该处理这个Intent的组件的种类。
    4. Type: 提供数据类型(MIME),如图像MIME:“image/png” or “image/jpeg”。Type与Data要么同时设置,否则两者会互斥。
  2. Explicit intents构成
    1. Component,Intent i2 = new Intent(getApplicationContext(), ImageShow.class);ImageShow.class is the component.
  3. Extras
    1. Passing data:Extras可以给Intent附加额外信息,供component接受。

Implicit intent隐式intent:
为了接受一个隐式intent,接收方组件应该在安卓系统里注册,通过manifest XML 里的 <intent-filter>块

Intent Filters:定义了一个软件能够接受哪些implicit intents,如各种浏览器都能打开网页,那么我们在自己的软件里要打开某个网页的时候,安卓系统就会弹出一个窗口让我们选择用哪一个浏览器打开。

判断一个intent是否通过intent filter(whether can resolve this intent):

如果接收方注册了<action android:name="action_name" />:那么它只会收到响应的action的intent,如果接收方没有注册action,则永远不会接受到intent。

如果接收方注册了<category android:name="category_name" />,它接受Intent时不需要Intent包含所有它注册了的category。对于某个Intent,接收方必须注册了这个Intent携带的所有category才能接受他。An intent with zero category will always pass the test. An intent with categories A, B matches a filter with categories A, B, C.
安卓系统对于startActivity和startActivityForResult传递的implicit intents会自动应用CATEGORY_DEFAULT。所以接收方intent filter至少要有android.intent.category.DEFAULT。

如果接收方注册了<data android:xxx="xxx">
那么他会筛选掉不在他注册的URI和MIME范围之内的intent。

例子:
尝试跳转到系统的计算器应用

尝试跳转到浏览器,并且跳到固定网页

自己设定一个intent filter

9.2. Broadcast

安卓应用可以发送(sendBroadcast)/接受(BroadcastReceiver)从别的应用/安卓系统发来的广播

接受广播:
Context.registerReceiver()
或Intent-filter(8.0以上版本被弃用)

在Activity的onCreate方法里设置receiver,然后在按钮回调里注册接收器。

Lec10 Permissions and Data Management

10.1. Permission

权限限制了软件的信息获取,保护了用户隐私,软件使用权限必须获得用户同意。

权限类型:

  1. Normal permissions,对用户隐私无危害,安装时会自动获取
  2. Dangerous permissions,会影响用户隐私或设备操作,用户必须显示的同意这类权限请求,应用才能使用这些权限

声明权限:
app在AndroidManifest XML里使用<uses-permissions>来声明需要的权限。

10.2. Data Management

Internal/External Files

内部存储:

  1. 永远可访问
  2. 文件默认只能由某个单独app访问
  3. 删除app时会自动清空
  4. 安卓10之后会自动加密
  5. 使用openFIleOutput()打开文件流并操作

外部存储:

  1. 不是永远可用
  2. 文件可被分享
  3. 卸载app时可以保留数据
  4. 需要权限
  5. 文件在Android\data\your.project.name\files

SharedPreferences

轻量级的存储私有数据,以键值对的形式在internal memory中。即使你的应用被杀了,数据也persist across user sessions。通常用于存储user id和喜欢的WiFi网络等
Context.getSharedPreferences(name,mode):对所有调用者返回同一实例
Activity.getPreferences(mode):每个Activity只会收到自己的私有实例
mode现在只有MODE_PRIVATE

例子:

SQLite Database

SQLite provides in-memory database。提供一个跨平台轻量化的数据库,提供ACID transactions:atomic, consistent, isolated & durable。

可以定义一个类来定义数据库每行的对象实例方便业务操作
一个继承了SQLiteOpenHelper的类提供数据库管理(创建,更新),定义数据库的业务操作。

Lec11 2D Graphics with Views

View:
就是canvas画板,为了绘制东西,要重写View类的onDraw()方法,在其内可以调用drawLines等方法。

Animated View:
在UI线程内调用view.invalidate(),在其他线程调用view.postInvalidate()来重绘。
动画效果通过使用线程和sleep控制View的绘图属性来完成。

SurfaceView:
引入缓存和锁的机制,减少每次重绘消耗的资源。
请求锁的时候如果没有画布则会返回null,此时可以添加回调来创建画布。
绘制SurfaceView无需在UI线程内

Lec12 2D Graphics with Drawable

可绘制的资源包括图像,矢量图形等。

BitmapDrawable:
文件放于res/drawable从文件流中获得bitmap,然后代码或xml设置。ImageView.setImageResource()

VectorDrawable:
矢量图存储绘图信息,通常以XML文件存储。

TransitionDrawable:
对Drawable的对象进行渐变转换

Lec13 Multi-Touch in Android

Single-Touch:
在View里重写onTouchEvent事件,还可以invalidate()来重绘,还可以用另外一个线程来控制绘制频率

Multi-Touch:
多点触控每个触控点都会有id以及动作(通过event.getActionMasked()获取),都会触发onTouchEvent。id会持续到这个触控点消失。每个点还有index,所有点存储在一个列表中,index和触控点的关系是会变的。

Lec14 Sensors and GPS

陀螺仪传感器,光线传感器等

  1. 得知手机能使用哪些传感器getSystemService()
  2. 检查自己需要的传感器是否存在sensorManager.getDefaultSensor() != null
  3. 注册传感器监听,监听传感器值变换和准确率变化,设置监听的采样频率

Sensor对象有value范围,最小实际延迟,value等

地理传感器非常耗电需要注意Pause

Lec15 Network

网络功能需要在manifest里申明权限:
<uses-permission android:name="android.permission.INTERNET"/>

  1. 创建URL对象URL url = new URL(httpURL);
  2. 创建HttpURLConnectionHttpURLConnection urlConn =(HttpURLConnection) urls[0].openConnection();
  3. 操作输入/输出流BufferedReader reader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
  4. 关闭IO流和HttpURLConnectionreader.close(); urlConn.disconnect();

Android网络类:

  1. jave.net-(Socket, URL)
  2. org.apache-(HttpRequest, HttpResponse)
  3. android.net - (URI, AndroidHttpClient, AudioStream)

HTTP:
HTTP is a protocol for communication between browsers and world wide web (WWW) servers. HTTP uses URL to locate resources: protocol://hostname[:port]/path/[;parameters][?query]#fragment,协议包括Protocol examples: http, file, ftp, ed2k, mailto,Query用于传递动态参数,适用于PHP,JSP,ASP等

Post和get区别:

  1. get请求参数包含在url后面,有长度限制
  2. post请求参数包含在请求体内,比较安全,没有大小限制(这个其实取决于后端设置,比起get来说可以说是没有限制了

解析响应体(后端可能返回json或,这里以XML为例:Document doc = dBuilder.parse(urlConn.getInputStream());

Socket:
A socket is an abstract representation (handle) for the local endpoint of a network communication path socket经常用于构建实时聊天室
一个Socket包含Protocol,Local IP,local port,Remote IP,remote port

Lec16 Context-Aware Systems and UI Design

16.1. Mobile human computer interaction (HCI)

What is HCI: It involves the study, planning, and design of the interaction between people (users) and computers

From PC to mobile:

  1. PC:固定位置,有线网,大显示屏,持续获取用户专注,多硬件支持
  2. mobile computing devices:动态位置,通常无线网,用户注意力不固定,显示设备有限,有限的硬件支持

Devirsity of Device Interaction:
Size: hand-sized, decimetre-sized, vs body-sized, etc.
Haptic input: two-handed vs one-handed vs hands free, 通常包含(键盘Keyboards,虚拟键盘Virtual keyboards, 触控屏Touch screens,声音Voice)
- 虚拟键盘Virtual keyboards优点:简单,适用于各种语言,节省了硬件物理空间。缺点:需要准确的点击,缺少物理反馈,需要挤占屏幕空间。可改进:预测输入,修正输入,放大光标Magnifier cursor
- 手写笔Character Recognition:基于笔的落下抬起移动,需要更高的处理能力,需要用户手写的训练集,错误率通常高。
- 声音输入Voice Input:语音转文字,一开始的时候受限于词汇量。优点:解放双手,节省屏幕空间,不需要打断用户如开车等动作。缺点:处理性能要求高,噪音环境错误率大,口音问题
- Virtual keyboard without screen基于投影和图像识别的键盘
- Stephen Hawking’s Wheelchair使用了眼球追踪eye tracking
- Brain Computer Interface脑机接口
Single user vs shared interaction: personal space vs public space
Posture for user: lying, sitting, standing, walking, etc.
Distance of output display to input control: centimetre to metre.
Position during operation: fixed vs mobile
Connectivity: stand-alone vs networked, wired vs wireless
Tasking: single task vs multi-task devices
Multimedia content access: voice and text communications, oriented alpha-numeric data or text-oriented, audiovisual-content access
Integrated: embedded integrated devices vs dynamically interoperable devices

Securities in Mobility:
一些敏感信息(个人信息,社交网络,网上银行等)容易被盗取,通过病毒Virus,黑客Hackers,未认证访问Unauthorized access
解决方法:基于设备及网络的安全验证Authentication以及信息加密Encryption

  • Authentication:用户信息验证,系统会在进行敏感操作前确认你就是你——通过密码或IC card或指纹或人脸。密码长短限制,记忆力限制;IC card携带型限制;指纹(fingerprint)和人脸(face profile)这类生物验证(Biometric Authentication)挺不错
  • 什么生物信息能用来身份验证:Universality (每个人都有这个特征);Uniqueness (世上不能有相同的特征);Permanence (不随时间改变, it is time invariant);Collectability (Can be quantitatively measured可以被量化)
  • 生物信息的潜在危险Potential threats:图像对抗,指纹复制,生物信息泄露

16.2. Context-Aware Systems

What is context-aware:

  • Systems that are aware of their own situation in the physical, virtual, and user environment. 系统关注自己所处的物理/虚拟/用户的环境

    • 天气预报默认显示用户所在地区
    • 音乐软件接听电话时自动暂停
    • 接听电话距离检测脸部靠近自动息屏

Why context-aware 意义何在:App can be more intelligent and less attention hungry, more comfortable/efficient to use

How to be context-aware(CA):

  • Adapt users’ operation or goal based on contextual cues from the environment or the user’s actions 适应用户操作的目标
  • Specifically, sense environment and determine what is relevant to the system’s task(s) 感知环境并确定与系统的任务相关的内容

16.2.1. Classifying CA systems

Passive context-aware systems:被动上下文感知
new context is presented to the user, to inform them of change——把某个东西的改变通知用户,交给用户选择后续操作。比如电池没电了的低电量提醒

Active context-aware system :主动上下文感知
behavior of the applications change automatically——应用自动改变自己的行为,如手机的夜晚模式。

Various ways of classifying CA software:

Proactive Triggering performing some interaction based on environmental perceptions
Streamlining Interaction travel guide for current location (reducing irrelevant information)
Memories for past events based on spatial or feature-based cues (contextual retrieval)
Reminders for future contexts tagging details regarding current context for future access
Optimizing patterns of behaviours changing interface based on situation
Sharing Experiences Social networking based on shared contexts

Context Creation:
基于传感器信息,可以创建新的上下文,也就是将低层面的raw context转为high level contexts。如地理位置信息由GPS信息转为街道名(Abstraction is often more useful:“this photo was taken at my parents home last Christmas”)

Challenges in Context Awareness:

  1. 环境信息可能是不准确的或错误的
  2. User contexts可能被错误地预测
  3. 环境和user context内在含义之间缺乏一致性
  4. 情境的使用可能减少用户的隐私
  5. 对context shifts或应用的变化可能使用户超负荷或分散注意力

Spatial Awareness空间感知:
连结contextual information(传感器的位置,活动,时间)和other people
It is the key element of Location-based service (LBS)
例子:

Location Acquisition地点感知:
通常指GPS/BDS等卫星定位/4G等网络定位/-航位推算等机械方法,现在也有WLAN based positioning,RFID based positioning,Ultrasonic/sonar positioning超声波定位,Infrared Position红外线定位

Satellite based Positioning卫星定位:
Trilateration positioning method三坐标定位法
Mobile device measures the signal propagation distance,Mobile device computes its position based on multiple measurements

Cellular Network based Positioning蜂窝网络定位:
使用base stations (BS)来定位

WLAN based Positioning

  • Access points (AP) broadcast radio signals

    • Somehow like a satellite or a BS, but
      Position of AP is unknown
      AP cannot measure the radio signal of mobile devices
  • A solution for Positioning
    • A geo-database of AP signal strength
      Locate the mobile user by searching the database
      Commonly known as the Fingerprint/Received signal strength method

Mechanic Positioning Methods力学定位:
基于previous position,travelling distance,travelling direction三个要素推断新的位置

Augmented Reality增强现实:
Combining live direct view of a physical real-world environment with virtual CGI

  • Typically in real-time using the semantics of environmental elements
  • Identify digital “cues” (e.g. 2D barcode) and overlay with a digital image
  • 优点:
    • Can be used to enhance the environment

      • Provide details about the environment, by “projecting” labels
      • or directions onto the street or building being viewed
    • Can be used for entertainment
      • Project games into the real-world, by identifying cues to determine location or features
      • Create virtual figures
    • Can be used to display information without disturbing
      • Head-up display
  • 挑战:
    • Image analysis is required to identify cues to overlay graphics

      • Positioning information required, to determine relative location of other artifacts that may be annotated
      • Live video is required to project the graphics onto

Lec17 The Shortest Path Problem

Dijkstra之前在INT102里写过,见这里

Dijkstra’s Algorithm:

  • Starting from a source vertex s in G(V,E)
  • Each node in V has a distance-from-source value.
    • Originally they are infinite. Except for s = 0.
  • Maintain two sets, S and Q
    • S contains the vertices whose minimum distance-from- source values have already been determined.
    • Q = V - S
  • Repeatedly select the vertex u from Q
    • u has the minimum distance-from-source estimate in Q
    • Remove u from Q and add u to S
    • Update the distances of all neighbouring vertices of u
  • Results would be a tree


Dijkstra算法使用贪心思想,要求路径权值不能为负数,一旦一个点被visited,则这么点在之后的搜索中不会被考虑。

Lec18 Wireless Networks

18.1. History

电磁波无线电的发展历史

18.2. Radio Wave

A type of electromagnetic radiation with wave length带有波长的电磁辐射,频率从3kHz到300GHz,人耳听力范围20Hz到20kHz

一些属性properties:

  • Radio speed=wavelength*frequency
  • 使用天线antenna,天线长度通常为波长的四分之一
  • 高频率Higher frequency电波的波长短,长距离下变化明显
  • Reflection反射,Refraction折射,Scattering散射,Diffraction衍射
  • 无线电信息和信源信息之间的转换被称为modulation调制

调制:

18.3. Wireless Networking

  1. WWAN:Wireless Wide Area Networks——2G/3G/4G/5G, licensed frequency bands,需要执照才能创建网络
  2. WLAN:Wireless Local Area Networks(WiFi,LiFi), unlicensed frequency bands,每个人都能用这些频段(frequency bands)创建网络
  3. WPAN:Wireless Personal Area Networks(Bluetooth)

五层网络模型:

  • Application
  • Transport
  • Network
  • Data Link (Wireless Network
  • Physical (Wireless Network

Wireless Interference无线干扰:
同一时间多只transmitter向同一接收者发送不同频率信息,接收者将会接收到混合的信号( the summation of the two signals)
解决方法:

  1. Circuit-level solutions 物理层
    • Frequency division multiple access (FDMA)
    • Time division multiple access (TDMA)
    • Space division multiple access (SDMA)
    • Code division multiple access (CDMA)
  2. Package level solutions 数据链路层
    • Carrier Sense Multiple Access (CSMA)

18.4. Multiple Access Methods

FDMA - Frequency Division Multiple Access

基于频率的划分,每个网络用户有自己的频率段(frequency band),频率段之间有一段间隔(guard bands)

优点:

  1. 解决了wireless interference问题
  2. 支持analog data模拟信息和digital data数字信息

数字信号和模拟信号

缺点:

  1. 间隔造成浪费
  2. 接收者需要调成正确了频率
  3. 频率段数量收到限制
  4. 每个段的最大流量(maximum flow rate)是固定的,而且很小

TDMA - Time Division Multiple Access

基于时间的划分,所有网络内用户基于同一频率传输信息,但是不同用户在不同时段传输

优点:

  1. 用户可以被给予不同的带宽(通过分配时段

缺点:

  1. 只支持数字信号digital data
  2. 需要设备的时间同步time synchronization

SDMA - Space Division Multiple Access

基于空间的划分,地理空间上划分users。

  • 强信号将会覆盖一小片区域
  • 定向(智能)天线(Directional/smart antennas)通常用于SDMA,以控制无线电广播空间

(重要)CDMA - Code Division Multiple Access码分多路访问

与FDMA不同,CDMA仅有一个通道占据链路整个的带宽。而与TDMA不同的是,所有的站点都可以同时发送/接受数据,没有时间的共享问题。即在CDMA中,一个通道同时承载所有的传输。总体来说,在码分多路访问中,站点使用不同的编码以达到多路访问。

码分多址详解

数学,向量点乘dot:

数学,克罗内克积The Kronecker product:
将B看成标量,element-wise乘后直接展开

CDMA使用点乘(R,C之间)和克罗内克积(E,C之间)

(重要)CDMA步骤:

  1. 网络内的每个节点都会得到自己的spreading code(C),C可以视作一个向量,这里假设signal A的code为(1,1), signal B的code为(1,-1)

    • code之间两两正交(点乘结果为0)
    • 每个code长度为N(N取2,4,8…, N大于等于网络内总节点数)
    • code自己点乘自己,结果为N, CA*CA=N (后面有用)
  2. 发送方将会发送数据(这里我们以向量D来表示
  3. 发送方将数据D转为E电子信号Electric Signal:1→1,0→-1,未发送→0。
    (以D=(1,0,1,1)为例,转为电子信号为E=(1,-1,1,1))
  4. 发送方计算它的E和C的克罗内克积
    (假设信号源A的电子信号EA为(1,-1,1,1),codeA=(1,1), 结果为(1,1,-1,-1,1,1,1,1)。
    同理,假设B的EB=(-1,-1,1,1), codeB=(1,-1), 结果为(-1,1,-1,1,1,-1,1,-1)
  5. 信号间产生overlapping,A的信号和B的信号重叠
    (1, 1, -1, -1, 1, 1, 1, 1) + (-1, 1 , -1, 1 , 1, -1 , 1, -1)= (0, 2, -2, 0, 2, 0, 2, 0)
  6. 接收方接受到信号(0, 2, -2, 0, 2, 0, 2, 0)后,如果它想获取signal A的信息,则将信号每N(网络节点数量)个一起组合向量,然后与CA点乘。最后将结果缩放到[-1,1]区间。
    1. 组合向量:(0, 2, -2, 0, 2, 0, 2, 0)→N=2→((0,2),(−2,0),(2,0),(2,0))((0, 2),( -2, 0), (2, 0), (2, 0))((0,2),(2,0),(2,0),(2,0))
    2. 点乘CA(由于C之间垂直,A之外的Ck点乘CA结果都是0,所以这步算出来的结果就是EA⋅CA⋅CA=NEAE_A \cdot C_A \cdot C_A=NE_AEACACA=NEA):
      ((0,2),(−2,0),(2,0),(2,0))⋅(1,1)=((0,2)⋅(1,1),(−2,0)⋅(1,1),(2,0)⋅(1,1),(2,0)⋅(1,1))=(2,−2,2,2)((0, 2),( -2, 0), (2, 0), (2, 0))\cdot(1,1)=((0, 2)\cdot(1,1),( -2, 0)\cdot(1,1), (2, 0)\cdot(1,1), (2, 0)\cdot(1,1))= (2, -2, 2, 2)((0,2),(2,0),(2,0),(2,0))(1,1)=((0,2)(1,1),(2,0)(1,1),(2,0)(1,1),(2,0)(1,1))=(2,2,2,2)
    3. 获取A的信息:DecodedA=(2,−2,2,2)=(1,−1,1,1)Decoded_A=(2,-2,2,2)=(1,-1,1,1)DecodedA=(2,2,2,2)=(1,1,1,1)

可见spreading code在这之中用处非常大,那么如何找出符合那些条件的code:
OVSF树的生成
树根为-1或1都行,学校这里树根为1
假设每个节点中的向量表示为W
每个节点可以分出两个分支,一个分支内向量为[W W],另一个分支为[W -W]
如[1,-1]分出两个分支[1,-1,1,-1],[1,-1,-1,1]
每层的codes即可用于CDMA。

CSMA - Carrier Sense Multiple Access载波感知多路存取

用于数据链路层Data Link,检测信道medium,等待直到它空闲后发送内容。如果信道忙,则在一个随机的时间后重新检测

  1. CSMA with collision detection(CSMA/CD)
    冲突检测:如果己方开始发送消息时信道中某节点也开始发送消息,停止发送,并等待一个随机时间后,重新开始发送。适用于集线形以太网hub-based Ethernet
    优点: 比CSMA更有效
    缺点:需要能够检测冲突的手段;无线信道的node是隐藏的,很难检测冲突;在发送时很难监听信道
  2. CSMA with collision avoidance(CSMA/CA)
    避免冲突:当己方察觉信道空闲,先发送一个“request to send”(RTS)消息,等待接收方发送clear to send(CTS)回来,开始正式发送数据包,接受方会发来acknoledgement(ACK)。适用于WLAN

Lec19 Wi-Fi

19.1. Basiscs of Wi-Fi

What is WIFI:
Wireless local area network (WLAN) products that are based on the Institute of Electrical and Electronics Engineers’ (IEEE) 802.11 standards.

了解即可:
IEEE 802.11 – “Wi-Fi 0”:1997年
IEEE 802.11b – “Wi-Fi 1”:1999年,使用2.4GHz,带宽11Mbps,13个信道,目前最广泛使用
IEEE 802.11a - “Wi-Fi 2”:1999年,5GHz,带宽54Mbps,12个信道,与上面这个不兼容
IEEE 802.11g - “Wi-Fi 3”:2003年,2.4GHz,54Mbps
IEEE 802.11n - “Wi-Fi 4”:2008年,2.4GHz/5GHz,600Mbps
(好老的课件…WiFi5,WiFi6都没有的吗)

Channels & Frequency:
划分了13个可用channel,交叉使用三个

19.2. Network Architecture

802.11 defines two Wi-Fi network options:
Infrastructure BSS结构型基本服务集:AP连结管理多个节点
Independent BSS独立型基本服务集:节点之间互相连结

AP:无线设备的网络管理节点,相当于一个连接有线网和无线网的桥梁,其主要作用是将各个无线网络客户端连接到一起,然后将无线网络接入以太网,从而达到网络无线覆盖的目的。

  1. Basic Service Set(BSS)
  • 所有连到一个AP上的节点以及这个AP一起被称为一个基本服务集 basic service set
    对于结构性网络,AP的MAC地址被用作BSS的ID;对于独立形网络,会生成一个48bit的作为BSSID
  • 由于BSSID太难记了,于是出现了Service Set Identifier (SSID),也就是我们在无线网设置界面看到的wifi名称。32-byte identification string
  1. Extended Service Set (ESS)
    多个BSS
  • ESSID(Extended Service Set ID):对于多个AP的WiFi网络,所有的AP的SSID相同,也被称作ESSID

如何实现无缝漫游mobility issues?(从CB的3楼走到CB的1楼,AP节点如何发生的更换),与#20讨论的COA不同,这里没有发生网络上的位置变换,路由还是那个路由:

IEEE 802.11没有规定,由各个厂商自己实现(目前比较流行AC+AP,mesh等方案),MS移动导致连结的AP切换后,AP需要更新它们的数据库,使DS能够分发正确的包到相应的AP

19.3. Wi-Fi Security

19.3.1 Service Set Identifier (SSID) hiding

隐藏网络的SSID,阻止经验不足的人连结你的wifi,属于不可靠的保护方法

19.3.2. MAC address filtering

筛选符合条件的MAC设备访问

优点:比隐藏SSID强
缺点:增加管理复杂性,降低了scalability,MAC地址可以伪造

19.3.3. Wired Equivalent Privacy (WEP) protocol

WEP:Wired Equivalent Privacy
1999年,802.11b,处于数据链路层。
只有认证用户才能接入,保护AP与节点间信息。
需要同个WLAN下的所有电脑和APs共享同一个密钥K(称作WEP key)
缺点:RC4密钥长度有限24bits,容易被爆破

例子:
Assume we have a computer trying to guess the password of the AP. Each attempt constantly sends a 1500 byte packet and the network speed is at 11Mbps (11Million bits per second: 11,000,000 bits/s). How long does it take to enumerate through all password possibilites?

224packets×1500bytespacket×8bits1byte÷11Mbps=18300s2^{24}\ packets \times \frac{1500bytes}{packet} \times \frac{8bits}{1byte} \div 11Mbps=18300s224packets×packet1500bytes×1byte8bits÷11Mbps=18300s
约5小时。密钥最大长度24bits,共224种组合,每试一下需要发送1500byte的包,1byte等于8bit要乘8,除以带宽11Mbps。

WPA:Wi-Fi Protected Access
2003年,802.11i
现有WEA硬件支持WPA(向上兼容!)
使用AES而不是RC4加密

19.4. Traffic Management in Data Link Layer

避免冲突(Collision Avoidance)

MAC:distributed foundation wireless Medium Access Control:

  • The mandatory basic method based on a version of CSMA/CA.
  • An optional method avoiding the hidden terminal problem.(这点和上面合起来称为distributed coordination function (DCF)
  • A contention-free polling method for time-bounded service.(称作 point coordination function (PCF)

介绍CSMA/CA (without RTS/CTS):

  1. 监听信道medium直到空闲(需要每个节点都有感知信道内是否繁忙的能力)
  2. 当信道空闲,额外等待一个时间间隔(这个过程称作backoff),然后发送数据包,得到ACK
  3. 如果发生冲突,AP会要求所有发送者停止发送并随机等待一段时间后再检测信道是否空闲

SIFS:short inter-frame space,发送者从发送数据包到收到ACK的时间
DIFS:distributed coordination function inter-frame space,检测到信道空闲后额外等待的时间

The Hidden Terminal Problem: 隐藏终端问题

"在无线网络中,当一个节点可以与一个无线接入点(AP)通信,但不能直接与其他与该AP通信的节点通信时,就会出现隐藏节点问题或隐藏终端问题。这导致了介质访问AC的困难,因为多个节点可以同时向接入点发送数据包,这在接入点产生干扰,导致数据包不能通过。“

设备之间过远无法检测信道繁忙与否(认为信道空闲,实际不空闲)

介绍CSMA/CA (with RTS/CTS)解决隐藏终端问题:
Request to send (RTS): Asking the AP to allocate a time. 向AP请求分配一个时间。
Clear to send (CTS): AP arranges the time and then tell everyone in the network. AP广播某个人的发送时间段,让别人这段时间别发东西。
这个发送时间段的正式名称为network allocation vector (NAV)

显然,由于RTS包和CTS包的存在,设备吞吐量减少了。因此只有在所有端节点分布的相当远或网络非常繁忙容易冲突的情况下使用。

The Exposed Terminal Problem:暴露终端问题

暴露终端问题:当设备之间距离过近,两个归属于不同AP的设备之间能够互相感知到对方的通讯。当他们本可以同时传输信息时(AP1和AP2在互相通讯距离之外。STA1打算向AP1发消息时,STA2正在向AP2发消息,使用同一信道,使得STA1能够通过物理载波认知到信道繁忙,然鹅实际上即时STA1向AP1发消息,并不会产生AP端的信号干扰),他们错认为各自所在的信道繁忙而不传输,从而造成浪费。(认为的繁忙不是真正繁忙)

暴露终端问题在多个AP(或者多个Receiver)时才有可能发生。

解决办法:

  1. RTS/CTS,当STA1听到STA2的RTS,而没有听到响应的CTS,则可以认为STA2所连结的AP与自己不是同一个AP,可以放心发送。这个方案需要,两个通讯的节点同步(synchronized),数据包大小(packet size),数据速率(data rates)等参数一致时才能确保正确工作。如果不一致,则STA1可能会错过STA2的RTS。
  2. Double medium双信道,一条信道用于传输数据,另一条信道2用于传输控制信号。当STA1想发送数据给AP2的时候,发现数据信道忙,则使用信道2广播自己通讯范围内的节点”你们是不是在给AP1发数据“来二次确认,如果此时STA2确实在给AP1发,则STA2使用信道2返回确认消息,使得STA1重新进入冷却;如果此时STA2在给AP2发,则STA2可以不响应或响应否消息,STA1开始发送。

Lec20 Mobile IP

移动设备的IP随地理位置变化,如何让网络上的其他设备不用知道你的新地址就能给你发消息。移动IP在你作为服务提供者(“serviceprovider)的时候非常有用,“Not useful if you are carrying your laptop around to just watch videos.”

与移动ip相对的是固定ip,比如想要访问某个ip固定的主机,直接浏览器访问ip即可。如果这个被访问主机是个移动设备,则它一旦离开当前网络,就无法接受包了

Mobile IP的思想是用一个动态的IP地址对应一个移动设备,其主要思想是打隧道tunnelling。假设移动设备之前所在网络为HN,现在所在网络为FN

术语表:

- -
Mobile node (MN) An end-system or router that can change its point of attachment to the internetusing mobile IP. 改变了位置的设备
Correspondent node (CN) Another node that communicates with the MN. 与MN交流的设备
Home network (HN) The network where MN belongs to. MN之前所属网络
Foreign network (FN) The network which MN is currently visiting. MN当前所属网络
Care-of address (COA) Define the current location of the MN from an IP point of view. All IP packets sent to the MN are delivered to the COA, not directly to the IP address of the MN.Think of it as a “delegate IP”. 隧道ip
Home agent (HA) The HA provides several services for the MN and is located in the home network. The tunnel for packets toward the MN starts at the HA. 隧道起点
Foreign agent (FA) Like HA, it acts as tunnel endpoint and forward packets to the MN. 隧道终点

Agent Discovery Methods
MN如何发现自己的网络位置发生变化

  • Agent advertisement广播:
    foreign agents and home agents advertise their presence periodically using special agent advertisement messages
  • Agent solicitation找寻:
    • If no agent advertisements are present or the inter-arrival time is too high, the MN will actively sending packets to find agents.

通过以上方法,MN可以知道自己的COA,care-of-address (COA).
- The FA will receive IP packets and forward to MN. 如果MN在新环境中只有本地局域网地址,没有广域网地址,FA接收到的IP包都被转发至MN
- If MN gets a WAN address, the COA will just be this WAN address. (also called colocated COA)可以将隧道ip设为MN现在的广域网地址

Registration of COA注册COA

  • Now MN has a COA in FN, it is time to register this new COA with the home agent.
  • There are two situations possible:
    • If the COA is at the FA. We need to form a tunnel from HA to FA. 如果隧道连到FA处,隧道从HA打到FA
    • If the MN gets a WAN address. We need to form a tunnel from HA directly to MN. 或者直接打通MN的广域网地址,隧道打到MN主机

If COA is at the FA:隧道打到MN所在路由

If the MN Gets a WAN Address:隧道打通MA的广域网地址
MN then becomes the endpoint of the tunnel itself.
• Packets sent to HA will be forwarded directly to MN.

Mobile IP: IP Packet Delivery:打通隧道以后

  1. CN sends an IP packet to the MN. CN依旧按照以前的地址尝试访问MN,先访问到MN之前的路由HA
  2. HA intercepts the packet, knowing that MN is currently not in its home network. A new header is put in front of the old IP header showing the COA as new destination and HA as source of the encapsulated packet. HA知晓现在MN不在它的网络内,但他知到MN现在在哪——COA。于是在这个包头添加隧道(COA)信息,转发包到COA的目的地,相当于一个中转代理:”嘿,MN,这有一个别人发给你的新消息,【从IPCN发来的消息内容】“
  3. The foreign agent receives the packet, removes the additional header. Then forwards the original packet to MN. FA或MN本身接收到包后,移除COA信息,将原始包发给MN处理,MN本身对于这场转发是无感知的,MN只接收到【从IPCN发来的消息内容】
  4. MN replies the CN. Packet goes to FA and then forwarded directly to CN. MN接受请求并响应包直接给CN【MN给IPCN的响应】,CN对中转也是无感知的

CAN301 移动计算 个人笔记相关推荐

  1. MeayunDB学习笔记(一) MeayunDB介绍及安装

    系列目录 MeayunDB介绍-高性能分布式内存数据库 MeayunDB学习笔记(一)MeayunDB介绍及安装 MeayunDB学习笔记(二)批量导入数据 MeayunDB学习笔记(三)索引应用 一 ...

  2. 【汇编语言与计算机系统结构笔记20】补充内容:可定制处理器指令集

    本次笔记内容: 31.补充内容--可定制处理器指令集-1 32.补充内容--可定制处理器指令集-2 注:我找到了对应内容的课件,请见我于GitHub的CS笔记仓库. 本节课对应幻灯片:汇编语言程序设计 ...

  3. 斯坦福大学CS143编译原理课程笔记:3.编译器的性价比

    目录 编译器性价比的三个问题 为什么会有那么多编程语言? 科学计算 并行处理 商业领域 系统编程 为什么会有新编程语言的诞生? 1.广泛使用的编程语言会改变的很慢 2.很容易产生一门新的语言 3.使用 ...

  4. 【Python自然语言处理】读书笔记:第五章:分类和标注词汇

    jupyter 版请见我的github:https://github.com/JackKuo666/Python_nlp_notes [Python自然语言处理]读书笔记:第五章:分类和标注词汇 本章 ...

  5. 经典神经网络论文超详细解读(三)——GoogLeNet InceptionV1学习笔记(翻译+精读+代码复现)

    前言 在上一期中介绍了VGG,VGG在2014年ImageNet 中获得了定位任务第1名和分类任务第2名的好成绩,而今天要介绍的就是同年分类任务的第一名--GoogLeNet . 作为2014年Ima ...

  6. Python笔记相关

    Python 2021.9.9 Turtle官方文档 货币兑换 money=input("请输入货币符号($/¥)和金额:") while 1+1==2:if money[0] i ...

  7. 分布式系统阅读笔记(十八)-----副本备份技术

    介绍 在分布式系统中,副本和备份是一个用来提供高可用性和一定的容错能力的手段和措施.HA(高可用性)在当前越来越成为一个趋势在一些移动计算的领域和一些失去连接的状态场景之下.在这篇笔记中,我会介绍一些 ...

  8. 读周傲英老师的论文:计算广告:以数据为核心的web综合应用笔记

    读周傲英老师的论文:计算广告:以数据为核心的web综合应用笔记 原文链接:http://cjc.ict.ac.cn/quanwenjiansuo/2011-10/zay.pdf 摘要 涉及学科:数据管 ...

  9. Hadoop(HDFS+MapReduce+Hive+数仓基础概念)学习笔记(自用)

    文章目录 修改虚拟机IP 复制网卡的配置 Vi编辑器的常用命令 实操部分 复制网卡的配置 Hadoop集群初体验 20.secondarynameNode如何辅助管理FSImage与Edits文件 ⭐ ...

最新文章

  1. 对话 | 不能与人类直接对话的智能硬件都是“伪”智能
  2. 【技术分享】如何解锁高通骁龙660上的安卓引导加载程序
  3. 将CAGradientLayer当做mask使用
  4. git gui here如何汉化_你不知道的一些在Git使用中的奇技淫巧!
  5. 4.3英寸屏双核 LG Prada K2通过FCC认证
  6. 研究生第一篇学术论文常犯问题总结
  7. 虚函数和虚表指针的例子
  8. 网易云免费OSS服务用做Markdown图床或博客图片外链
  9. java ee 容器_javaee中web的四大容器简介
  10. windows访问mysql57_windows下 Mysql5.5升级5.7(其实就是安装了两个版本的mysql)
  11. TensorFlow tf.keras.losses.CategoricalCrossentropy
  12. XCode 7.3.1(dmg) 官方直接下载地址
  13. [译]响应式编程笔记一:响应式总览
  14. 对初学者来说,Python难度不低于其他语言
  15. isPostBack解释
  16. Farrago for Mac 1.1.0 音频效果和音乐剪辑工具 破解版下载
  17. 移动硬盘无法访问需要格式化,怎样恢复移动硬盘数据
  18. Java基础-对象反序列化
  19. Hdmi 和vga 接口有什么区别?
  20. 利用python进行股票分析(五)通过tushare读取股票数据

热门文章

  1. 广义回归神经网络(GRNN) 讲解的较好的博客
  2. 第103课:动手实战联合使用Spark Streaming、Broadcast、Accumulator实现在线黑名单过滤和计数
  3. 苹果字体怎么改_苹果手机的APPLE ID密码忘了怎么改?
  4. 开漏极、开集电极输出
  5. MOS管的工作原理浅显易懂
  6. dokuwiki使用教程--创建页面和命名空间
  7. Intellij IDEA 接口实现的快捷键
  8. Erlang:[笔记一,构建工具rebar之编译]
  9. centos7安装rebar3
  10. Matlab:Voronoi 图