Permission denied even with 777 - android

So I'm developing an android app. It uses IR blaster to send signals to TVs and other stuff. It worked fine on CyanogenMod 11(Android 4.4.4) but after updating to CyanogenMod 12(Android 5.0) it stopped working. App is assessing these files: /dev/ttyHSL2 and /sys/devices/platform/ir_remote_control/enable . Normally their permissions are ok, but after updating they are "ok" but not ok :/ :
05-09 23:44:02.980 28282-28340/com.sssemil.ir E/libsonyir﹕ IRpowerOn : Error opaning power node /sys/devices/platform/ir_remote_control/enable error : Permission denied
05-09 23:44:03.981 28282-28340/com.sssemil.ir I/libsonyir﹕ IRserialOpen : CALLED
05-09 23:44:03.991 28282-28340/com.sssemil.ir E/libsonyir﹕ IRserialOpen : Error opaning serial device /dev/ttyHSL2 error : Permission denied
So I've tried to fix them:
su -c "chmod 222 /sys/devices/platform/ir_remote_control/enable"
su -c "chmod 666 /dev/ttyHSL2"
Still same errors. Then I've tried this:
su -c "chmod 777 /sys/devices/platform/ir_remote_control/enable"
su -c "chmod 777 /dev/ttyHSL2"
Still nothing... I've checked permissions and they were ok:
shell#odin:/ $ su -c "ls -l /dev/ttyHSL2"
crwxrwxrwx system system 244, 2 2015-05-09 22:27 ttyHSL2
shell#odin:/ $ ls -l /sys/devices/platform/ir_remote_control/enable
-rwxrwxrwx system system 4096 2015-05-09 22:27 enable
So if there are any ideas please help me. My app is open source so here is source code if you need it https://github.com/sssemil/android_packages_apps_IRRemote .
Thanks.

So, to fix it type: su -c "setenforce 0"

Related

on boot my android phone init .sh script run but not fully

Stack!
This my first question on this, so don't be too hard with me.
I want to run my own .sh script file on boot my android. To get this I rebuild kernel image and before that I add to init.rc file my own service which start after boot complete trigger:
on property:dev.bootcomplete=1
start fota-snoop
start fota-trigger
start startup-prober
start fairnet
the service itself:
service fairnet /system/bin/sh /system/etc/init.fairnet.sh
user root
group root
disabled
oneshot
permissions of /system/etc/init.fairnet.sh is set 644 like others init .sh scripts, and owner is root:root :
-rw-r--r-- root root 280 2018-01-09 01:03 init.fairnet.sh
init.fairnet.sh:
#!/system/bin/sh
insmod /system/lib/modules/xt_HL.ko
lsmod > /system/etc/curlsmod
/system/bin/iptables -t mangle -L > /system/etc/preiptables
/system/bin/iptables -t mangle -A POSTROUTING -o rmnet+ -j TTL --ttl-set 64
/system/bin/iptables -t mangle -L > /system/etc/postiptables
the most funny thing is command of load kernel module works fine, on boot too, but the other strings don't works: output files didn't exist, rule for iptables didn't add. I can't understand why insmod works and other commands don't.
Thanks for reading and sorry for my terrible English.
Problem solved!
SELinux blocked iptables in boot.
dmesg | grep iptables
gives me
<36>[ 39.819005] type=1400 audit(1516096993.541:9): avc: denied { create } for pid=2652 comm="iptables" lport=255 scontext=u:r:init_shell:s0 tcontext=u:r:init_shell:s0 tclass=rawip_socket op_res=-13 ppid=2640 pcomm="sh" tgid=2640 tgcomm="sh"
that means in current /sepolicy don't have rule i need.
For adding that rule i use sepolicy-inject, for build it need /usr/lib/libsepol.a, libsepol1-dev contains it. Also may use builded binaries for all archs (don't work for me, I build my own).
./sepolicy-inject -s init_shell -t init_shell -c rawip_socket -p getopt,create,setopt -P sepolicy -o sepolicy_new
add needed rule and make new sepolicy_new from old sepolicy from device.
Flash device with new sepolicy with new boot.img, I use AIK for Win.
Done! Now after boot my .sh script automatically runs and fully.
Thanks for reading and again sorry for my terrible English.
P.S. My own service I replaced from init.sony.rc to init.qcom.rc, also removed group root and disabled, but I done it only for ideological reasons and that not solve problem.
P.P.S. Change mode from Enforced to Permissive may do the thing, but I don't want to lost SELinux.

android modified su binary failes on setgid

I have created a custom su binary for testing purposes.
I have copied the binary to /system/xbin/mod_su
I have changed the files permissions with chmod 6755 /system/xbin/mod_su,
but still when I run the binary as a non-root user I fail on setgid(0) with 'Operation not permitted1'
Any ideas why this could happen ?
isn't 6755 permmisons enough ?
Did you chown root.root it before chmod?
Apart from chown you can also try
chmod 4755
The 4 specifies set user ID which can be the reason for the error.

Using ADB : How to get file modification date command

I have following command to get file date with time
adb shell ls -l /sdcard/sample.txt
Result of this command :
-rwxrwxr-x system sdcard_rw 676 2013-09-24 11:23 sample.txt
Now, I want 2013-09-24 11:23 time with seconds as well. like 2013-09-24 11:23:11
How I will get file modification date including seconds.
Thanks.. :)
If you have a stat command:
stat -c %y /sdcard/sample.txt
Seconds since Epoch
stat -c %Y /sdcard/sample.txt
By tweaking the code posted, I was able to get it worked using this command :
adb -d shell ls -l time-style="+%Y-%m-%d %H:%M:%S" path_to_file_in_device
The output is :
-rw-rw-r-- root sdcard_rw 22357385 2013-09-25 22:42 launcher.apk
ls -l --time-style="+%Y-%m-%d %H:%M:%S" /sdcard/sample.txt

How to get the PID from PS command output in Android shell

Can anyone tell how can I get the PID from the output of PS command in Android shell.
For example from the output:
u0_a51 20240 38 132944 22300 ffffffff 40037ebc S com.example.poc_service
pid value 20240 is to be got. I tried
ps -ef | grep com.example.poc_service
but to no avail. Also pgrep is not being recognized.
If you have shell access in Android you can also use pidof:
# pidof com.example.poc_service
20240
However, be careful as there may be multiple processes matching...
Its pretty nasty but it works:
for pid in `ls /proc`; do
cmd=`cat $pid/cmdline 2> /dev/null`;
if [ "X$cmd" == "Xcom.example.poc_service" ]; then
echo $pid;
fi
done
or as one line:
for pid in `ls /proc`; do cmd=`cat $pid/cmdline 2> /dev/null`; if [ "X$cmd" == "X/system/bin/mm-qcamera-daemon" ]; then echo $pid; fi done
Neither grep, egrep, fgrep, rgrep is available in Android.
If you are working on Unix, Linux, Mac or Cygwin, you can pipe the output of adb shell command to get the result you want.
$ adb shell ps |grep settings
system 23846 71 111996 22676 ffffffff 00000000 S com.android.settings
$ adb shell ps |grep settings |awk '{print $2}'
23846

Can't execute "stat" on android 2.3.4 command not found

So I am currently connected to my android phone using adb shell. When I do "stat file"
I get this message:
stat: not found
Do I need to install this script or what? Im on a 2.3.4 Gingerbread.
stat does not come with Android/AOSP.
If you run ls /system/bin you will get a list a lot shorter than what you are probably used to being able to do in most *NIX environments:
ATFWD-daemon
abcc
adb
am
app_process
applypatch
atrace
bdAddrLoader
bmgr
bootanimation
bridgemgrd
btnvtool
bu
bugreport
cat
chcon
chmod
chown
clatd
clear
cmp
conn_init
content
cp
dalvikvm
date
dd
debuggerd
dexopt
df
dhcpcd
diag_klog
diag_mdlog
dmesg
dnsmasq
drmserver
ds_fmc_appd
du
dumpstate
dumpsys
e2fsck
efsks
fsck_msdos
getenforce
getevent
getprop
getsebool
grep
gzip
hci_qcomm_init
hd
hostapd
id
ifconfig
iftop
ime
input
insmod
installd
ioctl
ionice
ip
ip6tables
iptables
keystore
kill
ks
linker
ln
load_policy
log
logcat
logwrapper
ls
lsmod
lsof
make_ext4fs
md5
mdnsd
media
mediaserver
mkdir
mksh
mm-qcamera-daemon
monkey
mount
mpdecision
mtpd
mv
nandread
ndc
netcfg
netd
netmgrd
netstat
newfs_msdos
nl_listener
notify
ping
pm
port-bridge
pppd
printenv
ps
qcks
qmuxd
qseecomd
racoon
radish
reboot
renice
requestsync
restorecon
rild
rm
rmdir
rmmod
rmt_storage
route
run-as
runcon
schedtest
schedtop
screencap
screenshot
sdcard
sendevent
sensors.qcom
sensorservice
service
servicemanager
setconsole
setenforce
setprop
setsebool
settings
sh
sleep
smd
start
stop
surfaceflinger
svc
sync
system_server
tc
thermald
toolbox
top
touch
uiautomator
umount
uptime
usbhub
usbhub_init
v4l2-qcamera-app
vdc
vmstat
vold
watchprops
wipe
wm
wpa_supplicant
No stat, as you can see. If you have root privileges, a simple solution is to install something like BusyBox which adds some such bread-and-butter scripted functions as stat to your environment:
[
[[
acpid
addgroup
adduser
adjtimex
ar
arp
arping
ash
awk
basename
beep
blkid
brctl
bunzip2
bzcat
bzip2
cal
cat
catv
chat
chattr
chgrp
chmod
chown
chpasswd
chpst
chroot
chrt
chvt
cksum
clear
cmp
comm
cp
cpio
crond
crontab
cryptpw
cut
date
dc
dd
deallocvt
delgroup
deluser
depmod
devmem
df
dhcprelay
diff
dirname
dmesg
dnsd
dnsdomainname
dos2unix
dpkg
du
dumpkmap
dumpleases
echo
ed
egrep
eject
env
envdir
envuidgid
expand
expr
fakeidentd
false
fbset
fbsplash
fdflush
fdformat
fdisk
fgrep
find
findfs
flash_lock
flash_unlock
fold
free
freeramdisk
fsck
fsck.minix
fsync
ftpd
ftpget
ftpput
fuser
getopt
getty
grep
gunzip
gzip
hd
hdparm
head
hexdump
hostid
hostname
httpd
hush
hwclock
id
ifconfig
ifdown
ifenslave
ifplugd
ifup
inetd
init
inotifyd
insmod
install
ionice
ip
ipaddr
ipcalc
ipcrm
ipcs
iplink
iproute
iprule
iptunnel
kbd_mode
kill
killall
killall5
klogd
last
length
less
linux32
linux64
linuxrc
ln
loadfont
loadkmap
logger
login
logname
logread
losetup
lpd
lpq
lpr
ls
lsattr
lsmod
lzmacat
lzop
lzopcat
makemime
man
md5sum
mdev
mesg
microcom
mkdir
mkdosfs
mkfifo
mkfs.minix
mkfs.vfat
mknod
mkpasswd
mkswap
mktemp
modprobe
more
mount
mountpoint
mt
mv
nameif
nc
netstat
nice
nmeter
nohup
nslookup
od
openvt
passwd
patch
pgrep
pidof
ping
ping6
pipe_progress
pivot_root
pkill
popmaildir
printenv
printf
ps
pscan
pwd
raidautorun
rdate
rdev
readlink
readprofile
realpath
reformime
renice
reset
resize
rm
rmdir
rmmod
route
rpm
rpm2cpio
rtcwake
run-parts
runlevel
runsv
runsvdir
rx
script
scriptreplay
sed
sendmail
seq
setarch
setconsole
setfont
setkeycodes
setlogcons
setsid
setuidgid
sh
sha1sum
sha256sum
sha512sum
showkey
slattach
sleep
softlimit
sort
split
start-stop-daemon
stat
strings
stty
su
sulogin
sum
sv
svlogd
swapoff
swapon
switch_root
sync
sysctl
syslogd
tac
tail
tar
taskset
tcpsvd
tee
telnet
telnetd
test
tftp
tftpd
time
timeout
top
touch
tr
traceroute
true
tty
ttysize
udhcpc
udhcpd
udpsvd
umount
uname
uncompress
unexpand
uniq
unix2dos
unlzma
unlzop
unzip
uptime
usleep
uudecode
uuencode
vconfig
vi
vlock
volname
watch
watchdog
wc
wget
which
who
whoami
xargs
yes
zcat
zcip
Great stuff - you won't need any computer but your phone, anymore!
the stat command is not available on the device. There is a very limited set of commands available. They are listed here:
http://developer.android.com/guide/developing/tools/adb.html
What are you trying to do?

Categories

Resources