mardi 21 février 2017

How to Enable System-Wide Immersive Mode without Root

As phone screens have become larger and larger, sometimes we want to hide the status and navigation bar so we can view our content using the entirety of the crisp, beautiful HD screen.

Starting with Android 4.4, applications could implement Immersive Mode to truly bring a full-screen experience to an end-user. Unfortunately, Google and OEMs have never exposed the ability for users to manually control when they want to enable Immersive Mode. A third-party application called GMD Full Screen Immersive Mode has provided a workaround for a few years now, but the biggest issue with using this app is that it breaks the soft keyboard.

Users have floated around an ADB command that triggers a system-wide Immersive Mode for quite some time, but for years it was believed that using this command when unplugged from an ADB terminal would require root access. However, late last year users discovered that certain ADB commands could in fact be triggered on the device without root access, provided the application has a certain permission. This means that you can enable system-wide immersive mode on demand. You can, for instance, create a Nougat tile to toggle Immersive Mode, or even set Immersive Mode on a per-app basis.


Toggle Immersive Mode without Root

As you can see in the video above, I’ve created a Nougat tile that toggles Immersive Mode when I press on it. This is on my unrooted Huawei Mate 9, but it should work on nearly every Android 4.4+ device. You only need two applications to make this work: Tasker and AutoTools. You’ll also need to install AutoNotification if you want to be make a Nougat tile out of this, but it isn’t required.

Once you’ve installed both applications, you’ll need to grant the WRITE_SECURE_SETTINGS permission to AutoTools in order to be able to toggle Immersive Mode (among other awesome settings that we’ll cover at a later time). This is because the command for Immersive Mode is defined under the Settings.Global class, though the exact syntax for the command is hidden in AOSP. We’ll first go over how to grant the necessary permission to AutoTools then how to use the command in Tasker.


Granting Secure Settings Permission to AutoTools

Under Android’s permission management system, applications define the permissions they want to be granted in the Manifest file. Users can then grant or deny permissions on installation (pre-Marshmallow) or on demand (Marshmallow+). However, there are certain permissions that applications cannot be granted even if they request it in the Manifest, such as WRITE_SECURE_SETTINGS. This is because granting any application a permission as powerful as this would give that app a ton of control over your device.

But there is one workaround that we can use to grant the WRITE_SECURE_SETTINGS permission to any app we want. By using ADB’s package manager (pm) tool, we can grant any permission to any application we want (provided that application requests that permission in the Manifest file).

The first thing you’ll need to do is install the ADB binary onto your computer followed by the right driver for your device. Then, enable USB Debugging in Developer Options (go to Settings –> About Phone and tap on Build number 7 times if you haven’t already) and connect your phone to your computer. Finally, send the following command once you’ve opened up a terminal:

adb shell pm grant com.joaomgcd.autotools android.permission.WRITE_SECURE_SETTINGS

Now AutoTools will have the ability to change any Global, Secure, or System setting on your device. There are various ways you can play around with these settings, and the list of available settings in each category completely depends on your device and software build, but that discussion is for another time. In any case, we’ll move on show you how to use AutoTools to toggle Immersive Mode.


Using Tasker to Toggle Immersive Mode via Nougat Tile

Toggling Immersive Mode via a tile obviously requires Android Nougat, so if you don’t have Nougat then skip this section to learn how to toggle it on a per-app basis. If you haven’t already, go download AutoNotification from the Google Play Store and grant it Notification Access. This Tasker plug-in is what we’ll use to make our own custom Notification Tile.

Here is the profile description for those of you who are familiar with Tasker. If you aren’t that familiar with Tasker, read on for step-by-step instructions.

Nougat Tile Immersive Mode Toggle

Profile: Toggle Immersive Mode (30)
Event: AutoNotification [ Configuration:Event Behaviour
Filter: immersivemode ]
Enter: Immersive Mode (33)
A1: AutoNotification Tiles [ Configuration:Tile: 1
Command: immersivemode
Label: Immersive mode
Icon: /storage/emulated/0/Tasker/immersive.png
State: 999 Timeout (Seconds):60 ]
A2: AutoTools Secure Settings [ Configuration:Immersive Mode: Toggle Timeout (Seconds):60 ]

Open up Tasker and press the + button in the bottom right corner. Create an Event context and select Plugin –> AutoNotification. Hit the pencil icon to open the configuration page for AutoNotification. Under the Command Filter enter immersivemode. This is the exact command that will be sent when we tap on a Nougat tile.

Now create a new Task (with any name) attached to this Profile, and for the first Action go to Plugin –> AutoNotification –> Tiles. For the tile number, pick the 1st tile. For the Command enter immersivemode exactly as written. The label is what will be displayed under the tile, so name it something like “Immersive Mode.” For the Icon, save the icon that I attached at the beginning of this section to your internal storage and use that. Finally for the State select Toggle Active/Inactive.

Once you’re done, run the Task once (press the play button in the bottom left of the Task creation screen) so the tile will be populated. Now once you expand the list of available Notification Tiles, you should see your new Immersive Mode toggle.


Using Tasker to Toggle Immersive Mode on a Per-App Basis

Toggling Immersive Mode on a per-app basis is quite simple, all we need to do is create an Application context in Tasker that will trigger when the application is launched or closed, and when it does so Immersive Mode is toggled. In order for Tasker to monitor applications, you’ll need to enable its Accessibility Service.

Here is the profile description for those of you who are familiar with Tasker. If you aren’t that familiar with Tasker, read on for step-by-step instructions.

Per-App Immersive Mode

Profile: Per-App Immersive Mode (192)
        Application: Chrome or XDA Labs
Enter: Anon (199)
        A1: AutoTools Secure Settings [ Configuration:Immersive Mode: Toggle Timeout (Seconds):60 ] 

Exit: Anon (204)
        A1: AutoTools Secure Settings [ Configuration:Immersive Mode: Toggle Timeout (Seconds):60 ]

You’ll first want to open up Tasker, as we’ll create a profile to start Immersive Mode when certain applications are open. Open up Tasker and press the + button in the bottom right corner to create a new Profile. For the context type, select Application and select all of the applications that you want Immersive Mode to be active in.

When you are done, press back and Tasker will ask you to create a Task. There’s no need to name the task, so just press the checkmark to begin the Task creation. Once you enter the Task creation screen, there’s only one Action you need to add. Press the + button at the bottom and go to Plugin –> AutoTools –> Secure Setting. Press the pencil icon to configure AutoTools. Here, go to Display then tap on Immersive Mode and choose “Toggle.”

There’s one last thing we need to do, and that’s to disable Immersive Mode when you exit the application. Go back to Tasker’s main screen and long-press on the Task you just created so you can create an Exit Task. When you create an exit task, simply add the same action you added in the first task – this will toggle Immersive Mode.


Fine-Tuning Immersive Mode

As I mentioned previously, the exact commands available for forcing Immersive Mode can be gleaned from AOSP. You can set Immersive Mode to only hide the notification bar or only hide the navigation bar as well, by issuing either of the following commands:

settings put global policy_control immersive.status=*
settings put global policy_control immersive.navigation=*

Of course, AutoTools doesn’t actually let you directly send shell commands like this, but instead you’ll send the command using its interface. Just select “Custom Setting” in AutoTools Secure Settings, set the Setting Type to “global”, set the “Input Type” to “String” and for the Name you have to enter “policy_control immersive.status=*” or “policy_control immersive.navigation=*”. You can use this command in place of the one we used for the Nougat Tile or per-app control if you prefer Immersive Mode hiding one of either the status bar or navigation bar.


Download and Import to Tasker

As always, we’re providing the script’s XML file that you can download and import. Simply download the file from the link below and save it anywhere on your internal storage. Open up Tasker and disable Beginner Mode in Preferences. Then, go back to the main screen and long-press on the “Profile” tab up top. You should see a pop-up with one of the options being “Import.” Tap on that and browse to where you saved the .prf.xml file and select that file to import.

If you choose to import the Notification Tile one, make sure you save the Immersive Mode icon as immersive.png and save it to /sdcard/Tasker. If you choose to import the Per-App profile, then make sure you go in and customize the applications that it will trigger on, as my sample is set to only trigger when using Chrome or XDA Labs.

Download the Notification Tile Immersive Mode Toggle Download the Per-App Immersive Mode Toggle Profile

We hope you find this tip useful. Let us know in the comments below if this works for you!



from xda-developers http://ift.tt/2lsz6RA
via IFTTT

Aucun commentaire:

Enregistrer un commentaire