Android security and permissions ① -- login userid and file access-security and permission

Source: Internet
Author: User

Shareduserid

Summary of shareduserid:

 

We know that each app generally has a unique Linux User ID, so that the permission is set to the file of the application to be visible only to the user and only to the application itself, but we can make them visible to other applications. This will make us use shareduserid, that is, let the two APK use the same userid, so that they can see the object of the other party. To save resources, APK with the same ID can also be performed in the same Linux Process (note that it is not necessary to run in a process) and share a virtual machine.

 

 

 

 

 

 

 

 

We can create two applications, test_a and test_ B. The purpose is to allow test_ B to access the files or data in test_a:

In the test_a application package COM. add anroid: Taobao userid = "com. test2 "(Note: Here test_a is the accessed APK, so with this android: exported =" false ", it indicates that it is private, and then it will make the login userid application more powerful)

The details are as follows:

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <manifest xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> package = "com. test1 "<br/> Android: shareduserid =" com. test2 "<br/> Android: exported =" false "<br/> Android: versioncode =" 1 "<br/> Android: versionname = "1.0"> <br/> <application Android: icon = "@ drawable/icon" Android: label = "@ string/app_name"> <br/> <activity Android: Name = ". testacitvity1 "<br/> Android: Label =" @ string/app_name "> <br/> <intent-filter> <br/> <action Android: Name =" android. intent. action. main "/> <br/> <category Android: Name =" android. intent. category. launcher "/> <br/> </intent-filter> <br/> </activity> <br/> </Application> </P> <p> </manifest>

Then add anroid: Taobao userid = "com. Test2" to manifest. xml under com. Test2 in the application test_ B package"

Then add the following code to testactivity2 of test_ B:

Private button. onclicklistener button_listener = new button. onclicklistener () {<br/> Public void onclick (view v) {<br/> intent = new intent (); </P> <p> intent. setclassname ("us. imnet. iceskysl. DB "," us. imnet. iceskysl. DB. dbsharedpreferences "); <br/> // intent. setclassname ("com. test1 "," com. test1.testactivity1 "); </P> <p> startactivity (intent); <br/>}< br/> };

In this way, you can adjust the jump and then run it. The complete code is:

Package COM. test2; </P> <p> Import android. app. activity; <br/> Import android. content. intent; <br/> Import android. OS. bundle; <br/> Import android. view. view; <br/> Import android. widget. button; </P> <p> public class testactivity2 extends activity {<br/>/** called when the activity is first created. */<br/> @ override <br/> Public void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. main); <br/> find_and_modify_button (); <br/>}< br/> private void find_and_modify_button () {<br/> button change_test1 = (button) findviewbyid (R. id. change_test1); <br/> change_test1.setonclicklistener (button_listener); <br/>}< br/> private button. onclicklistener button_listener = new button. onclicklistener () {<br/> Public void onclick (view v) {<br/> intent = new intent (); </P> <p> intent. setclassname ("us. imnet. iceskysl. DB "," us. imnet. iceskysl. DB. dbsharedpreferences "); <br/> // intent. setclassname ("com. test1 "," com. test1.testactivity1 "); </P> <p> startactivity (intent); <br/>}< br/>}; <br/>}

The running result is: From testactivity1 of test_ B, and then jump to testactivity2 to read the data in it.

File Access:

You can use getsharedpreferences (string, INT), openfileoutput (string, INT), or openorcreatedatabase (string, Int, sqlitedatabase. cursorfactory) when creating a new file, you can simultaneously or separately use the mode_world_readable and mode_world_writeable flag to allow other packages to read/write this file.

The following shows how to use getsharedpreferences (string, INT) to create a file and modify its attribute to mode_world_writeable. Then, the file permission of the file is changed:

(Supplement): file permissions under Linux

2nd ~ Each three of the 10 characters is a group. The three characters on the left indicate the owner permission, and the three characters in the middle indicate the permissions of users in the same group as the owner, the three characters on the right are the permissions of other users. These three groups contain nine characters, which indicate the following meanings:
R (read): For a file, you have the permission to read the file content; for a directory, you have the permission to browse the contents.
W (write): For a file, you have the permission to add or modify the file content. For a directory, you have the permission to delete or move files in the directory.
X (execute): For a file, you have the permission to execute the file. For a directory, you have the permission to enter the directory.
-: Indicates that this permission is not granted.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.