App with root access // Bluetooth - Android Software Development

Hi everyone,
I have a few questions. First of all, I've got a rooted HTC Magic with Super E.
I'm developing an app and, as far as I know, it is not possible to execute Java code as root. Is this correct? If there is a way, tell me. The only way I've found is by using shell comands:
Process p;
try {
// Preform su to get root privledges
p = Runtime.getRuntime().exec("su");
(...)
I would need root access for example to avoid the dialog asking for permission when I enable bluetooth discoverability, or the dialog asking for permission when installing a secondary app from the market.
Another question: is there a way to make the device permanently discoverable (bluetooth)?
By the way, how can I enable bluetooth and discoverability using shell comands?
Thanks!

Related

[Q] Slider Disabled, Not recognizing gesture.... now what?

I am running CM
So I disabled the slider unlock, but it stopped recognizing my gesture for some reason and I cannot figure out how to login to my phone. Running stable build of CM7.1, not sure if I can change that setting somehow from ADP or do something from a terminal... Any ideas?
When I say gesture, I am not referring to the password based on the motion with the dots, I am saying the screen where the unlock / silent toggle was has been disabled and I cannot get passed there.
Your help is appreciated
Did u try unlock with menu button?
I remember that from cm7
Sent from my MB525 running 4.5.1-134 DFP 231 DEFY+ ROM...
using XDA App
No menu button doesn't do anything....
Do you know WHERE this "Slider Disabled" setting is stored? I could go in thru ADB and change it but I don't know where to look.
Here are the things I have tried already
----
Attempt 1:
$ ./adb -d shell
# cd data/data
# sqlite3 ./com.android.providers.settings/databases/settings.db
sqlite> update system set value=1 where name='lockscreen_disabled';
sqlite> .exit
# reboot
Attempt 2:
adb shell
input keyevent 82
---
Neither of these worked. I think the solution should be in the updating the settings.db, but maybe its a different row/record that contains "ENABLE slider"?
Help would be appreciated!
could deleting the the offending theme restore to normal?? Just thinking out loud here ^^
don't know much about adb
Okay. No help here, but I found a fix and I thought i would share it since I have seen that apparently other people have had this problem with no help as well other than "Wipe and reinstall rom"
This app fixed it!
https://market.android.com/details?id=se.curity.android.screenlockbypass
Just make sure you follow the instructions, you have to install the app, than install any other random app and BAM- unlocked phone! Sweet

[APP Dev] Shells Java Class for Android App Devs ! Send Commands Easily !

Hi There Everybody ! I am Seaskyways and I am back with a surprise ! My Android Java Class "Shells" !
App Devs ! Shells Java Class
My Java class Shells is a class to simplify the use of sending normal commands (Shell Commands) and capturing their output ! The Reason its called Shells because it is not a single shell , its not only two or three methods , its a wide variety of methods that helps you complete your wanting easily ! Whoever , it is not totally stable and I need some help from app / java devs to fix some Exceptions , please anybody who knows contact me . The functions and uses of the class will be provided gradually in this thread (because I will have my term tests nearly) .... I might be updating this class about weekly , because I am busy , sorry
This Class will provide mainly a root shell for rooted devices , and a non-root shell for non-rooted devices , and free single command sending which returns the output , more info down
____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
Functions (Methods):
Start(): public void , returns nothing , used to start both the Root shell and Non-root Shell.
Stop(): public void , returns nothing , used to stop both the Root shell and Non-root Shell , plus it resets the variables used in those shells.
____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
Logsh(): public String , returns a String showing all the output of the commands sent using the Non-root shell , may cause the Non-root shell to stop , if an error occurs , please call Start() before using it . (please help here a small bug)
Logsu(): public String , returns a String showing all the output of the commands sent using the Root shell , may cause the Root shell to stop , if an error occurs , please call Start() before using it . (please help here a small bug)
____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
Readsh(): public String , returns a String showing the last command's output sent using the Non-Root shell , may cause the Non-root shell to stop , if an error occurs , please call Start() before using it .
Readsu(): public String , returns a String showing the last command's output sent using the Root shell , may cause the Root shell to stop , if an error occurs , please call Start() before using it .
____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
su(String): public void , returns nothing , this is the Root shell, it executes the command given as root , it is used in the following form
Code:
Start();
su("My command");
sh(String): public void , returns nothing , this is the Non-Root shell, it executes the command given as normal user , it is used in the following form
Code:
Start();
sh("My command");
____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
su(String[]): public void , returns nothing , this is the Root shell,it converts the array to a String then it executes the command given as root , it is used in the following form
Code:
Start();
su("My", "command");
sh(String[]): public void , returns nothing , this is the Non-Root shell,it converts the array to a String then it executes the command given as normal user , it is used in the following form
Code:
Start();
sh("My", "command");
____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
Shells(); public static Shells , it returns new Shells()
____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
Download Dev-host
More Explanations coming later​
Reserved in case needed !
Looks usable!
Sent from my Galaxy Nexus running Android 4.2 JB
Its Very usable , but I need help in fixing it ! Plus I tried posting this on the portal , but seemed uninteresting to XDA
seaskyways said:
Its Very usable , but I need help in fixing it ! Plus I tried posting this on the portal , but seemed uninteresting to XDA
Click to expand...
Click to collapse
This is almost a year old, but this looks like exactly what I need! Seems the link is down Can you PM me or reply ? If you have time of course.

Script/App for Shutdown

Hey,
I'm having a rooted Nook Simple Touch (FW 1.2.1) and want to add a shortcut (to launcher 8) for powering off the device. Unfortunately every tried command (adb reboot -p, several java shutdown methods) results in an immediate shutdown of the device and it looks like the device is frozen. After pressing the power button, you can see the usual "device is powering on" screen.
Does anybody know how I can power off my device, with showing the "Your NOOK has turned off completely" screen? Already tried some sendevent commands for simulating touch events, but with no success.
Thanks in advanced.
I always just hold the power button.
Do you want it to shutdown without even the confirm menu?
It's trivial, it's just an Intent, android.intent.action.ACTION_REQUEST_SHUTDOWN
Oh, but you just can't just:
Code:
# am start -a android.intent.action.ACTION_REQUEST_SHUTDOWN
Starting: Intent { act=android.intent.action.ACTION_REQUEST_SHUTDOWN }
[i]blah, blah, blah[/i] requires android.permission.SHUTDOWN
Unfortunately (or fortunately for security) android.permission.SHUTDOWN can only be obtained by a system app.
The solution? Write an app, put the permission in AndroidManifest.xml and sign it with the system signature.
This is only possible if you have re-signed your entire system.
It works fine on my Nook.
Yes, I want it without the confirm menu.
I tried your suggestion with the intent, transferred the app to with su to system app, but with no results. Do I have to generate a key by myself and sign the app to get the shutdown permission from android?
After a deeper system scan, I found the images which are shown if the device is shutdown or restarting under /system/assets. So I wrote an App set the image cold_boot_screen.png as background and shutting down the device with reboot -p. So this is working for me.
black-lord said:
I tried your suggestion with the intent, transferred the app to with su to system app, but with no results.
Click to expand...
Click to collapse
You should have seen "Not granting permission android.permission.SHUTDOWN" in logcat when installing.
You should have seen java.lang.SecurityException in logcat when attempting to run.
black-lord said:
So this is working for me.
Click to expand...
Click to collapse
True.
Still, that's really a Linux shutdown and not the kinder, gentler Android shutdown.
Or maybe not?
Maybe zygote gets a signal to shutdown and shuts down everything gracefully?
I don't know.
Re-signing your system does not have to be a big deal.
Moreover, if you want to go modifying some of the Nook's framework or Reader you'll have to do that anyway.

[Tutorial] Manage System Permissions in Android Marshmallow

Hello,
I create that thread to offer you a new tutorial aiming to learn how to manage System Permissions in Android Marshmallow. You can discover the tutorial in video also :
Manage System Permissions on Android 6 Marshmallow
Beginning in Android 6 Marshmallow, users grand permissions to apps while the app is running, not when they install the app. This approach gives the user more control over the app's functionality. Thus, he can choose to give the access to read contacts but not to the device location. Furthermore, users can revoke the permissions at any time, by going to the app's Settings screen.
Note that system permissions are divided into two categories : normal and dangerous. Normal permissions are granted automatically. For dangerous permissions, the user has to give approval to your application at runtime. So, developers must manage permissions at runtime before using some dangerous features.
To manage permissions inside an application, we're going to imagine we want to read contacts. This feature will use the READ_CONTACTS permission that is marked as dangerous. So, the first step is to check for READ_CONTACTS permission. If the permission has already been granted, you can use the feature that read contacts. If not, you have to request for permissions with a custom request code that will be named MY_PERMISSIONS_REQUEST_READ_CONTACTS in our example.
Code:
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[] { Manifest.permission.READ_CONTACTS },
MY_PERMISSIONS_REQUEST_READ_CONTACTS);
} else {
readContacts();
}
Note that when your application requests for permissions, the system shows a standard dialog box to user that cannot be customized. Now, you need to handle the permissions request response by overriding the onRequestPermissionsResult method :
Code:
@Override
public void onRequestPermissionsResult(int requestCode,
@NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_READ_CONTACTS :
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
readContacts();
} else {
if(ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.READ_CONTACTS)) {
new AlertDialog.Builder(this).
setTitle("Read Contacts permission").
setMessage("You need to grant read contacts permission to use read" +
" contacts feature. Retry and grant it !").show();
} else {
new AlertDialog.Builder(this).
setTitle("Read Contacts permission denied").
setMessage("You denied read contacts permission." +
" So, the feature will be disabled. To enable it" +
", go on settings and " +
"grant read contacts for the application").show();
}
}
break;
}
}
Like you can see, managing permissions in your Android application is not really hard.
Don't hesitate to give me your feedbacks or ideas for new tutorials.
Thanks.
Sylvain
Nice Tutorial.
Keep them coming
Black_Eyes said:
Nice Tutorial.
Keep them coming
Click to expand...
Click to collapse
Thanks
Hello,
The tutorial is now also available on my blog : http://www.ssaurel.com/blog/manage-permissions-on-android-6-marshmallow/ .
Don't hesitate to give me your advice and ideas for future tutorials.
Thanks.
Sylvain
They were intimidating at first but once you do it once, you've pretty much got the hang of it.
Jay Rock said:
They were intimidating at first but once you do it once, you've pretty much got the hang of it.
Click to expand...
Click to collapse
True. When you understand the mechanism, it becomes simple to use permissions in your Android code.
Christie37 said:
As I'm new mobile developer this tutorial helped me lot. Thanks keep going!!
Click to expand...
Click to collapse
Great . I made some other tutorials that could be interesting for you. Don't hesitate to look at them
Thanks man awsome
nice bro
@DSttr said:
nice bro
Click to expand...
Click to collapse
Thanks
@sylsau Thanks..
BTW, does this work properly on Android 5.1.1 and below?
I mean, what does this below code do for 5.1.1 and below? :
Code:
ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)
Does it always return true, or is there a chance of exceptions or errors?
I'm asking this because I don't have Android Device below 5.1 to test it..
Or should I wrap it up like this:
Code:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions();
}

Is it possible to deinstall the Lockscreen on HD 10?

So the Lockscreen on my new HD 10 is pretty garbage, so far I've managed to get rid of the ads, but I can't change the Lockscreen wallpaper and I don't get any preview of a notification (e.g. the mail subject etc.)
Is there a workaround for those problems? Because simply isntalling a new lockscreen app, just makes me unlock my tablet twice, which isn't ideal.
Did you manually disable com.amazon.kindle.kso (special offers/lockscreen ads) over ADB in fire os 5.4.0.0 or lower using the method DragonFire1024 posted? If so, then yes, I found a fix that allows you to see notifications on the lockscreen without swiping down, more like the stock Android 5.x lockscreen.
lakitu47 said:
Did you manually disable com.amazon.kindle.kso (special offers/lockscreen ads) over ADB in fire os 5.4.0.0 or lower using the method DragonFire1024 posted? If so, then yes, I found a fix that allows you to see notifications on the lockscreen without swiping down, more like the stock Android 5.x lockscreen.
Click to expand...
Click to collapse
I did it over adb yes, but on the newest release of fire OS (5.6)
wieli99 said:
I did it over adb yes, but on the newest release of fire OS (5.6)
Click to expand...
Click to collapse
I thought Amazon broke the ability to disable apps over ADB with the release of 5.4.0.1. Did that not affect the new 2017 HD 10?
Sent from my Amazon KFGIWI using XDA Labs
lakitu47 said:
I thought Amazon broke the ability to disable apps over ADB with the release of 5.4.0.1. Did that not affect the new 2017 HD 10?
Click to expand...
Click to collapse
It works for me in adb shell with
pm clear --user 0 com.amazon.kindle.kso
Well, I don't know if this will work with your exact tablet, but try this:
1. If you haven't already, get the Google Play store/services on your tablet
2. Download this app without the quotes: "https://play.google.com/store/apps/details?id=by4a.setedit22&hl=en"
3. Follow on-screen instructions to grant tablet permission to edit secure settings (worked on 2 devices on 5.6)
BE CAREFUL WHAT YOU EDIT. If you change the wrong settings, your tablet can and probably bootloop or get bricked.
4. Go to the "secure" tab, scroll down to "limit_ad_tracking" and change value to 1
5. Go to "global" tab, scroll down to "LOCKSCREEN_AD_ENABLED" and change value to 0. Immediately reboot your device.
This was tested and worked on two HD 8 tablets on 5.6, with special offers manually disabled on 5.4. Since Amazon still thinks you are subscribed to special offers (ads), the notifications are hidden. This workaround actually makes the ads gone (hopefully), so the notifications will appear as soon as you turn on the screen, without a swipe down gesture.
Open up command prompt. Type in "adb shell", Then type in "su"
Then copy this into command prompt.
sqlite3 /data/system/locksettings.db "UPDATE locksettings SET value = '1' WHERE name = 'lockscreen.disabled'"
You will not get a confirmation, now type "exit", then type "reboot".
Let the device reboot and enjoy! Now install a new lockscreen.
Want it back?
sqlite3 /data/system/locksettings.db "UPDATE locksettings SET value = '0' WHERE name = 'lockscreen.disabled'"
*This is messing with the sqlite in the actual android system files, please becareful and don't go around changing values in system files.
source: Tips Tricks and the Root
Jned said:
Open up command prompt. Type in "adb shell", Then type in "su"
Then copy this into command prompt.
sqlite3 /data/system/locksettings.db "UPDATE locksettings SET value = '1' WHERE name = 'lockscreen.disabled'"
You will not get a confirmation, now type "exit", then type "reboot".
Let the device reboot and enjoy! Now install a new lockscreen.
Want it back?
sqlite3 /data/system/locksettings.db "UPDATE locksettings SET value = '0' WHERE name = 'lockscreen.disabled'"
*This is messing with the sqlite in the actual android system files, please becareful and don't go around changing values in system files.
source: Tips Tricks and the Root
Click to expand...
Click to collapse
do you have to have root for this? i did su and it said, " su not found."
Jned said:
Open up command prompt. Type in "adb shell", Then type in "su"
Then copy this into command prompt.
sqlite3 /data/system/locksettings.db "UPDATE locksettings SET value = '1' WHERE name = 'lockscreen.disabled'"
You will not get a confirmation, now type "exit", then type "reboot".
Let the device reboot and enjoy! Now install a new lockscreen.
Want it back?
sqlite3 /data/system/locksettings.db "UPDATE locksettings SET value = '0' WHERE name = 'lockscreen.disabled'"
*This is messing with the sqlite in the actual android system files, please becareful and don't go around changing values in system files.
source: Tips Tricks and the Root
Click to expand...
Click to collapse
Like that one eh? That was one of the first ones I found. Works without root too.
wieli99 said:
So the Lockscreen on my new HD 10 is pretty garbage, so far I've managed to get rid of the ads, but I can't change the Lockscreen wallpaper and I don't get any preview of a notification (e.g. the mail subject etc.)
Is there a workaround for those problems? Because simply isntalling a new lockscreen app, just makes me unlock my tablet twice, which isn't ideal.
Click to expand...
Click to collapse
Personally, I'd suggest just rooting it and disabling it. I did it a few months ago on my Dad's HD10 by following one of the guides here- I just can't remember which one, but it was simple. I also installed Gravity Screen Pro since I have his set up more like a laptop. The screen turns on/off when opened/ closed without ever having to see a lock screen. I might stop by my parents today (depending on the weather) and if i do, I'll try to trace my steps and link the guide I followed
dondraper23 said:
Personally, I'd suggest just rooting it and disabling it. I did it a few months ago on my Dad's HD10 by following one of the guides here- I just can't remember which one, but it was simple. I also installed Gravity Screen Pro since I have his set up more like a laptop. The screen turns on/off when opened/ closed without ever having to see a lock screen. I might stop by my parents today (depending on the weather) and if i do, I'll try to trace my steps and link the guide I followed
Click to expand...
Click to collapse
There are also a few Xposed modules that work too.
Sent from my Samsung Galaxy S4 using XDA Labs
wieli99 said:
So the Lockscreen on my new HD 10 is pretty garbage, so far I've managed to get rid of the ads, but I can't change the Lockscreen wallpaper and I don't get any preview of a notification (e.g. the mail subject etc.)
Is there a workaround for those problems? Because simply isntalling a new lockscreen app, just makes me unlock my tablet twice, which isn't ideal.
Click to expand...
Click to collapse
I followed this guide: https://forum.xda-developers.com/hd8-hd10/help/root-required-completely-disable-enable-t3739257
I just had to do it again today because attempted to use Xposed and wound up getting in over my head and got caught in a bootloop, but at least I can reaffirm that this guide works
---------- Post added at 07:56 AM ---------- Previous post was at 07:49 AM ----------
DragonFire1024 said:
There are also a few Xposed modules that work too.
Sent from my Samsung Galaxy S4 using XDA Labs
Click to expand...
Click to collapse
I love all your posts- it's your guide I followed to disable the lockscreen. Unfortunately, Xposed is a bit much for a "noob" like me. I attempted to install it and got caught in a bootloop and had to do a factory reset. Considering what my dad uses it for, the negatives far outway the positives for me to bother with Xposed ever again

Categories

Resources