Skip to content

Commit

Permalink
Update android.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
KazuCocoa authored Jan 8, 2024
1 parent 8596281 commit cb9948b
Showing 1 changed file with 30 additions and 36 deletions.
66 changes: 30 additions & 36 deletions lib/helpers/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -809,56 +809,50 @@ const AndroidHelpers: AndroidHelpers = {

// Reinstall would stop the settings helper process anyway, so
// there is no need to continue if the application is still running
if (await adb.processExists(SETTINGS_HELPER_PKG_ID)) {
if (await adb.hasRunningSettingsAppForegroundService()) {

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

View workflow job for this annotation

GitHub Actions / test (20)

Property 'hasRunningSettingsAppForegroundService' does not exist on type 'ADB'.

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

View workflow job for this annotation

GitHub Actions / test (18)

Property 'hasRunningSettingsAppForegroundService' does not exist on type 'ADB'.

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

View workflow job for this annotation

GitHub Actions / test (16)

Property 'hasRunningSettingsAppForegroundService' does not exist on type 'ADB'.

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

View workflow job for this annotation

GitHub Actions / test (20)

Property 'hasRunningSettingsAppForegroundService' does not exist on type 'ADB'.

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

View workflow job for this annotation

GitHub Actions / test (18)

Property 'hasRunningSettingsAppForegroundService' does not exist on type 'ADB'.

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

View workflow job for this annotation

GitHub Actions / test (16)

Property 'hasRunningSettingsAppForegroundService' does not exist on type 'ADB'.
logger.debug(
`${SETTINGS_HELPER_PKG_ID} is already running. ` +
`There is no need to reset its permissions.`
);
} 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);
}
return;
}

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);
}
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}`)
);
try {
await adb.shell([
'cmd',
'notification',
'allow_listener',
SETTING_NOTIFICATIONS_LISTENER_SERVICE,
]);
} catch (err) {
logger.debug((err as Error).message);
}
}

// Some commands by adb such as 'adb shell cmd notification'
// could launch the app process but it was not started via activity.
// 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.
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}`)
);
}

// 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,
});
} catch (err) {
logger.debug(err);
Expand Down

0 comments on commit cb9948b

Please sign in to comment.