Application with MTK preset detachable

Source: Internet
Author: User

Create a new system bin to copy the APK when it is started. The specific implementation is as follows:

1. This is a feature. To enable or disable this function for various projects, you need to define macro control;

Add:

Rgk_preinstall_app_uninstall = Yes

 

2. Create a folder under Code \ External:

This folder contains the files required for this bin. Name customization. do not duplicate the name with the existing bin. Here we set it to userapp, and create a c file under userapp to copy the APK:

Create copyapp. C:

# Include <ctype. h>

# Include <errno. h>

# Include <fcntl. h>

# Include <getopt. h>

# Include <limits. h>

# Include <Linux/input. h>

# Include <stdio. h>

# Include <stdlib. h>

# Include <string. h>

# Include <sys/reboot. h>

# Include <sys/STAT. h>

# Include <sys/types. h>

# Include <time. h>

# Include <unistd. h>

# Include <dirent. h>

 

# Define buffer_size 1024

 

Static void copy_file (char * SRC, char * DST)

{

Intsrc_fd, dst_fd;

Intbytes_read, bytes_write;

Charbuffer [buffer_size];

Char * PTR;

If (src_fd = open (SRC, o_rdonly) =-1 ){

}

If (dst_fd = open (DST, o_wronly | o_creat, s_irusr | s_iwusr | s_irgrp | s_iroth) =-1 ){

}

While (bytes_read = read (src_fd, buffer, buffer_size ))

{

If (bytes_read =-1) & (errno! = Eintr ))

{

Break;

}

Else if (bytes_read> 0)

{

PTR = buffer;

While (bytes_write = write (dst_fd, PTR, bytes_read ))

{

If (bytes_write =-1) & (errno! = Eintr ))

{

Break;

}

Else if (bytes_write = bytes_read)

Break;

Else if (bytes_write> 0)

{

PTR + = bytes_write;

Bytes_read-= bytes_write;

}

}

If (bytes_write =-1)

{

Break;

}

}

}

Close (src_fd );

Close (dst_fd );

}

 

Int main (){

Int fdcheck = 0;

If (fdcheck = open ("/data/APP/copyapp.txt", o_rdonly) <0)

{

Struct dirent ** dataapplist;

Int app_num =-1;

App_num = scandir ("/data/APP", & dataapplist, 0, alphasort );

If (app_num <0)

{

;

}

Else

{

Int I = 0;

For (; I <app_num; I ++)

{

Charapp_name [256] = "/data/APP /";

Strcat (app_name, dataapplist [I]-> d_name );

Remove (app_name );

Free (dataapplist [I]);

}

Free (dataapplist );

}

}

Else

{

Close (fdcheck );

Return exit_success;

}

 

Structdirent ** namelist;

Intfile_num = scandir ("/system/pre_install", & namelist, 0, alphasort );

If (file_num <0)

{

;

}

Else

{

Int ret = mkdir ("/data/APP", s_irwxu | s_irwxg | s_irwxo );

If (Ret! = 0)

{

}

Int I = 0;

For (; I <file_num; I ++)

{

Char src_name [256] = "/system/pre_install /";

Char dst_name [256] = "/data/APP /";

If (strstr (namelist [I]-> d_name, ". APK "))

{

Strcat (src_name, namelist [I]-> d_name );

Strcat (dst_name, namelist [I]-> d_name );

// Copy/system/pre_install/xx.apk to/data/APP/xx.apk

Copy_file (src_name, dst_name );

}

Free (namelist [I]);

}

Free (namelist );

}

Fdcheck = open ("/data/APP/copyapp.txt", o_wronly | o_creat, s_irusr | s_iwusr | s_irgrp | s_iroth );

Close (fdcheck );

Returnexit_success;

}

 

3. Create an MK file under userapp:

Create Android. mk:

Ifeq ($ (Strip $ (rgk_preinstall_app_uninstall), yes)

Local_path: = $ (call my-DIR)

Include $ (clear_vars)

Local_src_files: = copyapp. c

Local_module: = userapp

Include $ (build_executable)

Endif

 

4. Add the implemented bin to init. Rc. Add the following to init. RC under code/mediatek \ config \ ratech75cu_nand_gb2:

Service userapp/system/bin/userapp

Oneshot

It indicates that our bin is executed once during initialization.

 

5. Add the following to the user_tags.mk file in the code/build/Core directory:

Grandfathered_user_modules + = userapp

6. Create the pre_install directory under the Code \ vendor directory, which stores the app files pre-installed and detachable, and create a new Android. mk file:

Android. mk content:

Ifeq ($ (Strip $ (rgk_preinstall_app_uninstall), yes)

Include $ (clear_vars)

Local_path: = vendor/pre_install

Product_copy_files + = \

$ (Local_path)/qqsecure2.0_android.apk: System/pre_install/qqsecure2.0_android.apk

Endif

7. You need to remove the copy statement of the app in the Android. mk file in the Code \ vendor \ third_party directory.

//////////////////////////////////////// /// // End ///////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////

-------- An detachable Application

1 add userapp/Android. mk

Ifeq ($ (Strip $ (rgk_preinstall_app_uninstall), yes)

Local_path: = $ (call my-DIR)

Include $ (clear_vars)

# Local_module_path: = $ (target_out)/bin

Local_src_files: = copyapp. c

Local_module: = userapp

# Local_module_tags: = optional # Eng user

Include $ (build_executable)

Endif

2 add external/userapp/copyapp. c
# Include <ctype. h>
# Include <errno. h>
# Include <fcntl. h>
# Include <getopt. h>
# Include <limits. h>
# Include <Linux/input. h>
# Include <stdio. h>
# Include <stdlib. h>
# Include <string. h>
# Include <sys/reboot. h>
# Include <sys/STAT. h>
# Include <sys/types. h>
# Include <time. h>
# Include <unistd. h>
# Include <dirent. h>

# Define buffer_size 1024

Static void copy_file (char * SRC, char * DST)
{
Int src_fd, dst_fd;
Int bytes_read, bytes_write;
Char buffer [buffer_size];
Char * PTR;
If (src_fd = open (SRC, o_rdonly) =-1 ){
}
If (dst_fd = open (DST, o_wronly | o_creat, s_irusr | s_iwusr | s_irgrp | s_iroth) =-1 ){
}
While (bytes_read = read (src_fd, buffer, buffer_size ))
{
If (bytes_read =-1) & (errno! = Eintr ))
{
Break;
}
Else if (bytes_read> 0)
{
PTR = buffer;
While (bytes_write = write (dst_fd, PTR, bytes_read ))
{
If (bytes_write =-1) & (errno! = Eintr ))
{
Break;
}
Else if (bytes_write = bytes_read)
Break;
Else if (bytes_write> 0)
{
PTR + = bytes_write;
Bytes_read-= bytes_write;
}
}
If (bytes_write =-1)
{
Break;
}
}
}
Close (src_fd );
Close (dst_fd );
}

Int main (){
Int fdcheck = 0;
If (fdcheck = open ("/data/APP/copyapp.txt", o_rdonly) <0)
{
Struct dirent ** dataapplist;
Int app_num =-1;
App_num = scandir ("/data/APP", & dataapplist, 0, alphasort );
If (app_num <0)
{
;
}
Else
{
Int I = 0;
For (; I <app_num; I ++)
{
Char app_name [256] = "/data/APP /";
Strcat (app_name, dataapplist [I]-> d_name );
Remove (app_name );
Free (dataapplist [I]);
}
Free (dataapplist );

}
}
Else
{
Close (fdcheck );
Return exit_success;
}

Struct dirent ** namelist;
Int file_num = scandir ("/system/pre_install", & namelist, 0, alphasort );
If (file_num <0)
{
;
}
Else
{
Int ret = mkdir ("/data/APP", s_irwxu | s_irwxg | s_irwxo );
If (Ret! = 0)
{

}
Int I = 0;
For (; I <file_num; I ++)
{
Char src_name [256] = "/system/pre_install /";
Char dst_name [256] = "/data/APP /";
If (strstr (namelist [I]-> d_name, ". APK "))
{
Strcat (src_name, namelist [I]-> d_name );
Strcat (dst_name, namelist [I]-> d_name );
// Copy/system/pre_install/xx.apk to/data/APP/xx.apk
Copy_file (src_name, dst_name );
}
Free (namelist [I]);
}
Free (namelist );
}
Fdcheck = open ("/data/APP/copyapp.txt", o_wronly | o_creat, s_irusr | s_iwusr | s_irgrp | s_iroth );
Close (fdcheck );
Return exit_success;
}

3 add build/CORE/user_tags.mk
Add the end:

# Port this by chenweiwei
Ifeq ($ (Strip $ (rgk_preinstall_app_uninstall), yes)
Grandfathered_user_modules + = userapp
Endif

4 rgt_projects/g503hh_d_qc/projectconfig. mk

# Add By chenweiwei for Qingcheng 20120630
Rgt_g503hh_d_custom_qc_support = Yes
# Preinstalled applications can be uninstalled

Rgk_preinstall_app_uninstall = Yes

5 mediatek/build/tools/javaoption. PM

Rgk_preinstall_app_uninstall

6 vendor/pre_install/Android. mk

Ifeq ($ (Strip $ (rgk_preinstall_app_uninstall), yes)
Include $ (clear_vars)
Local_path: = vendor/pre_install

Ifeq ($ (rgt_g503hh_d_custom_qc_support), yes)

Product_copy_files + = \
$ (Local_path)/baidusearch_qc/APK/baidusearch_qc.apk: System/pre_install/baidusearch_qc.apk \
$ (Local_path)/qq_qc/APK/qq2012_qc.apk: System/pre_install/qq2012_qc.apk \
$ (Local_path)/touchpal_qc/APK/touchpal_qc.apk: System/pre_install/touchpal_qc.apk \
$ (Local_path)/qingchengplay_qc/APK/qingchengplay.apk: System/pre_install/qingchengplay.apk

Endif

Endif

7 add mediatek/config/ratech77_ics2/init. Project. RC
Add in the end:
# Port by chenweiwei 20120713 start
Service userapp/system/bin/userapp
Oneshot
# Port by chenweiwei 20120713 end

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.