Nativescript: tns run android enables auto rotate on device

Created on 24 Jul 2017  路  15Comments  路  Source: NativeScript/NativeScript

Tell us about the problem

When installing an app using tns run android , auto rotate of device is turned on every time.

Which platform(s) does your issue occur on?

Android
(iOS not tested)

Please provide the following version numbers that your issue occurs with:

  • CLI: 3.0.3
  • Cross-platform modules: (check the 'version' attribute in the
    node_modules/tns-core-modules/package.json file in your project)
  • Runtime(s): android

Please tell us how to recreate the issue in as much detail as possible.

  1. Open powershell(windows)
  2. do tns create appName
  3. cd to directory
  4. turn off auto rotate on android device
  5. tns run android

this turns auto rotate on.

android

All 15 comments

Same thing here...

I've meant to look into this for a long time, been happening since the 2x days from what I recall. Device has disable screen rotation but once you run a NS app it enables screen rotation without any indication. Can confirm it's 100% consistent on Motorola Droid Turbo 2 when running android 6 & 7.

@tsonevn Apparently you removed your comment, however, I've tested this on Xiaomi Redmi Note 3 android 6.0.1 and Moto G5 plus android 7.

And also, looks like I'm not the only one facing this.

Hi @aaayushsingh,
Indeed we were able to reproduce this issue on our side. However, we will need some time to research, what is causing this behavior.

@tsonevn It happens between these two tasks. Could it be something in the nativescript-cli?
Refreshing application...
Successfully synced application org.nativescript.create on device 8c66cee7.

and also that auto-rotate is enabled every time a hot-swap of code takes place.

@aaayushsingh, @shabib3, @bradmartin, @tsonevn the problem is we use the monkey tool to start the application and for some reason, it turns on autorotate.

One possible solution is to revert the way we start the application:

await this.adb.executeShellCommand(["am",
    "start", "-a", "android.intent.action.MAIN",
    "-n", appIdentifier + "/com.tns.NativeScriptActivity"
    ]);

but that means we need to specify the main activity we want to start: /com.tns.NativeScriptActivity, and if the user changes the main activity, cli wouldn't be able to start the application, without adding custom logic and reading the AndroidManifest.xml.

PS. I'm working to find a better way to fix the problem and disable the "autorotate" option on application start.

_Edit_
One possible solution is turning the auto rotate option back to portrait right after the application start:

adb shell content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:0

@Plamen5kov I don't like the idea of forcing device rotation manually, for one, you may have to know of the original state, to be able to do it properly, and I've also noticed that the adb monkey tool doesn't always unlock automatic rotation.

In order to determine which Activity to send a MAIN intent to using the Activity Manager (adb am), we could do a package dump, and grep the Activity Resolver Table. For an application with a single activity it looks like this:

  Activity Resolver Table:
    Non-Data Actions:
        android.intent.action.MAIN:
          2e5610f org.nativescript.volunteerupapp/com.tns.NativeScriptActivity filter c0aef3
            Action: "android.intent.action.MAIN"
            Category: "android.intent.category.LAUNCHER"
            AutoVerify=false

If I executed adb shell pm dump org.nativescript.volunteerupapp | grep -A 1 MAIN I would end up with just this, which is fairly parseable:

        android.intent.action.MAIN:
          2e5610f org.nativescript.volunteerupapp/com.tns.NativeScriptActivity filter c0aef3
            Action: "android.intent.action.MAIN"
            Category: "android.intent.category.LAUNCHER"

There is an alternative to using pm dump to get the Activity Resolver table, and that's using cmd package resolve-activity --brief org.nativescript.volunteerupapp, which unfortunately appears to be unavailable on devices API 24 or lower. Following is the result when the command is executed:

priority=0 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=false
org.nativescript.volunteerupapp/com.tns.NativeScriptActivity

I've also noticed that the adb monkey tool doesn't always unlock automatic rotation.

@Pip3r4o can you share those cases?

Maybe we can pass some additional argument to monkey tool in order to stop this behavior. For example --pct-rotation 0. I'm not familiar with all possible options, but we can try some of them described here

Some more infromation:
https://stackoverflow.com/questions/12872917/change-screen-orientations-during-monkey-run

@Plamen5kov the SO post that Roskata posted contains other commenters claiming that Rotation may or may not happen, and that it is all random. - https://stackoverflow.com/a/12873010/6408287

@rosen-vladimirov @Pip3r4o my vote goes towards removing the monkey altogether and using the Android Activity Manager am tool instead. What do you think?

Based on popular vote: removing monkey from implementation and replacing it with am tool.

@Plamen5kov
You have any ETA about when it will be out?

@shabib3 the fix will be in for the next release. It's already implemented, but it's not in master branch yet.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings