Moment of android phone disconnection [non-Incoming call]

Source: Internet
Author: User

First, I would like to lament that android is powerful. It can run different Actvity values in the same apk in different processes. For example, I want my app to run Activity IN THE Phone process, so I need to do three things.

This article contains three knowledge points:

1. Listen to power-on and connect to 2.apk to get root permissions 3. push apk to system/app during runtime

(1)

 

[Java]
<Activity
Ndroid: process = "com. android. phone"
Android: label = "@ string/app_name"
Android: name = ". AutoCallActivity">

</Activity>

<Activity
Android: process = "com. android. phone"
Android: label = "@ string/app_name"
Android: name = ". AutoCallActivity">

</Activity> (2)


[Java]
<Manifest xmlns: android = "http://schemas.android.com/apk/res/android"
Package = "com. spreadst. drag"
CoreApp = "true"
Oid: sharedUserId = "android. uid. system"
Android: versionCode = "1"

<Manifest xmlns: android = "http://schemas.android.com/apk/res/android"
Package = "com. spreadst. drag"
CoreApp = "true"
Android: sharedUserId = "android. uid. system"
Android: versionCode = "1"
(3) [java]
LOCAL_PACKAGE_NAME: = autocall
# LOCAL_CERTIFICATE: = shared
LOCAL_CERTIFICATE: = platform

LOCAL_PACKAGE_NAME: = autocall
# LOCAL_CERTIFICATE: = shared
LOCAL_CERTIFICATE: = platform why is this requirement required? In TelephonyManager, the status is only IDLE, incoming call, and outgoing call. See the following in phone:
Phone phone = PhoneFactory. getDefaultPhone ();
This call cannot run in a process other than phone. If you do not believe it, try it. Remember that the Logoff of the main thread of a process is unique.

The reason is as follows:

[Java]
If (slot! = Lorule. mylorule ()){
Throw new RuntimeException (
"PhoneFactory. getDefaultPhone must be called from low.thread ");
}

If (slot! = Lorule. mylorule ()){
Throw new RuntimeException (
"PhoneFactory. getDefaultPhone must be called from low.thread ");
} The code will be hung up after several seconds of power-off. Because hide class is used, it must be compiled under the android source code. Of course, you can also use reflection, AIDL, and class. jar and other methods to solve this problem.


[Java]
CallManager mCM = CallManager. getInstance ();
Phone phone = PhoneFactory. getDefaultPhone ();

MCM. registerPhone (phone );
MCM. registerForPreciseCallStateChanged (mHandler, PHONE_STATE_CHANGED, null );

CallManager mCM = CallManager. getInstance ();
Phone phone = PhoneFactory. getDefaultPhone ();
 
MCM. registerPhone (phone );
MCM. registerForPreciseCallStateChanged (mHandler, PHONE_STATE_CHANGED, null );
[Java]
Private Handler mHandler = new Handler (){

Public void handleMessage (android. OS. Message msg ){
Switch (msg. what ){
Case PHONE_STATE_CHANGED:
UpdatePhoneSateChange ();
Break;
Default:
Break;
}
};

};

Private Handler mHandler = new Handler (){

Public void handleMessage (android. OS. Message msg ){
Switch (msg. what ){
Case PHONE_STATE_CHANGED:
UpdatePhoneSateChange ();
Break;
Default:
Break;
}
};

};
[Java]
Private void updatePhoneSateChange (){
Call fgCall = mCM. getActiveFgCall ();
If (mCM. hasActiveRingingCall ()){
FgCall = mCM. getFirstActiveRingingCall ();
}

Final Call. State state = fgCall. getState ();
Switch (state ){
Case IDLE:
Break;

Case ACTIVE: // power-off
Log. d ("yzy", "ACTVIE ");
Final Timer timer = new Timer ();
If (mode = Mode. mode2 ){
Timer. schedule (new TimerTask (){
@ Override
Public void run (){
Try {
Log. d ("yzy", "endcall ()");

MITelephony. endCall ();
Timer. cancel ();
} Catch (RemoteException e ){
E. printStackTrace ();
}
}
}, HoldonDuration * 1000, holdonDuration * 1000 );
}
// MITelephony. endCall ();
Break;
Default:
Break;
}

}

Private void updatePhoneSateChange (){
Call fgCall = mCM. getActiveFgCall ();
If (mCM. hasActiveRingingCall ()){
FgCall = mCM. getFirstActiveRingingCall ();
}

Final Call. State state = fgCall. getState ();
Switch (state ){
Case IDLE:
Break;

Case ACTIVE: // power-off
Log. d ("yzy", "ACTVIE ");
Final Timer timer = new Timer ();
If (mode = Mode. mode2 ){
Timer. schedule (new TimerTask (){
@ Override
Public void run (){
Try {
Log. d ("yzy", "endcall ()");

MITelephony. endCall ();
Timer. cancel ();
} Catch (RemoteException e ){
E. printStackTrace ();
}
}
}, HoldonDuration * 1000, holdonDuration * 1000 );
}
// MITelephony. endCall ();
Break;
Default:
Break;
}

}
If you run the simple install command on this apk, the following error will be reported: the shared user does not exist or the signature does not match. This is because [java] view plaincopyprint? Android: sharedUserId = "android. uid. system"

Android: sharedUserId = "android. uid. system" must be placed in the system/app directory to work. This involves two issues: Temporary root permission acquisition and runtime copy.

Other key code:


[Java]
Private ITelephony mITelephony;
MITelephony = ITelephony. Stub. asInterface (ServiceManager
. GetService (Context. TELEPHONY_SERVICE ));
MPhoneStateListener = getPhoneStateListener ();
(TelephonyManager) getSystemService (Context. TELEPHONY_SERVICE). listen (
MPhoneStateListener, PhoneStateListener. LISTEN_CALL_STATE );
Private PhoneStateListener getPhoneStateListener (){
 
Return new PhoneStateListener (){
@ Override
Public void onCallStateChanged (int state, String incomingNumber ){
Try {
Log. d ("yzy", "state :"
+ MITelephony. getCallState ());
 
} Catch (RemoteException e ){
E. printStackTrace ();
}
 
}
};
 
}

Related Article

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.