This article describes the Android programming system restart and shutdown method. Share to everyone for your reference, specific as follows:
Recently in doing something, coincidence encountered the problem of Shareduserid, so collected some information, save archive backup.
Every APK file installed in the device, Android assigns a separate user space to each APK process, and the userid in the manifest is the one that Linux users will be assigned to a unified Linux user ID and create a sandbox for it. To prevent other applications (or other applications from affecting it).
The user ID is assigned when the application is installed in the device, and it is persisted in this device.
Multiple apk with the same user ID through the Shared user ID can be configured to run in the same process. So the default is that you can access arbitrary data to each other. It can also be configured to run as a different process, with access to databases and files in other APK data directories. Just like accessing the data in this program.
For a APK, if you want to use a shared UID, you have to do three steps:
1, add the Android:shareduserid attribute in the Manifest node.
2, add the definition of local_certificate in android.mk.
If the above attribute is added but no corresponding local_certificate is defined, the APK is not installed.
Hint error is:
Package Com.test.MyTest has no signatures that match those in shared user Android.uid.system; ignoring!
In other words, only two application signatures with the same signature and the same Shareduserid label are assigned the same user ID.
For example, all APK associated with media/download use Android.media as Shareduserid, and they must have the same signature media.
3, the source of the APK to the packages/apps/directory, with the MM to compile.
For example.
All apk that use Android.uid.system as the shared UID in the system are first added to the manifest node:
Android:shareduserid= "Android.uid.system"
And then add in the Android.mk.
Local_certificate: = Platform
You can see settings and so on.
All APK that use android.uid.shared as the shared UID in the system will be added to the manifest node
Android:shareduserid= "Android.uid.shared"
And then add in the Android.mk.
Local_certificate: = Shared
You can see launcher, etc.
All APK that use Android.media as the shared UID in the system will be added to the manifest node
Android:shareduserid= "Android.media"
And then add in the Android.mk.
Local_certificate: = Media
You can see gallery and so on.
In addition, any files created by the application are assigned to the user identity of the application and are normally not accessible by other packages.
When you pass Getsharedpreferences (String,int), Openfileoutput (string, int), or OpenOrCreate Database (string, int, Sqlitedatabase.cursorfactory)
When creating a new file, developers can use the mode_world_readable and mode_world_riteable flags to allow other packages to read/write the file at the same time or separately. When these flags are set, the file still belongs to its own application, but its global read/write and read/write permissions are set, so any other application can see it.
about Signatures :
There are four sets of default signatures in the Build/target/product/security directory for Android.mk to use in compilation apk:
1, TestKey: Ordinary APK, use by default.
2, platform: the APK to complete some of the core functions of the system. After a test of access to a folder that exists in the system, the UID of the process that is compiled in this way is System APK.
3. Shared: The APK needs to share data with the home/contacts process.
4. Media: The APK is a link in the Media/download system.
There is a local_certificate field in the application's android.mk that specifies which key signature to use, and the unspecified default TestKey
In the application layer how to implement the Android system restart through the code, share to everyone.
This article is based on the Android system development, so if you are pure app development, you may be disappointed.
The code was successfully tested on the real machine and failed to test on the emulator.
Under Linux, rebooting the PC requires that the non-root user perform sudo reboot, so rebooting the machine under Android also requires certain privileges.
Application interface:
1. Create a new Android project reboot
2. Preparation of ANDROID.MK
Local_path:= $ (call My-dir)
include $ (clear_vars)
local_module_tags: = Optional
Local_src_files: = $ (call All-java-files-under, SRC)
local_package_name: = Reboot
local_certificate: = Platform
include $ (build_ PACKAGE)
# Use the folloing include-to-make, our test apk.
Include $ (call all-makefiles-under,$ (Local_path))
The specific meaning may consult the data by oneself. Attention:
Local_certificate: = Platform
3. Preparation of supplementary Androidmenifest.xml
<?xml version= "1.0" encoding= "Utf-8"?> <manifest xmlns:android=
"http://schemas.android.com/apk/res/" Android "
package=" Mark.zhang "
android:versioncode=" 1 "
android:versionname=" 1.0 ">
< USES-SDK android:minsdkversion= "7"/>
<application
android:icon= "@drawable/ic_launcher"
Android:label= "@string/app_name"
android:shareduserid= "Android.uid.system" >
<activity
Android:label= "@string/app_name"
android:name= ". Rebootactivity ">
<intent-filter >
<action android:name=" Android.intent.action.MAIN "/>
<category android:name= "Android.intent.category.LAUNCHER"/>
</intent-filter>
</ activity>
</application>
</manifest>
Attention:
Android:shareduserid= "Android.uid.system"
4. Write Logical Code Rebootactivity.java
Package Mark.zhang;
Import android.app.Activity;
Import android.content.Intent;
Import Android.os.Bundle;
Import Android.view.View; public class Rebootactivity extends the activity {//Whether Show Shutdown confirmation dialog box//False does not show confirmation shutdown dialog box, direct shutdown/True Display confirmation shutdown dialog box, let the user choose whether
Acknowledge shutdown public static final Boolean showshutdowndialog = false;
@Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
/** * Send broadcast.
* @param view */public void Onreboot (view view) {Intent reboot = new Intent (intent.action_reboot);
Reboot.putextra ("nowait", 1);
Reboot.putextra ("Interval", 1);
Reboot.putextra ("window", 0);
Sendbroadcast (reboot);
}/** * Initiates activity. * @param view */public void OnShutdown (view view) {public void OnShutdown (view view) {Intent Shu
Tdown = new Intent (Intent.action_request_shutdown);
Shutdown.putextra (Intent.extra_key_confirm, Showshutdowndialog);Shutdown.setflags (Intent.flag_activity_clear_top |
Intent.flag_activity_new_task);
StartActivity (shutdown);
}
}
}
Attention:
Intent.action_request_shutdown
intent.extra_key_confirm
An error occurs because the property is {@hide}.
Do not worry about putting it into the system compile, notice the steps below.
5. Put the entire project into the Android source code compiled
A. Manually copy reboot under Src/packages/app
B. Mm-j4 start compiling (refer to the Basics tutorial on Android primer)
If the compilation succeeds, there will be one more reboot.apk file under the/out/target/product/generic/system/app directory.
6. Install APK
The APK must be placed under System/app, the ADB push Reboot.apk/system/app
Thinking :
Shutdown or reboot, one is to send the broadcast, one is to start the activity.
You can find the corresponding class by looking for the appropriate action or string resource, such as the shutdown key.
We know that Framwork's MK files, resource files, and so on are:
/frameworks/base/core/res, Frameworks/base/core/res/res
For example, the activity of the shutdown is Shutdownactiviy, which calls Shutdownthread.shutdown.
The associated class of the reboot is Watchdog.java (The associated amount is defined), and its internal class Rebootrequestreceiver is the main code.
Keep tracking and you'll understand the whole process.
For more information on Android-related content readers can view the site topics: "Android Development Introduction and Advanced Course", "Android Multimedia operating skills Summary (audio, video, recording, etc.)", "Android Basic Components Usage Summary", " Android View tips Summary, Android layout layout tips and a summary of Android controls usage
I hope this article will help you with the Android program.