日期:2014-05-16  浏览次数:20951 次

Android安全和权限①----ShareUserId和文件访问(File Access)--Security and Permission

关于SharedUserId的总结:

?我们知道一般每个app都有一个唯一的linux user ID,则这样权限就被设置成该应用程序的文件只对该用户可见,只对该应用程序自身可见,而我们可以使他们对其他的应用程序可见,这会使我们用到 SharedUserId,也就是让两个apk使用相同的userID,这样它们就可以看到对方的文件。为了节省资源,具有相同ID的apk也可以在相同 的linux进程中进行(这儿需要注意,并不是一定要在一个进程里面运行),共享一个虚拟机。

我们可以建立两个application,分别为test_a和test_b,我们的目的就是让test_b访问test_a里面的文件或者是数据:具体做法如下

在test_a应用程序的包com.test1的manifest里面添加anroid:shareuserid=“com.test2”(注:这 儿test_a是被访的apk,so 加上这句? android:exported="false"说明它是私有的,然后会让shareuserid应用更有力)

具体内容如下:

view plain copy to clipboard print ?
  1. <? xml ? version = "1.0" ? encoding = "utf-8" ?> ??
  2. < manifest ? xmlns:android = "http://schemas.android.com/apk/res/android" ??
  3. ??????package = "com.test1" ??
  4. ??????android:sharedUserId = "com.test2" ??
  5. ??????android:exported = "false" ??
  6. ??????android:versionCode = "1" ??
  7. ??????android:versionName = "1.0" > ??
  8. ????< application ? android:icon = "@drawable/icon" ? android:label = "@string/app_name" > ??
  9. ????????< activity ? android:name = ".TestAcitvity1" ??
  10. ??????????????????android:label = "@string/app_name" > ??
  11. ????????????< intent-filter > ??
  12. ????????????????< action ? android:name = "android.intent.action.MAIN" ? /> ??
  13. ????????????????< category ? android:name = "android.intent.category.LAUNCHER"