文档库 最新最全的文档下载
当前位置:文档库 › 对Android近期任务列表(Recent Applications)的简单分析

对Android近期任务列表(Recent Applications)的简单分析

对Android近期任务列表(Recent Applications)的简单分析
对Android近期任务列表(Recent Applications)的简单分析

这里的近期任务列表就是长按Home键出来的那个Dialog,里面放着近期打开过的应用,当然3.0以上系统的多任务切换键也是。

这个Dialog的实现在Android源码的.

接下来就对这个源码分析一下。

先把整个源码贴出来:

1public class RecentApplicationsDialog extends Dialog implements OnClickListener { 2// Elements for debugging support

3// private static final String LOG_TAG = "RecentApplicationsDialog";

4private static final boolean DBG_FORCE_EMPTY_LIST = false;

5

6static private StatusBarManager sStatusBar;

7

8private static final int NUM_BUTTONS = 8;

9private static final int MAX_RECENT_TASKS = NUM_BUTTONS * 2; // allow for some discards

10

11final TextView[] mIcons = new TextView[NUM_BUTTONS];

12 View mNoAppsText;

13 IntentFilter mBroadcastIntentFilter = new

IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);

14

15class RecentTag {

16 ActivityManager.RecentTaskInfo info;

17 Intent intent;

18 }

19

20 Handler mHandler = new Handler();

21 Runnable mCleanup = new Runnable() {

22public void run() {

23// dump extra memory we're hanging on to

24for (TextView icon: mIcons) {

25 icon.setCompoundDrawables(null, null, null, null);

26 icon.setTag(null);

27 }

28 }

29 };

30

31public RecentApplicationsDialog(Context context) {

32super(context, com.android.internal.R.style.Theme_Dialog_RecentApplications);

33

34 }

35

36/**

37 * We create the recent applications dialog just once, and it stays around (hidden)

38 * until activated by the user.

39 *

40 * @see PhoneWindowManager#showRecentAppsDialog

41*/

42 @Override

43protected void onCreate(Bundle savedInstanceState) {

44super.onCreate(savedInstanceState);

45

46 Context context = getContext();

47

48if (sStatusBar == null) {

49 sStatusBar =

(StatusBarManager)context.getSystemService(Context.STATUS_BAR_SERVICE);

50 }

51

52 Window window = getWindow();

53 window.requestFeature(Window.FEATURE_NO_TITLE);

54 window.setType(https://www.wendangku.net/doc/c115038954.html,youtParams.TYPE_SYSTEM_DIALOG);

55 window.setFlags(https://www.wendangku.net/doc/c115038954.html,youtParams.FLAG_ALT_FOCUSABLE_IM,

56 https://www.wendangku.net/doc/c115038954.html,youtParams.FLAG_ALT_FOCUSABLE_IM);

57 window.setTitle("Recents");

58

59 setContentView(https://www.wendangku.net/doc/c115038954.html,yout.recent_apps_dialog);

60

61final https://www.wendangku.net/doc/c115038954.html,youtParams params = window.getAttributes();

62 params.width = https://www.wendangku.net/doc/c115038954.html,youtParams.MATCH_PARENT;

63 params.height = https://www.wendangku.net/doc/c115038954.html,youtParams.MATCH_PARENT;

64 window.setAttributes(params);

65 window.setFlags(0, https://www.wendangku.net/doc/c115038954.html,youtParams.FLAG_DIM_BEHIND);

66

67//默认显示8个

68 mIcons[0] = (TextView)findViewById(com.android.internal.R.id.button0);

69 mIcons[1] = (TextView)findViewById(com.android.internal.R.id.button1);

70 mIcons[2] = (TextView)findViewById(com.android.internal.R.id.button2);

71 mIcons[3] = (TextView)findViewById(com.android.internal.R.id.button3);

72 mIcons[4] = (TextView)findViewById(com.android.internal.R.id.button4);

73 mIcons[5] = (TextView)findViewById(com.android.internal.R.id.button5);

74 mIcons[6] = (TextView)findViewById(com.android.internal.R.id.button6);

75 mIcons[7] = (TextView)findViewById(com.android.internal.R.id.button7);

76 mNoAppsText = findViewById(com.android.internal.R.id.no_applications_message); 77

78//关键在哪,你懂得...

79for (TextView b: mIcons) {

80 b.setOnClickListener(this);

81 }

82 }

83

84 @Override

85public boolean onKeyDown(int keyCode, KeyEvent event) {

86if (keyCode == KeyEvent.KEYCODE_TAB) {

87// Ignore all meta keys other than SHIFT. The app switch key could be a 88// fallback action chorded with ALT, META or even CTRL depending on the key map.

89// DPad navigation is handled by the ViewRoot elsewhere.

90final boolean backward = event.isShiftPressed();

91final int numIcons = mIcons.length;

92int numButtons = 0;

93while (numButtons < numIcons && mIcons[numButtons].getVisibility() == View.VISIBLE) {

94 numButtons += 1;

95 }

96if (numButtons != 0) {

97int nextFocus = backward ? numButtons - 1 : 0;

98for (int i = 0; i < numButtons; i++) {

99if (mIcons[i].hasFocus()) {

100if (backward) {

101 nextFocus = (i + numButtons - 1) % numButtons;

102 } else {

103 nextFocus = (i + 1) % numButtons;

104 }

105break;

106 }

107 }

108final int direction = backward ? View.FOCUS_BACKWARD : View.FOCUS_FORWARD; 109if (mIcons[nextFocus].requestFocus(direction)) {

110 mIcons[nextFocus].playSoundEffect(

111

SoundEffectConstants.getContantForFocusDirection(direction));

112 }

113 }

114

115// The dialog always handles the key to prevent the ViewRoot from

116// performing the default navigation itself.

117return true;

118 }

119

120return super.onKeyDown(keyCode, event);

121 }

122

123/**

124 * Dismiss the dialog and switch to the selected application.

125*/

126public void dismissAndSwitch() {

127final int numIcons = mIcons.length;

128 RecentTag tag = null;

129for (int i = 0; i < numIcons; i++) {

130if (mIcons[i].getVisibility() != View.VISIBLE) {

131break;

132 }

133if (i == 0 || mIcons[i].hasFocus()) {

134 tag = (RecentTag) mIcons[i].getTag();

135if (mIcons[i].hasFocus()) {

136break;

137 }

138 }

139 }

140if (tag != null) {

141 switchTo(tag);

142 }

143 dismiss();

144 }

145

146/**

147 * Handler for user clicks. If a button was clicked, launch the corresponding activity. 148*/

149public void onClick(View v) {

150for (TextView b: mIcons) {

151if (b == v) {

152 RecentTag tag = (RecentTag)b.getTag();

153 switchTo(tag);

154break;

155 }

156 }

157 dismiss();

158 }

159

160//

161private void switchTo(RecentTag tag) {

162if (https://www.wendangku.net/doc/c115038954.html,.id >= 0) {

163// This is an active task; it should just go to the foreground.

164final ActivityManager am = (ActivityManager)

165 getContext().getSystemService(Context.ACTIVITY_SERVICE);

166 am.moveTaskToFront(https://www.wendangku.net/doc/c115038954.html,.id, ActivityManager.MOVE_TASK_WITH_HOME); 167 } else if (tag.intent != null) {

168 tag.intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY

169 | Intent.FLAG_ACTIVITY_TASK_ON_HOME);

170try {

171 getContext().startActivity(tag.intent);

172 } catch (ActivityNotFoundException e) {

173 Log.w("Recent", "Unable to launch recent task", e);

174 }

175 }

176 }

177

178/**

179 * Set up and show the recent activities dialog.

180*/

181 @Override

182public void onStart() {

183super.onStart();

184 reloadButtons();

185if (sStatusBar != null) {

186 sStatusBar.disable(StatusBarManager.DISABLE_EXPAND);

187 }

188

189// receive broadcasts

190 getContext().registerReceiver(mBroadcastReceiver, mBroadcastIntentFilter); 191

192 mHandler.removeCallbacks(mCleanup);

193 }

194

195/**

196 * Dismiss the recent activities dialog.

197*/

198 @Override

199public void onStop() {

200super.onStop();

201

202if (sStatusBar != null) {

203 sStatusBar.disable(StatusBarManager.DISABLE_NONE);

204 }

205

206// stop receiving broadcasts

207 getContext().unregisterReceiver(mBroadcastReceiver);

208

209 mHandler.postDelayed(mCleanup, 100);

210 }

211

212/**

213 * Reload the 6 buttons with recent activities

214*/

215private void reloadButtons() {

216

217final Context context = getContext();

218final PackageManager pm = context.getPackageManager();

219final ActivityManager am = (ActivityManager)

220 context.getSystemService(Context.ACTIVITY_SERVICE);

221final List recentTasks =

222 am.getRecentTasks(MAX_RECENT_TASKS,

ActivityManager.RECENT_IGNORE_UNAVAILABLE);

223

224 ActivityInfo homeInfo =

225new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME)

226 .resolveActivityInfo(pm, 0);

227

228 IconUtilities iconUtilities = new IconUtilities(getContext());

229

230// Performance note: Our android performance guide says to prefer Iterator when 231// using a List class, but because we know that getRecentTasks() always returns 232// an ArrayList<>, we'll use a simple index instead.

233int index = 0;

234int numTasks = recentTasks.size();

235for (int i = 0; i < numTasks && (index < NUM_BUTTONS); ++i) {

236final ActivityManager.RecentTaskInfo info = recentTasks.get(i);

237

238// for debug purposes only, disallow first result to create empty lists

239if (DBG_FORCE_EMPTY_LIST && (i == 0)) continue;

240

241 Intent intent = new Intent(info.baseIntent);

242if (info.origActivity != null) {

243 intent.setComponent(info.origActivity);

244 }

245

246// Skip the current home activity.

247if (homeInfo != null) {

248if (homeInfo.packageName.equals(

249 intent.getComponent().getPackageName())

250 && https://www.wendangku.net/doc/c115038954.html,.equals(

251 intent.getComponent().getClassName())) { 252continue;

253 }

254 }

255

256

intent.setFlags((intent.getFlags()&~Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) 257 | Intent.FLAG_ACTIVITY_NEW_TASK);

258final ResolveInfo resolveInfo = pm.resolveActivity(intent, 0); 259if (resolveInfo != null) {

260final ActivityInfo activityInfo = resolveInfo.activityInfo; 261final String title = activityInfo.loadLabel(pm).toString(); 262 Drawable icon = activityInfo.loadIcon(pm);

263

264if (title != null && title.length() > 0 && icon != null) { 265final TextView tv = mIcons[index];

266 tv.setText(title);

267 icon = iconUtilities.createIconDrawable(icon);

268 tv.setCompoundDrawables(null, icon, null, null);

269 RecentTag tag = new RecentTag();

270 https://www.wendangku.net/doc/c115038954.html, = info;

271 tag.intent = intent;

272 tv.setTag(tag);

273 tv.setVisibility(View.VISIBLE);

274 tv.setPressed(false);

275 tv.clearFocus();

276 ++index;

277 }

278 }

279 }

280

281// handle the case of "no icons to show"

282 mNoAppsText.setVisibility((index == 0) ? View.VISIBLE : View.GONE); 283

284// hide the rest

285for (; index < NUM_BUTTONS; ++index) {

286 mIcons[index].setVisibility(View.GONE);

287 }

288 }

289

290/**

291 * This is the listener for the ACTION_CLOSE_SYSTEM_DIALOGS intent. It's an indication that

292 * we should close ourselves immediately, in order to allow a higher-priority UI to take over

293 * (e.g. phone call received).

294*/

295private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {

296 @Override

297public void onReceive(Context context, Intent intent) {

298 String action = intent.getAction();

299if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {

300 String reason =

intent.getStringExtra(PhoneWindowManager.SYSTEM_DIALOG_REASON_KEY);

301if (!

PhoneWindowManager.SYSTEM_DIALOG_REASON_RECENT_APPS.equals(reason)) {

302 dismiss();

303 }

304 }

305 }

306 };

307 }

从源码可以看出,关键部分有三处。

一个很关键的内部类:

// 每个任务都包含一个Tag,这个Tag保存着这个App的一些非常有用的信息

class RecentTag {

ActivityManager.RecentTaskInfo info;

Intent intent;

}

这个RecentTag保存在每个近期任务的图标里,并且保存着这个任务的原始信息。

刚启动Dialog时对每个任务的初始化:

1private void reloadButtons() {

2

3final Context context = getContext();

4final PackageManager pm = context.getPackageManager();

5final ActivityManager am = (ActivityManager)

6 context.getSystemService(Context.ACTIVITY_SERVICE);

7

8//拿到最近使用的应用的信息列表

9final List recentTasks =

10 am.getRecentTasks(MAX_RECENT_TASKS,

ActivityManager.RECENT_IGNORE_UNAVAILABLE);

11

12//自制一个home activity info,用来区分

13 ActivityInfo homeInfo =

14new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME) 15 .resolveActivityInfo(pm, 0);

16

17 IconUtilities iconUtilities = new IconUtilities(getContext());

18

19int index = 0;

20int numTasks = recentTasks.size();

21//开始初始化每个任务的信息

22for (int i = 0; i < numTasks && (index < NUM_BUTTONS); ++i) {

23final ActivityManager.RecentTaskInfo info = recentTasks.get(i); 24

25//复制一个任务的原始Intent

26 Intent intent = new Intent(info.baseIntent);

27if (info.origActivity != null) {

28 intent.setComponent(info.origActivity);

29 }

30

31//跳过home activity

32if (homeInfo != null) {

33if (homeInfo.packageName.equals(

34 intent.getComponent().getPackageName())

35 && https://www.wendangku.net/doc/c115038954.html,.equals(

36 intent.getComponent().getClassName())) {

37continue;

38 }

39 }

40

41

intent.setFlags((intent.getFlags()&~Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) 42 | Intent.FLAG_ACTIVITY_NEW_TASK);

43final ResolveInfo resolveInfo = pm.resolveActivity(intent, 0); 44if (resolveInfo != null) {

45final ActivityInfo activityInfo = resolveInfo.activityInfo; 46final String title = activityInfo.loadLabel(pm).toString();

47 Drawable icon = activityInfo.loadIcon(pm);

48

49if (title != null && title.length() > 0 && icon != null) {

50final TextView tv = mIcons[index];

51 tv.setText(title);

52 icon = iconUtilities.createIconDrawable(icon);

53 tv.setCompoundDrawables(null, icon, null, null);

54//new一个Tag,保存这个任务的RecentTaskInfo和Intent

55 RecentTag tag = new RecentTag();

56 https://www.wendangku.net/doc/c115038954.html, = info;

57 tag.intent = intent;

58 tv.setTag(tag);

59 tv.setVisibility(View.VISIBLE);

60 tv.setPressed(false);

61 tv.clearFocus();

62 ++index;

63 }

64 }

65 }

66

67 ...//无关紧要的代码

68 }

这里的过程是:先用ActivityManager获取RecentTasks并生成一个List,然后利用这个List为Dialog中的每个任务初始化,并生成对应的信息RecentTag。

需要注意的是,RecentTag中的Intent是从对应任务的原始Intent复制过来的,这意味着那个原始Intent的一些Extra参数将会一并复制过来,

我来举个例子:比如我的App支持从第三方启动,并且第三方要提供一个token,当然这个token就以Extra参数的形式放进Intent里,然后通过startActivity()启动我的App;然后我的App根据这个token来处理,注意这里,当我的App退出后,再从近期任务里启动这个App,之前的那个token还会传递给我的App,这里就会出现错误了,原因就是上面分析的。这就是为什么从第三方跳转的应用不会出现在近期任务的列表里(比如点击短信里的url启动一个浏览器,之后近期任务里只有短信app,不会出现浏览器app)。要想不出现在近期任务里,可以给Intent设置FLAG_ACTIVITY_NO_HISTORY标志。

响应每个任务的点击事件:

1private void switchTo(RecentTag tag) {

2if (https://www.wendangku.net/doc/c115038954.html,.id >= 0) {

3// 这个Task没有退出,直接移动到前台

4final ActivityManager am = (ActivityManager)

5 getContext().getSystemService(Context.ACTIVITY_SERVICE);

6 am.moveTaskToFront(https://www.wendangku.net/doc/c115038954.html,.id, ActivityManager.MOVE_TASK_WITH_HOME);

7 } else if (tag.intent != null) {

8//task退出了的话,id为-1,则使用RecentTag中的Intent重新启动

9 tag.intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY

10 | Intent.FLAG_ACTIVITY_TASK_ON_HOME);

11try {

12 getContext().startActivity(tag.intent);

13 } catch (ActivityNotFoundException e) {

14 Log.w("Recent", "Unable to launch recent task", e);

15 }

16 }

17 }

如果该Task没有退出,只是切到后台,则切换到前台;如果已经退出,就要重新启动了。

这里的Intent就是之前说的,重复使用的旧Intent了,这里注意,系统添加了FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY和FLAG_ACTIVITY_TASK_ON_HOME标志,所以我们可以在App中通过判断Intent的flag是否包含这两个来判断是否是从近期任务里启动的。注意FLAG_ACTIVITY_TASK_ON_HOME标志是Api 11添加的,所以11一下的之判断

权限说明大全

程序执行需要读取到安全敏感项必需在androidmanifest.xml中声明相关权限请求, 各种权限说明如下: android.permission.ACCESS_CHECKIN_PROPERTIES 允许读写访问”properties”表在checkin数据库中,改值可以修改上传( Allows read/write access to the “properties” table in the checkin database, to change values that get upload ed) android.permission.ACCESS_COARSE_LOCATION 允许一个程序访问CellID或WiFi热点来获取粗略的位置(Allows an application to access coarse (e.g., Cell-ID, WiFi) location) android.permission.ACCESS_FINE_LOCATION 允许一个程序访问精良位置(如GPS) (Allows an application to access fine (e.g., GPS) location) android.permission.ACCESS_LOCATION_EXTRA_COMMANDS 允许应用程序访问额外的位置提供命令(Allows an application to access extra location provider commands) android.permission.ACCESS_MOCK_LOCA TION 允许程序创建模拟位置提供用于测试(Allows an application to create mock location providers for testing) android.permission.ACCESS_NETWORK_STA TE 允许程序访问有关GSM网络信息(Allows applications to access information about networks) android.permission.ACCESS_SURFACE_FLINGER 允许程序使用SurfaceFlinger底层特性(Allows an application to use SurfaceF linger’s low level features) android.permission.ACCESS_WIFI_STATE 允许程序访问Wi-Fi网络状态信息(Allows applications to access information about Wi-Fi networks) android.permission.ADD_SYSTEM_SERVICE 允许程序发布系统级服务(Allows an application to publish system-level services). android.permission.BA TTERY_STATS 允许程序更新手机电池统计信息(Allows an application to update the collected battery statistics) android.permission.BLUETOOTH 允许程序连接到已配对的蓝牙设备(Allows applications to connect to paired bluetooth devices) android.permission.BLUETOOTH_ADMIN 允许程序发现和配对蓝牙设备(Allows applications to discover and pair bluetooth devices) android.permission.BRICK 请求能够禁用设备(非常危险)(Required to be able to disable the device (very *erous!).) android.permission.BROADCAST_PACKAGE_REMOVED 允许程序广播一个提示消息在一个应用程序包已经移除后(Allows an application to broadcast a notification that an application package has been removed) android.permission.BROADCAST_STICKY 允许一个程序广播常用intents(Allows an application to broadcast sticky intents) android.permission.CALL_PHONE

Android用户权限列表

我们在安装Android软件的时候,系统会提示该软件所需要的权限,相对于其他系统,android的权限非常多。我们在开发软件的时候,也需要声明相应的权限,比如希望软件能发短信,需要声明软件调用短信的权限,否则软件运行的时候就会报错。 Android的权限在AndroidManifest.xml文件里配置。AndroidManifest文件中有四个标签与permission有关,它们分别是 。其中最常用的是 ,当我们需要获取某个权限的时候就必须在我们的manifest文件中声明 。 [html]view plain copy 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. ... 11. 12. 的作用相似,两者之间的不同之处, 是android预定义的权限,是自己定义的权 限。 用的相对较少, 这两个标签就更少见了,简单说 就是声明一个标签,该标签代 表了一组permissions,而是为一组permissions声明了一个namespace。后面三个标签具体使用方法见后续文章。 定义方法如下:

Android权限清单

允许读写访问"properties"表在checkin数据库中,改值可以修改上传 允许一个程序访问CellID或WiFi热点来获取粗略的位置 允许一个程序访问精良位置(如GPS) < uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" > 允许应用程序访问额外的位置提供命令 允许程序创建模拟位置提供用于测试 允许程序访问有关GSM网络信息 允许程序使用SurfaceFlinger底层特性 允许程序访问Wi-Fi网络状态信息 允许程序发布系统级服务 允许程序更新手机电池统计信息 允许程序连接到已配对的蓝牙设备 允许程序发现和配对蓝牙设备 请求能够禁用设备 允许程序广播一个提示消息在一个应用程序包已经移除后 允许一个程序广播常用intents

Android permission 访问权限说明手册

Android permission 访问权限说明手册 tech.er 2011年2月12日 android平台上的权限许可分得很细,如果软件无法正常执行时,首先要检查是不是缺少相关的permission声明,以下就把permission 访问权限列举出来供大家参考。 程序执行需要读取到安全敏感项必需在androidmanifest.xml中声明相关权限请求, 完整列表如下: android.permission.ACCESS_CHECKIN_PROPERTIES 允许读写访问”properties”表在checkin数据库中,改值可以修改上传( Allows read/write access to the “properties” table in the checkin database, to change values that get uploaded) android.permission.ACCESS_COARSE_LOCATION 允许一个程序访问CellID或WiFi热点来获取粗略的位置(Allows an application to access coarse (e.g., Cell-ID, WiFi) location) android.permission.ACCESS_FINE_LOCATION 允许一个程序访问精良位置(如GPS) (Allows an application to access fine (e.g., GPS) location) android.permission.ACCESS_LOCATION_EXTRA_COMMANDS 允许应用程序访问额外的位置提供命令(Allows an application to access extra location provider commands) android.permission.ACCESS_MOCK_LOCATION 允许程序创建模拟位置提供用于测试(Allows an application to create mock location providers for testing) android.permission.ACCESS_NETWORK_STATE 允许程序访问有关GSM网络信息(Allows applications to access information about networks) android.permission.ACCESS_SURFACE_FLINGER 允许程序使用SurfaceFlinger底层特性(Allows an application to use SurfaceFlinger’s low level features) android.permission.ACCESS_WIFI_STATE 允许程序访问Wi-Fi网络状态信息(Allows applications to access information about Wi-Fi networks) android.permission.ADD_SYSTEM_SERVICE 允许程序发布系统级服务(Allows an application to publish system-level services). android.permission.BATTERY_STATS 允许程序更新手机电池统计信息(Allows an application to update the collected battery statistics) android.permission.BLUETOOTH

Android权限大全

Android权限大全 允许程序写入外部存储,如SD卡上写文件 录音 允许编写短信 允许读写系统设置项 允许程序读写系统安全敏感的设置项 允许程序写入Google Map服务数据 写入联系人,但不可读取 写入日程,但不可读取 写入网络GPRS接入点设置 允许程序在手机屏幕关闭后后台进程仍然运行 允许振动 允许程序使用SIP视频服务 允许程序请求验证从AccountManager 更新设备状态 显示系统窗口 入或修改订阅内容的数据库 访问订阅信息的数据库

安卓平板电脑ROOT权限说明

安卓平板电脑ROOT权限说明 就在我前面一节中就给大家提到过ROOT相关问题,此篇将给大家详细讲解ROOT权限,如果你以前经常去各大论坛一定也会接触到“ROOT”,他的出现频率很高,在各个论坛上,网友的字里行间经常会出现,那么ROOT权限是什么呢?可以给我们带来怎样的好处呢? 什么是root,我需要它做什么? root就是平板电脑的神经中枢,它可以访问和修改你平板电脑几乎所有的文件,这些东西可能是生产平板电脑的公司不愿意你修改和触碰的东西,因为他们有可能影响到平板电脑的稳定,还容易被一些黑客入侵(Root是Linux等类UNIX系统中的超级管理员用户帐户,该帐户拥有整个系统至高无上的权利,所有对象他都有可以操作的权利,所以很多黑客在入侵系统时,都要把权限提升到Root权限,就是将自己的非法帐户添加到Root用户组。类比于Administrator是Windows NT内核系统中的超级管理员用户帐户,也拥有最高的权限。但不同的是,在WINDOWS下Administrator的资源和别的用户资源是共享的,简单的说,别的用户可以访问Administrator的文件。而Linux中,别的用户是不能访问Root用户的家目录(/root)下文件的。因此,Linux比Windows更安全) 既然root权限这么重要,我们为什么还要去获取它? 其实用root的权限主要是因为我们很多东西是受限制的,我们只能利用这些权限来做我们被限制的去做的事情,比如Google禁止我们看到市场里很多免费或付费软件,我们可以用Marketenabler进去看;很多朋友只能看不能下,不能绑定gmail,我们可以修改hosts 来搞定他们,但这些都需要root权限(由于Root权限对于系统具有最高的统治权,便可方便的对于系统的部件进行删除或更改。对于玩家而言,最大的诱惑是在于“刷机”,只有获得Root权限,我们便可随心所欲地对自己的爱机进行“重新包装”,感受新版本软件的优点) 取得root的好处? 1 可以备份系统 2 使用高级的程序例如资源管理器 3 修改系统的程序 4 把程序安装在SD卡上(默认是不支持的) 绝大多数自制的rom都已经获取了root,如果你的rom没有的话,就要自己取得。 很重要的提示:如果你的平板电脑是行货,在保修之内,获取root就会丧失保修的权利。不知道通过以上内容,你是否对root权限有了更为透彻的了解了呢?当然ROOT也应该根据我们所需,如果你是个爱玩,爱研究平板电脑的机友,那么root权限就会对你很重要,但是如果你只是用平板电脑看看网页,看看电影,上上QQ,那么root显然和你没什么关系

AndroidManifest.xml配置文件详解

AndroidManifest.xml配置文件对于Android应用开发来说是非常重要的基础知识,本文旨在总结该配置文件中重点的用法,以便日后查阅。下面是一个标准的AndroidManifest.xml文件样例。 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. . . . 33. 34. 35. 36. 37. 38. . . . 39. 40.

Android权限说明

Android权限分的很细,但命名比较人性化,Android permission比SymbianCapabilities有了不少改进,下面就来看看权限许可都有哪些定义吧,发现还是比较繁多的,如果发现你的程序某个地方调试错误很可能是Androidpermission 的访问控制在作怪,这也是为了安全防止手机成为病毒的场所。Android开发网获取到的消息来看不用购买高昂的数字签名证书,权限许可权由用户决定而不是手机制造商和平台提供商,这一点不得不说明为Android开发人员着想,下面的信息都是需要添加在androidmanifest.xml文件中。 程序执行需要读取到安全敏感项必需在androidmanifest.xml 中声明相关权限请求,Android开发网已经翻译并使用中英文对照 android.permission.ACCESS_CHECKIN_PROPERTIES允许读写访问"properties"表在checkin数据库中,改值可以修改上传( Allows read/write access to the "properties" table inthe checkin database, to change values that get uploaded) android.permission.ACCESS_COARSE_LOCATION允许一个程序访问CellID或WiFi热点来获取粗略的位置(Allows an application to access coarse (e.g., Cell-ID, WiFi)location) android.permission.ACCESS_FINE_LOCATION允许一个程序访问精良位置(如GPS) (Allows an application to access fine(e.g., GPS) location)

安卓开发手机权限大全

android.permission.ACCESS_NETWORK_STATE允许程序访问有关GSM网络信息(Allowsapplications to access information about networks) android.permission.ACCESS_WIFI_STATE允许程序访问Wi-Fi网络状态信息(Allowsapplications to access information about Wi-Fi networks) android.permission.BLUETOOTH允许程序连接到已配对的蓝牙设备(Allowsapplications to connect to paired bluetooth devices) android.permission.BLUETOOTH_ADMIN允许程序发现和配对蓝牙设备(Allowsapplicationsto discover and pair bluetooth devices) android.permission.CHANGE_WIFI_STATE允许程序改变Wi-Fi连接状态(Allowsapplications to change Wi-Fi connectivity state) android.permission.DEVICE_POWER允许访问底层电源管理(Allowslow-level access to power management)

android.permission.DISABLE_KEYGUARD允许程序禁用键盘锁(Allowsapplications to disable the keyguard ) android.permission.EXPAND_STATUS_BAR允许一个程序扩展收缩在状态栏,Android开发网提示应该是一个类似WindowsMobile中的托盘程序(Allows an application to expand or collapse the status bar.) android.permission.GET_DETAILED_TASKS 检索正在运行的应用的详细信息,恶意程序可借此获得其他应用的私密信息 android.permission.GET_TASKS 检索正在运行的应用,可用于了解当前设备上使用了哪些应用 android.permission.INJECT_EVENTS 将自身的输入事件(例如按键)提供给其他应用,恶意程序可坚持控制手机 android.permission.INTERNAL_SYSTEM_WINDOW 允许创建未授权的内部系统窗口,普通应用绝不应该使用此权限

Android开发之- API包类最全面说明

android-->包含应用平台和在定义应用程序所用到android系统功能的应用权限的资料文件类, android.accessibilityservice-->这个包中的类用于为无障碍服务的开发提供替代或增强的反馈给用户 android.accounts--> android.animation-->这些类提供动画系统的功能特性,它允许使用任何类型的动画对象属性,int,float和16进制颜色值都是默认支持的,也可以通过自定义一个动画让告诉应用按你的设置去运行 android.app-->封装好的Andorid全部应用程序模型类 android.app.admin-->提供系统级的设备管理功能,允许您创建安全感知的应用程序用于android系统企业级别的设置,如可以让你的应用程序也能执行屏幕锁定,屏幕亮度调节、出厂设置等功能 android.app.backup-->此包下的类包含了备份和修复应用程度功能的,如果用户清除设备上的数据或升级到一个新的系统,当应用程序在重新安装时可通过已启用的备份用于修复用户之前的数据 android.appwidget-->此包下的类包含在创建一个应用小部件时所必需要组件,用户可将它嵌入在其他应用程序(如主屏幕),无需启动一个新的活动就可快速访问自身应用程序的数据和服务, android.bluetooth-->此包下的类提供手机蓝牙管理功能,例如搜索设备,连接设备,管理设备之间的数据的传输, android.content-->设备上的数据访问和发布。 android.content.pm-->此包下的类提供访问一个应用包的相应信息,信息内容包括:活动,权限,服务,应用签名,提供者, android.content.res-->此包下的类用于访问应用程序的资源,例如:原文件,颜色,图片,多媒体等,和一些可影响设备运行的重要配置的详细信息 android.database-->此包下类的用于探索通过内容提供者返回的数据 android.database.sqlite-->此包下类的包含SQLITE数据库管理类,用于一个应用程序去管理的它所拥有的私有的数据库 android.drm-->此包下的用于管理DRM系统机制和控件DRM机制的插件的功能,DRM解释:DRM提供一套机制对用户使用手机上的媒体内容(如ringtong, mp3等)进行限制,如限制拷贝给第三方,限制使用次数或时限等,从而保护内容提供商的权利, android.gesture-->此包下的类用于创建,识别,加载,保存一个手势 android.graphics-->此包下的类提供一些低级的绘图功具,例如:画布,颜色过滤,顶点坐标,和长方形以便于发开者的绘图直接处理在设备屏幕上, android.graphics.drawable.shapes-->此包下的类用于几何绘图 android.hardware-->提供支持硬件功能的类,例如:照像机和其它传感器 android.hardware.input--> https://www.wendangku.net/doc/c115038954.html,b-->提供支持android系统设备的USB接口与外围设备的相连 android.inputmethodservice-->输入法的基类 android.location-->包括的类用于定义android地理位置和与此关系的服务 android.media-->提供管理各种各样音频和视频接口的类 android.media.audiofx-->提供管理多媒体框架中实现的音频效果的 android.media.effect-->提供允许你运用各种图像和视频的视觉效果的类 android.mtp-->提供的API让你直接连接照像机和其它设备与之互动,

基于权限分类的Android静态检测

基于权限分类的Android应用程序的静态分析 吴俊昌1,骆培杰1,程绍银1,王嘉捷2,蒋凡1 (1. 中国科学技术大学信息安全测评中心,合肥230027;2. 中国信息安全测评中心,北京100085) 摘要:Android系统有着严格的权限管理机制,应用程序需要获得相应的权限才可以在Android系统上运行。本文提出了一种基于Android权限分类的静态分析方法,用于检测Android应用程序的恶意代码。为了便于处理Android中的大量权限,将其权限划分成四个等级,并将能与外界进行信息交互的权限视为锚点,引入灰函数来描述其他权限所对应的函数,然后利用块与函数变量关联表生成引擎构建块和函数变量关联表,采用静态污点传播和其他静态分析技术相结合的方法对变量关联表进行分析。实验结果表明该方法在分析Android应用程序时是有效的,能够大大减少人为的分析难度和强度。 关键字:恶意应用;软件分析;静态分析;Android 中图分类号:TP302.1 文献标识码:A Static Analysis of Android Apps Based on Permission classification WU Junchang1, LUO Peijie1, CHENG Shaoyin1, WANG Jiajie2, JIANG Fan1 (1. Information Technology Security Evaluation Center, University of Science and Technology of China, Hefei 230027, China; 2. China Information Technology Security Evaluation Center, Beijing 100085, China) Abstract: Android has a strict management mechanism of permissions. If an application wants to run on Android, it must have some suitable permissions. In this paper, a permission-based algorithm of static analysis is presented, which is applied to detect malcode of Android apps. In order to deal with so many permissions, these permissions are divided into four groups. And set the permissions, which can interact with internet or smartphones, as sink function. Use grey function to describe other permissions. Then use block and function analyzer to construct variables’ associating table of block and function. At last use static taint propagation and other static methods to analyze the variables’ associating table. The result of experiment proves that the algorithm is efficient, also can help analyst-programmer reduce the difficulty and intensity of work. Keywords: malware; software analysis; static analysis; Android 随着科学技术的进步和生产力水平的不断提高以智能手机为代表的便携式智能终端便在时下流行起来。与以前的个人计算机的发展所面临的问题一样,智能手机上的安全问题日益凸显出来。智能手机不但有丰富的功能,而且还可以添加各种扩充功能的软件,这就为恶意软件提供生存环境,且智能手机可以保存用户各种帐号及密码等涉及用户隐私的信息,从而给智能手机用户带来巨大经济损失和精神上伤害。 恶意软件虽然是在智能手机上运行的,但是其在各种特征上与在计算机上运行的软件并无很大差异,所以完全可以借鉴传统的软件分析技术对其进行分析。随着软件业的发展,计算机软件分析技术也得到了迅速的发展[1]。静态分析是一种不需运行软件就可以对软件进行分析的过程,常见的有:数据流分析、控制流分析、类型分析等;符号执行[2,3]也 收稿日期: 2011-05-31 基金项目:中央高校基本科研业务费专项资金资助(WK0110000007) 作者简介:吴俊昌(1986-),男(汉),安徽,硕士研究生 通讯作者: 程绍银,讲师,E-mail: sycheng@https://www.wendangku.net/doc/c115038954.html, 是常用的分析技术,是一种路径敏感的分析策略,需综合考虑路径调度、约束求解等问题。 Android系统有着严格的权限管理机制,应用软件如果想在系统中运行就必须要有相应的运行权

android的用户权限

android.permission.ACCESS_CHECKIN_PROPERTIES 允许读写访问”properties”表在checkin数据库中,改值可以修改上传( Allows read/write access to the “properties”table in the checkin database, to change values that get uploaded) android.permission.ACCESS_COARSE_LOCA TION 允许一个程序访问CellID或WiFi热点来获取粗略的位置(Allows an application to access coarse (e.g., Cell-ID, WiFi) location) android.permission.ACCESS_FINE_LOCA TION 允许一个程序访问精良位置(如GPS) (Allows an application to access fine (e.g., GPS) location) android.permission.ACCESS_LOCA TION_EXTRA_COMMANDS 允许应用程序访问额外的位置提供命令(Allows an application to access extra location provider commands) android.permission.ACCESS_MOCK_LOCA TION 允许程序创建模拟位置提供用于测试(Allows an application to create mock location providers for testing) android.permission.ACCESS_NETWORK_STA TE 允许程序访问有关GSM网络信息(Allows applications to access information about networks) android.permission.ACCESS_SURFACE_FLINGER 允许程序使用SurfaceFlinger底层特性(Allows an application to use SurfaceFlinger’s low level features) android.permission.ACCESS_WIFI_STA TE 允许程序访问Wi-Fi网络状态信息(Allows applications to access information about Wi-Fi networks) android.permission.ADD_SYSTEM_SERVICE 允许程序发布系统级服务(Allows an application to publish system-level services). android.permission.BA TTERY_STA TS 允许程序更新手机电池统计信息(Allows an application to update the collected battery statistics) android.permission.BLUETOOTH 允许程序连接到已配对的蓝牙设备(Allows applications to connect to paired bluetooth devices) android.permission.BLUETOOTH_ADMIN 允许程序发现和配对蓝牙设备(Allows applications to discover and pair bluetooth devices) android.permission.BRICK 请求能够禁用设备(非常危险)(Required to be able to disable the device (very *erous!).)

五种控制Android应用的权限的方法

五种控制Android应用的权限的方法 这篇文章目的在于介绍Android系统上控制权限的方法,读者只要使用过Android,或是对智能机平台有所了解,就能看懂,不需要专门的编程知识。 1 为什么Android总是事无巨细地告诉你应用索取的每一项权限? 相比Apple,Microsoft严格控制生态系统(从苹果给开发者的"App Store Guideline"可见一斑),只允许通过官方应用商店安装应用,并对每份上传进行仔细地审查而言,Android的开放就意味着,Google需要向用户提供一系列用于为自己负责的流程、工具。所以在安装应用前,Android总是要事无巨细地告诉你,应用肯需要控制什么权限。 同样,开发者也制作了一系列易用的工具,用以鉴别可疑的应用程序,或是控制权限。

图1 Android 官方市场会强制提醒用Andoird哪里开放了?

在Android中,用户能自由从本地安装应用,自由地对SD卡进行操作,自由选择应用市场。 如果愿意放弃保修,用户还能轻易地实行root,解锁基带(baseband)。只有一些产品会严密地锁定bootloader(如摩托罗拉)。 最重要的是,因为ASOP(Android源代码开放计划)的存在,绝大部分的Android代码都是开源的,开发者可以由此对Android系统进行深入的修改,甚至可以自行编写一个符合Android规范的系统实例(如Cyanogen Mod)。正是因为ASOP,这篇文章才可能介绍多达5种原理不同的权限控制方法。 图2 Android开源计划的标志 开放的风险 不考虑Symbian,Windows Phone 6.5(及以下)平台,那么几乎所有的智能手机病毒都是Android平台的,甚至官方Android Market也闹过几次乌龙。在国内水货横行的市场,情况更是火上浇油,不法业者可以在手机的ROM,甚至是bootloader中做好手脚,让用户有病无法医。 在Android中,用户可以允许系统安装来自"未知源"(也就是非Google 官方的,或手机预置市场的)应用程序。于是,移动平台最重要的门神------数字签名就被绕过了。

Android一些常用权限

An droid 权限 随着An droid 手机版本的不断更新,An droid 手机的的开发需要的东西越来越 多,对于手机更新,An droid 一些权限往往不能在文件中使用,所以,一些权限 需要动态获取;例如,用户可以选择给予相机应用相机的权限但是不允许使用设 备位置的权限。用户可进入应用设置随时撤销权限。 系统权限被分为两种类型,正常的(normal )和敏感的(dangerous ): 正常的权限不会直接让用户的隐私处于危险中。 如果你的应用在清单文件中列入 了正常的权限,系统会自动允许这些权限。 敏感权限给予应用方位用户的机密数据。如果你的应用在清单文件中列入危险类 权限,会明确地让用户对你的应用允许权限。 在所有的An droid 版本中,你的应用需要在清单文件中去申明它需要的正常的和 危险的权限。然而,声明的影响是不同的,依赖于系统版本和你应用的目标 SDK 等级: 如果设备运行在An droid 或更低,或者你的应用的target SDK 是22或者更低; 如果你在清单文件中加入了敏感权限,当他们在安装应用的时候必须同意权限; 如果他们不同意权限,系统则不会安装应用。 如果设备运行在An droid 或更高的版本,或者你的应用的 target SDK 是 23或者 更高。应用必须在manifest 文件中加入权限,而且在应用运行过程中必须在它需 要的时候请求每一个危险的权限。用户可以允许或者拒绝每一个权限,即使用户 拒绝了一个权限的请求而应用可以在限制功能地继续运行。 正常权限: ,读取或写入登记check-in 数据库属性表的权限 ,通过WiFi 或移动基站的方式获取用户错略的经纬度信息, 定位精度大 概误差在30?1500米 在(API 23) 中,下面权限被定义为正常权限 访问登记属 获取错略位

相关文档
相关文档 最新文档