[TOOLS][ZIPS][SCRIPTS] osm0sis' Odds and Ends [Multiple Devices/Platforms]

osm0sis

Senior Recognized Developer / Recognized Contribut
Mar 14, 2012
14,347
32,235
263
Halifax
...
I also submitted a script to Open GApps today to fix the GApps issue with Google Dialer causing reboots when it's not set as default (edit: final commit now live), ...
More (frustrating) adventures in computing!

In addition to my above fix to Open GApps, I also tried to tackle the GApps issue where CMSetupWizard being removed on a clean install (useful because it allows Google's SetupWizard to grant default permissions, which naturally helps the GApps permissions issues present in Marshmallow and above) breaks the Quick Settings pull-down, not allowing it to expand from the Notifications layout.

@MastahF and I have documented it on the Open GApps wiki, but basically, I found the true issue was CM made a change to have the pull-down rely only on the "cm_setup_wizard_completed" setting from their wizard, (similar to Google's "device_provisioned" setting), and found setting it manually (with `su -c 'settings --cm put secure cm_setup_wizard_completed 1'`) instantly resolved the issue of the broken pull-down. The annoying part of this is of course that it means CMSetupWizard isn't even necessary to provision Quick Settings, since it gets set up perfectly well without it, and suggests this limitation to be artificial and arbitrary, so their code change should just be reverted.

Sorry if I sound a little bitter, but I spent a day trying to reverse engineer their cmsettings.db with sqlite3 to see if we could force the setting in from recovery like we did with setting Dialer as default in Google's settings_secure.xml, only to find there was no way to acceptably build it from scratch (hung boot) due to some differences in the way the CMSettings APK creates SQlite B-tree cell arrays versus doing it from the sqlite3 command-line, despite no PRAGMA differences or content differences. Using a prebuilt hacked/modified (stripped of all settings but cm_setup_wizard_completed) cmsettings.db would boot, but either a) not get provisioned with all the other settings it normally would from first-boot because the CMSettings APK isn't built to handle that if the cmsettings.db file exists or the db "user_version" was set >2, or b) overwrite our inserted settings as part of "upgrading" the db from a version <4.

Here is my script of failed attempts, for those interested, or in case it's helpful in the future. As shown it'll attempt to create the db; commented out is the hacked db replacement attempt.

cmsetup_fix.sh:
Code:
#!/sbin/sh
# osm0sis @ xda-developers
# WIP

mount /system 2> /dev/null
sqlite3="/system/xbin/sqlite3"
#cmsettings="/tmp/cmsettings.db"

cmdb() {
cat <<EOF
PRAGMA foreign_keys=OFF;
PRAGMA page_size=4096;
PRAGMA user_version=4;
BEGIN TRANSACTION;
CREATE TABLE android_metadata (locale TEXT);
INSERT INTO "android_metadata" VALUES('en_US');
CREATE TABLE system (_id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT UNIQUE ON CONFLICT REPLACE,value TEXT);
CREATE TABLE secure (_id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT UNIQUE ON CONFLICT REPLACE,value TEXT);
CREATE TABLE global (_id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT UNIQUE ON CONFLICT REPLACE,value TEXT);
CREATE INDEX systemIndex1 ON system (name);
CREATE INDEX secureIndex1 ON secure (name);
CREATE INDEX globalIndex1 ON global (name);
INSERT INTO "secure" VALUES(1,'cm_setup_wizard_completed','1');
DELETE FROM sqlite_sequence;
INSERT INTO "sqlite_sequence" VALUES('system',0);
INSERT INTO "sqlite_sequence" VALUES('secure',1);
INSERT INTO "sqlite_sequence" VALUES('global',0);
COMMIT;
EOF
}

if [ ! -d "/data/data/org.cyanogenmod.cmsettings/databases" ]; then
  install -d "/data/data/org.cyanogenmod.cmsettings/databases"
  #cp "$cmsettings" "/data/data/org.cyanogenmod.cmsettings/databases/cmsettings.db"
  $sqlite3 -batch "/data/data/org.cyanogenmod.cmsettings/databases/cmsettings.db" "$(cmdb)"
  chown 1000:1000 "/data/data"
  chown -R 1000:1000 "/data/data/org.cyanogenmod.cmsettings"
  chmod 771 "/data/data" "/data/data/org.cyanogenmod.cmsettings/databases"
  chmod 751 "/data/data/org.cyanogenmod.cmsettings"
  chmod 660 "/data/data/org.cyanogenmod.cmsettings/databases/cmsettings.db"
fi
So, it seems the only thing that can be done to work around it has to be executing that original `settings <...>` command from booted CM after Google's SetupWizard has finished.

Anyway, TL;DR: I've added a new package, UPDATE-CMSetup.Fix.For.GApps.Installer-signed.zip, to the OP to automatically fix the Quick Settings pull-down issue for people wanting to use CM ROMs with GApps and allow them to continue to not pointlessly/detrimentally leave CMSetupWizard installed. It requires a SuperSU installation (for su.d support), so flash it after the SuperSU zip and your GApps. It will install the su.d script which follows, and if the fix has already been applied the script executes and does nothing, so, if you're a CM user, pretty much flash-and-forget as part of your clean ROM+GApps+SuperSU flash ritual.

000cmsetupfix:
Code:
#!/system/bin/sh
# chmod -R 755 /system/su.d /su/su.d
#
# Fix CM Quick Settings + GApps w/o CMSetupWizard
# osm0sis @ xda-developers

# run in an asynchronous subshell to not impede the boot with su.d
{

# ensure the cm settings database exists before attempting changes
until [ -f /data/data/org.cyanogenmod.cmsettings/databases/cmsettings.db ]; do
  sleep 1;
done;

# wait until boot is complete to ensure any boot-time database setup is complete
until [ "$(getprop sys.boot_completed)" == 1 ]; do
  sleep 1;
done;

# wait until general device setup is completed
until [ "$(settings get global device_provisioned)" == 1 ]; do
  sleep 1;
done;

# set flag to restore quick settings functionality if it is not already
if [ "$(settings --cm get secure cm_setup_wizard_completed)" != 1 ]; then
  settings --cm put secure cm_setup_wizard_completed 1;
fi;

}&

Lastly, on a brighter note - woot! My busybox fix when building for Android API 21 is in the v1.25.0 code drop from yesterday, but the version is currently labeled "unstable" so we'll have to wait a little while longer (probably 1.25.1 stable) for new builds. :good: :cool:

I work on these projects in my limited time off, so if you like the progress I'm making, or enjoy anything else I've done on xda, please do hit the donate link from my profile. Thanks for your support!

Edit: Added the CMSetup Fix blurb to the Installers section of the OP. :)
 
Last edited:

808phoneaddict

Senior Member
Dec 26, 2011
950
135
0
Hey I needed to fix my sdcard permissions, apparently, and came here and downloaded and flashed your script for my nexus 6

I couldn't take and save screenshots and phone would say that I was out of memory...

Your script worked perfectly! Thanks!

Sent from my Nexus 6 using XDA-Developers mobile app
 
  • Like
Reactions: osm0sis

The Fer-Shiz-Nizzle

Senior Member
Jun 17, 2010
931
822
123
38
Plano, TX
@osm0sis

I have seen your profile in many of my subscribed threads on XDA, and have meant to donate to you simply out of appreciation for your contributions. Well, apparently I had a few too many , and was messing around with some su.d scripts. The result was a bootloop. My latest nandroid was a couple weeks ago, and I didn't want to lose my current data. I remembered your SUmount.zip. Unfortunately, my phone is currently my only source of Internet. So I restored my old backup, went to XDA, downloaded your SUmount.zip...restored my new backup, flashed the zip and deleted the offending su.d script and rebooted successfully. Thank you so much for this and all your other contributions! I might not need them, but if I do, I know where to find them.

Thanks,
Transaction ID:*5MV19910S8484252P


Sent from my Sprint HTC 10 using Tapatalk
 

osm0sis

Senior Recognized Developer / Recognized Contribut
Mar 14, 2012
14,347
32,235
263
Halifax
@osm0sis

I have seen your profile in many of my subscribed threads on XDA, and have meant to donate to you simply out of appreciation for your contributions. Well, apparently I had a few too many , and was messing around with some su.d scripts. The result was a bootloop. My latest nandroid was a couple weeks ago, and I didn't want to lose my current data. I remembered your SUmount.zip. Unfortunately, my phone is currently my only source of Internet. So I restored my old backup, went to XDA, downloaded your SUmount.zip...restored my new backup, flashed the zip and deleted the offending su.d script and rebooted successfully. Thank you so much for this and all your other contributions! I might not need them, but if I do, I know where to find them.

Thanks,
Transaction ID:*5MV19910S8484252P
My general goal has been to fill in whatever gaps I see in my daily use/tinkering, in a "how can I make this easier for myself?" sort of way, so it's always great to hear others are finding my tools useful, or a good success story using one of them! I am humbled by your kind words and generous support. Thank you! :)
 
Last edited:

fhem

Senior Member
Nov 4, 2013
880
1,573
93
Pittsburgh, PA
More (frustrating) adventures in computing!

Lastly, on a brighter note - woot! My busybox fix when building for Android API 21 is in the v1.25.0 code drop from yesterday, but the version is currently labeled "unstable" so we'll have to wait a little while longer (probably 1.25.1 stable) for new builds. :good: :cool:

:)
I don't get it (them not you)!!! They showing it stable here???
 
Last edited:
  • Like
Reactions: osm0sis

osm0sis

Senior Recognized Developer / Recognized Contribut
Mar 14, 2012
14,347
32,235
263
Halifax
I don't get it (them not you)!!! They showing it stable here???
Git branch labels versus how they actually treat each major revision; if you scroll down on the official homepage you find each 1.x.0 release is deemed "unstable," then they add some bug fixes from feedback to that branch, and release a "stable" 1.x.1. :)
 
Last edited:

osm0sis

Senior Recognized Developer / Recognized Contribut
Mar 14, 2012
14,347
32,235
263
Halifax
  • Like
Reactions: skulldreamz

skulldreamz

Senior Member
Mar 13, 2012
1,402
1,175
143
Baltimore, MD

Attachments

Last edited:

osm0sis

Senior Recognized Developer / Recognized Contribut
Mar 14, 2012
14,347
32,235
263
Halifax
While it's true you can make/run builds from master branch HEAD of the busybox git repo, and the version number is set for the next major release (1.26.0 in this case), that still does not make that version released and definitely does not make it stable. That's just how a lot of people run their development cycle; they set the next version number at the beginning rather than the end, and @_that is correct, they add a version git commit tag, fork to a new 1_x_stable branch, and make an official announcement when it's done.

I'd also like to reiterate they have their release process for a reason. Look through the patch directories for all the recent releases, you'll see that they always find something broken and needing patching, especially in the 1.x.0 unstable releases.

I'm waiting on 1.25.1 stable for this very reason (which will come from the 1_25_stable branch), since even though it may run now, I'd rather wait until busybox themselves declare it stable before I include it in all my projects, since there's a better chance nothing is broken that way.
 
Last edited:

skulldreamz

Senior Member
Mar 13, 2012
1,402
1,175
143
Baltimore, MD
While it's true you can run builds from master branch HEAD of the busybox git repo, and the version number is set for the next major release, that still does not make that version released and definitely does not make it stable.

They have their release process for a reason. Look through the patch directories for all the last releases, you'll see that they always find something broken and needing patching.

I'm waiting on 1.25.1 stable for this very reason (which will come from the 1.25.0_stable branch), since even though it may run now, I'd rather wait until busybox themselves declare it stable.
Makes total sense, always appreciate your enlightenment :D

---------- Post added at 04:30 PM ---------- Previous post was at 04:14 PM ----------

@osm0sis just curious are you having trouble with a new applet for example blkdiscard. I thought this was a much needed applet for a while now, even though you can always dd and dev/null a block, this has helped with a shorter cmdline writeout and adds the extra function of not needing the fastboot binary to remove a block if your not around a pc at the time. Always love to hear your spot on added insight, :D
 
Last edited:
  • Like
Reactions: osm0sis

mikeoswego

Senior Member
May 4, 2014
903
773
0
Northern Indiana
I'm waiting on 1.25.1 stable for this very reason (which will come from the 1_25_stable branch), since even though it may run now, I'd rather wait until busybox themselves declare it stable before I include it in all my projects, since there's a better chance nothing is broken that way.
I noticed the other day that the BusyBox version of 'ls' doesn't support the '-Z' option to show security contexts. Do you know if that is intentional, an oversight, or..?
 

mikeoswego

Senior Member
May 4, 2014
903
773
0
Northern Indiana

Attachments

osm0sis

Senior Recognized Developer / Recognized Contribut
Mar 14, 2012
14,347
32,235
263
Halifax
@osm0sis just curious are you having trouble with a new applet for example blkdiscard. I thought this was a much needed applet for a while now, even though you can always dd and dev/null a block, this has helped with a shorter cmdline writeout and adds the extra function of not needing the fastboot binary to remove a block if your not around a pc at the time. Always love to hear your spot on added insight, :D
Not sure what is up with it since I haven't done the bring-up to 1.25 for my NDK patchset yet. I'll try to enable it when we do get there though.

I noticed the other day that the BusyBox version of 'ls' doesn't support the '-Z' option to show security contexts. Do you know if that is intentional, an oversight, or..?
Are you saying that 'ls -Z' has been added in v1.26? On mine, the stock/toolbox 'ls' is found in /system/bin before the BusyBox link in /system/xbin. Stock/toolbox 'ls -Z' works, BusyBox doesn't. Screenshot attached. (I discovered this after installing BusyBox into a CM 13 rom which apparently has xbin before bin in the path.)
It's been a build config option for a few versions now, but ls -Z (and the other context commands) only works if you compile busybox with the selinux libraries. Most don't include them because they're pretty big libraries and add a bit too much bulk to a static binary if it's not necessary.

Here's the last time we discussed it here and I outlined the required config/build changes required if someone wanted to build their own:
http://forum.xda-developers.com/showthread.php?p=66160631#post66160631
 
Last edited:

bigsupersquid

Senior Member
Sep 22, 2010
2,249
1,666
193
BFE, MO
Just a bump. the tools keep getting updated.
I keep finding myself back here from time to time for useful little gems like the sdcard permissions fixer for MM.

Thanks again for sharing all your awesome work, Osmosis!
 
Last edited:
  • Like
Reactions: osm0sis