I found some interesting methods in telephonyManager class like turning mobile data off/on but when trying to use them it obviously throws me security exception.("No carrier privilege"). I Googled it, but didn't find any helpful solution.
Because it's carrier privilege I thought it may be possible to get its permission by telephonyManager.getIccAuthentication(int appType, int authType, String data) but I'm having problems with input parameters because I can't figure out what should I pass in to make it work.
From documentation to the first parameter would pass TelephonyManager.APPTYPE_SIM or/and TelephonyManager.APPTYPE_USIM depending on if it has big meaning in using setDataEnabled(boolean).
If I would pass TelephonyManager.APPTYPE_SIM as a first argument I think I should passed TelephonyManager.AUTHTYPE_EAP_SIM as a second argument (correct me if I'm wrong) and vice versa, when TelephonyManager.APPTYPE_USIM as first so TelephonyManager.AUTHTYPE_EAP_AKA as second one.
And then there is the third argument. There must be encoded Base64 to string. I found in TelephonyProvider this line of code:
String base64Challenge = Base64.encodeToString(byteParam, Base64.NO_WRAP); where byteParam is an input byte from another method which is being preceding by thousands other methods. If I pass "" as third parameter to getIccAuthentication method I get again securityException (it's obviously, wrong param) but it throws me lack of getIccSimChallengeResponse. I'm afraid of it may be infinite loop of methods, but maybe someone has any idea or help me to break this through?
My sample code:
public class MainActivity extends AppCompatActivity {
private static final String TAG = MainActivity.class.getSimpleName();
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.buttonPanel);
button.setOnClickListener(new View.OnClickListener() {
#RequiresApi(api = Build.VERSION_CODES.O)
#Override
public void onClick(View view) {
try {
Process p = Runtime.getRuntime().exec("su");
tel();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
#RequiresApi(api = Build.VERSION_CODES.O)
private void tel(){
// String base64Challenge = Base64.encodeToString(,
Base64.NO_WRAP);
TelephonyManager telephonyManager = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
boolean isCarrier = telephonyManager.hasCarrierPrivileges();
String authentication =
telephonyManager.getIccAuthentication(TelephonyManager.APPTYPE_SIM,
TelephonyManager.AUTHTYPE_EAP_SIM, "");
Log.v(TAG, authentication);
if (isCarrier) {
Log.v(TAG, "privs granted");
telephonyManager.setDataEnabled(false);
} else {
Log.v(TAG, "no privilegies");
}
}
}
From the docs:
Requires Permission: READ_PRIVILEGED_PHONE_STATE or that the calling
app has carrier privileges (see hasCarrierPrivileges()).
The first of those requires you to be installed as a privileged system app (requires root or owning system certificate). The second requires your UID to be the carrier's. Without that no combo of parameters will work.
Related
Currently, I am working to create a Stripe payment method in an Android Studio App. This will involve a credit card object which will be stored by Stripe into my Firestore DB. Unfortunately, one of the lines in the tutorial that I have used is outdated since it uses getContext() without a view.
Background on Stripe:
https://www.youtube.com/watch?v=JeyxolsJ3aE
Background on Firestore:
https://firebase.google.com/docs/firestore
Here is the link to the tutorial that I am following:
https://stripe.com/docs/mobile/android
Unfortunately, I have not had much luck finding a tutorial that is knew, uses the same format and does not use getContext().
I have already completed all steps up to inserting the line:
final Stripe stripe = new Stripe(
getContext(),
"pk_test_TYooMQauvdEDq54NiTphI7jx"
);
In my version of Android Studio (3.4.1), it seems getContext() cannot be used without a View (shows up as red). As a result, I have tried to substitute a variety of commands. However, they all produce the same crash with message "Invalid Content Provider: null". I believe that "Content Provider" refers to the Context passed in.
I should mention that the Stripe object is created within an On-Click listener. Further, I know that the "pk_test" key is correct and I have tested other valid ids also to no avail. Further, through tests with commenting out code, I am certain that this is the line producing my error.
My theory is that the context is being rejected by Stripe or Firebase. This is because the Stripe Context is known as a "Stripe Provider" (https://lh3.googleusercontent.com/-ByYW3X0ua38/XQ_kRpmddLI/AAAAAAAAAAI/YfhjxSJ9iO0aJwZ8RtANeCXKXyYglWX1QCK8BGAs/s0/2019-06-23.png)
Some of the commands that I have tried are:
getContext() (not recognized)
getApplicationContext()
getBaseContext()
this
this.getApplicationContext()
ClassName.this.getApplicationContext()
ClassName.this.getBaseContext()
Submit.getContext()
WrappingLayoutView.getContext()
I have also tried to capture the Context in OnCreate above the OnClick listener in a variable.
Since none of these are working, I am rather stuck as to what to do.
Here is my Java Code:
public class AddCardActivity extends AppCompatActivity {
private Button submit;
public Context mContext;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_card);
init();
mContext = this.getApplicationContext();
//Not working
/**View mV=findViewById(R.id.myLView);
mContext=mV.getContext();**/
submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Use stripe to add new payment to firestore
//This line causes a crash
Stripe stripe = new Stripe(submit.getContext(),
"pk_test_t6NMvJpXDEZd3eOn5SU4y6DA"
);
// The Card class will normalize the card number
final Card card = Card.create("4242-4242-4242-4242", 12, 2020, "123");
//Update this with more useful error messages
if (card == null) {
Toast.makeText(getApplicationContext(), "Invalid Card!", Toast.LENGTH_LONG).show();
}
card.validateNumber();
card.validateCVC();
stripe.createToken(
card,
new TokenCallback() {
public void onSuccess(#NonNull Token token) {
// Send token to your server
}
public void onError(#NonNull Exception error) {
// Show localized error message
Toast.makeText(getApplicationContext(), "Invalid Card!", Toast.LENGTH_LONG).show();
}
}
);
}
});
}
private void init() {
submit = (Button) findViewById(R.id.addCardActivityButton);
}
Here you go:
Token token = null;
final Card card = new Card(cardNumber, month, year, cvc);
final Stripe stripe = new Stripe(getApplicationContext());
try {
token = stripe.createTokenSynchronous(card, "pk_test_TYooMQauvdEDq54NiTphI7jx");
} catch (StripeException stripeEx) {
errorMessage = stripeEx.getLocalizedMessage();
}
So I've debugged my program and have found that the part of my program is updating, whilst another isn't.
I have a method:
public void storeApplication(String name, String item){
Application app = new Application(name, item);
peopleAttending.add(app);
}
The debugger reports that an object is contained in the LinkedList (peopleAttending).
In another method:
public void populateListView() {
int noOfPeopleAttending = peopleAttending.size();
String noPeopleAttending = String.valueOf(noOfPeopleAttending);
Toast.makeText(GuestsAttending.this, noPeopleAttending, Toast.LENGTH_SHORT).show();
}
This method can be called after the previous one and states that there isn't an object within the LinkedList.
I've checked the object references just to make sure that they are pointing at the same reference and they are.
Any help would be greatly appreciated.
EDIT: Entire Class:
public class GuestsAttending extends Activity {
private LinkedList<Application> peopleAttending = new LinkedList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_guests_attending);
populateListView();
}
public void storeApplication(String name, String item){
Application app = new Application(name, item);
peopleAttending.add(app);
}
public void populateListView() {
// GuestsAdapter adapter = new GuestsAdapter(this, peopleAttending);
// ListView listView = (ListView) findViewById(R.id.listView);
// listView.setAdapter(adapter);
peopleAttending.size();
int noOfPeopleAttending = peopleAttending.size();
String noPeopleAttending = String.valueOf(noOfPeopleAttending);
Toast.makeText(GuestsAttending.this, noPeopleAttending, Toast.LENGTH_SHORT).show();
}
Second Edit:
Java Booking Screen Method:
public void saveBookingInfo(View view) {
GuestsAttending sendApplication = new GuestsAttending();
EditText applicantNameText = (EditText) findViewById(R.id.applicantNameTextField);
EditText itemToBurnText = (EditText) findViewById(R.id.itemToBurnTextField);
String appName = applicantNameText.getText().toString();
String appItemToBurn = itemToBurnText.getText().toString();
if (appItemToBurn.isEmpty() || appName.isEmpty()) {
Toast.makeText(BookingScreen.this, "Please fill in all fields.", Toast.LENGTH_SHORT).show();
}
else {
sendApplication.storeApplication(appName, appItemToBurn);
}
}
GuestsAttending Java Class: -- See Above.
Useful hint: It's really popular to set type of List as a List<> interface from java.util package instead of LinkedList<> itself.
Anyway, i am pretty sure that storeApplication method is not automatically triggered before onCreate method ran by Activity framework. Maybe your debugger is stopoing on it in different order (because of using threads or smth), but you should to log some invoke. Try to find it out.
I've found out what the problem is:
When I submit the booking information, it runs all the necessary methods. However, when the "storeApplication()" method has finished executing, the ArrayList 'empties' all the objects out.
I only noticed this when I used breakpoint and tried running the method twice, on the second time I entered booking details, the ArrayList stated it was empty.
I'm going to see if I can try and store the ArrayList in a more secure place.
I am working with the Weemo sdk and up to now it is looking very promising. However I have encountered one problem while writing app based on it. I have registered a CallStatusChanged listener to the eventbus and I have no problem receiving the event on the receiver when the caller calls. However the WeemoCall object is not well constructed and the getCallId() method returns 0 (see the following code ). To my understanding event.getCaller will return the id of the caller so we can latter on use it to establish a call. can anyone help me to solve this ? I have attached a screenshot of the call object I took during debuging.
#WeemoEventListener
public void onCallStatusChanged(final CallStatusChangedEvent event){
String msg = "";
Log.i(TAG,"onCallStatusChanged" + event.toString());
switch (event.getCallStatus()){
case CREATED:
msg = "call created";
break;
...
case RINGING:
msg = "call is ringing";
Intent i = new Intent(this, VideoCallingActivity.class);
i.putExtra(INCOMING_CALL_ID_EXTRA, event.getCall().getCallId()); //getCallId returns 0 ?!
startActivity(i);
break;
...
}
Log.i(TAG,msg);
}
The WeemoCall.getCallId() method returns an int that is used internally as a index.
This way, the first call will have its getCallId() equals to 0, the second will have it equals to 1, and so on and so forth.
So, in order to get the corresponding WeemoCall object on your second activity, you can simply do the following:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int callId = savedInstanceState.getInt(INCOMING_CALL_ID_EXTRA);
WeemoCall call = Weemo.instance().getCall(callId);
}
You could also use this method that will return the current WeemoCall:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WeemoCall call = Weemo.instance().getCurrentCall();
}
Having a bit of problem as I would like on my application for the user to enter an IP address and for that IP entry to be used to connect to the other device. In these two classes, the IPEntry class is set up to read the IP through the EditText and get coverts it to a string. I then want it to be passed and used within my ClientUpload class. Obviously I had attempted to already solve this to no avail. When I use it with the following way it says it cannot find the IP so it isn't transferring. I also tried to get in within a method and call upon that but that didn't work either. Is there anyway to do this?
Thanks
IPEntry Class
public class IPEntry extends Activity {
Button Submit;
EditText IP;
TextView Thistext;
public String ipadd;
public Intent intent;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.ipentry);
Submit = (Button) findViewById(R.id.bIPSubmit);
Thistext = (TextView) findViewById(R.id.tvTextIP);
IP = (EditText) findViewById(R.id.edIPBar);
Submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
ipadd = IP.getText().toString();
Intent Trans = new Intent("wishift.mat.ANDROIDEXPLORER");
startActivity(Trans);
}
}
);
}}
Relevant Part of Client Upload Class
public class ClientUpload extends Thread{
IPEntry ipentry = new IPEntry();
public int UploadFile(File file) throws UnknownHostException, IOException
{
//loop
int serverPort = 6880;
// String ip = "192.168.1.73";
String ip = ipentry.ipadd;
Socket socket = new Socket(ip, serverPort);
As you can see I commented out the part which does work but I would very much not like to manually add the IP in code.
The issue here is that the IPEntry object created here: IPEntry ipentry = new IPEntry(); in ClientUpload is a new IPEntry object; it does not share the same value of ipadd. The default constructor will set it to null.
There are many ways to solve this; you can either add a constructor to ClientUpload with a String argument for the IP address and save it in an instance variable or add another argument to the uploadFile() method to accept the IP address.
You can also make the ipadd varible static, allowing it to be accessed across all IPEntry instances, although I do not recommend this as it is completely unnecessary and multiple IPEntry objects will require more (unnecessary) memory and overhead.
I am retrieving the outgoing number from the broadcast receiver and trying to send it to the activity thru a method getNumber() however the value is coming out null. Im my code below In the activity class the String phonenumber is null
BroadcastReciever Class:
public class OutgoingBroadcastReceiver extends BroadcastReceiver {
String phonenumber = null;
#Override
public void onReceive(Context context, Intent intent) {
phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL"))
{
Log.i("System out", "IN OUTGOING CALL......... :IF");
MyPhoneStateListener phoneListener = new MyPhoneStateListener(
context);
TelephonyManager telephony = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
telephony.listen(phoneListener,
PhoneStateListener.LISTEN_CALL_STATE);
} else {
Log.i("System out", "IN INCOMING CALL.........:else:receiver");
}
public String getNumber()
{
return phonenumber;
}
Activity Class:
public class OutgoingCallScreenDisplay extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.outgoing_main);
OutgoingBroadcastReceiver outreciever = new OutgoingBroadcastReceiver();
String phonenumber= outreciever.getNumber();//this is coming out NULL needs to be the outgoing number
}
Phone no. is null because u r making a new instance of broadcastreceiver whose values are not initilized. You can receive a phone no. in "onReceive" ONLY ,from there u should start a new activity if u want to pass it further
See:
Firstly you shud either use a broadcast receiver or a phone state listener. In ur case if u r using a broadcast receiver then u simple need intent extra:EXTRA_PHONE_NUMBER
and permission : process outgoin call .That's it.....
Two things immediately come to mind:
The onReceive method needs to be called before you can get the phone number.
You are assigning the phone number to a local variable and not the instance member.
use putExtra if you want to pass data to an activity