[Android Apps and Games] daxgirl:
Removing Acquiring Su dialog at app launch

To precede, I would like to say that this application for it's main use does not require a rooted device. The only functions that require SU are:

1. Reboot functions (those can be replaced with actual android built in reboot sequences for all reboot functions, except rebooting systemui, killing apps and fast reboot). That is provided the app is installed in priv-app.

2. Running scripts. We run scripts under SU because majority of them requires it, as most binaries in system/bin cannot be ran, unless explicitly allowed in kernel source code for UID of the application.

For editing Settings storage daatabase tables we need no SU, BUT (there is always a BUT):

1. Editing tables like Secure and Global requires app to be installed in priv-app. We currently don't have those tables included in our application, we only use System table. This is a completely different topic, so nuff said.

2. Editing System table requires no root. It also can be done from app installed in data, UNLESS the target sdk of build is set to 23+ in app gradle.build script. We currently have it set to 21. If any of you update the target sdk (not necessary!), you can ONLY run this app from system (app or priv-app). Permission to WRITE_SETTINGS has been revoked completely from user apps on MM and up. It is granted to any system app or app compiled for any SDK < 23. App compiled for sdk 21 runs no problem on sdk 23 platform. So no worries there.

To remove the su dialog. Go to MainViewActivity.java

Find onCreate method and remove the lines in red:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*Calling theme selector class to set theme upon start activity*/
ThemeSelectorUtility theme = new ThemeSelectorUtility(this);
theme.onActivityCreateSetTheme(this);
//Getting root privileges upon first boot or if was not yet given su
[COLOR="red"]CheckSu suPrompt = new CheckSu();
suPrompt.execute();[/COLOR]
}

Now in the same class find an inner class called CheckSu and inside of it lets go to method onPostExecute(Boolean result)

Now look what we do, we copy the lines in red from that method and we paste them (in blue) into onCreate method. So we will have:

@Override
protected void onPostExecute(Boolean result) {
mProgressDialog.dismiss();
//If the device is not rooted or su has been denied the app will not run.
//A dialog will be shown announcing that with a single button, upon clicking which the activity will finish.
if (!result) {
//If no su access detected, throw and alert dialog with single button that will finish the activity
AlertDialog.Builder mNoSuBuilder = new AlertDialog.Builder(MainViewActivity.this);
mNoSuBuilder.setTitle(R.string.missing_su_title);
mNoSuBuilder.setMessage(R.string.missing_su);
mNoSuBuilder.setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
mNoSuBuilder.create();
Dialog mNoSu = mNoSuBuilder.create();
mNoSu.show();

} else {
//Provided the su privileges have been established, we run the activity as usual, beginning with setting content view
[COLOR="red"] setContentView(R.layout.activity_main_view);
mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
setSupportActionBar(mToolbar);

mNavigationDrawerFragment = (NavigationDrawerFragment)
getFragmentManager().findFragmentById(R.id.fragment_drawer);

// Set up the drawer. Look in NavigationDrawerFragment for more details
mNavigationDrawerFragment.setup(R.id.fragment_drawer, (DrawerLayout) findViewById(R.id.drawer), mToolbar, MainViewActivity.this);
initRebootMenu();[/COLOR]

}

}

........................................
@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
/*Calling theme selector class to set theme upon start activity*/
ThemeSelectorUtility theme = new ThemeSelectorUtility(this);
theme.onActivityCreateSetTheme(this);
[COLOR="Blue"][B] setContentView(R.layout.activity_main_view);
mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
setSupportActionBar(mToolbar);

mNavigationDrawerFragment = (NavigationDrawerFragment)
getFragmentManager().findFragmentById(R.id.fragment_drawer);

// Set up the drawer. Look in NavigationDrawerFragment for more details
mNavigationDrawerFragment.setup(R.id.fragment_drawer, (DrawerLayout) findViewById(R.id.drawer), mToolbar, MainViewActivity.this);
initRebootMenu();[/B][/COLOR]

}

Now you can completely delete the CheckSu class. It's useless.

Please note:

1. Copying assets (your scripts) is also done inside the async task. But since you don't want root functionality, you will not need scripts. Or we can change the class to just copy the assets.

2. Root functionality will still work. For the first time you perform action which requires root it WILL call su dialog. No worries. This just removes the asynchronous su request on first app launch.

[MENTION=3986004]civato[/MENTION], let me know how that goes.