I am unlocking SIM PIN dynamically through my app via these lines
TelephonyManager manager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
int state = manager.getSimState();
if(state == TelephonyManager.SIM_STATE_PIN_REQUIRED || state == TelephonyManager.SIM_STATE_PUK_REQUIRED)
{
try {
#SuppressWarnings("rawtypes")
Class clazz = Class.forName(manager.getClass().getName());
Method m = clazz.getDeclaredMethod("getITelephony");
m.setAccessible(true);
ITelephony it = (ITelephony) m.invoke(manager);
if (it.supplyPin(simPin)) {
Toast.makeText(context,"SIM UnLocked",Toast.LENGTH_LONG).show();
} else {
Toast.makeText(context,"SIM UNLOCK FAILED",Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
//
e.printStackTrace();
}
}else{
Toast.makeText(context,"SIM is not Locked",Toast.LENGTH_LONG).show();
}
now I want to know how much number of tries already made to unlock the SIM like default SIM PIN/PUK unlocker tells"two attempts left" . let me know if there is any possibility.
Just create an int that counts from 3 to 0 if sim unlock fails..
int attempts = 3;
} else {
Toast.makeText(context,"SIM UNLOCK FAILED",Toast.LENGTH_LONG).show();
attempts --;
}
Related
I have one very unusual case when calling an Android hidden API over reflection freezes the calling thread eternally. I cannot debug the underlying code as it is a code from Android itself normally not visible. I tried running the code in an asynctask, in a normal thread but nor asynctask.cancel nor thread.interrupt kills the thread, the thread stays visible, I can see it while debugging. Is it really not possible to run a code encapsulated and kill it completely eventually?
This problems occurs only on Android O and only on some devices, that's why I need to test-run it to see if it works on the current device and be able to activate a feature according to that. The code below, I don't really see a solution for this:
Thread endCallThread;
Runnable myRunnable;
private void checkFeatureSupport(final Context context) {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
myRunnable = new Runnable() {
#Override
public void run() {
doInBackgroundWrapper();
if (getActivity() != null) {
getActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
//handleResult();
}
});
}
}
};
endCallThread = new Thread(myRunnable, "endCallThread");
endCallThread.start();
new CountDownTimer(3000, 3000) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
Log.e("TESTAUTOMATION", "endCall did not finished in 3 seconds");
// stop async task if not in progress
if (endCallThread.isAlive()) {
try {
endCallThread.interrupt();
endCallThread = null;
myRunnable = null;
System.gc();
Log.e("TESTAUTOMATION", "endCallThread interrupted");
} catch (Exception ex) {
Log.e("TESTAUTOMATION", "endCallThread interrupted exception");
}
//handleResult();
}
}
}.start();
} else {
mEndCallSupported = true;
}
}
}
private void doInBackgroundWrapper() {
try {
if (getContext() == null) {
return;
}
final TelephonyManager telMan = (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
if (telMan == null) {
return;
}
final Class<?> classTemp = Class.forName(telMan.getClass().getName());
final Method methodTemp = classTemp.getDeclaredMethod("getITelephony");
methodTemp.setAccessible(true);
ITelephony telephonyService = (ITelephony) methodTemp.invoke(telMan);
// If this call does not return a security exception we say the call principally works.
Log.d("TESTAUTOMATION", "endCall before");
// This call endCall may freeze depending on device, mostly seen on Nexus 5x with Android 8&8.1
telephonyService.endCall();
Log.d("TESTAUTOMATION", "endCall after");
mSupported = true;
} catch (Exception ex) {
ex.printStackTrace();
mSupported = false;
}
}
To reproduce this the device should better no have a SIM inserted.
Thread.interrupt() in a common case does not stop a thread, it just marks specific boolean field (isInterrupted) as true. If a developer wants to stop thread's work at some point (after calling Thread.interrupt()) he can rely on this boolean filed Thread.isInterrupted() when he is implementing some work in a separate thread.
So I guess there is no such checking in the reflected hidden method what you are trying to call.
To stop your thread you can try deprecated Thread.stop() but it is a really bad practice.
We have 2 cisco phones: one for call manager and another for his superviser.
We need to create a conference when the manager answers and put the supervisor's phone on mute. We are trying to achieve it using JTApi: wait for event TermConnActiveEv, then trying to create conference.
Here is the code sample.
if (callEv instanceof TermConnActiveEv) {
CiscoCall thisCall = (CiscoCall) callEv.getCall();
TerminalConnection connection = ((TermConnActiveEv) callEv).getTerminalConnection();
if (thisCall.getState() != Call.ACTIVE)
{
System.out.println("call is not active");
return;
}
try {
CiscoCall newCall = (CiscoCall) provider.createCall();
newCall.consult(connection);
newCall.conference(thisCall);
....
However, PreConditionException is thrown. What are we doing wrong?
You don't need to use Barge to create a conference.
You can try to do something like that:
if (callEv instanceof TermConnActiveEv) {
CiscoCall thisCall = (CiscoCall) callEv.getCall();
TerminalConnection tc = thisCall.getConferenceController();
Connection[] connections = thisCall.getConnections();
TerminalConnection[] tcs = connections[0].getTerminalConnections();
if (tcs.length > 0 && tc == null) {
tc = tcs[0];
}
if (tc == null) {
System.out.println("Conference controller is null.");
} else {
try {
Call call = provider.createCall();
call.connect(thisAddress.getTerminals()[0], thisAddress, superVisorAddress);
thisCall.conference(call);
} catch (Exception ex) {
System.out.println("Exception " + ex);
ex.printStackTrace();
}
}
}
To set mute you can use:
((CiscoTerminal)termConnections[i].getTerminal().sendData("<CiscoIPPhoneExecute><ExecuteItem Priority=\"0\"URL=\"Key:Mute\"/></CiscoIPPhoneExecute>");
Before the application can make use of this feature, it must add TerminalObserver on the terminal.
I have implemented below given to unlock my app (this code works for only systems apps so I have done my app as system app )
TelephonyManager manager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
int state = manager.getSimState();
if(state == TelephonyManager.SIM_STATE_PIN_REQUIRED || state == TelephonyManager.SIM_STATE_PUK_REQUIRED)
{
try {
#SuppressWarnings("rawtypes")
Class clazz = Class.forName(manager.getClass().getName());
Method m = clazz.getDeclaredMethod("getITelephony");
m.setAccessible(true);
ITelephony it = (ITelephony) m.invoke(manager);
if (it.supplyPin(simPin)) {
Toast.makeText(context,"SIM UnLocked",Toast.LENGTH_LONG).show();
} else {
Toast.makeText(context,"SIM UNLOCK FAILED",Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
//
e.printStackTrace();
}
}else{
Toast.makeText(context,"SIM is not Locked",Toast.LENGTH_LONG).show();
}
It works fine for me, but now I need to implement setting or resetting SIM PIN programmatically, let me know if it is possible or not. if possible than how can I implement that?
String ussdCode = "**04*"+oldPin+"*"+newPin+"*"+newPin+"#";
startActivity(new Intent("android.intent.action.CALL", Uri.parse("tel:" + ussdCode)));
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Trouble with reading phone state
I want to get a call state of phone in my application. I am doing one application in which , When user dial to a number, then my application should come to know whether other side phone is Busy, Not-reachable or power-off states etc. For this I used com.android.internal API's they are
Call.java<http://hi-android.info/src/com/android/internal/telephony/Call.java.html>,
CallManger.java<http://hi-android.info/src/com/android/internal/telephony/CallManager.java.html> and
Connection.java<http://hi-android.info/src/com/android/internal/telephony/Connection.java.html>. I created subclass of Call.java like this:
public class MyCall extends Call{
CallManager cm = CallManager.getInstance();
Connection c;
Phone mDefaultPhone;
private final ArrayList<Connection> emptyConnections = new ArrayList<Connection>();
int size;
List<Call> ringingCall = cm.getForegroundCalls();
#Override
public List<Connection> getConnections() {
System.out.println("**value of list***"+ringingCall.size());
if(ringingCall != null && !ringingCall.isEmpty()){
System.out.println("inside if****");
System.out.println("**call is not null***");
System.out.println("value of call"+ringingCall);
return ((MyCall) ringingCall).getConnections();
}
else{
System.out.println("**list is null***");
return emptyConnections;
}
}
#Override
public Phone getPhone() {
// TODO Auto-generated method stub
System.out.println("**inside getPhone***");
return null;
}
#Override
public void hangup() throws CallStateException {
// TODO Auto-generated method stub
System.out.println("**inside hangUp***");
}
#Override
public boolean isMultiparty() {
// TODO Auto-generated method stub
System.out.println("**inside isMultiparty***");
return false;
}
public Connection
getEarliestConnection() {
Connection myConn = new MyConnection();
System.out.println("inside EarliestConnection");
List<Connection> l;
long time = Long.MAX_VALUE;
Connection c;
Connection earliest = null;
l = getConnections();
System.out.println("value of connection is=="+l);
if (l == null) {
return null;
}else if ( l.size() == 0)
{
return null;
}
for (int i = 0, s = l.size() ; i < s ; i++) {
c = (Connection) l.get(i);
long t;
t = c.getCreateTime();
if (t < time) {
earliest = c;
time = t;
}
}
return earliest;
}
}
Here I am getting the ringingCall.size is 0 for that it is executing else part. And one more class is CallUpdate.java.
public class CallUpdate {
Call myCall = new MyCall();
CallManager cm = CallManager.getInstance();
public Object getCallFailedString(){
Connection myConn = myCall.getEarliestConnection();
System.out.println("myConn is ******"+myConn);
System.out.println("myCall is ******"+myCall);
if(myConn == null){
System.out.println("myConn is null ******");
return null;
}
else
{
Connection.DisconnectCause cause = myConn.getDisconnectCause();
System.out.println("myconn is not null ******"+cause);
switch(cause){
case BUSY :
System.out.println("inside busy");
break;
case NUMBER_UNREACHABLE :
System.out.println("inside un-reachable");
break;
case POWER_OFF :
System.out.println("inside power off");
break;
}
}
return myConn;
}
}
In this code getting myConn value is null. I called CallManger class is like this:
CallManager cm = CallManager.getInstance();
But when I print this getting null pointer exception. System.out.println("value of cm"+cm); why this exception? Can anybody tell me?
You cannot obtain call related info like user busy, phone switch off etc directly by accessing internal API. Android does not provide these details for security reasons.
All you can do is trace the Log. we have three kinds of logs, so you have to trace
"Radio Log" only.
It consist of solcited and unsolicited commands, which are nothing but instructions sent from phone modem to Android OS and vice versa.
There you will find the line: onDisconnect Cause: XXXX which will be answer to your question.
you really should take a look at the code in PhoneApp.java. tracing this line, you will find out that 'cm = CallManager.getInstance()' is useless . the key to this problem is GsmCall.java and GsmCallTracker
I'm having problem when taking a picture using VideoControl.getSnapshot() method. It always throw the exception: getSnapshot not Supported. I'm using JRE 5.0.0 with Eclipse and BlackBerry® Java® SDK 5.0 Plugin.
What I do first is to list the encoding supported by Blackberry SmartPhone selected (bold 9700) with the command System.getProperty("video.snapshot.encodings") and select one encoding from the list and pass it as the getSnapshot argument.
I've tested on several Blackberry and the same exception is thrown.
Part of the code:
mPlayer = Manager.createPlayer("capture://video?encoding=video/3gpp");
mPlayer.realize();
mPlayer = Manager.createPlayer("capture://video?encoding=video/3gpp");
mPlayer.start();
videoControl = (VideoControl)mPlayer.getControl("VideoControl");
Field cameraView = (Field) videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");
Thread.sleep(1000);
UiApplication.getUiApplication().pushScreen(new TempScreen(cameraView));
byte[] snapShot = videoControl.getSnapshot("encoding=jpeg&width=480&height=360&quality=superfine");
Bitmap image = Bitmap.createBitmapFromBytes(snapShot, 0, snapShot.length, 1);
UiApplication.getUiApplication().pushScreen(new TempScreen(image));
}catch (MediaException e){
UiApplication.getUiApplication().pushScreen(new TempScreen("Exception: " + e.getMessage())); }
catch (IOException e){
UiApplication.getUiApplication().pushScreen(new TempScreen("IO Exception: " + e.getMessage()));
}
catch (InterruptedException e){UiApplication.getUiApplication().pushScreen(new TempScreen("Interrupted Exception: "+ e.getMessage()));}
Not sure is my answer is actual after more than a half of year, but may be it will be useful.
You may try to use Thread.sleep(1000); before getSnapshot() call.
The problem may be related with that fact: "viewfinder must actually be visible on the screen prior to calling getSnapShot()."
So if you call getSnapshot immediately after UiApplication.getUiApplication().pushScreen(new TempScreen(cameraView));
the camera isn't prepared for the next shot.
Also are you really sure that getSnapshot() API is supported exactly on your device? Some manufacturers may not support it, despite the API defines this method. Did you run System.getProperty("video.snapshot.encodings") exactly on the same device where you test getSnapshot()?
Player _p;
VideoControl _vc ;
RecordControl _rc ;
String PATH;
FileConnection fileconn;
Object canvas= new Object();
public static boolean SdcardAvailabulity() {
String root = null;
Enumeration e = FileSystemRegistry.listRoots();
while (e.hasMoreElements()) {
root = (String) e.nextElement();
if( root.equalsIgnoreCase("sdcard/") ) {
return true;
}else if( root.equalsIgnoreCase("store/") ) {
return false;
}
}
class MySDListener implements FileSystemListener {
public void rootChanged(int state, String rootName) {
if( state == ROOT_ADDED ) {
if( rootName.equalsIgnoreCase("sdcard/") ) {
}
} else if( state == ROOT_REMOVED ) {
}
}
}
return true;
}
protected boolean invokeAction(int action){
boolean handled = super.invokeAction(action);
if(SdcardAvailabulity()){
PATH = System.getProperty("fileconn.dir.memorycard.videos")+"Video_"+System.currentTimeMillis()+".3gpp";//here "str" having the current Date and Time;
} else {
PATH = System.getProperty("fileconn.dir.videos")+"Video_"+System.currentTimeMillis()+".3gpp";
}
if(!handled){
if(action == ACTION_INVOKE){
try{
if(_p!=null)
_p.close();
}catch(Exception e){
}
}
}
return handled;
}
public MyScreen(){
setTitle("Video recording demo");
ButtonField AddPhoto = new ButtonField("push",ButtonField.FOCUSABLE | ButtonField.FIELD_HCENTER | ButtonField.FIELD_VCENTER | DrawStyle.HCENTER | ButtonField.NEVER_DIRTY | Field.USE_ALL_WIDTH);
FieldChangeListener PhotoListener = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
ButtonField Button = (ButtonField) field;
if (Button.getLabel().equals("push")){
}
}
};
AddPhoto.setChangeListener(PhotoListener);
add(AddPhoto);
}
}