Skip to main content
Glama
zillow
by zillow

rotate

Set device orientation to portrait or landscape for Android or iOS platforms during mobile automation testing.

Instructions

Rotate the device to a specific orientation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
orientationYesThe orientation to set
platformYesPlatform of the device

Implementation Reference

  • The main handler function for the 'rotate' tool. It instantiates the Rotate class and calls its execute method with the desired orientation.
    // Rotate handler
    const rotateHandler = async (device: BootedDevice, args: RotateArgs, progress?: ProgressCallback) => {
      try {
        const rotate = new Rotate(device);
        const result = await rotate.execute(args.orientation, progress);
    
        return createJSONToolResponse({
          message: `Rotated device to ${args.orientation} orientation`,
          observation: result.observation,
          ...result
        });
      } catch (error) {
        throw new ActionableError(`Failed to rotate device: ${error}`);
      }
    };
  • Zod schema defining the input parameters for the rotate tool: orientation (portrait/landscape) and platform.
    export const rotateSchema = z.object({
      orientation: z.enum(["portrait", "landscape"]).describe("The orientation to set"),
      platform: z.enum(["android", "ios"]).describe("Platform of the device")
    });
  • Registers the 'rotate' tool with the ToolRegistry, providing name, description, schema, and handler.
    // Register the new rotate tool
    ToolRegistry.registerDeviceAware(
      "rotate",
      "Rotate the device to a specific orientation",
      rotateSchema,
      rotateHandler,
      true // Supports progress notifications
    );
  • Core implementation class for rotating the device. Handles current orientation detection, orientation lock, ADB commands to set rotation, verification, and returns RotateResult. Extends BaseVisualChange for observation.
    export class Rotate extends BaseVisualChange {
      constructor(
        device: BootedDevice,
        adb: AdbUtils | null = null,
        axe: Axe | null = null
      ) {
        super(device, adb, axe);
      }
    
      /**
         * Get the current device orientation
         * @returns Promise with current orientation ("portrait" or "landscape")
         */
      async getCurrentOrientation(): Promise<string> {
        try {
          // Get current user_rotation setting
          const result = await this.adb.executeCommand("shell settings get system user_rotation");
          const userRotationStr = result.stdout.trim();
    
          // Check if the result is a valid number
          if (!/^\d+$/.test(userRotationStr)) {
            logger.warn(`Invalid user_rotation value: ${userRotationStr}, defaulting to portrait`);
            return "portrait";
          }
    
          const userRotation = parseInt(userRotationStr, 10);
    
          // Convert numeric value to orientation string
          // 0 = portrait, 1 = landscape (90°), 2 = reverse portrait (180°), 3 = reverse landscape (270°)
          // For simplicity, we'll treat 0,2 as portrait and 1,3 as landscape
          return (userRotation === 0 || userRotation === 2) ? "portrait" : "landscape";
        } catch (error) {
          logger.warn(`Failed to get current orientation: ${error}`);
          // If we can't detect current orientation, assume portrait as default
          return "portrait";
        }
      }
    
      /**
         * Check if orientation is locked
         * @returns Promise with boolean indicating if auto-rotation is disabled
         */
      async isOrientationLocked(): Promise<boolean> {
        try {
          const result = await this.adb.executeCommand("shell settings get system accelerometer_rotation");
          const autoRotate = parseInt(result.stdout.trim(), 10);
          // 0 = locked (auto-rotation disabled), 1 = unlocked (auto-rotation enabled)
          return autoRotate === 0;
        } catch (error) {
          logger.warn(`Failed to check orientation lock status: ${error}`);
          // If we can't check, assume it's not locked
          return false;
        }
      }
    
      async execute(
        orientation: "portrait" | "landscape",
        progress?: ProgressCallback
      ): Promise<RotateResult> {
        return this.observedInteraction(
          async () => {
    
            const value = orientation === "portrait" ? 0 : 1;
    
            // Get current orientation
            const currentOrientation = await this.getCurrentOrientation();
    
            // Check if device is already in the desired orientation
            if (currentOrientation === orientation) {
              return {
                success: true,
                orientation,
                value,
                currentOrientation,
                previousOrientation: currentOrientation,
                rotationPerformed: false,
                orientationLockHandled: false,
                message: `Device is already in ${orientation} orientation`
              };
            }
    
            // Check if orientation is locked
            const isLocked = await this.isOrientationLocked();
            let orientationUnlocked = false;
    
            try {
    
              // If orientation is locked, unlock it temporarily
              if (isLocked) {
                logger.info("Orientation is locked, temporarily unlocking for rotation");
                await this.adb.executeCommand("shell settings put system accelerometer_rotation 1");
                orientationUnlocked = true;
              }
    
              // Disable accelerometer rotation and set user rotation
              await this.adb.executeCommand("shell settings put system accelerometer_rotation 0");
              await this.adb.executeCommand(`shell settings put system user_rotation ${value}`);
    
              // Wait for rotation to complete
              await this.awaitIdle.waitForRotation(value);
    
              // If orientation was originally locked, restore the lock
              if (orientationUnlocked) {
                await this.adb.executeCommand("shell settings put system accelerometer_rotation 0");
                logger.info("Restored orientation lock");
              }
    
              // Verify the rotation was successful
              const newOrientation = await this.getCurrentOrientation();
              const rotationSuccessful = newOrientation === orientation;
    
              return {
                success: rotationSuccessful,
                orientation,
                value,
                currentOrientation,
                previousOrientation: currentOrientation,
                rotationPerformed: true,
                orientationLockHandled: orientationUnlocked,
                message: rotationSuccessful
                  ? `Successfully rotated from ${currentOrientation} to ${orientation}`
                  : `Failed to rotate to ${orientation}, current orientation is ${newOrientation}`
              };
            } catch (error) {
              // Restore orientation lock if we unlocked it
              if (orientationUnlocked) {
                try {
                  await this.adb.executeCommand("shell settings put system accelerometer_rotation 0");
                  logger.info("Restored orientation lock after error");
                } catch (restoreError) {
                  logger.warn(`Failed to restore orientation lock: ${restoreError}`);
                }
              }
    
              return {
                success: false,
                orientation,
                value,
                currentOrientation,
                previousOrientation: currentOrientation,
                rotationPerformed: false,
                orientationLockHandled: orientationUnlocked,
                error: `Failed to change device orientation: ${error}`
              };
            }
          },
          {
            changeExpected: true,
            timeoutMs: 5000,
            progress
          }
        );
      }
    }
  • TypeScript interface defining the structure of the result returned by the rotate operation, including success status, orientations, and observation.
    /**
     * Result of a rotate operation
     */
    export interface RotateResult {
      success: boolean;
      orientation: string;
      value: number;
      observation?: ObserveResult;
      error?: string;
    
      // Enhanced fields for intelligent rotation
      currentOrientation?: string;
      previousOrientation?: string;
      rotationPerformed?: boolean;
      orientationLockHandled?: boolean;
      message?: string;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It states the tool sets orientation, implying a mutation, but doesn't disclose behavioral traits like whether it requires specific device states, has side effects (e.g., affecting apps), or error conditions. This is a significant gap for a mutation tool with zero annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, with zero waste.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given this is a mutation tool with no annotations, no output schema, and 2 required parameters, the description is incomplete. It lacks information on behavioral context (e.g., device requirements, effects), usage guidelines, and output expectations. The high schema coverage helps but doesn't compensate for missing behavioral details.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with both parameters ('orientation' and 'platform') well-documented in the schema with enums and descriptions. The description adds no additional meaning beyond what the schema provides, such as explaining interactions between parameters. Baseline is 3 when schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('rotate') and the target ('the device'), specifying it sets a specific orientation. It uses a specific verb+resource combination. However, it doesn't distinguish this tool from potential sibling tools that might also manipulate device orientation, though none are explicitly listed among siblings.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., device must be active), exclusions, or related tools. Among siblings, tools like 'setDeviceMode' or 'shake' might be alternatives in some contexts, but no comparison is made.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/zillow/auto-mobile'

If you have feedback or need assistance with the MCP directory API, please join our Discord server