MCPcopy Index your code
hub / github.com/callstack/agent-device / setAndroidSetting

Function setAndroidSetting

src/platforms/android/settings.ts:25–162  ·  view source on GitHub ↗
(
  device: DeviceInfo,
  setting: string,
  state: string,
  appPackage?: string,
  options?: SettingOptions,
)

Source from the content-addressed store, hash-verified

23
24// fallow-ignore-next-line complexity
25export async function setAndroidSetting(
26 device: DeviceInfo,
27 setting: string,
28 state: string,
29 appPackage?: string,
30 options?: SettingOptions,
31): Promise<Record<string, unknown> | void> {
32 const normalized = setting.toLowerCase();
33 switch (normalized) {
34 case 'wifi': {
35 const enabled = parseSettingState(state);
36 await runAndroidAdb(device, ['shell', 'svc', 'wifi', enabled ? 'enable' : 'disable']);
37 return;
38 }
39 case 'airplane': {
40 const enabled = parseSettingState(state);
41 const flag = enabled ? '1' : '0';
42 const bool = enabled ? 'true' : 'false';
43 await runAndroidAdb(device, ['shell', 'settings', 'put', 'global', 'airplane_mode_on', flag]);
44 await runAndroidAdb(device, [
45 'shell',
46 'am',
47 'broadcast',
48 '-a',
49 'android.intent.action.AIRPLANE_MODE',
50 '--ez',
51 'state',
52 bool,
53 ]);
54 return;
55 }
56 case 'location': {
57 if (state.toLowerCase() === 'set') {
58 if (device.kind !== 'emulator') {
59 throw new AppError(
60 'UNSUPPORTED_OPERATION',
61 'Android precise location coordinates are supported only on emulators.',
62 {
63 deviceId: device.id,
64 hint: 'Use an Android emulator for adb emu geo fix, or configure location through device/provider tooling.',
65 },
66 );
67 }
68 const { latitude, longitude } = requireLocationCoordinates(options);
69 await runAndroidAdb(device, ['emu', 'geo', 'fix', String(longitude), String(latitude)]);
70 return { latitude, longitude };
71 }
72 const enabled = parseSettingState(state);
73 const mode = enabled ? '3' : '0';
74 await runAndroidAdb(device, ['shell', 'settings', 'put', 'secure', 'location_mode', mode]);
75 return;
76 }
77 case 'animations': {
78 const enabled = parseSettingState(state);
79 const scale = enabled ? '1' : '0';
80 for (const key of ANDROID_ANIMATION_SCALE_SETTINGS) {
81 await runAndroidAdb(device, ['shell', 'settings', 'put', 'global', key, scale]);
82 }

Callers 2

createAndroidInteractorFunction · 0.90
index.test.tsFile · 0.90

Calls 11

parseSettingStateFunction · 0.90
runAndroidAdbFunction · 0.90
resolveAndroidAppFunction · 0.90
parsePermissionActionFunction · 0.90

Tested by

no test coverage detected