Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: io.appium.settings process check with isSettingsAppServiceRunningInForeground #895

Merged
merged 7 commits into from
Jan 9, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 35 additions & 29 deletions lib/helpers/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -814,45 +814,51 @@
`${SETTINGS_HELPER_PKG_ID} is already running. ` +
KazuCocoa marked this conversation as resolved.
Show resolved Hide resolved
`There is no need to reset its permissions.`
);
return;
KazuCocoa marked this conversation as resolved.
Show resolved Hide resolved
}

const apiLevel = await adb.getApiLevel();
if (apiLevel >= 29) {
// https://github.com/appium/io.appium.settings#internal-audio--video-recording
try {
await adb.shell(['appops', 'set', SETTINGS_HELPER_PKG_ID, 'PROJECT_MEDIA', 'allow']);
} catch (err) {
logger.debug((err as Error).message);
} else {
const apiLevel = await adb.getApiLevel();
if (apiLevel >= 29) {
// https://github.com/appium/io.appium.settings#internal-audio--video-recording
try {
await adb.shell(['appops', 'set', SETTINGS_HELPER_PKG_ID, 'PROJECT_MEDIA', 'allow']);
} catch (err) {
logger.debug((err as Error).message);
}
try {
await adb.shell([
'cmd',
'notification',
'allow_listener',
SETTING_NOTIFICATIONS_LISTENER_SERVICE,
]);
} catch (err) {
logger.debug((err as Error).message);
}
}
try {
await adb.shell([
'cmd',
'notification',
'allow_listener',
SETTING_NOTIFICATIONS_LISTENER_SERVICE,
]);
} catch (err) {
logger.debug((err as Error).message);
if (apiLevel <= 23) {
// Android 6- devices should have granted permissions
// https://github.com/appium/appium/pull/11640#issuecomment-438260477
const perms = ['SET_ANIMATION_SCALE', 'CHANGE_CONFIGURATION', 'ACCESS_FINE_LOCATION'];
logger.info(`Granting permissions ${perms} to '${SETTINGS_HELPER_PKG_ID}'`);
await adb.grantPermissions(
SETTINGS_HELPER_PKG_ID,
perms.map((x) => `android.permission.${x}`)
);
}
}
if (apiLevel <= 23) {
// Android 6- devices should have granted permissions
// https://github.com/appium/appium/pull/11640#issuecomment-438260477
const perms = ['SET_ANIMATION_SCALE', 'CHANGE_CONFIGURATION', 'ACCESS_FINE_LOCATION'];
logger.info(`Granting permissions ${perms} to '${SETTINGS_HELPER_PKG_ID}'`);
await adb.grantPermissions(
SETTINGS_HELPER_PKG_ID,
perms.map((x) => `android.permission.${x}`)
);
}

// Some commands by adb such as 'adb shell cmd notification'
// could launch the app process but it was not started via activity.
KazuCocoa marked this conversation as resolved.
Show resolved Hide resolved
// It could cause wrong io.appium.settings process launches,
// thus it is safe to start the app process forcefully every session start
// to ensure the settings app process starts.

// launch io.appium.settings app due to settings failing to be set
// if the app is not launched prior to start the session on android 7+
// see https://github.com/appium/appium/issues/8957
try {
await adb.requireRunningSettingsApp({
timeout: AndroidHelpers.isEmulator(adb, opts) ? 30000 : 5000,
forceStartSettingsApp: true,

Check failure on line 861 in lib/helpers/android.ts

View workflow job for this annotation

GitHub Actions / test (20)

Argument of type '{ timeout: number; forceStartSettingsApp: boolean; }' is not assignable to parameter of type 'SettingsAppStartupOptions'.

Check failure on line 861 in lib/helpers/android.ts

View workflow job for this annotation

GitHub Actions / test (18)

Argument of type '{ timeout: number; forceStartSettingsApp: boolean; }' is not assignable to parameter of type 'SettingsAppStartupOptions'.

Check failure on line 861 in lib/helpers/android.ts

View workflow job for this annotation

GitHub Actions / test (16)

Argument of type '{ timeout: number; forceStartSettingsApp: boolean; }' is not assignable to parameter of type 'SettingsAppStartupOptions'.

Check failure on line 861 in lib/helpers/android.ts

View workflow job for this annotation

GitHub Actions / test (20)

Argument of type '{ timeout: number; forceStartSettingsApp: boolean; }' is not assignable to parameter of type 'SettingsAppStartupOptions'.

Check failure on line 861 in lib/helpers/android.ts

View workflow job for this annotation

GitHub Actions / test (18)

Argument of type '{ timeout: number; forceStartSettingsApp: boolean; }' is not assignable to parameter of type 'SettingsAppStartupOptions'.

Check failure on line 861 in lib/helpers/android.ts

View workflow job for this annotation

GitHub Actions / test (16)

Argument of type '{ timeout: number; forceStartSettingsApp: boolean; }' is not assignable to parameter of type 'SettingsAppStartupOptions'.
});
} catch (err) {
logger.debug(err);
Expand Down
Loading